Search in sources :

Example 96 with XSDParticle

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

the class UtilTest method testGetChildElements.

@Test
public void testGetChildElements() throws Exception {
    EList<XSDElementDeclaration> xsdElementDeclarations = schema.getElementDeclarations();
    XSDElementDeclaration conceptEl = null;
    for (XSDElementDeclaration el : xsdElementDeclarations) {
        if (el.getName().equals("Entity")) {
            // $NON-NLS-1$
            conceptEl = el;
            break;
        }
    }
    // $NON-NLS-1$
    Map<String, XSDParticle> childElements = Util.getChildElements("", conceptEl, false, new HashSet<Object>());
    assertNotNull(childElements);
    assertEquals(7, childElements.size());
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDParticle(org.eclipse.xsd.XSDParticle) Test(org.junit.Test)

Example 97 with XSDParticle

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

the class UtilTest method testGetforeignKeyOfElement.

@Test
public void testGetforeignKeyOfElement() {
    // $NON-NLS-1$
    String attKey = "source";
    // $NON-NLS-1$
    String attValue = "X_ForeignKey";
    // $NON-NLS-1$
    String namespaceURI = "http://www.w3.org/XML/1998/namespace";
    // $NON-NLS-1$
    String qualifiedName = "appinfo";
    Set<String> list = new HashSet<String>();
    try {
        Util.getforeignKeyOfElement(list, null);
        assertTrue(list.isEmpty());
        // 
        Document doc = getEmptyDocument();
        Element appinfoElement1 = doc.createElementNS(namespaceURI, qualifiedName);
        appinfoElement1.setAttribute(attKey, attValue);
        // $NON-NLS-1$
        appinfoElement1.appendChild(doc.createTextNode("StoreA/Id"));
        // $NON-NLS-1$
        Element appinfoElement2 = doc.createElementNS(namespaceURI, "appinfosssss");
        appinfoElement2.setAttribute(attKey, attValue);
        // $NON-NLS-1$
        appinfoElement2.appendChild(doc.createTextNode("StoreB/Id"));
        XSDAnnotation xsdAnnotation = XSDFactory.eINSTANCE.createXSDAnnotation();
        EList<Element> applicationInformations = xsdAnnotation.getApplicationInformation();
        applicationInformations.add(appinfoElement1);
        applicationInformations.add(appinfoElement2);
        // prepare a
        XSDAnnotation xsdAnnotation_a = XSDFactory.eINSTANCE.createXSDAnnotation();
        Element appElement_a = doc.createElementNS(namespaceURI, qualifiedName);
        // $NON-NLS-1$
        appElement_a.setAttribute(attKey, attValue);
        // $NON-NLS-1$
        appElement_a.appendChild(doc.createTextNode("StoreC/Id"));
        xsdAnnotation_a.getApplicationInformation().add(appElement_a);
        XSDElementDeclaration xsdElementDeclaration_a = XSDFactory.eINSTANCE.createXSDElementDeclaration();
        xsdElementDeclaration_a.setAnnotation(xsdAnnotation_a);
        XSDParticle xsdParticle_a = XSDFactory.eINSTANCE.createXSDParticle();
        xsdParticle_a.setTerm(xsdElementDeclaration_a);
        // prepare b
        XSDAnnotation xsdAnnotation_b = XSDFactory.eINSTANCE.createXSDAnnotation();
        Element appElement_b = doc.createElementNS(namespaceURI, qualifiedName);
        // $NON-NLS-1$
        appElement_b.setAttribute(attKey, attValue);
        // $NON-NLS-1$
        appElement_b.appendChild(doc.createTextNode("StoreD/Id"));
        xsdAnnotation_b.getApplicationInformation().add(appElement_b);
        XSDElementDeclaration xsdElementDeclaration_b = XSDFactory.eINSTANCE.createXSDElementDeclaration();
        xsdElementDeclaration_b.setAnnotation(xsdAnnotation_b);
        XSDParticle xsdParticle_b = XSDFactory.eINSTANCE.createXSDParticle();
        xsdParticle_b.setTerm(xsdElementDeclaration_b);
        // prepare c
        XSDAnnotation xsdAnnotation_c = XSDFactory.eINSTANCE.createXSDAnnotation();
        Element appElement_c = doc.createElementNS(namespaceURI, qualifiedName);
        // $NON-NLS-1$
        appElement_c.setAttribute(attKey, attValue);
        // $NON-NLS-1$
        appElement_c.appendChild(doc.createTextNode("StoreE/Id"));
        xsdAnnotation_c.getApplicationInformation().add(appElement_c);
        XSDElementDeclaration xsdElementDeclaration_c = XSDFactory.eINSTANCE.createXSDElementDeclaration();
        xsdElementDeclaration_c.setAnnotation(xsdAnnotation_c);
        XSDComplexTypeDefinition xsdComplexTypeDefinition_c = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
        xsdElementDeclaration_c.setTypeDefinition(xsdComplexTypeDefinition_c);
        XSDParticle xsdParticle_c_1 = XSDFactory.eINSTANCE.createXSDParticle();
        xsdComplexTypeDefinition_c.setContent(xsdParticle_c_1);
        XSDModelGroup xsdModelGroup_c_1 = XSDFactory.eINSTANCE.createXSDModelGroup();
        xsdParticle_c_1.setTerm(xsdModelGroup_c_1);
        XSDParticle xsdParticle_c_2 = XSDFactory.eINSTANCE.createXSDParticle();
        xsdModelGroup_c_1.getContents().add(xsdParticle_c_2);
        XSDElementDeclaration xsdElementDeclaration_c_2 = XSDFactory.eINSTANCE.createXSDElementDeclaration();
        xsdParticle_c_2.setTerm(xsdElementDeclaration_c_2);
        XSDAnnotation xsdAnnotation_c_2 = XSDFactory.eINSTANCE.createXSDAnnotation();
        Element appElement_c_2 = doc.createElementNS(namespaceURI, qualifiedName);
        // $NON-NLS-1$
        appElement_c_2.setAttribute(attKey, attValue);
        // $NON-NLS-1$
        appElement_c_2.appendChild(doc.createTextNode("StoreF/Id"));
        xsdAnnotation_c_2.getApplicationInformation().add(appElement_c_2);
        xsdElementDeclaration_c_2.setAnnotation(xsdAnnotation_c_2);
        XSDParticle xsdParticle_c = XSDFactory.eINSTANCE.createXSDParticle();
        xsdParticle_c.setTerm(xsdElementDeclaration_c);
        XSDModelGroup xsdModelGroup_a = XSDFactory.eINSTANCE.createXSDModelGroup();
        xsdModelGroup_a.getContents().add(xsdParticle_a);
        // referecened
        xsdModelGroup_a.getContents().add(xsdParticle_b);
        xsdModelGroup_a.getContents().add(xsdParticle_c);
        XSDParticle xsdParticle_child = XSDFactory.eINSTANCE.createXSDParticle();
        xsdParticle_child.setTerm(xsdModelGroup_a);
        XSDComplexTypeDefinition xsdComplexTypeDefinition = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
        xsdComplexTypeDefinition.setContent(xsdParticle_child);
        XSDElementDeclaration xsdElementDeclaration = xsdElementDeclaration_b;
        xsdElementDeclaration.setAnnotation(xsdAnnotation);
        xsdElementDeclaration.setTypeDefinition(xsdComplexTypeDefinition);
        // run and check
        Util.getforeignKeyOfElement(list, xsdElementDeclaration);
        assertTrue(list.size() == 4);
        // $NON-NLS-1$
        assertTrue(list.contains("StoreA"));
        // $NON-NLS-1$
        assertTrue(list.contains("StoreC"));
        // $NON-NLS-1$
        assertTrue(list.contains("StoreE"));
        // $NON-NLS-1$
        assertTrue(list.contains("StoreF"));
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) Element(org.w3c.dom.Element) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Document(org.w3c.dom.Document) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 98 with XSDParticle

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

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

the class UtilTest method testFindElementsUsingType.

@Test
public void testFindElementsUsingType() {
    // $NON-NLS-1$
    String typenameA = "ComplexTypeA";
    // $NON-NLS-1$
    String typenameB = "ComplexTypeB";
    XSDParticle xsdParticle0 = XSDFactory.eINSTANCE.createXSDParticle();
    // 
    XSDSimpleTypeDefinition xsdSimpleTypeDefinition = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
    List<Object> objList = new ArrayList<Object>();
    objList.add(xsdSimpleTypeDefinition);
    boolean findElements = Util.findElementsUsingType(objList, xsdSimpleTypeDefinition);
    assertFalse(findElements);
    // 
    objList.clear();
    XSDComplexTypeDefinition xsdComplexTypeDefinition1 = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
    objList.add(xsdComplexTypeDefinition1);
    findElements = Util.findElementsUsingType(objList, xsdComplexTypeDefinition1);
    assertFalse(findElements);
    // 
    objList.clear();
    xsdComplexTypeDefinition1.setName(typenameA);
    XSDComplexTypeDefinition xsdComplexTypeDefinition2 = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
    xsdComplexTypeDefinition2.setName(typenameA);
    objList.add(xsdComplexTypeDefinition2);
    findElements = Util.findElementsUsingType(objList, xsdComplexTypeDefinition1);
    assertTrue(findElements);
    // 
    objList.clear();
    XSDElementDeclaration xsdElementDeclaration = XSDFactory.eINSTANCE.createXSDElementDeclaration();
    xsdElementDeclaration.setTypeDefinition(xsdComplexTypeDefinition2);
    objList.add(xsdElementDeclaration);
    findElements = Util.findElementsUsingType(objList, xsdComplexTypeDefinition1);
    assertTrue(findElements);
    objList.clear();
    xsdParticle0.setContent(xsdElementDeclaration);
    objList.add(xsdParticle0);
    findElements = Util.findElementsUsingType(objList, xsdComplexTypeDefinition1);
    assertTrue(findElements);
    // 
    objList.clear();
    XSDComplexTypeDefinition xsdComplexTypeDefinition_child = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
    xsdComplexTypeDefinition_child.setName(typenameA);
    XSDElementDeclaration xsdElementDeclaration_child = XSDFactory.eINSTANCE.createXSDElementDeclaration();
    xsdElementDeclaration_child.setTypeDefinition(xsdComplexTypeDefinition_child);
    XSDParticle xsdParticle_child = XSDFactory.eINSTANCE.createXSDParticle();
    xsdParticle_child.setContent(xsdElementDeclaration_child);
    EList<XSDParticle> elist = new BasicEList<XSDParticle>();
    elist.add(xsdParticle_child);
    XSDModelGroup xsdModelGroup = XSDFactory.eINSTANCE.createXSDModelGroup();
    xsdModelGroup.getContents().addAll(elist);
    XSDParticle xsdParticle = XSDFactory.eINSTANCE.createXSDParticle();
    xsdParticle.setTerm(xsdModelGroup);
    xsdComplexTypeDefinition2.setName(typenameB);
    xsdComplexTypeDefinition2.setContent(xsdParticle);
    objList.add(xsdElementDeclaration);
    findElements = Util.findElementsUsingType(objList, xsdComplexTypeDefinition1);
    assertTrue(findElements);
    objList.clear();
    xsdParticle0.setContent(xsdElementDeclaration);
    objList.add(xsdParticle0);
    findElements = Util.findElementsUsingType(objList, xsdComplexTypeDefinition1);
    assertTrue(findElements);
    // 
    objList.clear();
    objList.add(xsdComplexTypeDefinition2);
    findElements = Util.findElementsUsingType(objList, xsdComplexTypeDefinition1);
    assertTrue(findElements);
    // 
    XSDSimpleTypeDefinition xsdSimpleTypeDefinition_child = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
    xsdSimpleTypeDefinition_child.setName(typenameA);
    xsdElementDeclaration_child.setTypeDefinition(xsdSimpleTypeDefinition_child);
    findElements = Util.findElementsUsingType(objList, xsdComplexTypeDefinition1);
    assertFalse(findElements);
    // 
    objList.clear();
    XSDSimpleTypeDefinition xsdSimpleBaseTypeDef = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
    xsdSimpleBaseTypeDef.setName(typenameA);
    XSDSimpleTypeDefinition xsdSimpleTypeDef = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
    xsdSimpleTypeDef.setBaseTypeDefinition(xsdSimpleBaseTypeDef);
    XSDSimpleTypeDefinition xsdSimpleTypeDef_tosearch = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
    xsdSimpleTypeDef_tosearch.setName(typenameA);
    objList.add(xsdSimpleTypeDef);
    findElements = Util.findElementsUsingType(objList, xsdSimpleTypeDef_tosearch);
    assertTrue(findElements);
    // 
    objList.clear();
    XSDElementDeclaration xsdElementDecl = XSDFactory.eINSTANCE.createXSDElementDeclaration();
    xsdElementDecl.setTypeDefinition(xsdSimpleTypeDef);
    objList.add(xsdElementDecl);
    findElements = Util.findElementsUsingType(objList, xsdSimpleTypeDef_tosearch);
    assertTrue(findElements);
    objList.clear();
    xsdParticle0.setContent(xsdElementDecl);
    objList.add(xsdParticle0);
    findElements = Util.findElementsUsingType(objList, xsdSimpleTypeDef_tosearch);
    assertTrue(findElements);
    // 
    XSDComplexTypeDefinition xsdComplexTypedef_search = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
    xsdComplexTypedef_search.setName(typenameB);
    findElements = Util.findElementsUsingType(objList, xsdComplexTypedef_search);
    assertFalse(findElements);
    // 
    objList.clear();
    objList.add(xsdSimpleTypeDef);
    findElements = Util.findElementsUsingType(objList, xsdComplexTypedef_search);
    assertFalse(findElements);
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) BasicEList(org.eclipse.emf.common.util.BasicEList) ArrayList(java.util.ArrayList) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) Test(org.junit.Test)

Example 100 with XSDParticle

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

the class XSDUtilTest method testGetAnnotationValue.

@Test
public void testGetAnnotationValue() throws Exception {
    // $NON-NLS-1$
    String fileName = "Product_0.1.xsd";
    // $NON-NLS-1$
    String elementName = "Family";
    // $NON-NLS-1$
    String fk = "Store/Id";
    String xsdString = TestUtil.readTestResource(XSDUtilTest.this.getClass(), fileName);
    assertNotNull(xsdString);
    XSDSchema xsdSchema = Util.getXSDSchema(xsdString);
    for (XSDElementDeclaration element : xsdSchema.getElementDeclarations()) {
        XSDTypeDefinition typeDefinition = element.getTypeDefinition();
        if (typeDefinition instanceof XSDComplexTypeDefinition) {
            XSDComplexTypeContent xsdComplexTypeContent = ((XSDComplexTypeDefinition) typeDefinition).getContent();
            if (xsdComplexTypeContent instanceof XSDParticle) {
                XSDParticleContent content = ((XSDParticle) xsdComplexTypeContent).getContent();
                if (content instanceof XSDModelGroup) {
                    for (XSDParticle particle : ((XSDModelGroup) content).getParticles()) {
                        XSDTerm term = particle.getTerm();
                        if (term instanceof XSDElementDeclaration) {
                            XSDElementDeclaration elementDeclaration = (XSDElementDeclaration) term;
                            if (elementDeclaration.getName().equals(elementName)) {
                                String value = XSDUtil.getAnnotationValue(elementDeclaration, X_FOREIGN_KEY);
                                assertEquals(fk, value);
                                return;
                            }
                        }
                    }
                }
            }
        }
    }
    fail();
}
Also used : XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDParticleContent(org.eclipse.xsd.XSDParticleContent) XSDTerm(org.eclipse.xsd.XSDTerm) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) Test(org.junit.Test)

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