Search in sources :

Example 86 with XSDParticle

use of org.eclipse.xsd.XSDParticle 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 87 with XSDParticle

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

the class Util method getComplexTypeGroupType.

public static XSDCompositor getComplexTypeGroupType(XSDComplexTypeDefinition type) {
    if (type == null || !(type.getContent() instanceof XSDParticle) || !(((XSDParticle) type.getContent()).getContent() instanceof XSDModelGroup)) {
        return null;
    }
    XSDParticle groupParticle = (XSDParticle) type.getContent();
    XSDModelGroup group = (XSDModelGroup) groupParticle.getContent();
    return group.getCompositor();
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 88 with XSDParticle

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

the class Util method findOutAllSonElements.

private static List<XSDElementDeclaration> findOutAllSonElements(XSDElementDeclaration decl, Set<XSDConcreteComponent> complexTypes) {
    List<XSDElementDeclaration> holder = new ArrayList<XSDElementDeclaration>();
    if (decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
        XSDComplexTypeDefinition type = (XSDComplexTypeDefinition) decl.getTypeDefinition();
        if (complexTypes.contains(type)) {
            return holder;
        }
        if (type.getContent() instanceof XSDParticle) {
            XSDParticle particle = (XSDParticle) type.getContent();
            if (particle.getTerm() instanceof XSDModelGroup) {
                XSDModelGroup group = (XSDModelGroup) particle.getTerm();
                EList<XSDParticle> elist = group.getContents();
                boolean addComplexType = false;
                for (XSDParticle pt : elist) {
                    if (pt.getContent() instanceof XSDElementDeclaration) {
                        XSDElementDeclaration elem = (XSDElementDeclaration) pt.getContent();
                        if (!addComplexType) {
                            complexTypes.add(type);
                            addComplexType = true;
                        }
                        if (StringUtils.equals(elem.getName(), decl.getName())) {
                            if (ObjectUtils.equals(elem.getType(), decl.getType())) {
                                if (StringUtils.equals(elem.getTargetNamespace(), decl.getTargetNamespace())) {
                                    continue;
                                }
                            }
                        }
                        holder.add(elem);
                    }
                }
            }
        }
    }
    return holder;
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 89 with XSDParticle

use of org.eclipse.xsd.XSDParticle 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 90 with XSDParticle

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

the class Util method retrieveXSDComponentPath.

public static List<String> retrieveXSDComponentPath(Object component, XSDSchema schema, List<String> buffer) {
    String name = null;
    if (component instanceof XSDElementDeclaration) {
        XSDElementDeclaration decl = (XSDElementDeclaration) component;
        name = decl.getName();
        // $NON-NLS-1$//$NON-NLS-2$
        buffer.add("//xsd:element[@name='" + name + "']");
        if (decl.getContainer() instanceof XSDSchemaImpl) {
            return buffer;
        } else {
            return retrieveXSDComponentPath(decl.getContainer(), schema, buffer);
        }
    } else if (component instanceof XSDParticle) {
        XSDParticle particle = (XSDParticle) component;
        XSDTerm term = particle.getTerm();
        if (term instanceof XSDElementDeclaration && !(((XSDElementDeclaration) term).getContainer() instanceof XSDParticle)) {
            String prefix = null;
            String ns = ((XSDElementDeclaration) term).getTargetNamespace();
            Iterator<Map.Entry<String, String>> iter = schema.getQNamePrefixToNamespaceMap().entrySet().iterator();
            while (iter.hasNext() && ns != null) {
                Map.Entry<String, String> entry = iter.next();
                if (entry.getValue().equals(ns)) {
                    prefix = entry.getKey();
                }
            }
            name = ((XSDElementDeclaration) term).getName();
            buffer.add(// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
            "//xsd:element[@name='" + name + "' or @ref='" + (prefix != null ? (prefix + ":" + name) : name) + "']");
            return retrieveXSDComponentPath(particle.getContainer(), schema, buffer);
        } else {
            retrieveXSDComponentPath(particle.getContainer(), schema, buffer);
        }
    } else if (component instanceof XSDComplexTypeDefinition) {
        XSDComplexTypeDefinition type = (XSDComplexTypeDefinition) component;
        name = type.getName();
        // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
        buffer.add("//xsd:complexType" + (name != null ? "[@name='" + name + "']" : ""));
        if (type.getContainer() instanceof XSDSchemaImpl) {
            return buffer;
        }
        return retrieveXSDComponentPath(type.getContainer(), schema, buffer);
    } else if (component instanceof XSDSimpleTypeDefinition) {
        // TreePath tPath=((TreeSelection)selection).getPaths()[0];
        // Object elem = tPath.getSegment(0);
        // return retrieveXSDComponentPath(elem, schema, buffer, selection);
        String typeName = ((XSDSimpleTypeDefinition) component).getName();
        // $NON-NLS-1$//$NON-NLS-2$
        buffer.add("//xsd:simpleType[@name='" + typeName + "']");
        return buffer;
    } else if (component instanceof XSDModelGroup) {
        XSDModelGroup group = (XSDModelGroup) component;
        String literal = group.getCompositor().getLiteral();
        // $NON-NLS-1$
        buffer.add("//xsd:" + literal);
        return retrieveXSDComponentPath(group.getContainer(), schema, buffer);
    } else if (component instanceof XSDIdentityConstraintDefinition) {
        XSDIdentityConstraintDefinition identify = (XSDIdentityConstraintDefinition) component;
        XSDConcreteComponent c = identify.getContainer();
        // $NON-NLS-1$//$NON-NLS-2$
        buffer.add("//xsd:unique[@name='" + identify.getName() + "']");
        return retrieveXSDComponentPath(c, schema, buffer);
    } else if (component instanceof XSDXPathDefinition) {
        XSDXPathDefinition path = (XSDXPathDefinition) component;
        // $NON-NLS-1$//$NON-NLS-2$
        buffer.add("//xsd:field[@xpath='" + path.getValue() + "']");
        return retrieveXSDComponentPath(path.getContainer(), schema, buffer);
    } else if (component instanceof XSDAnnotation) {
        XSDAnnotation annon = (XSDAnnotation) component;
        // $NON-NLS-1$
        buffer.add("//xsd:annotation");
        return retrieveXSDComponentPath(annon.getContainer(), schema, buffer);
    } else {
        return buffer;
    }
    return buffer;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) ZipEntry(java.util.zip.ZipEntry) Entry(java.util.Map.Entry) JarEntry(java.util.jar.JarEntry) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSchemaImpl(org.eclipse.xsd.impl.XSDSchemaImpl) Iterator(java.util.Iterator) XSDTerm(org.eclipse.xsd.XSDTerm) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) MultiKeyMap(org.apache.commons.collections.map.MultiKeyMap) HashMap(java.util.HashMap) XSDParticle(org.eclipse.xsd.XSDParticle)

Aggregations

XSDParticle (org.eclipse.xsd.XSDParticle)146 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)103 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)93 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)75 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)36 ArrayList (java.util.ArrayList)34 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)34 XSDTerm (org.eclipse.xsd.XSDTerm)31 XSDFactory (org.eclipse.xsd.XSDFactory)27 XSDComplexTypeContent (org.eclipse.xsd.XSDComplexTypeContent)24 XSDSchema (org.eclipse.xsd.XSDSchema)24 Test (org.junit.Test)23 Iterator (java.util.Iterator)21 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)21 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)19 EList (org.eclipse.emf.common.util.EList)17 XSDParticleContent (org.eclipse.xsd.XSDParticleContent)17 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)16 Element (org.w3c.dom.Element)16 List (java.util.List)15