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);
}
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);
}
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 + "']"));
}
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");
}
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);
}
Aggregations