Search in sources :

Example 6 with XSDParticleImpl

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

the class XSDChangeToComplexTypeAction method getUsablePKFields.

private List<String> getUsablePKFields(XSDComplexTypeDefinition complexType, List<XSDElementDeclaration> elementDeclarations) {
    List<String> fields = new ArrayList<String>();
    List<String> definedPKs = new ArrayList<String>();
    XSDComplexTypeDefinition rootType = (XSDComplexTypeDefinition) complexType.getRootType();
    for (XSDElementDeclaration decla : elementDeclarations) {
        if (decla.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
            XSDComplexTypeDefinition typeDefinition = (XSDComplexTypeDefinition) decla.getTypeDefinition();
            XSDTypeDefinition arootType = typeDefinition.getRootTypeDefinition();
            if (arootType == rootType) {
                recordFields(decla, definedPKs);
            }
        }
    }
    if (definedPKs.size() > 0) {
        List<XSDComplexTypeDefinition> allSuperComplexTypes = Util.getAllSuperComplexTypes(complexType);
        for (int i = allSuperComplexTypes.size() - 1; i >= 0; i--) {
            XSDComplexTypeDefinition cTypeDef = allSuperComplexTypes.get(i);
            if (cTypeDef.getContent() instanceof XSDParticle) {
                XSDParticleImpl particle = (XSDParticleImpl) cTypeDef.getContent();
                if (particle.getTerm() instanceof XSDModelGroup) {
                    XSDModelGroup group = (XSDModelGroup) particle.getTerm();
                    EList<XSDParticle> particles = group.getParticles();
                    for (XSDParticle part : particles) {
                        if (part.getTerm() instanceof XSDElementDeclaration) {
                            XSDElementDeclaration xsdDecl = (XSDElementDeclaration) part.getTerm();
                            if (definedPKs.contains(xsdDecl.getName())) {
                                fields.add(xsdDecl.getName());
                            }
                        }
                    }
                }
            }
        }
    }
    return fields;
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) XSDParticleImpl(org.eclipse.xsd.impl.XSDParticleImpl) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Aggregations

XSDParticleImpl (org.eclipse.xsd.impl.XSDParticleImpl)6 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)4 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)3 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)3 XSDParticle (org.eclipse.xsd.XSDParticle)3 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)2 XSDModelGroupImpl (org.eclipse.xsd.impl.XSDModelGroupImpl)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 XSDCompositor (org.eclipse.xsd.XSDCompositor)1 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)1