Search in sources :

Example 66 with XSDElementDeclaration

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

the class UtilTest method testIsSimpleTypedParticle.

@Test
public void testIsSimpleTypedParticle() {
    boolean isSimpleTypedParticle = Util.isSimpleTypedParticle(null);
    assertFalse(isSimpleTypedParticle);
    XSDFactory factory = XSDFactory.eINSTANCE;
    XSDParticle particle = factory.createXSDParticle();
    isSimpleTypedParticle = Util.isSimpleTypedParticle(particle);
    assertFalse(isSimpleTypedParticle);
    XSDElementDeclaration elementDeclaration = factory.createXSDElementDeclaration();
    elementDeclaration.setTypeDefinition(factory.createXSDSimpleTypeDefinition());
    particle.setContent(elementDeclaration);
    isSimpleTypedParticle = Util.isSimpleTypedParticle(particle);
    assertTrue(isSimpleTypedParticle);
    XSDModelGroup modelGroup = factory.createXSDModelGroup();
    particle.setContent(modelGroup);
    isSimpleTypedParticle = Util.isSimpleTypedParticle(particle);
    assertFalse(isSimpleTypedParticle);
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDParticle(org.eclipse.xsd.XSDParticle) Test(org.junit.Test)

Example 67 with XSDElementDeclaration

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

the class UtilTest method testGetComplexTypeDefinitionChildren.

/**
 * Test method for
 * {@link com.amalto.workbench.utils.Util#getComplexTypeDefinitionChildren(org.eclipse.xsd.XSDComplexTypeDefinition, boolean)}
 * .
 */
@Test
public void testGetComplexTypeDefinitionChildren() throws Exception {
    // get test model
    XSDSchema xsdSchema = getXSDSchema();
    EList<XSDElementDeclaration> elementDeclarations = xsdSchema.getElementDeclarations();
    // test
    assertEquals(1, elementDeclarations.size());
    XSDTypeDefinition typeDefinition = elementDeclarations.get(0).getTypeDefinition();
    ArrayList<Object> children = Util.getComplexTypeDefinitionChildren((XSDComplexTypeDefinition) typeDefinition, true);
    assertEquals(3, children.size());
    children = Util.getComplexTypeDefinitionChildren((XSDComplexTypeDefinition) typeDefinition, false);
    assertEquals(1, children.size());
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDSchema(org.eclipse.xsd.XSDSchema) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) Test(org.junit.Test)

Example 68 with XSDElementDeclaration

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

the class UtilTest method testGetChildElements4TypeArg.

@Test
public void testGetChildElements4TypeArg() 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;
        }
    }
    assertNotNull(conceptEl);
    Map<String, XSDParticle> childElements = Util.getChildElements("", (XSDComplexTypeDefinition) conceptEl.getTypeDefinition(), false, // $NON-NLS-1$
    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 69 with XSDElementDeclaration

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

the class XSDUtilTest method testIsFirstLevelChild.

@Test
public void testIsFirstLevelChild() throws Exception {
    // $NON-NLS-1$
    String fileName = "Product_0.1.xsd";
    // $NON-NLS-1$
    String elementName = "Product";
    String xsdString = TestUtil.readTestResource(XSDUtilTest.this.getClass(), fileName);
    assertNotNull(xsdString);
    XSDSchema xsdSchema = Util.getXSDSchema(xsdString);
    XSDElementDeclaration decl = null;
    for (XSDElementDeclaration element : xsdSchema.getElementDeclarations()) {
        if (element.getName().equals(elementName)) {
            decl = element;
        }
    }
    if (decl != null) {
        XSDComplexTypeDefinition ctypeDefinition = (XSDComplexTypeDefinition) decl.getTypeDefinition();
        XSDComplexTypeContent content = ctypeDefinition.getContent();
        if (content instanceof XSDParticle) {
            XSDParticle xsdParticle = (XSDParticle) content;
            XSDParticleContent particleContent = xsdParticle.getContent();
            if (particleContent instanceof XSDModelGroup) {
                XSDModelGroup modelGroup = (XSDModelGroup) particleContent;
                EList<XSDParticle> contents = modelGroup.getContents();
                for (XSDParticle particle : contents) {
                    assertTrue(XSDUtil.isFirstLevelChild(particle));
                    if (particle.getTerm() instanceof XSDElementDeclaration) {
                        XSDElementDeclaration xsdElementDecl = (XSDElementDeclaration) particle.getTerm();
                        XSDTypeDefinition typeDefinition = xsdElementDecl.getTypeDefinition();
                        if (typeDefinition instanceof XSDComplexTypeDefinition) {
                            XSDParticle childPart = (XSDParticle) ((XSDComplexTypeDefinition) typeDefinition).getContent();
                            XSDModelGroup childModelGroup = (XSDModelGroup) childPart.getContent();
                            for (XSDParticle childParticle : childModelGroup.getContents()) {
                                assertFalse(XSDUtil.isFirstLevelChild(childParticle));
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDParticleContent(org.eclipse.xsd.XSDParticleContent) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) Test(org.junit.Test)

Example 70 with XSDElementDeclaration

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

the class XSDUtilTest method testGetKeyFields.

@Test
public void testGetKeyFields() throws Exception {
    XSDFactory factory = XSDFactory.eINSTANCE;
    // $NON-NLS-1$
    String conceptName = "Product";
    // $NON-NLS-1$ //$NON-NLS-2$
    String[] fields = { "Id", "code" };
    XSDElementDeclaration concept = factory.createXSDElementDeclaration();
    concept.setName(conceptName);
    XSDIdentityConstraintDefinition ideCDef = factory.createXSDIdentityConstraintDefinition();
    XSDXPathDefinition xpathDefinition1 = factory.createXSDXPathDefinition();
    xpathDefinition1.setValue(fields[0]);
    ideCDef.getFields().add(xpathDefinition1);
    concept.getIdentityConstraintDefinitions().add(ideCDef);
    List<String> keyFields = XSDUtil.getKeyFields(concept);
    assertTrue(keyFields.isEmpty());
    // 
    ideCDef.setName(conceptName);
    XSDXPathDefinition xpathDefinition2 = factory.createXSDXPathDefinition();
    xpathDefinition2.setValue(fields[1]);
    ideCDef.getFields().add(xpathDefinition2);
    keyFields = XSDUtil.getKeyFields(concept);
    assertTrue(keyFields.size() == 2);
    assertTrue(keyFields.contains(fields[0]));
    assertTrue(keyFields.contains(fields[1]));
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) Test(org.junit.Test)

Aggregations

XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)222 XSDParticle (org.eclipse.xsd.XSDParticle)103 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)93 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)87 ArrayList (java.util.ArrayList)60 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)57 XSDSchema (org.eclipse.xsd.XSDSchema)48 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)47 Test (org.junit.Test)44 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)38 XSDFactory (org.eclipse.xsd.XSDFactory)37 XSDTerm (org.eclipse.xsd.XSDTerm)32 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)30 EList (org.eclipse.emf.common.util.EList)29 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)28 Iterator (java.util.Iterator)27 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)27 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)24 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)21 Element (org.w3c.dom.Element)21