Search in sources :

Example 11 with XSDComplexTypeContent

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

the class XSDUtil method isPrimaryKeyElement.

public static boolean isPrimaryKeyElement(XSDParticle particle) {
    if (isSimpleTypeElement(particle)) {
        Map<XSDElementDeclaration, List<XSDComplexTypeDefinition>> entityMapComplexTypes = buildEntityUsedComplexTypeMap((XSDSchema) particle.getRootContainer());
        Iterator<XSDElementDeclaration> iterator = entityMapComplexTypes.keySet().iterator();
        while (iterator.hasNext()) {
            XSDElementDeclaration concept = iterator.next();
            List<String> keyFields = getKeyFields(concept);
            if (keyFields.contains(((XSDElementDeclaration) particle.getTerm()).getName())) {
                List<XSDComplexTypeDefinition> ctypes = entityMapComplexTypes.get(concept);
                for (XSDComplexTypeDefinition ctype : ctypes) {
                    XSDComplexTypeContent ctypeContent = ctype.getContent();
                    if (ctypeContent instanceof XSDParticle) {
                        XSDParticle typeParticle = (XSDParticle) ctypeContent;
                        XSDParticleContent particleContent = typeParticle.getContent();
                        if (particleContent instanceof XSDModelGroup) {
                            XSDModelGroup particleGroup = (XSDModelGroup) particleContent;
                            if (particleGroup.getContents().contains(particle)) {
                                return true;
                            }
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDParticleContent(org.eclipse.xsd.XSDParticleContent) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) NodeList(org.w3c.dom.NodeList) EList(org.eclipse.emf.common.util.EList) List(java.util.List) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 12 with XSDComplexTypeContent

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

the class XSDUtil method isFirstLevelChild.

public static boolean isFirstLevelChild(XSDParticle particle) {
    XSDSchema schema = (XSDSchema) particle.getRootContainer();
    Map<XSDElementDeclaration, List<XSDComplexTypeDefinition>> entityMapComplexTypes = buildEntityUsedComplexTypeMap(schema);
    Iterator<XSDElementDeclaration> iterator = entityMapComplexTypes.keySet().iterator();
    while (iterator.hasNext()) {
        XSDElementDeclaration concept = iterator.next();
        List<XSDComplexTypeDefinition> ctypes = entityMapComplexTypes.get(concept);
        for (XSDComplexTypeDefinition ctype : ctypes) {
            XSDComplexTypeContent ctypeContent = ctype.getContent();
            if (ctypeContent instanceof XSDParticle) {
                XSDParticle typeParticle = (XSDParticle) ctypeContent;
                XSDParticleContent particleContent = typeParticle.getContent();
                if (particleContent instanceof XSDModelGroup) {
                    XSDModelGroup particleGroup = (XSDModelGroup) particleContent;
                    if (particleGroup.getContents().contains(particle)) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDParticleContent(org.eclipse.xsd.XSDParticleContent) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) NodeList(org.w3c.dom.NodeList) EList(org.eclipse.emf.common.util.EList) List(java.util.List) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 13 with XSDComplexTypeContent

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

the class Util method getAllComplexTypeChildren.

/**
 * get all complex types's complextype children
 *
 * @param complexTypeDefinition
 * @return
 */
public static ArrayList<Object> getAllComplexTypeChildren(XSDElementDeclaration declaration) {
    XSDComplexTypeDefinition complexTypeDefinition = (XSDComplexTypeDefinition) declaration.getTypeDefinition();
    XSDComplexTypeContent xsdComplexTypeContent = complexTypeDefinition.getContent();
    ArrayList<Object> list = new ArrayList<Object>();
    // Now determine whether ref. If ref look at the base Type definition
    if (xsdComplexTypeContent == null) {
        XSDTypeDefinition typeDefinition = complexTypeDefinition.getBaseTypeDefinition();
        if (typeDefinition instanceof XSDComplexTypeDefinition) {
            list.add(((XSDComplexTypeDefinition) typeDefinition).getContent());
        }
    }
    // check if we are extending a complex Definition
    if ("extension".equals(complexTypeDefinition.getDerivationMethod().getName())) {
        // $NON-NLS-1$
        if (complexTypeDefinition.getBaseTypeDefinition() instanceof XSDComplexTypeDefinition) {
            XSDComplexTypeDefinition complex = (XSDComplexTypeDefinition) complexTypeDefinition.getBaseTypeDefinition();
            XSDParticle particle = (XSDParticle) complex.getContent();
            if (particle.getTerm() instanceof XSDModelGroup) {
                XSDModelGroup group = (XSDModelGroup) particle.getTerm();
                EList<XSDParticle> elist = group.getContents();
                for (XSDParticle pt : elist) {
                    if (pt.getContent() instanceof XSDElementDeclaration) {
                        XSDTypeDefinition typeDef = ((XSDElementDeclaration) pt.getContent()).getTypeDefinition();
                        if (typeDef instanceof XSDComplexTypeDefinition) {
                            list.addAll(getAllComplexTypeChildren((XSDElementDeclaration) pt.getContent()));
                        }
                    }
                }
            }
        }
    }
    // now check what we have in the content
    // if (xsdComplexTypeContent instanceof XSDComplexTypeDefinition) {
    list.add(declaration);
    if (xsdComplexTypeContent instanceof XSDParticle) {
        XSDParticle particle = (XSDParticle) xsdComplexTypeContent;
        if (particle.getTerm() instanceof XSDModelGroup) {
            XSDModelGroup group = (XSDModelGroup) particle.getTerm();
            EList<XSDParticle> elist = group.getContents();
            for (XSDParticle pt : elist) {
                if (pt.getContent() instanceof XSDElementDeclaration) {
                    XSDTypeDefinition typeDef = ((XSDElementDeclaration) pt.getContent()).getTypeDefinition();
                    if (typeDef instanceof XSDComplexTypeDefinition) {
                        list.addAll(getAllComplexTypeChildren((XSDElementDeclaration) pt.getContent()));
                    }
                }
            }
        }
    }
    return list;
}
Also used : XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) XObject(com.sun.org.apache.xpath.internal.objects.XObject) TreeObject(com.amalto.workbench.models.TreeObject) EObject(org.eclipse.emf.ecore.EObject) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 14 with XSDComplexTypeContent

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

the class Util method isReferrenced.

private static boolean isReferrenced(XSDElementDeclaration element, XSDElementDeclaration term) {
    if (element == term) {
        return true;
    }
    if (term.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
        XSDComplexTypeContent fromcomplexType = ((XSDComplexTypeDefinition) term.getTypeDefinition()).getContent();
        if (fromcomplexType instanceof XSDParticle) {
            XSDParticle particle = (XSDParticle) fromcomplexType;
            if (particle.getTerm() instanceof XSDModelGroup) {
                XSDModelGroup modelGroup = ((XSDModelGroup) particle.getTerm());
                EList<?> fromlist = modelGroup.getContents();
                for (Object obj : fromlist) {
                    XSDTerm t = ((XSDParticle) obj).getTerm();
                    if (t == element) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDTerm(org.eclipse.xsd.XSDTerm) XObject(com.sun.org.apache.xpath.internal.objects.XObject) TreeObject(com.amalto.workbench.models.TreeObject) EObject(org.eclipse.emf.ecore.EObject) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 15 with XSDComplexTypeContent

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

the class Util method getComplexTypeDefinitionChildren.

public static ArrayList<Object> getComplexTypeDefinitionChildren(XSDComplexTypeDefinition complexTypeDefinition, boolean ignoreRestriction) {
    XSDComplexTypeContent xsdComplexTypeContent = complexTypeDefinition.getContent();
    ArrayList<Object> list = new ArrayList<Object>();
    // Now determine whether ref. If ref look at the base Type definition
    XSDTypeDefinition baseTypeDefinition = complexTypeDefinition.getBaseTypeDefinition();
    if (xsdComplexTypeContent == null) {
        XSDTypeDefinition typeDefinition = baseTypeDefinition;
        // if a simple type return the simple type
        if (typeDefinition instanceof XSDSimpleTypeDefinition) {
            list.add(typeDefinition);
            return list;
        } else {
        }
        // it is a complex Type
        xsdComplexTypeContent = ((XSDComplexTypeDefinition) typeDefinition).getContent();
    }
    // check if we are extending a complex Definition
    if ("extension".equals(complexTypeDefinition.getDerivationMethod().getName())) {
        if (baseTypeDefinition instanceof XSDComplexTypeDefinition && baseTypeDefinition != complexTypeDefinition) {
            String name = ((XSDComplexTypeDefinition) baseTypeDefinition).getDerivationMethod().getName();
            if (name.equals("restriction") || ignoreRestriction) {
                // $NON-NLS-1$
                list.addAll(getComplexTypeDefinitionChildren((XSDComplexTypeDefinition) baseTypeDefinition, ignoreRestriction));
            // 
            }
        }
    }
    // Attributes
    if (complexTypeDefinition.getAttributeContents() != null) {
        list.addAll(complexTypeDefinition.getAttributeContents());
    }
    // Annotations
    if (complexTypeDefinition.getAnnotations() != null) {
        list.addAll(complexTypeDefinition.getAnnotations());
    }
    // simple type return the simple type
    if (xsdComplexTypeContent instanceof XSDSimpleTypeDefinition) {
        list.add(xsdComplexTypeContent);
        return list;
    }
    // xsd Particle: we have a model group
    if (xsdComplexTypeContent instanceof XSDParticle) {
        // log.info("Model Group?: "+((XSDParticle)xsdComplexTypeContent).getTerm());
        if (((XSDParticle) xsdComplexTypeContent).getTerm() instanceof XSDModelGroup) {
            // return the model group
            list.add(((XSDParticle) xsdComplexTypeContent).getTerm());
            return list;
        } else {
            // wild card or element declaration '?)
            list.add(((XSDParticle) xsdComplexTypeContent).getTerm());
            return list;
        }
    }
    // what else could it be ?
    list.add(xsdComplexTypeContent);
    return list;
}
Also used : XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) ArrayList(java.util.ArrayList) XObject(com.sun.org.apache.xpath.internal.objects.XObject) TreeObject(com.amalto.workbench.models.TreeObject) EObject(org.eclipse.emf.ecore.EObject) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

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