Search in sources :

Example 76 with XSDModelGroup

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

the class UtilTest method testIsDecimal.

@Test
public void testIsDecimal() {
    XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) schema.getElementDeclarations().get(0).getTypeDefinition();
    XSDModelGroup group = (XSDModelGroup) ((XSDParticle) complexType.getContent()).getTerm();
    XSDElementDeclaration el = (XSDElementDeclaration) group.getParticles().get(0).getTerm();
    boolean ret = Util.isDecimal((XSDSimpleTypeDefinition) el.getTypeDefinition());
    assertEquals(ret, false);
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) Test(org.junit.Test)

Example 77 with XSDModelGroup

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

the class UtilTest method testIsDouble.

@Test
public void testIsDouble() {
    XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) schema.getElementDeclarations().get(0).getTypeDefinition();
    XSDModelGroup group = (XSDModelGroup) ((XSDParticle) complexType.getContent()).getTerm();
    XSDElementDeclaration el = (XSDElementDeclaration) group.getParticles().get(0).getTerm();
    boolean ret = Util.isDouble((XSDSimpleTypeDefinition) el.getTypeDefinition());
    assertEquals(ret, false);
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) Test(org.junit.Test)

Example 78 with XSDModelGroup

use of org.eclipse.xsd.XSDModelGroup 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 79 with XSDModelGroup

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

the class UtilTest method testGetParticleName.

@Test
public void testGetParticleName() {
    XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) schema.getElementDeclarations().get(0).getTypeDefinition();
    XSDModelGroup group = (XSDModelGroup) ((XSDParticle) complexType.getContent()).getTerm();
    String name = Util.getParticleName(group.getParticles().get(0));
    // $NON-NLS-1$
    assertEquals(name, "id");
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) Test(org.junit.Test)

Example 80 with XSDModelGroup

use of org.eclipse.xsd.XSDModelGroup 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)

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