Search in sources :

Example 41 with XSDComplexTypeDefinition

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

the class UtilTest method testIsSpecifiedBuildInType.

@Test
public void testIsSpecifiedBuildInType() {
    XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) schema.getElementDeclarations().get(0).getTypeDefinition();
    XSDModelGroup group = (XSDModelGroup) ((XSDParticle) complexType.getContent()).getTerm();
    XSDElementDeclaration el = (XSDElementDeclaration) group.getParticles().get(0).getTerm();
    // $NON-NLS-1$
    boolean ret = Util.isSpecifiedBuildInType((XSDSimpleTypeDefinition) el.getTypeDefinition(), "string");
    assertEquals(ret, true);
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) Test(org.junit.Test)

Example 42 with XSDComplexTypeDefinition

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

the class UtilTest method testGetTypeDefinition.

@Test
public void testGetTypeDefinition() {
    // $NON-NLS-1$
    String s_name = "simpleType";
    // $NON-NLS-1$
    String c_name = "complexType";
    // $NON-NLS-1$
    String e_name = "xsdElementDeclaration";
    XSDSchema xsdSchema = XSDFactory.eINSTANCE.createXSDSchema();
    XSDSimpleTypeDefinition xsdSimpleTypeDefinition1 = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
    XSDSimpleTypeDefinition xsdSimpleTypeDefinition2 = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
    XSDComplexTypeDefinition xsdComplexTypeDefinition1 = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
    XSDComplexTypeDefinition xsdComplexTypeDefinition2 = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
    xsdSimpleTypeDefinition1.setName(s_name + 1);
    xsdSimpleTypeDefinition2.setName(s_name + 2);
    xsdComplexTypeDefinition1.setName(c_name + 1);
    xsdComplexTypeDefinition2.setName(c_name + 2);
    xsdSimpleTypeDefinition1.setBaseTypeDefinition(// $NON-NLS-1$ anyType
    xsdSchema.resolveSimpleTypeDefinition(xsdSchema.getSchemaForSchemaNamespace(), "string"));
    xsdSimpleTypeDefinition2.setBaseTypeDefinition(// $NON-NLS-1$
    xsdSchema.resolveSimpleTypeDefinition(xsdSchema.getSchemaForSchemaNamespace(), "string"));
    xsdComplexTypeDefinition1.setBaseTypeDefinition(// $NON-NLS-1$
    xsdSchema.resolveComplexTypeDefinition(xsdSchema.getSchemaForSchemaNamespace(), "anyType"));
    xsdComplexTypeDefinition2.setBaseTypeDefinition(// $NON-NLS-1$
    xsdSchema.resolveComplexTypeDefinition(xsdSchema.getSchemaForSchemaNamespace(), "anyType"));
    EList<XSDSchemaContent> contents = xsdSchema.getContents();
    contents.add(xsdSimpleTypeDefinition1);
    contents.add(xsdSimpleTypeDefinition2);
    contents.add(xsdComplexTypeDefinition1);
    contents.add(xsdComplexTypeDefinition2);
    XSDElementDeclaration xsdElementDeclaration = XSDFactory.eINSTANCE.createXSDElementDeclaration();
    xsdElementDeclaration.setName(e_name);
    contents.add(xsdElementDeclaration);
    Map<String, XSDTypeDefinition> typeDefinition = Util.getTypeDefinition(xsdSchema);
    assertNotNull(typeDefinition);
    assertTrue(typeDefinition.size() == 4);
    assertTrue(typeDefinition.keySet().contains(s_name + 1));
    assertTrue(typeDefinition.keySet().contains(s_name + 2));
    assertTrue(typeDefinition.keySet().contains(c_name + 1));
    assertTrue(typeDefinition.keySet().contains(c_name + 2));
    assertTrue(typeDefinition.values().contains(xsdSimpleTypeDefinition1));
    assertTrue(typeDefinition.values().contains(xsdSimpleTypeDefinition2));
    assertTrue(typeDefinition.values().contains(xsdComplexTypeDefinition1));
    assertTrue(typeDefinition.values().contains(xsdComplexTypeDefinition2));
}
Also used : XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSchemaContent(org.eclipse.xsd.XSDSchemaContent) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDSchema(org.eclipse.xsd.XSDSchema) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) Test(org.junit.Test)

Example 43 with XSDComplexTypeDefinition

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

the class UtilTest method testIsAllComplexType.

@Test
public void testIsAllComplexType() {
    XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) schema.getElementDeclarations().get(0).getTypeDefinition();
    boolean ret = Util.isAllComplexType(complexType);
    assertEquals(ret, true);
}
Also used : XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) Test(org.junit.Test)

Example 44 with XSDComplexTypeDefinition

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

the class UtilTest method testIsFloat.

@Test
public void testIsFloat() {
    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.isFloat((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 45 with XSDComplexTypeDefinition

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

the class UtilTest method testGetTopParent.

@Test
public void testGetTopParent() {
    // 
    List<Object> topParent = Util.getTopParent(null);
    assertNull(topParent);
    XSDFactory factory = XSDFactory.eINSTANCE;
    // 
    XSDElementDeclaration concept = factory.createXSDElementDeclaration();
    topParent = Util.getTopParent(concept);
    assertNull(topParent);
    // concept with three children
    // $NON-NLS-1$
    String element1 = "Id";
    // $NON-NLS-1$
    String element2 = "code";
    // $NON-NLS-1$
    String element3 = "address";
    XSDSchema xsdSchema = factory.createXSDSchema();
    xsdSchema.getContents().add(concept);
    XSDComplexTypeDefinition xsdComplexTypeDef = factory.createXSDComplexTypeDefinition();
    xsdComplexTypeDef.setBaseTypeDefinition(// $NON-NLS-1$
    xsdSchema.resolveComplexTypeDefinition(xsdSchema.getSchemaForSchemaNamespace(), "anyType"));
    concept.setAnonymousTypeDefinition(xsdComplexTypeDef);
    XSDParticle xsdParticle = factory.createXSDParticle();
    xsdComplexTypeDef.setContent(xsdParticle);
    XSDModelGroup xsdModelGroup = factory.createXSDModelGroup();
    xsdParticle.setContent(xsdModelGroup);
    XSDParticle childParticle1 = factory.createXSDParticle();
    XSDElementDeclaration childElement1 = factory.createXSDElementDeclaration();
    childElement1.setName(element1);
    childParticle1.setContent(childElement1);
    XSDParticle childParticle2 = factory.createXSDParticle();
    XSDElementDeclaration childElement2 = factory.createXSDElementDeclaration();
    childElement2.setName(element2);
    childParticle2.setContent(childElement2);
    XSDParticle childParticle3 = factory.createXSDParticle();
    XSDElementDeclaration childElement3 = factory.createXSDElementDeclaration();
    childElement3.setName(element3);
    childParticle3.setContent(childElement3);
    xsdModelGroup.getContents().add(childParticle1);
    xsdModelGroup.getContents().add(childParticle2);
    xsdModelGroup.getContents().add(childParticle3);
    XSDIdentityConstraintDefinition xsdIdConsDef = factory.createXSDIdentityConstraintDefinition();
    concept.getIdentityConstraintDefinitions().add(xsdIdConsDef);
    XSDXPathDefinition xsdXPathDefinition1 = factory.createXSDXPathDefinition();
    xsdXPathDefinition1.setValue(element1);
    XSDXPathDefinition xsdXPathDefinition2 = factory.createXSDXPathDefinition();
    xsdXPathDefinition2.setValue(element2);
    xsdIdConsDef.getFields().add(xsdXPathDefinition1);
    xsdIdConsDef.getFields().add(xsdXPathDefinition2);
    // complex type with one child
    XSDComplexTypeDefinition xsdComplexTypeDef2 = factory.createXSDComplexTypeDefinition();
    xsdComplexTypeDef2.setBaseTypeDefinition(// $NON-NLS-1$
    xsdSchema.resolveComplexTypeDefinition(xsdSchema.getSchemaForSchemaNamespace(), "anyType"));
    XSDParticle xsdParticle2 = factory.createXSDParticle();
    xsdComplexTypeDef2.setContent(xsdParticle2);
    XSDModelGroup xsdModelGroup2 = factory.createXSDModelGroup();
    xsdParticle2.setContent(xsdModelGroup2);
    XSDParticle childParticle_2 = factory.createXSDParticle();
    XSDElementDeclaration childElement_2 = factory.createXSDElementDeclaration();
    childElement_2.setName(element1);
    childParticle_2.setContent(childElement_2);
    xsdModelGroup2.getContents().add(childParticle_2);
    xsdSchema.getContents().add(xsdComplexTypeDef2);
    // 
    topParent = Util.getTopParent(childElement1);
    assertNotNull(topParent);
    assertTrue(topParent.size() == 2);
    // 
    topParent = Util.getTopParent(childElement_2);
    assertNull(topParent);
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema) Test(org.junit.Test)

Aggregations

XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)162 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)93 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)76 XSDParticle (org.eclipse.xsd.XSDParticle)75 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)66 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)53 ArrayList (java.util.ArrayList)43 XSDSchema (org.eclipse.xsd.XSDSchema)37 Test (org.junit.Test)37 EList (org.eclipse.emf.common.util.EList)25 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)25 XSDFactory (org.eclipse.xsd.XSDFactory)23 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)21 XSDTerm (org.eclipse.xsd.XSDTerm)21 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)20 XSDComplexTypeContent (org.eclipse.xsd.XSDComplexTypeContent)20 Iterator (java.util.Iterator)19 List (java.util.List)19 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)16