Search in sources :

Example 41 with XSDModelGroup

use of org.eclipse.xsd.XSDModelGroup in project tmdm-studio-se by Talend.

the class UtilMockTest method buildXSDParticleWithChildren.

private XSDParticle buildXSDParticleWithChildren(int childrenNumb, String[] childrenNames) {
    XSDParticle xsdParticle = XSDFactory.eINSTANCE.createXSDParticle();
    XSDModelGroup xsdModelGroup = XSDFactory.eINSTANCE.createXSDModelGroup();
    xsdParticle.setTerm(xsdModelGroup);
    for (int i = 0; i < childrenNumb && i < childrenNames.length; i++) {
        XSDParticle xsdParticle_child = XSDFactory.eINSTANCE.createXSDParticle();
        XSDElementDeclaration xsdElementDeclaration_child = XSDFactory.eINSTANCE.createXSDElementDeclaration();
        xsdElementDeclaration_child.setName(childrenNames[i]);
        xsdParticle_child.setTerm(xsdElementDeclaration_child);
        xsdModelGroup.getContents().add(xsdParticle_child);
    }
    return xsdParticle;
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 42 with XSDModelGroup

use of org.eclipse.xsd.XSDModelGroup in project tmdm-studio-se by Talend.

the class UtilMockTest method testUpdateReferenceToXSDTypeDefinition.

@Test
public void testUpdateReferenceToXSDTypeDefinition() {
    // $NON-NLS-1$
    String method_getall = "getAllObject";
    // $NON-NLS-1$
    String method_updateref = "updateReferenceToXSDTypeDefinition";
    PowerMockito.mockStatic(Util.class);
    try {
        PowerMockito.when(Util.class, method_updateref, any(), any(XSDTypeDefinition.class), any(IStructuredContentProvider.class)).thenCallRealMethod();
        Object[] allNodes = {};
        XSDFactory factory = XSDFactory.eINSTANCE;
        XSDTypeDefinition[] newTypes = { factory.createXSDComplexTypeDefinition(), factory.createXSDSimpleTypeDefinition() };
        for (XSDTypeDefinition newType : newTypes) {
            // 
            // 
            XSDElementDeclaration mockElementDecl = mock(XSDElementDeclaration.class);
            when(mockElementDecl.getTypeDefinition()).thenReturn(newType);
            // 
            // 
            XSDParticle xsdParticle1 = mock(XSDParticle.class);
            XSDElementDeclaration mockElementDec2 = mock(XSDElementDeclaration.class);
            when(mockElementDec2.getTypeDefinition()).thenReturn(newType);
            when(xsdParticle1.getTerm()).thenReturn(mockElementDec2);
            // 
            // 
            XSDParticle xsdParticle2 = mock(XSDParticle.class);
            XSDParticle particle_c1 = mock(XSDParticle.class);
            XSDElementDeclaration mockElementDec_c1 = mock(XSDElementDeclaration.class);
            when(mockElementDec_c1.getTypeDefinition()).thenReturn(newType);
            when(particle_c1.getContent()).thenReturn(mockElementDec_c1);
            XSDParticle particle_c2 = mock(XSDParticle.class);
            XSDElementDeclaration mockElementDec_c2 = mock(XSDElementDeclaration.class);
            when(mockElementDec_c2.getTypeDefinition()).thenReturn(newType);
            when(particle_c2.getContent()).thenReturn(mockElementDec_c2);
            XSDParticle particle_c3 = mock(XSDParticle.class);
            XSDElementDeclaration mockElementDec_c3 = mock(XSDElementDeclaration.class);
            when(mockElementDec_c3.getTypeDefinition()).thenReturn(factory.createXSDComplexTypeDefinition());
            when(particle_c3.getContent()).thenReturn(mockElementDec_c3);
            XSDModelGroup xsdModelGroup = mock(XSDModelGroup.class);
            EList<XSDParticle> elist = new BasicEList<XSDParticle>();
            elist.add(particle_c1);
            elist.add(particle_c2);
            elist.add(particle_c3);
            when(xsdModelGroup.getContents()).thenReturn(elist);
            when(xsdParticle2.getTerm()).thenReturn(xsdModelGroup);
            allNodes = new Object[] { mockElementDecl, xsdParticle1, xsdParticle2 };
            // 
            PowerMockito.when(Util.class, method_getall, any(), anyList(), any(IStructuredContentProvider.class)).thenReturn(allNodes);
            Util.updateReferenceToXSDTypeDefinition(new Object(), newType, mock(IStructuredContentProvider.class));
            Mockito.verify(mockElementDecl).setTypeDefinition(newType);
            Mockito.verify(mockElementDec2).setTypeDefinition(newType);
            Mockito.verify(mockElementDec_c1).setTypeDefinition(newType);
            Mockito.verify(mockElementDec_c2).setTypeDefinition(newType);
            if (newType instanceof XSDComplexTypeDefinition) {
                PowerMockito.verifyStatic();
                Util.updateChildrenReferenceToComplexType((XSDComplexTypeDefinition) newType);
            }
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) BasicEList(org.eclipse.emf.common.util.BasicEList) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 43 with XSDModelGroup

use of org.eclipse.xsd.XSDModelGroup in project tmdm-studio-se by Talend.

the class UtilMockTest method testFindOutAllSonElements.

@Test
public void testFindOutAllSonElements() {
    XSDFactory factory = XSDFactory.eINSTANCE;
    Set<XSDConcreteComponent> complexTypes = new HashSet<XSDConcreteComponent>();
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    String[] targetNameSpaces = { "http://www.w3.org/2001/XMLSchema", "", "" };
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    String[] names = { "p1", "p2", "p3" };
    XSDTypeDefinition[] types = { factory.createXSDSimpleTypeDefinition(), factory.createXSDSimpleTypeDefinition(), factory.createXSDSimpleTypeDefinition() };
    XSDElementDeclaration xsdElementDeclaration = factory.createXSDElementDeclaration();
    xsdElementDeclaration.setName(names[0]);
    xsdElementDeclaration.setTargetNamespace(targetNameSpaces[0]);
    XSDComplexTypeDefinition xsdComplexTypeDef = factory.createXSDComplexTypeDefinition();
    xsdElementDeclaration.setAnonymousTypeDefinition(xsdComplexTypeDef);
    XSDParticle typeParticle = factory.createXSDParticle();
    xsdComplexTypeDef.setContent(typeParticle);
    XSDModelGroup xsdModelGroup = factory.createXSDModelGroup();
    for (int i = 0; i < names.length; i++) {
        XSDElementDeclaration xsdEleDec = factory.createXSDElementDeclaration();
        xsdEleDec.setName(names[i]);
        xsdEleDec.setTargetNamespace(targetNameSpaces[i]);
        if (i == 0) {
            xsdEleDec.setTypeDefinition(xsdComplexTypeDef);
        } else {
            xsdEleDec.setTypeDefinition(types[i]);
        }
        XSDParticle xsdParticle = factory.createXSDParticle();
        xsdParticle.setContent(xsdEleDec);
        xsdModelGroup.getContents().add(xsdParticle);
    }
    typeParticle.setContent(xsdModelGroup);
    PowerMockito.mockStatic(Util.class);
    try {
        // $NON-NLS-1$
        String methodToExecute = "findOutAllSonElements";
        PowerMockito.when(Util.class, methodToExecute, any(XSDElementDeclaration.class), anySet()).thenCallRealMethod();
        List<XSDElementDeclaration> allson = Whitebox.invokeMethod(Util.class, methodToExecute, xsdElementDeclaration, complexTypes);
        assertNotNull(allson);
        assertTrue(allson.size() == 2);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 44 with XSDModelGroup

use of org.eclipse.xsd.XSDModelGroup in project webtools.sourceediting by eclipse.

the class MoveXSDElementAction method run.

/*
   * @see IAction#run()
   */
public void run() {
    int originalIndex = 0;
    for (Iterator particles = parentModelGroup.getContents().iterator(); particles.hasNext(); ) {
        XSDParticle particle = (XSDParticle) particles.next();
        XSDParticleContent particleContent = particle.getContent();
        if (particleContent == selected) {
            parentModelGroup.getContents().remove(particle);
            break;
        }
        originalIndex++;
    }
    int index = 0;
    boolean addedBack = false;
    if (insertType == INSERT_DIRECT) {
        XSDConcreteComponent container = selected.getContainer();
        if (container != null) {
            XSDConcreteComponent container2 = container.getContainer();
            if (container2 instanceof XSDModelGroup) {
                ((XSDModelGroup) container2).getContents().remove(container);
            }
            if (insertAtEnd)
                parentModelGroup.getContents().add(container);
            else
                parentModelGroup.getContents().add(0, container);
            addedBack = true;
        }
        return;
    }
    List particles = parentModelGroup.getContents();
    for (Iterator iterator = particles.iterator(); iterator.hasNext(); ) {
        XSDParticle particle = (XSDParticle) iterator.next();
        XSDParticleContent particleContent = particle.getContent();
        if (insertType == INSERT_BEFORE) {
            if (particleContent == nextRefComponent) {
                parentModelGroup.getContents().add(index, selected.getContainer());
                addedBack = true;
                break;
            }
            if (selected == nextRefComponent && originalIndex == index) {
                parentModelGroup.getContents().add(index, selected.getContainer());
                addedBack = true;
                break;
            }
        } else if (insertType == INSERT_AFTER) {
            if (particleContent == previousRefComponent) {
                parentModelGroup.getContents().add(index + 1, selected.getContainer());
                addedBack = true;
                break;
            }
            if (selected == previousRefComponent && originalIndex == index) {
                parentModelGroup.getContents().add(index, selected.getContainer());
                addedBack = true;
                break;
            }
        }
        index++;
    }
    if (particles.size() == 0) {
        parentModelGroup.getContents().add(selected.getContainer());
        addedBack = true;
    }
    if (!addedBack) {
        parentModelGroup.getContents().add(originalIndex, selected.getContainer());
    }
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) Iterator(java.util.Iterator) XSDParticleContent(org.eclipse.xsd.XSDParticleContent) List(java.util.List) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 45 with XSDModelGroup

use of org.eclipse.xsd.XSDModelGroup in project webtools.sourceediting by eclipse.

the class AddXSDModelGroupAction method run.

public void run() {
    Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
    if (selection instanceof XSDBaseAdapter) {
        XSDConcreteComponent xsdComponent = (XSDConcreteComponent) ((XSDBaseAdapter) selection).getTarget();
        AddXSDModelGroupCommand command = null;
        if (xsdComponent instanceof XSDElementDeclaration) {
            XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration) xsdComponent;
            command = new AddXSDModelGroupCommand(getLabel(xsdCompositor), xsdElementDeclaration, xsdCompositor);
            getCommandStack().execute(command);
        } else if (xsdComponent instanceof XSDModelGroup) {
            XSDModelGroup xsdModelGroup = (XSDModelGroup) xsdComponent;
            command = new AddXSDModelGroupCommand(getLabel(xsdCompositor), xsdModelGroup, xsdCompositor);
            getCommandStack().execute(command);
        } else if (xsdComponent instanceof XSDComplexTypeDefinition || xsdComponent instanceof XSDModelGroupDefinition) {
            command = new AddXSDModelGroupCommand(getLabel(xsdCompositor), xsdComponent, xsdCompositor);
            getCommandStack().execute(command);
        }
        if (command != null) {
            Adapter adapter = XSDAdapterFactory.getInstance().adapt(command.getAddedComponent());
            if (adapter != null)
                provider.setSelection(new StructuredSelection(adapter));
        }
    }
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) AddXSDModelGroupCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDModelGroupCommand) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) Adapter(org.eclipse.emf.common.notify.Adapter) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition)

Aggregations

XSDModelGroup (org.eclipse.xsd.XSDModelGroup)119 XSDParticle (org.eclipse.xsd.XSDParticle)93 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)87 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)76 ArrayList (java.util.ArrayList)33 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)32 XSDTerm (org.eclipse.xsd.XSDTerm)28 XSDFactory (org.eclipse.xsd.XSDFactory)26 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)26 Test (org.junit.Test)25 XSDSchema (org.eclipse.xsd.XSDSchema)23 XSDComplexTypeContent (org.eclipse.xsd.XSDComplexTypeContent)22 EList (org.eclipse.emf.common.util.EList)21 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)20 XSDModelGroupDefinition (org.eclipse.xsd.XSDModelGroupDefinition)19 List (java.util.List)18 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)18 Iterator (java.util.Iterator)16 XSDWildcard (org.eclipse.xsd.XSDWildcard)16 TreeObject (com.amalto.workbench.models.TreeObject)15