Search in sources :

Example 51 with XSDParticle

use of org.eclipse.xsd.XSDParticle 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 52 with XSDParticle

use of org.eclipse.xsd.XSDParticle 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 53 with XSDParticle

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

the class AddXSDAnyElementCommand method execute.

public void execute() {
    try {
        if (doCreateModelGroupForComplexType) {
            Assert.isNotNull(complexType);
            beginRecording(complexType.getElement());
            createModelGroup();
        } else {
            beginRecording(parent.getElement());
        }
        XSDWildcard wildCard = XSDFactory.eINSTANCE.createXSDWildcard();
        XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
        particle.setContent(wildCard);
        parent.getContents().add(particle);
        addedXSDConcreteComponent = wildCard;
        formatChild(parent.getElement());
    } finally {
        endRecording();
    }
}
Also used : XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 54 with XSDParticle

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

the class AddXSDElementCommand method createXSDElementReference.

protected XSDParticle createXSDElementReference() {
    List list = xsdModelGroup.getSchema().getElementDeclarations();
    XSDElementDeclaration referencedElement = null;
    if (list.size() > 0) {
        referencedElement = (XSDElementDeclaration) list.get(0);
    } else {
        referencedElement = createGlobalXSDElementDeclaration();
        // $NON-NLS-1$
        Text textNode = xsdSchema.getDocument().createTextNode("\n");
        xsdSchema.getElement().appendChild(textNode);
        xsdSchema.getContents().add(referencedElement);
    }
    XSDElementDeclaration element = XSDFactory.eINSTANCE.createXSDElementDeclaration();
    element.setResolvedElementDeclaration(referencedElement);
    XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
    particle.setContent(element);
    addedXSDConcreteComponent = element;
    return particle;
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) List(java.util.List) Text(org.w3c.dom.Text) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 55 with XSDParticle

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

the class AddXSDElementCommand method createXSDElementDeclaration.

protected XSDParticle createXSDElementDeclaration() {
    // $NON-NLS-1$
    XSDSimpleTypeDefinition type = xsdModelGroup.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("string");
    XSDElementDeclaration element = XSDFactory.eINSTANCE.createXSDElementDeclaration();
    XSDConcreteComponent comp = xsdModelGroup.getContainer();
    ArrayList usedAttributeNames = new ArrayList();
    XSDCommonUIUtils.resetVisitedGroupsStack();
    usedAttributeNames.addAll(XSDCommonUIUtils.getChildElements(xsdModelGroup));
    while (comp != null) {
        if (comp instanceof XSDModelGroupDefinition) {
            usedAttributeNames.addAll(XSDCommonUIUtils.getAllAttributes((XSDModelGroupDefinition) comp));
            break;
        } else if (comp instanceof XSDComplexTypeDefinition) {
            usedAttributeNames.addAll(XSDCommonUIUtils.getAllAttributes((XSDComplexTypeDefinition) comp));
            usedAttributeNames.addAll(XSDCommonUIUtils.getInheritedAttributes((XSDComplexTypeDefinition) comp));
            break;
        }
        comp = comp.getContainer();
    }
    element.setName(XSDCommonUIUtils.createUniqueElementName(nameToAdd == null ? "NewElement" : nameToAdd, // $NON-NLS-1$
    usedAttributeNames));
    element.setTypeDefinition(type);
    XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
    particle.setContent(element);
    addedXSDConcreteComponent = element;
    return particle;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Aggregations

XSDParticle (org.eclipse.xsd.XSDParticle)146 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)103 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)93 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)75 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)36 ArrayList (java.util.ArrayList)34 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)34 XSDTerm (org.eclipse.xsd.XSDTerm)31 XSDFactory (org.eclipse.xsd.XSDFactory)27 XSDComplexTypeContent (org.eclipse.xsd.XSDComplexTypeContent)24 XSDSchema (org.eclipse.xsd.XSDSchema)24 Test (org.junit.Test)23 Iterator (java.util.Iterator)21 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)21 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)19 EList (org.eclipse.emf.common.util.EList)17 XSDParticleContent (org.eclipse.xsd.XSDParticleContent)17 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)16 Element (org.w3c.dom.Element)16 List (java.util.List)15