Search in sources :

Example 31 with XSDFactory

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

the class XSDCommonUIUtils method getInputXSDAnnotation.

public static XSDAnnotation getInputXSDAnnotation(XSDConcreteComponent input, boolean createIfNotExist) {
    XSDAnnotation xsdAnnotation = null;
    XSDFactory factory = XSDFactory.eINSTANCE;
    if (input instanceof XSDAttributeDeclaration) {
        XSDAttributeDeclaration xsdComp = (XSDAttributeDeclaration) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDAttributeGroupDefinition) {
        XSDAttributeGroupDefinition xsdComp = (XSDAttributeGroupDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDElementDeclaration) {
        XSDElementDeclaration xsdComp = (XSDElementDeclaration) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDNotationDeclaration) {
        XSDNotationDeclaration xsdComp = (XSDNotationDeclaration) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDXPathDefinition) {
        XSDXPathDefinition xsdComp = (XSDXPathDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDModelGroup) {
        XSDModelGroup xsdComp = (XSDModelGroup) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDModelGroupDefinition) {
        XSDModelGroupDefinition xsdComp = (XSDModelGroupDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDIdentityConstraintDefinition) {
        XSDIdentityConstraintDefinition xsdComp = (XSDIdentityConstraintDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDWildcard) {
        XSDWildcard xsdComp = (XSDWildcard) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDSchema) {
        XSDSchema xsdComp = (XSDSchema) input;
        List list = xsdComp.getAnnotations();
        if (list.size() > 0) {
            xsdAnnotation = (XSDAnnotation) list.get(0);
        } else {
            if (createIfNotExist && xsdAnnotation == null) {
                xsdAnnotation = factory.createXSDAnnotation();
                if (xsdComp.getContents() != null) {
                    xsdComp.getContents().add(0, xsdAnnotation);
                }
            }
        }
        return xsdAnnotation;
    } else if (input instanceof XSDFacet) {
        XSDFacet xsdComp = (XSDFacet) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDTypeDefinition) {
        XSDTypeDefinition xsdComp = (XSDTypeDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDInclude) {
        XSDInclude xsdComp = (XSDInclude) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDImport) {
        XSDImport xsdComp = (XSDImport) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDRedefine) {
        XSDRedefine xsdComp = (XSDRedefine) input;
        List contents = xsdComp.getContents();
        for (int i = 0; i < contents.size(); i++) {
            Object content = contents.get(i);
            if (content instanceof XSDAnnotation) {
                xsdAnnotation = (XSDAnnotation) content;
                break;
            }
        }
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            contents.add(0, xsdAnnotation);
        }
        return xsdAnnotation;
    } else if (input instanceof XSDAnnotation) {
        xsdAnnotation = (XSDAnnotation) input;
    }
    if (createIfNotExist) {
        formatAnnotation(xsdAnnotation);
    }
    return xsdAnnotation;
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDRedefine(org.eclipse.xsd.XSDRedefine) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDNotationDeclaration(org.eclipse.xsd.XSDNotationDeclaration) XSDFacet(org.eclipse.xsd.XSDFacet) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) EObject(org.eclipse.emf.ecore.EObject) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDImport(org.eclipse.xsd.XSDImport) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDSchema(org.eclipse.xsd.XSDSchema) XSDInclude(org.eclipse.xsd.XSDInclude)

Example 32 with XSDFactory

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

the class UtilTest method testGetComponentName.

@Test
public void testGetComponentName() {
    // $NON-NLS-1$ //$NON-NLS-2$
    String prefix = "name=\"", suffix = "\"";
    String[] objNames = { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    "product_elementdeclaration", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    "product_particle", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    "p_complextype", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    "p_simpletype", "product_identityconstraintdef", // $NON-NLS-1$ //$NON-NLS-2$
    "p_xpathdef" };
    String[] expectedObjNames = new String[objNames.length];
    for (int i = 0; i < objNames.length - 1; i++) {
        expectedObjNames[i] = prefix + objNames[i] + suffix;
    }
    // $NON-NLS-1$
    expectedObjNames[objNames.length - 1] = "xpath=\"" + objNames[objNames.length - 1] + suffix;
    XSDFactory factory = XSDFactory.eINSTANCE;
    try {
        XSDElementDeclaration xsdElementDeclaration = factory.createXSDElementDeclaration();
        xsdElementDeclaration.setName(objNames[0]);
        XSDParticle xsdParticle = factory.createXSDParticle();
        XSDElementDeclaration xsdParticleDeclaration = factory.createXSDElementDeclaration();
        xsdParticleDeclaration.setName(objNames[1]);
        xsdParticle.setTerm(xsdParticleDeclaration);
        XSDComplexTypeDefinition xsdComplexTypeDefinition = factory.createXSDComplexTypeDefinition();
        xsdComplexTypeDefinition.setName(objNames[2]);
        XSDSimpleTypeDefinition xsdSimpleTypeDefinition = factory.createXSDSimpleTypeDefinition();
        xsdSimpleTypeDefinition.setName(objNames[3]);
        XSDIdentityConstraintDefinition xsdIdConsDef = factory.createXSDIdentityConstraintDefinition();
        xsdIdConsDef.setName(objNames[4]);
        XSDXPathDefinition xsdPathDefinition = factory.createXSDXPathDefinition();
        xsdPathDefinition.setValue(objNames[5]);
        String name = Util.getComponentName(xsdElementDeclaration);
        assertEquals(expectedObjNames[0], name);
        name = Util.getComponentName(xsdParticle);
        assertEquals(expectedObjNames[1], name);
        name = Util.getComponentName(xsdComplexTypeDefinition);
        assertEquals(expectedObjNames[2], name);
        name = Util.getComponentName(xsdSimpleTypeDefinition);
        assertEquals(expectedObjNames[3], name);
        name = Util.getComponentName(xsdIdConsDef);
        assertEquals(expectedObjNames[4], name);
        name = Util.getComponentName(xsdPathDefinition);
        assertEquals(expectedObjNames[5], name);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Test(org.junit.Test)

Example 33 with XSDFactory

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

the class UtilTest method testRetrieveXSDComponentPath.

@Test
public void testRetrieveXSDComponentPath() {
    // $NON-NLS-1$
    String conceptName = "Product";
    // $NON-NLS-1$
    String complextypeName = "ctype";
    // $NON-NLS-1$
    String simpletypeName = "stype";
    // $NON-NLS-1$
    String identityName = "identityName";
    // $NON-NLS-1$
    String xsdxpathValue = "Id";
    // $NON-NLS-1$
    String childelementName = "childelementName";
    List<String> xsdComponentPath = null;
    XSDFactory factory = XSDFactory.eINSTANCE;
    XSDSchema xschema = factory.createXSDSchema();
    XSDElementDeclaration concept = factory.createXSDElementDeclaration();
    concept.setName(conceptName);
    xschema.getContents().add(concept);
    XSDComplexTypeDefinition complexTypeDefinition = factory.createXSDComplexTypeDefinition();
    complexTypeDefinition.setBaseTypeDefinition(// $NON-NLS-1$ );
    xschema.resolveComplexTypeDefinition(xschema.getSchemaForSchemaNamespace(), "anyType"));
    xschema.getContents().add(complexTypeDefinition);
    XSDSimpleTypeDefinition simpleTypeDefinition = factory.createXSDSimpleTypeDefinition();
    simpleTypeDefinition.setName(simpletypeName);
    XSDModelGroup modelGroup = factory.createXSDModelGroup();
    modelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
    XSDParticle typeparticle = factory.createXSDParticle();
    complexTypeDefinition.setContent(typeparticle);
    typeparticle.setContent(modelGroup);
    XSDParticle childParticle = factory.createXSDParticle();
    XSDElementDeclaration childelement = factory.createXSDElementDeclaration();
    childelement.setName(childelementName);
    childParticle.setContent(childelement);
    childParticle.setTerm(childelement);
    modelGroup.getContents().add(childParticle);
    XSDIdentityConstraintDefinition IdConsDef = factory.createXSDIdentityConstraintDefinition();
    IdConsDef.setName(identityName);
    concept.getIdentityConstraintDefinitions().add(IdConsDef);
    XSDXPathDefinition xsdXPathDefinition = factory.createXSDXPathDefinition();
    xsdXPathDefinition.setValue(xsdxpathValue);
    IdConsDef.getFields().add(xsdXPathDefinition);
    XSDAnnotation conceptAnnotation = factory.createXSDAnnotation();
    concept.setAnnotation(conceptAnnotation);
    XSDElementDeclaration anotherConcept = factory.createXSDElementDeclaration();
    // $NON-NLS-1$
    String concept2name = "anotherConcept";
    anotherConcept.setName(concept2name);
    xschema.getContents().add(anotherConcept);
    // 
    List<String> buffer = new ArrayList<String>();
    xsdComponentPath = Util.retrieveXSDComponentPath(concept, xschema, buffer);
    assertEquals(1, xsdComponentPath.size());
    // $NON-NLS-1$ //$NON-NLS-2$
    assertEquals("//xsd:element[@name='" + conceptName + "']", xsdComponentPath.get(0));
    // 
    buffer.clear();
    xsdComponentPath = Util.retrieveXSDComponentPath(complexTypeDefinition, xschema, buffer);
    assertEquals(1, xsdComponentPath.size());
    // $NON-NLS-1$
    assertEquals("//xsd:complexType", xsdComponentPath.get(0));
    // 
    buffer.clear();
    complexTypeDefinition.setName(complextypeName);
    xsdComponentPath = Util.retrieveXSDComponentPath(complexTypeDefinition, xschema, buffer);
    assertEquals(1, xsdComponentPath.size());
    // $NON-NLS-1$ //$NON-NLS-2$
    assertEquals("//xsd:complexType[@name='" + complextypeName + "']", xsdComponentPath.get(0));
    // 
    buffer.clear();
    xsdComponentPath = Util.retrieveXSDComponentPath(simpleTypeDefinition, xschema, buffer);
    assertEquals(1, xsdComponentPath.size());
    // $NON-NLS-1$ //$NON-NLS-2$
    assertEquals("//xsd:simpleType[@name='" + simpletypeName + "']", xsdComponentPath.get(0));
    // 
    buffer.clear();
    xsdComponentPath = Util.retrieveXSDComponentPath(modelGroup, xschema, buffer);
    assertEquals(2, xsdComponentPath.size());
    // $NON-NLS-1$
    assertTrue(xsdComponentPath.contains("//xsd:" + XSDCompositor.SEQUENCE_LITERAL.getLiteral()));
    // $NON-NLS-1$ //$NON-NLS-2$
    assertTrue(xsdComponentPath.contains("//xsd:complexType[@name='" + complextypeName + "']"));
    // 
    buffer.clear();
    xsdComponentPath = Util.retrieveXSDComponentPath(IdConsDef, xschema, buffer);
    assertEquals(2, xsdComponentPath.size());
    // $NON-NLS-1$ //$NON-NLS-2$
    assertTrue(xsdComponentPath.contains("//xsd:element[@name='" + conceptName + "']"));
    // $NON-NLS-1$ //$NON-NLS-2$
    assertTrue(xsdComponentPath.contains("//xsd:unique[@name='" + identityName + "']"));
    // 
    buffer.clear();
    xsdComponentPath = Util.retrieveXSDComponentPath(xsdXPathDefinition, xschema, buffer);
    assertEquals(3, xsdComponentPath.size());
    // $NON-NLS-1$ //$NON-NLS-2$
    assertTrue(xsdComponentPath.contains("//xsd:element[@name='" + conceptName + "']"));
    // $NON-NLS-1$ //$NON-NLS-2$
    assertTrue(xsdComponentPath.contains("//xsd:unique[@name='" + identityName + "']"));
    // $NON-NLS-1$ //$NON-NLS-2$
    assertTrue(xsdComponentPath.contains("//xsd:field[@xpath='" + xsdxpathValue + "']"));
    // 
    buffer.clear();
    xsdComponentPath = Util.retrieveXSDComponentPath(conceptAnnotation, xschema, buffer);
    assertEquals(2, xsdComponentPath.size());
    // $NON-NLS-1$ //$NON-NLS-2$
    assertTrue(xsdComponentPath.contains("//xsd:element[@name='" + conceptName + "']"));
    // $NON-NLS-1$
    assertTrue(xsdComponentPath.contains("//xsd:annotation"));
    // 
    buffer.clear();
    xsdComponentPath = Util.retrieveXSDComponentPath(childParticle, xschema, buffer);
    assertEquals(2, xsdComponentPath.size());
    // $NON-NLS-1$
    assertTrue(xsdComponentPath.contains("//xsd:" + XSDCompositor.SEQUENCE_LITERAL.getLiteral()));
    // $NON-NLS-1$ //$NON-NLS-2$
    assertTrue(xsdComponentPath.contains("//xsd:complexType[@name='" + complextypeName + "']"));
    // 
    buffer.clear();
    xsdComponentPath = Util.retrieveXSDComponentPath(childelement, xschema, buffer);
    assertEquals(3, xsdComponentPath.size());
    // $NON-NLS-1$
    assertTrue(xsdComponentPath.contains("//xsd:" + XSDCompositor.SEQUENCE_LITERAL.getLiteral()));
    // $NON-NLS-1$ //$NON-NLS-2$
    assertTrue(xsdComponentPath.contains("//xsd:complexType[@name='" + complextypeName + "']"));
    // $NON-NLS-1$ //$NON-NLS-2$
    assertTrue(xsdComponentPath.contains("//xsd:element[@name='" + childelementName + "']"));
    // 
    buffer.clear();
    childelement.setResolvedElementDeclaration(anotherConcept);
    xsdComponentPath = Util.retrieveXSDComponentPath(childParticle, xschema, buffer);
    assertEquals(3, xsdComponentPath.size());
    // $NON-NLS-1$
    assertTrue(xsdComponentPath.contains("//xsd:" + XSDCompositor.SEQUENCE_LITERAL.getLiteral()));
    // $NON-NLS-1$ //$NON-NLS-2$
    assertTrue(xsdComponentPath.contains("//xsd:complexType[@name='" + complextypeName + "']"));
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    assertTrue(xsdComponentPath.contains("//xsd:element[@name='" + concept2name + "' or @ref='" + concept2name + "']"));
    // 
    buffer.clear();
    // $NON-NLS-1$
    String targetNamespace = "targetnamespace";
    // $NON-NLS-1$
    String key = "prefix";
    anotherConcept.setTargetNamespace(targetNamespace);
    xschema.getQNamePrefixToNamespaceMap().put(key, targetNamespace);
    xsdComponentPath = Util.retrieveXSDComponentPath(childParticle, xschema, buffer);
    assertEquals(3, xsdComponentPath.size());
    // $NON-NLS-1$
    assertTrue(xsdComponentPath.contains("//xsd:" + XSDCompositor.SEQUENCE_LITERAL.getLiteral()));
    // $NON-NLS-1$ //$NON-NLS-2$
    assertTrue(xsdComponentPath.contains("//xsd:complexType[@name='" + complextypeName + "']"));
    assertTrue(xsdComponentPath.contains(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    "//xsd:element[@name='" + concept2name + "' or @ref='" + key + ":" + concept2name + "']"));
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) ArrayList(java.util.ArrayList) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema) Test(org.junit.Test)

Example 34 with XSDFactory

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

the class UtilTest method testFilterOutDuplicatedElems.

@Test
public void testFilterOutDuplicatedElems() {
    // $NON-NLS-1$
    String simpletypeName = "simpletype";
    // $NON-NLS-1$
    String complextypeName = "complextype";
    // $NON-NLS-1$
    String concepName = "concept";
    // $NON-NLS-1$
    String idconstraintName = "identityconstraint";
    // $NON-NLS-1$
    String modelgroupName = "modelgroup";
    XSDFactory factory = XSDFactory.eINSTANCE;
    XSDSimpleTypeDefinition simpleTypeDefinition = factory.createXSDSimpleTypeDefinition();
    XSDComplexTypeDefinition complexTypeDefinition = factory.createXSDComplexTypeDefinition();
    XSDElementDeclaration elementDeclaration = factory.createXSDElementDeclaration();
    XSDIdentityConstraintDefinition identityConstraintDefinition = factory.createXSDIdentityConstraintDefinition();
    XSDModelGroupDefinition modelGroupDefinition = factory.createXSDModelGroupDefinition();
    simpleTypeDefinition.setName(simpletypeName);
    complexTypeDefinition.setName(complextypeName);
    elementDeclaration.setName(concepName);
    identityConstraintDefinition.setName(idconstraintName);
    modelGroupDefinition.setName(modelgroupName);
    XSDNamedComponent[] checkedElements = { simpleTypeDefinition, complexTypeDefinition, elementDeclaration, identityConstraintDefinition, modelGroupDefinition };
    Object[] duplicatedElems = Util.filterOutDuplicatedElems(checkedElements);
    List<XSDNamedComponent> allElements = Arrays.asList(checkedElements);
    assertNotNull(duplicatedElems);
    assertTrue(checkedElements.length == duplicatedElems.length);
    for (int i = 0; i < duplicatedElems.length; i++) {
        assertTrue(allElements.contains(duplicatedElems[i]));
    }
    // 
    XSDSimpleTypeDefinition simpleTypeDefinition2 = factory.createXSDSimpleTypeDefinition();
    XSDComplexTypeDefinition complexTypeDefinition2 = factory.createXSDComplexTypeDefinition();
    XSDElementDeclaration elementDeclaration2 = factory.createXSDElementDeclaration();
    XSDIdentityConstraintDefinition identityConstraintDefinition2 = factory.createXSDIdentityConstraintDefinition();
    XSDModelGroupDefinition modelGroupDefinition2 = factory.createXSDModelGroupDefinition();
    simpleTypeDefinition2.setName(simpletypeName);
    complexTypeDefinition2.setName(complextypeName);
    elementDeclaration2.setName(concepName);
    identityConstraintDefinition2.setName(idconstraintName);
    modelGroupDefinition2.setName(modelgroupName);
    XSDNamedComponent[] checkedElements2 = { simpleTypeDefinition, complexTypeDefinition, elementDeclaration, identityConstraintDefinition, modelGroupDefinition, simpleTypeDefinition2, complexTypeDefinition2, elementDeclaration2, identityConstraintDefinition2, modelGroupDefinition2 };
    duplicatedElems = Util.filterOutDuplicatedElems(checkedElements2);
    assertNotNull(duplicatedElems);
    assertTrue(checkedElements.length == duplicatedElems.length);
    for (int i = 0; i < duplicatedElems.length; i++) {
        assertTrue(allElements.contains(duplicatedElems[i]));
    }
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) Test(org.junit.Test)

Example 35 with XSDFactory

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

the class XSDUtilTest method testIsSimpleTypeElement.

@Test
public void testIsSimpleTypeElement() {
    XSDFactory factory = XSDFactory.eINSTANCE;
    XSDParticle particle = factory.createXSDParticle();
    XSDElementDeclaration xsdElementDeclaration = factory.createXSDElementDeclaration();
    XSDSimpleTypeDefinition xsdSimpleTypeDefinition = factory.createXSDSimpleTypeDefinition();
    xsdElementDeclaration.setTypeDefinition(xsdSimpleTypeDefinition);
    particle.setContent(xsdElementDeclaration);
    boolean isSimpleTypeElement = XSDUtil.isSimpleTypeElement(particle);
    assertTrue(isSimpleTypeElement);
    xsdElementDeclaration.setTypeDefinition(factory.createXSDComplexTypeDefinition());
    isSimpleTypeElement = XSDUtil.isSimpleTypeElement(particle);
    assertFalse(isSimpleTypeElement);
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) Test(org.junit.Test)

Aggregations

XSDFactory (org.eclipse.xsd.XSDFactory)50 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)37 XSDParticle (org.eclipse.xsd.XSDParticle)27 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)26 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)23 Test (org.junit.Test)19 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)15 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)13 ArrayList (java.util.ArrayList)12 XSDSchema (org.eclipse.xsd.XSDSchema)12 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)12 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)12 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)9 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)8 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)6 HashSet (java.util.HashSet)5 Iterator (java.util.Iterator)5 List (java.util.List)5