Search in sources :

Example 16 with XSDComplexTypeContent

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

Example 17 with XSDComplexTypeContent

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

the class XSDUtilTest method testIsEntity.

@Test
public void testIsEntity() 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;
        }
        assertTrue(XSDUtil.isEntity(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) {
                    if (particle.getContent() instanceof XSDElementDeclaration) {
                        assertFalse(XSDUtil.isEntity(particle.getContent()));
                    }
                }
            }
        }
    }
}
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) Test(org.junit.Test)

Example 18 with XSDComplexTypeContent

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

the class XSDUtilTest method testIsPrimaryKeyElement.

@Test
public void testIsPrimaryKeyElement() 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 ctypeContent = ctypeDefinition.getContent();
        if (ctypeContent instanceof XSDParticle) {
            XSDParticle typeParticle = (XSDParticle) ctypeContent;
            XSDParticleContent particleContent = typeParticle.getContent();
            if (particleContent instanceof XSDModelGroup) {
                XSDModelGroup particleGroup = (XSDModelGroup) particleContent;
                for (XSDParticle particle : particleGroup.getContents()) {
                    if (particle.getContent() instanceof XSDElementDeclaration && ((XSDElementDeclaration) particle.getContent()).getName().equals("Id")) {
                        // $NON-NLS-1$
                        assertTrue(XSDUtil.isPrimaryKeyElement(particle));
                    } else {
                        assertFalse(XSDUtil.isPrimaryKeyElement(particle));
                    }
                }
            }
        }
    }
}
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) Test(org.junit.Test)

Example 19 with XSDComplexTypeContent

use of org.eclipse.xsd.XSDComplexTypeContent in project webtools.sourceediting by eclipse.

the class XSDComplexTypeDefinitionAdapter method getChildren.

public ITreeElement[] getChildren() {
    XSDComplexTypeDefinition xsdComplexTypeDefinition = getXSDComplexTypeDefinition();
    List list = new ArrayList();
    // Add attributes
    for (Iterator i = xsdComplexTypeDefinition.getAttributeContents().iterator(); i.hasNext(); ) {
        Object obj = i.next();
        if (obj instanceof XSDAttributeUse) {
            list.add(((XSDAttributeUse) obj).getAttributeDeclaration());
        } else if (obj instanceof XSDAttributeGroupDefinition) {
            getAttributeUses((XSDAttributeGroupDefinition) obj, list);
        }
    }
    // Add enumerations
    boolean canHaveEnumerations = xsdComplexTypeDefinition.getContentType() instanceof XSDSimpleTypeDefinition && XSDDerivationMethod.RESTRICTION_LITERAL.equals(xsdComplexTypeDefinition.getDerivationMethod());
    if (canHaveEnumerations) {
        Object contentType = getContentType();
        if (contentType != null) {
            for (Iterator iterator = ((XSDSimpleTypeDefinition) contentType).getEnumerationFacets().iterator(); iterator.hasNext(); ) {
                XSDEnumerationFacet enumerationFacet = (XSDEnumerationFacet) iterator.next();
                list.add(enumerationFacet);
            }
        }
    }
    XSDWildcard anyAttr = xsdComplexTypeDefinition.getAttributeWildcard();
    if (anyAttr != null)
        list.add(anyAttr);
    // get immediate XSD Model Group of this complex type
    if (xsdComplexTypeDefinition.getContent() != null) {
        XSDComplexTypeContent xsdComplexTypeContent = xsdComplexTypeDefinition.getContent();
        if (xsdComplexTypeContent instanceof XSDParticle) {
            XSDParticleContent particleContent = ((XSDParticle) xsdComplexTypeContent).getContent();
            if (particleContent instanceof XSDModelGroup) {
                list.add(particleContent);
            }
        }
    }
    // get inherited XSD Model Group of this complex type
    boolean showInheritedContent = XSDEditorPlugin.getPlugin().getShowInheritedContent();
    if (showInheritedContent) {
        XSDTypeDefinition typeDef = xsdComplexTypeDefinition.getBaseTypeDefinition();
        if (typeDef instanceof XSDComplexTypeDefinition) {
            XSDComplexTypeDefinition baseCT = (XSDComplexTypeDefinition) typeDef;
            if (baseCT.getTargetNamespace() != null && !baseCT.getTargetNamespace().equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001)) {
                if (baseCT.getContent() != null) {
                    XSDComplexTypeContent xsdComplexTypeContent = baseCT.getContent();
                    if (xsdComplexTypeContent instanceof XSDParticle) {
                        XSDParticleContent particleContent = ((XSDParticle) xsdComplexTypeContent).getContent();
                        if (particleContent instanceof XSDModelGroup) {
                            list.add(particleContent);
                        }
                    }
                }
            }
        }
    }
    List adapterList = new ArrayList();
    populateAdapterList(list, adapterList);
    return (ITreeElement[]) adapterList.toArray(new ITreeElement[0]);
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) ArrayList(java.util.ArrayList) XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDParticleContent(org.eclipse.xsd.XSDParticleContent) ITreeElement(org.eclipse.wst.xsd.ui.internal.adt.outline.ITreeElement) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) IADTObject(org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 20 with XSDComplexTypeContent

use of org.eclipse.xsd.XSDComplexTypeContent in project webtools.sourceediting by eclipse.

the class AddXSDElementCommand method getModelGroup.

// PORT
public XSDModelGroup getModelGroup(XSDComplexTypeDefinition cType) {
    XSDParticle particle = null;
    XSDComplexTypeContent xsdComplexTypeContent = cType.getContent();
    if (xsdComplexTypeContent instanceof XSDParticle) {
        particle = (XSDParticle) xsdComplexTypeContent;
    }
    if (particle == null) {
        return null;
    }
    Object particleContent = particle.getContent();
    XSDModelGroup group = null;
    if (particleContent instanceof XSDModelGroupDefinition) {
        group = ((XSDModelGroupDefinition) particleContent).getResolvedModelGroupDefinition().getModelGroup();
    } else if (particleContent instanceof XSDModelGroup) {
        group = (XSDModelGroup) particleContent;
    }
    if (group == null) {
        return null;
    }
    return group;
}
Also used : XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Aggregations

XSDComplexTypeContent (org.eclipse.xsd.XSDComplexTypeContent)26 XSDParticle (org.eclipse.xsd.XSDParticle)24 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)22 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)20 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)16 ArrayList (java.util.ArrayList)10 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)10 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)9 XSDParticleContent (org.eclipse.xsd.XSDParticleContent)8 XSDTerm (org.eclipse.xsd.XSDTerm)8 EList (org.eclipse.emf.common.util.EList)7 XSDSchema (org.eclipse.xsd.XSDSchema)7 TreeObject (com.amalto.workbench.models.TreeObject)6 Iterator (java.util.Iterator)6 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)6 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)5 List (java.util.List)4 EObject (org.eclipse.emf.ecore.EObject)4 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)4 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)4