Search in sources :

Example 76 with XSDTypeDefinition

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

the class Util method findElementsUsingType.

/**
 * Find elementDeclarations that use any types derived from a named type.
 *
 * <p>
 * This shows one way to query the schema for elementDeclarations and then how to find specific kinds of
 * typeDefinitions.
 * </p>
 *
 * @param objList collection set to search for elemDecls
 * @param localName for the type used
 * @return Boolean indicate any XSDElementDeclarations is found or not
 */
public static boolean findElementsUsingType(List<Object> objList, XSDTypeDefinition localTypedef) {
    for (Object obj : objList) {
        if (obj == localTypedef) {
            continue;
        }
        if (obj instanceof XSDParticle || obj instanceof XSDElementDeclaration || obj instanceof XSDTypeDefinition) {
            XSDTypeDefinition typedef = null;
            if (obj instanceof XSDParticle) {
                XSDParticle xsdParticle = (XSDParticle) obj;
                if (xsdParticle.getTerm() instanceof XSDElementDeclaration) {
                    obj = xsdParticle.getTerm();
                }
            }
            if (obj instanceof XSDElementDeclaration) {
                XSDElementDeclaration elem = (XSDElementDeclaration) obj;
                if (elem.getAnonymousTypeDefinition() != null) {
                    typedef = elem.getAnonymousTypeDefinition();
                } else if (elem.getTypeDefinition() != null) {
                    typedef = elem.getTypeDefinition();
                } else {
                    // thus it's not using our type
                    continue;
                }
            } else {
                typedef = (XSDTypeDefinition) obj;
            }
            if (typedef instanceof XSDComplexTypeDefinition) {
                XSDComplexTypeDefinition type = (XSDComplexTypeDefinition) typedef;
                if (localTypedef.getName().equals(type.getName()) && (localTypedef instanceof XSDComplexTypeDefinition)) {
                    return true;
                }
                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();
                        for (XSDParticle pt : elist) {
                            if (pt.getContent() instanceof XSDElementDeclaration) {
                                XSDTypeDefinition typeDef = ((XSDElementDeclaration) pt.getContent()).getTypeDefinition();
                                boolean sameType = (typeDef instanceof XSDComplexTypeDefinition && localTypedef instanceof XSDComplexTypeDefinition) || (typeDef instanceof XSDSimpleTypeDefinition && localTypedef instanceof XSDSimpleTypeDefinition);
                                if (typeDef != null && typeDef.getName() != null && sameType) {
                                    if ((localTypedef.getName().equals(typeDef.getName()))) {
                                        return true;
                                    }
                                }
                            }
                        }
                    }
                }
            } else if (typedef instanceof XSDSimpleTypeDefinition) {
                XSDSimpleTypeDefinition type = (XSDSimpleTypeDefinition) typedef;
                XSDSimpleTypeDefinition baseType = type.getBaseTypeDefinition();
                if (baseType != null && baseType.getName().equals(localTypedef.getName()) && localTypedef instanceof XSDSimpleTypeDefinition) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) 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 77 with XSDTypeDefinition

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

the class Util method isTypeDerivedFrom.

/**
 *******************************************************************
 * XSD Utils
 ********************************************************************
 */
public static boolean isTypeDerivedFrom(XSDTypeDefinition typedef, String namespace, String localName) {
    // Walk the baseTypes from this typedef seeing if any
    // of them match the requested one
    XSDTypeDefinition baseType = typedef.getBaseType();
    // As this convenience method if our parameters match
    if (baseType.hasNameAndTargetNamespace(localName, namespace)) {
        return true;
    }
    // If not, check to see if we've run up to the top
    // Performance note: this is horribly inefficient,
    // re-calling this same method every time; but it
    // serves as a good example
    XSDTypeDefinition rootType = typedef.getRootType();
    if (rootType == baseType) {
        // If we've hit the root, we aren't derived from it
        return false;
    } else {
        // Otherwise continue to traverse upwards
        return isTypeDerivedFrom(baseType, namespace, localName);
    }
}
Also used : XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 78 with XSDTypeDefinition

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

the class Util method getAllSuperComplexTypes.

/**
 * contains childType itself
 */
public static List<XSDComplexTypeDefinition> getAllSuperComplexTypes(XSDComplexTypeDefinition childType) {
    if (childType == null) {
        return new ArrayList<XSDComplexTypeDefinition>();
    }
    XSDTypeDefinition rootType = childType.getRootType();
    XSDTypeDefinition typeDefinition = childType;
    List<XSDComplexTypeDefinition> hierarchyComplexTypes = new ArrayList<XSDComplexTypeDefinition>();
    while (typeDefinition != null && typeDefinition instanceof XSDComplexTypeDefinition) {
        hierarchyComplexTypes.add((XSDComplexTypeDefinition) typeDefinition);
        if (typeDefinition.equals(rootType)) {
            break;
        }
        typeDefinition = typeDefinition.getBaseType();
    }
    return hierarchyComplexTypes;
}
Also used : ArrayList(java.util.ArrayList) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 79 with XSDTypeDefinition

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

the class XSDAnnotationsStructure method setAutoExpand.

/**
 **************************************************************************
 * Auto Expand
 * @throws Exception
 ***************************************************************************
 */
public boolean setAutoExpand(String value) throws Exception {
    if (!(declaration.getTypeDefinition() instanceof XSDComplexTypeDefinition)) {
        return false;
    }
    XSDSchema xsd = schema != null ? schema : declaration.getSchema();
    // $NON-NLS-1$
    String auto = "X_AutoExpand";
    String xsdString = Util.nodeToString(xsd.getDocument().getDocumentElement());
    ArrayList<Object> objs = Util.getAllComplexTypeChildren(declaration);
    for (Object obj : objs) {
        if (obj instanceof XSDElementDeclaration || obj instanceof XSDParticle) {
            boolean isImported = false;
            if (obj instanceof XSDParticle) {
                XSDParticle particle = (XSDParticle) obj;
                if (particle.getTerm() instanceof XSDElementDeclaration) {
                    XSDElementDeclaration decl = (XSDElementDeclaration) particle.getTerm();
                    if (Util.IsAImporedElement(decl, xsdString)) {
                        XSDTypeDefinition typeDef = decl.getTypeDefinition();
                        if (Util.IsAImporedElement(typeDef, xsdString)) {
                            isImported = true;
                        }
                    }
                }
            } else if (obj instanceof XSDElementDeclaration) {
                XSDElementDeclaration decl = (XSDElementDeclaration) obj;
                if (Util.IsAImporedElement(decl, xsdString)) {
                    isImported = true;
                }
            }
            if (!isImported) {
                XSDAnnotationsStructure annotion = new XSDAnnotationsStructure((XSDComponent) obj);
                annotion.setAppInfo(auto, value, true);
            }
        }
    }
    return true;
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 80 with XSDTypeDefinition

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

the class XSDAnnotationsStructure method setAccessRole.

/**
 **************************************************************************
 * WRITE ACCESS
 *
 * @throws XtentisException
 ***************************************************************************
 */
public boolean setAccessRole(Collection<String> roles, boolean recursive, IStructuredContentProvider provider, String access) throws Exception {
    XSDSchema xsd = schema != null ? schema : declaration.getSchema();
    String xsdString = Util.nodeToString(xsd.getDocument().getDocumentElement());
    if (recursive) {
        ArrayList<Object> objList = new ArrayList<Object>();
        XSDComponent component = declaration;
        if (declaration == null) {
            component = this.componet;
        }
        Object[] objs = Util.getAllObject(component, objList, provider);
        while (objs.length > 0) {
            Object[] objCpys = objs;
            for (Object obj : objCpys) {
                if (obj instanceof XSDElementDeclaration || obj instanceof XSDParticle) {
                    boolean isImported = false;
                    if (obj instanceof XSDParticle) {
                        XSDParticle particle = (XSDParticle) obj;
                        if (particle.getTerm() instanceof XSDElementDeclaration) {
                            XSDElementDeclaration decl = (XSDElementDeclaration) particle.getTerm();
                            if (Util.IsAImporedElement(decl, xsdString)) {
                                XSDTypeDefinition typeDef = decl.getTypeDefinition();
                                if (Util.IsAImporedElement(typeDef, xsdString)) {
                                    isImported = true;
                                }
                            }
                        }
                    } else if (obj instanceof XSDElementDeclaration) {
                        XSDElementDeclaration decl = (XSDElementDeclaration) obj;
                        if (Util.IsAImporedElement(decl, xsdString)) {
                            isImported = true;
                        }
                    }
                    if (!isImported) {
                        XSDAnnotationsStructure annotion = new XSDAnnotationsStructure((XSDComponent) obj);
                        // see 7993, if UUID/AUTO_INCREMENT ,should not add write access
                        if (obj instanceof XSDParticle) {
                            XSDParticle o = (XSDParticle) obj;
                            // String name=Util.getFirstTextNode(o.getElement(), "@name");
                            // $NON-NLS-1$
                            String type = Util.getFirstTextNode(o.getElement(), "@type");
                            if (EUUIDCustomType.AUTO_INCREMENT.equals(type) || EUUIDCustomType.UUID.equals(type)) {
                                objList.remove(obj);
                                objs = objList.toArray();
                                continue;
                            }
                        }
                        // X_Write
                        annotion.removeAppInfos(access);
                        for (Iterator<String> iter = roles.iterator(); iter.hasNext(); ) {
                            String role = iter.next();
                            annotion.addAppInfo(access, role);
                        }
                    }
                }
                objList.remove(obj);
                objs = objList.toArray();
            }
        }
        return setAccessRole(roles, access);
    } else {
        if (Util.IsAImporedElement(declaration, xsdString)) {
            return false;
        }
        return setAccessRole(roles, access);
    }
}
Also used : ArrayList(java.util.ArrayList) XSDComponent(org.eclipse.xsd.XSDComponent) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema)

Aggregations

XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)119 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)66 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)57 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)46 ArrayList (java.util.ArrayList)39 XSDParticle (org.eclipse.xsd.XSDParticle)36 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)32 Iterator (java.util.Iterator)26 XSDSchema (org.eclipse.xsd.XSDSchema)26 List (java.util.List)22 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)17 EList (org.eclipse.emf.common.util.EList)16 TreeObject (com.amalto.workbench.models.TreeObject)14 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)14 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)13 XSDTerm (org.eclipse.xsd.XSDTerm)13 XSDFactory (org.eclipse.xsd.XSDFactory)12 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)11 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)10 XSDComplexTypeContent (org.eclipse.xsd.XSDComplexTypeContent)10