Search in sources :

Example 6 with XSDElementDeclaration

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

the class Util method getTopElement.

public static String getTopElement(XSDElementDeclaration parent, XSDElementDeclaration son) {
    XSDTypeDefinition type = parent.getTypeDefinition();
    if (!(type instanceof XSDComplexTypeDefinition)) {
        return null;
    }
    List<XSDComplexTypeDefinition> hierarchyComplexTypes = getAllSuperComplexTypes((XSDComplexTypeDefinition) type);
    for (XSDComplexTypeDefinition complexType : hierarchyComplexTypes) {
        if (complexType.getContent() instanceof XSDParticle) {
            XSDParticle particle = (XSDParticle) complexType.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) {
                        XSDElementDeclaration ele = (XSDElementDeclaration) pt.getContent();
                        if (ele == son) {
                            return ele.getName();
                        /*
                                 * ArrayList<String> complexTypes = new ArrayList<String>(); XSDElementDeclaration spec
                                 * = findOutSpecialSonElement( (XSDElementDeclaration) pt.getContent(), son,
                                 * complexTypes); if (spec != null) return spec.getName();
                                 */
                        // if (ele.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
                        // 
                        // return ele.getName() + "/"//$NON-NLS-1$
                        // + getTopElement(ele, son, (XSDComplexTypeDefinition) ele.getTypeDefinition());
                        // 
                        // 
                        // }
                        }
                    }
                }
            }
        }
    }
    // $NON-NLS-1$
    return "";
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 7 with XSDElementDeclaration

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

the class Util method getRealKeyInfos.

public static List<Object> getRealKeyInfos(XSDElementDeclaration currentEntity, XSDParticle son) {
    if (currentEntity == null || son == null) {
        return null;
    }
    if (!isDirectChild(currentEntity, son)) {
        return null;
    }
    List<Object> list = new ArrayList<Object>();
    XSDTerm term = son.getTerm();
    if (term instanceof XSDElementDeclaration) {
        String primaryKey = ((XSDElementDeclaration) term).getName();
        EList<XSDIdentityConstraintDefinition> idtylist = currentEntity.getIdentityConstraintDefinitions();
        for (XSDIdentityConstraintDefinition idty : idtylist) {
            EList<XSDXPathDefinition> fields = idty.getFields();
            for (XSDXPathDefinition path : fields) {
                if ((path.getValue()).equals(primaryKey)) {
                    list.add(idty);
                    list.add(path);
                    break;
                }
            }
        }
    }
    return list;
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) XSDTerm(org.eclipse.xsd.XSDTerm) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XObject(com.sun.org.apache.xpath.internal.objects.XObject) TreeObject(com.amalto.workbench.models.TreeObject) EObject(org.eclipse.emf.ecore.EObject) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition)

Example 8 with XSDElementDeclaration

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

the class Util method updateReference.

public static void updateReference(Object decl, Object[] objs, Object[] allForeignKeyAndInfos, String oldValue, String newValue) {
    if (!(decl instanceof XSDElementDeclaration)) {
        return;
    }
    updatePrimaryKeyInfo((XSDElementDeclaration) decl, oldValue, newValue);
    updateForeignKeyRelatedInfo(oldValue, newValue, allForeignKeyAndInfos);
    for (Object obj : objs) {
        if (obj instanceof XSDParticle) {
            XSDTerm term = ((XSDParticle) obj).getTerm();
            if (term instanceof XSDElementDeclaration) {
                XSDElementDeclaration xsdElem = (XSDElementDeclaration) term;
                if (xsdElem == decl) {
                    ((XSDParticle) obj).setTerm((XSDElementDeclaration) decl);
                    ((XSDParticle) obj).updateElement();
                }
            }
            if (!(((XSDParticle) obj).getContent() instanceof XSDElementDeclaration)) {
                continue;
            }
            XSDElementDeclaration elem = (XSDElementDeclaration) ((XSDParticle) obj).getContent();
            if (elem.isElementDeclarationReference()) {
                if (elem.getResolvedElementDeclaration() == decl) {
                    elem.setResolvedElementDeclaration((XSDElementDeclaration) decl);
                }
            }
        }
    }
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) 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) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 9 with XSDElementDeclaration

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

the class Util method getConcepts.

public static List<String> getConcepts(XSDSchema schema) {
    EList<XSDElementDeclaration> xsdElementDeclarations = schema.getElementDeclarations();
    List<String> list = new ArrayList<String>();
    for (XSDElementDeclaration el : xsdElementDeclarations.toArray(new XSDElementDeclaration[xsdElementDeclarations.size()])) {
        if (!el.getIdentityConstraintDefinitions().isEmpty()) {
            list.add(el.getName());
        }
    }
    return list;
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList)

Example 10 with XSDElementDeclaration

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

the class Util method getParent.

public static Object getParent(Object son) {
    if (!((son instanceof XSDElementDeclaration) || (son instanceof XSDParticle))) {
        return null;
    }
    XSDElementDeclaration elem = null;
    if (son instanceof XSDParticle) {
        elem = (XSDElementDeclaration) ((XSDParticle) son).getContent();
    } else if (son instanceof XSDElementDeclaration) {
        elem = (XSDElementDeclaration) son;
    }
    if (elem == null || elem.getSchema() == null) {
        return null;
    }
    EList<XSDSchemaContent> parentList = elem.getSchema().getContents();
    for (XSDSchemaContent top : parentList) {
        if (!(top instanceof XSDElementDeclaration) && !(top instanceof XSDComplexTypeDefinition)) {
            continue;
        }
        if (top instanceof XSDElementDeclaration) {
            XSDElementDeclaration decl = (XSDElementDeclaration) top;
            if (decl == son) {
                return decl;
            }
            if (decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
                XSDComplexTypeDefinition type = (XSDComplexTypeDefinition) decl.getTypeDefinition();
                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) {
                                if (((XSDElementDeclaration) pt.getContent()) == elem) {
                                    return decl;
                                }
                            }
                            Set<XSDConcreteComponent> complexTypes = new HashSet<XSDConcreteComponent>();
                            XSDElementDeclaration spec = findOutSpecialSonElement((XSDElementDeclaration) pt.getContent(), elem, complexTypes);
                            if (spec != null) {
                                return spec;
                            }
                        }
                    }
                }
            }
        } else {
            XSDComplexTypeDefinition type = (XSDComplexTypeDefinition) top;
            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) {
                            if (((XSDElementDeclaration) pt.getContent()) == elem) {
                                return top;
                            }
                        }
                        if (pt.getContent() instanceof XSDElementDeclaration) {
                            Set<XSDConcreteComponent> complexTypes = new HashSet<XSDConcreteComponent>();
                            XSDElementDeclaration spec = findOutSpecialSonElement((XSDElementDeclaration) pt.getContent(), elem, complexTypes);
                            if (spec != null) {
                                return spec;
                            }
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSchemaContent(org.eclipse.xsd.XSDSchemaContent) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) HashSet(java.util.HashSet)

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