Search in sources :

Example 21 with XSDXPathDefinition

use of org.eclipse.xsd.XSDXPathDefinition in project webtools.sourceediting by eclipse.

the class XSDCommonUIUtils method getInputXSDAnnotation.

public static XSDAnnotation getInputXSDAnnotation(XSDConcreteComponent input, boolean createIfNotExist) {
    XSDAnnotation xsdAnnotation = null;
    XSDFactory factory = XSDFactory.eINSTANCE;
    if (input instanceof XSDAttributeDeclaration) {
        XSDAttributeDeclaration xsdComp = (XSDAttributeDeclaration) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDAttributeGroupDefinition) {
        XSDAttributeGroupDefinition xsdComp = (XSDAttributeGroupDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDElementDeclaration) {
        XSDElementDeclaration xsdComp = (XSDElementDeclaration) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDNotationDeclaration) {
        XSDNotationDeclaration xsdComp = (XSDNotationDeclaration) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDXPathDefinition) {
        XSDXPathDefinition xsdComp = (XSDXPathDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDModelGroup) {
        XSDModelGroup xsdComp = (XSDModelGroup) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDModelGroupDefinition) {
        XSDModelGroupDefinition xsdComp = (XSDModelGroupDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDIdentityConstraintDefinition) {
        XSDIdentityConstraintDefinition xsdComp = (XSDIdentityConstraintDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDWildcard) {
        XSDWildcard xsdComp = (XSDWildcard) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDSchema) {
        XSDSchema xsdComp = (XSDSchema) input;
        List list = xsdComp.getAnnotations();
        if (list.size() > 0) {
            xsdAnnotation = (XSDAnnotation) list.get(0);
        } else {
            if (createIfNotExist && xsdAnnotation == null) {
                xsdAnnotation = factory.createXSDAnnotation();
                if (xsdComp.getContents() != null) {
                    xsdComp.getContents().add(0, xsdAnnotation);
                }
            }
        }
        return xsdAnnotation;
    } else if (input instanceof XSDFacet) {
        XSDFacet xsdComp = (XSDFacet) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDTypeDefinition) {
        XSDTypeDefinition xsdComp = (XSDTypeDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDInclude) {
        XSDInclude xsdComp = (XSDInclude) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDImport) {
        XSDImport xsdComp = (XSDImport) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDRedefine) {
        XSDRedefine xsdComp = (XSDRedefine) input;
        List contents = xsdComp.getContents();
        for (int i = 0; i < contents.size(); i++) {
            Object content = contents.get(i);
            if (content instanceof XSDAnnotation) {
                xsdAnnotation = (XSDAnnotation) content;
                break;
            }
        }
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            contents.add(0, xsdAnnotation);
        }
        return xsdAnnotation;
    } else if (input instanceof XSDAnnotation) {
        xsdAnnotation = (XSDAnnotation) input;
    }
    if (createIfNotExist) {
        formatAnnotation(xsdAnnotation);
    }
    return xsdAnnotation;
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDRedefine(org.eclipse.xsd.XSDRedefine) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDNotationDeclaration(org.eclipse.xsd.XSDNotationDeclaration) XSDFacet(org.eclipse.xsd.XSDFacet) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) EObject(org.eclipse.emf.ecore.EObject) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDImport(org.eclipse.xsd.XSDImport) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDSchema(org.eclipse.xsd.XSDSchema) XSDInclude(org.eclipse.xsd.XSDInclude)

Example 22 with XSDXPathDefinition

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

the class EntityKeyConfigComposite method getFieldNames.

private List<String> getFieldNames(XSDIdentityConstraintDefinition xsdIdentityConstraintDefinition) {
    List<String> fieldNames = new ArrayList<String>();
    if (xsdIdentityConstraintDefinition == null) {
        EList<XSDIdentityConstraintDefinition> identityConstraintDefinitions = entityWrapper.getSourceEntity().getIdentityConstraintDefinitions();
        for (XSDIdentityConstraintDefinition idc : identityConstraintDefinitions) {
            EList<XSDXPathDefinition> fields = idc.getFields();
            for (XSDXPathDefinition fd : fields) {
                fieldNames.add(fd.getValue());
            }
        }
    } else {
        XSDIdentityConstraintDefinition idc = xsdIdentityConstraintDefinition;
        EList<XSDXPathDefinition> fields = idc.getFields();
        for (XSDXPathDefinition fd : fields) {
            fieldNames.add(fd.getValue());
        }
    }
    return fieldNames;
}
Also used : ArrayList(java.util.ArrayList) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition)

Example 23 with XSDXPathDefinition

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

the class EntityCommitHandler method commitKeyUpdate_Fields_Removal.

private boolean commitKeyUpdate_Fields_Removal(KeyWrapper keyWrapper) {
    boolean hasChanges = false;
    for (XSDXPathDefinition eachNeedRemovedField : getNeedRemovedFields(keyWrapper)) {
        keyWrapper.getSourceKey().getFields().remove(eachNeedRemovedField);
        keyWrapper.getSourceKey().updateElement();
        hasChanges = true;
    }
    return hasChanges;
}
Also used : XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition)

Example 24 with XSDXPathDefinition

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

the class EntityCommitHandler method getNeedRemovedFields.

private XSDXPathDefinition[] getNeedRemovedFields(KeyWrapper keyWrapper) {
    List<XSDXPathDefinition> curLeftFields = new ArrayList<XSDXPathDefinition>();
    List<XSDXPathDefinition> needRemovedFields = new ArrayList<XSDXPathDefinition>();
    for (FieldWrapper eachField : keyWrapper.getFields()) {
        if (!eachField.isUserCreated()) {
            curLeftFields.add(eachField.getSourceField());
        }
    }
    for (XSDXPathDefinition eachSourceField : keyWrapper.getSourceKey().getFields()) {
        if (!curLeftFields.contains(eachSourceField)) {
            needRemovedFields.add(eachSourceField);
        }
    }
    return needRemovedFields.toArray(new XSDXPathDefinition[0]);
}
Also used : ArrayList(java.util.ArrayList) FieldWrapper(com.amalto.workbench.detailtabs.sections.model.entity.FieldWrapper) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition)

Example 25 with XSDXPathDefinition

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

the class EntityCommitHandler method commitKeyUpdate_Fields_Addition.

private boolean commitKeyUpdate_Fields_Addition(KeyWrapper keyWrapper) {
    boolean hasChanges = false;
    for (FieldWrapper eachField : keyWrapper.getFields()) {
        if (!eachField.isUserCreated()) {
            continue;
        }
        XSDXPathDefinition newXpath = XSDSchemaBuildingTools.getXSDFactory().createXSDXPathDefinition();
        newXpath.setValue(eachField.getXPath());
        newXpath.setVariety(XSDXPathVariety.FIELD_LITERAL);
        keyWrapper.getSourceKey().getFields().add(newXpath);
        keyWrapper.getSourceKey().updateElement();
        hasChanges = true;
    }
    return hasChanges;
}
Also used : FieldWrapper(com.amalto.workbench.detailtabs.sections.model.entity.FieldWrapper) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition)

Aggregations

XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)37 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)32 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)21 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)16 ArrayList (java.util.ArrayList)15 XSDParticle (org.eclipse.xsd.XSDParticle)15 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)14 XSDFactory (org.eclipse.xsd.XSDFactory)12 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)12 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)10 Iterator (java.util.Iterator)8 XSDTerm (org.eclipse.xsd.XSDTerm)8 Element (org.w3c.dom.Element)7 EList (org.eclipse.emf.common.util.EList)6 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)6 XSDSchema (org.eclipse.xsd.XSDSchema)6 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)6 TreeObject (com.amalto.workbench.models.TreeObject)5 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)5