Search in sources :

Example 21 with XSDIdentityConstraintDefinition

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

the class TypesLabelProvider method getImage.

@Override
public Image getImage(Object obj) {
    if (obj instanceof XSDElementDeclaration) {
        // top declaration
        XSDElementDeclaration decl = (XSDElementDeclaration) obj;
        // check if concept or "just" element
        boolean isConcept = false;
        EList l = decl.getIdentityConstraintDefinitions();
        for (Iterator iter = l.iterator(); iter.hasNext(); ) {
            XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) iter.next();
            if (icd.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
                isConcept = true;
                break;
            }
        }
        // display approprite image
        if (isConcept) {
            return ImageCache.getCreatedImage(EImage.CONCEPT.getPath());
        } else {
            return ImageCache.getCreatedImage(EImage.ELEMENT_ONLY.getPath());
        /*
                 * if (decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) return
                 * PlatformUI.getWorkbench().getSharedImages().getCreatedImage(ISharedImages.IMG_OBJ_FOLDER); else
                 * return ImageCache.getCreatedImage( "icons/elements_obj_+.gif");
                 */
        }
    }
    if (obj instanceof XSDParticle) {
        XSDParticle xsdParticle = (XSDParticle) obj;
        XSDTerm xsdTerm = xsdParticle.getTerm();
        if (xsdTerm instanceof XSDElementDeclaration) {
            // get Type of Parent Group
            // if (Util.getKeyInfo(xsdTerm) != null && Util.getKeyInfo(xsdTerm).size() > 0) {
            // return ImageCache.getCreatedImage(EImage.PRIMARYKEY.getPath());
            // }
            XSDConcreteComponent xsdConcreteComponent = xsdParticle.getContainer();
            if (XSDUtil.hasFKInfo((XSDElementDeclaration) xsdTerm)) {
                return ImageCache.getCreatedImage(EImage.FK_OBJ.getPath());
            }
            if (xsdConcreteComponent instanceof XSDModelGroup) {
                return ImageCache.getCreatedImage(EImage.SCHEMAELEMENT.getPath());
            }
        /*
                 * if(((XSDElementDeclaration) xsdTerm).getAnonymousTypeDefinition() instanceof
                 * XSDComplexTypeDefinition) return ImageCache.getCreatedImage( EImage.COMPLEXTYPE.getPath()); else
                 * return ImageCache.getCreatedImage( EImage.SIMPLETYPE.getPath());
                 */
        } else if (xsdTerm instanceof XSDModelGroup) {
            int type = ((XSDModelGroup) xsdTerm).getCompositor().getValue();
            switch(type) {
                case XSDCompositor.ALL:
                    return ImageCache.getCreatedImage(EImage.COMPLEX_ALL.getPath());
                case XSDCompositor.CHOICE:
                    return ImageCache.getCreatedImage(EImage.COMPLEX_CHOICE.getPath());
                case XSDCompositor.SEQUENCE:
                    return ImageCache.getCreatedImage(EImage.COMPLEX_SEQUENCE.getPath());
            }
        } else if (xsdTerm instanceof XSDWildcard) {
            // $NON-NLS-1$
            return ImageCache.getCreatedImage("icons/wildcard.gif");
        } else {
            log.info(Messages.TypesLabelProvider_16 + xsdTerm.getClass().getName());
            // $NON-NLS-1$
            return ImageCache.getCreatedImage("icons/error.gif");
        }
    }
    if (obj instanceof XSDSimpleTypeDefinition) {
        return ImageCache.getCreatedImage(EImage.SIMPLETYPE.getPath());
    }
    if (obj instanceof XSDComplexTypeDefinition) {
        XSDComplexTypeDefinition ctd = (XSDComplexTypeDefinition) obj;
        XSDComplexTypeContent ctc = ctd.getContent();
        if (ctc instanceof XSDParticle) {
            if (((XSDParticle) ctc).getTerm() instanceof XSDModelGroup) {
                int type = ((XSDModelGroup) ((XSDParticle) ctc).getTerm()).getCompositor().getValue();
                switch(type) {
                    case XSDCompositor.ALL:
                        return ImageCache.getCreatedImage(EImage.COMPLEX_ALL.getPath());
                    case XSDCompositor.CHOICE:
                        return ImageCache.getCreatedImage(EImage.COMPLEX_CHOICE.getPath());
                    case XSDCompositor.SEQUENCE:
                        return ImageCache.getCreatedImage(EImage.COMPLEX_SEQUENCE.getPath());
                }
            }
        } else {
            // $NON-NLS-1$
            return ImageCache.getCreatedImage("icons/error.gif");
        }
    }
    if (obj instanceof XSDModelGroup) {
        int type = ((XSDModelGroup) obj).getCompositor().getValue();
        switch(type) {
            case XSDCompositor.ALL:
                return ImageCache.getCreatedImage(EImage.COMPLEX_ALL.getPath());
            case XSDCompositor.CHOICE:
                return ImageCache.getCreatedImage(EImage.COMPLEX_CHOICE.getPath());
            case XSDCompositor.SEQUENCE:
                return ImageCache.getCreatedImage(EImage.COMPLEX_SEQUENCE.getPath());
        }
    }
    if (obj instanceof XSDFacet) {
        return ImageCache.getCreatedImage(EImage.FACET.getPath());
    }
    if (obj instanceof XSDIdentityConstraintDefinition) {
        XSDIdentityConstraintDefinition identity = (XSDIdentityConstraintDefinition) obj;
        if (identity.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
            return ImageCache.getCreatedImage(EImage.KEYS.getPath());
        }
        return ImageCache.getCreatedImage(EImage.PRIMARYKEY.getPath());
    }
    if (obj instanceof XSDXPathDefinition) {
        XSDXPathDefinition xpath = (XSDXPathDefinition) obj;
        if (xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL)) {
            // $NON-NLS-1$
            return ImageCache.getCreatedImage("icons/field.gif");
        }
        // $NON-NLS-1$
        return ImageCache.getCreatedImage("icons/selector.gif");
    }
    if (obj instanceof XSDAttributeGroupDefinition) {
        // $NON-NLS-1$
        return ImageCache.getCreatedImage("icons/attribute_group.gif");
    }
    if (obj instanceof XSDAttributeUse) {
        XSDAttributeUse att = (XSDAttributeUse) obj;
        if ("xmlns".equals(att.getAttributeDeclaration().getTargetNamespace())) {
            // $NON-NLS-1$
            return ImageCache.getCreatedImage(EImage.ANNOTATION.getPath());
        }
        if (att.getUse().equals(XSDAttributeUseCategory.REQUIRED_LITERAL)) {
            // $NON-NLS-1$
            return ImageCache.getCreatedImage("icons/attribute_mandatory.gif");
        } else {
            // $NON-NLS-1$
            return ImageCache.getCreatedImage("icons/attribute.gif");
        }
    }
    if (obj instanceof XSDAnnotation) {
        return ImageCache.getCreatedImage(EImage.ANNOTATION.getPath());
    }
    if (obj instanceof Element) {
        try {
            Element e = (Element) obj;
            if (e.getLocalName().equals("documentation")) {
                // $NON-NLS-1$
                return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
            } else if (e.getLocalName().equals("appinfo")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                String source = e.getAttribute("source");
                if (source != null) {
                    if (source.startsWith("X_Label_")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.LABEL.getPath());
                    } else if (source.equals("X_ForeignKey")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.FK_OBJ.getPath());
                    } else if (source.equals("X_ForeignKeyInfo")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.KEYINFO.getPath());
                    } else if (source.equals("X_FKIntegrity")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.KEYINFO.getPath());
                    } else if (source.equals("X_FKIntegrity_Override")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.KEYINFO.getPath());
                    } else if (source.equals("X_SourceSystem")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.SOURCESYSTEM.getPath());
                    } else if (source.equals("X_TargetSystem")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.TARGETSYSTEM.getPath());
                    } else if (source.startsWith("X_Description_")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
                    } else if (source.equals("X_Write")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
                    } else if (source.equals("X_Hide")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
                    } else if (source.equals("X_Deny_Create")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
                    } else if (source.equals("X_Deny_LogicalDelete")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
                    } else if (source.equals("X_Deny_PhysicalDelete")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
                    } else if (source.equals("X_AutoExpand")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.DEFAULT.getPath());
                    } else {
                        return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
                    }
                } else {
                    return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
                }
            } else {
                return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
    // $NON-NLS-1$
    return ImageCache.getCreatedImage("icons/tree_object.gif");
// return PlatformUI.getWorkbench().getSharedImages().getCreatedImage(ISharedImages.IMG_OBJ_ELEMENT);
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) Element(org.w3c.dom.Element) XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) XSDFacet(org.eclipse.xsd.XSDFacet) EList(org.eclipse.emf.common.util.EList) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Iterator(java.util.Iterator) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDTerm(org.eclipse.xsd.XSDTerm) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 22 with XSDIdentityConstraintDefinition

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

the class UtilTest method testGetRealKeyInfos.

@Test
public void testGetRealKeyInfos() throws Exception {
    XSDSchema xsdSchema = createSchema();
    XSDElementDeclaration elementDeclaration = null;
    EList<XSDElementDeclaration> declarations = xsdSchema.getElementDeclarations();
    for (XSDElementDeclaration xed : declarations) {
        if (xed.getName().equals("opo")) {
            // $NON-NLS-1$
            elementDeclaration = xed;
            break;
        }
    }
    if (elementDeclaration != null) {
        XSDComplexTypeDefinition childType = (XSDComplexTypeDefinition) elementDeclaration.getType();
        childType = (XSDComplexTypeDefinition) childType.getBaseTypeDefinition();
        childType = (XSDComplexTypeDefinition) childType.getBaseTypeDefinition();
        XSDParticle xsdParticle = (XSDParticle) childType.getContent();
        XSDModelGroup modelGroup = (XSDModelGroup) xsdParticle.getTerm();
        EList<XSDParticle> particles = modelGroup.getParticles();
        XSDParticle primaryKeyParticle = null;
        XSDParticle nonePrimaryKeyParticle = null;
        for (XSDParticle particle : particles) {
            XSDElementDeclaration term = (XSDElementDeclaration) particle.getTerm();
            if (term.getName().equals("Id")) {
                // $NON-NLS-1$
                primaryKeyParticle = particle;
                break;
            } else {
                nonePrimaryKeyParticle = particle;
            }
        }
        if (nonePrimaryKeyParticle == null) {
            nonePrimaryKeyParticle = particles.get(particles.size() - 1);
        }
        assertNull(Util.getRealKeyInfos(null, null));
        assertNull(Util.getRealKeyInfos(elementDeclaration, null));
        assertNull(Util.getRealKeyInfos(null, primaryKeyParticle));
        assertEquals(Util.getRealKeyInfos(elementDeclaration, nonePrimaryKeyParticle).size(), 0);
        List<Object> realKeyInfos = Util.getRealKeyInfos(elementDeclaration, primaryKeyParticle);
        assertNotNull(realKeyInfos);
        assertEquals(realKeyInfos.size(), 2);
        assertTrue((realKeyInfos.get(0) instanceof XSDIdentityConstraintDefinition));
        assertTrue((realKeyInfos.get(1) instanceof XSDXPathDefinition));
        // $NON-NLS-1$
        assertEquals(((XSDXPathDefinition) realKeyInfos.get(1)).getValue(), "Id");
    }
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema) Test(org.junit.Test)

Example 23 with XSDIdentityConstraintDefinition

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

the class UtilTest method testGetTopParent.

@Test
public void testGetTopParent() {
    // 
    List<Object> topParent = Util.getTopParent(null);
    assertNull(topParent);
    XSDFactory factory = XSDFactory.eINSTANCE;
    // 
    XSDElementDeclaration concept = factory.createXSDElementDeclaration();
    topParent = Util.getTopParent(concept);
    assertNull(topParent);
    // concept with three children
    // $NON-NLS-1$
    String element1 = "Id";
    // $NON-NLS-1$
    String element2 = "code";
    // $NON-NLS-1$
    String element3 = "address";
    XSDSchema xsdSchema = factory.createXSDSchema();
    xsdSchema.getContents().add(concept);
    XSDComplexTypeDefinition xsdComplexTypeDef = factory.createXSDComplexTypeDefinition();
    xsdComplexTypeDef.setBaseTypeDefinition(// $NON-NLS-1$
    xsdSchema.resolveComplexTypeDefinition(xsdSchema.getSchemaForSchemaNamespace(), "anyType"));
    concept.setAnonymousTypeDefinition(xsdComplexTypeDef);
    XSDParticle xsdParticle = factory.createXSDParticle();
    xsdComplexTypeDef.setContent(xsdParticle);
    XSDModelGroup xsdModelGroup = factory.createXSDModelGroup();
    xsdParticle.setContent(xsdModelGroup);
    XSDParticle childParticle1 = factory.createXSDParticle();
    XSDElementDeclaration childElement1 = factory.createXSDElementDeclaration();
    childElement1.setName(element1);
    childParticle1.setContent(childElement1);
    XSDParticle childParticle2 = factory.createXSDParticle();
    XSDElementDeclaration childElement2 = factory.createXSDElementDeclaration();
    childElement2.setName(element2);
    childParticle2.setContent(childElement2);
    XSDParticle childParticle3 = factory.createXSDParticle();
    XSDElementDeclaration childElement3 = factory.createXSDElementDeclaration();
    childElement3.setName(element3);
    childParticle3.setContent(childElement3);
    xsdModelGroup.getContents().add(childParticle1);
    xsdModelGroup.getContents().add(childParticle2);
    xsdModelGroup.getContents().add(childParticle3);
    XSDIdentityConstraintDefinition xsdIdConsDef = factory.createXSDIdentityConstraintDefinition();
    concept.getIdentityConstraintDefinitions().add(xsdIdConsDef);
    XSDXPathDefinition xsdXPathDefinition1 = factory.createXSDXPathDefinition();
    xsdXPathDefinition1.setValue(element1);
    XSDXPathDefinition xsdXPathDefinition2 = factory.createXSDXPathDefinition();
    xsdXPathDefinition2.setValue(element2);
    xsdIdConsDef.getFields().add(xsdXPathDefinition1);
    xsdIdConsDef.getFields().add(xsdXPathDefinition2);
    // complex type with one child
    XSDComplexTypeDefinition xsdComplexTypeDef2 = factory.createXSDComplexTypeDefinition();
    xsdComplexTypeDef2.setBaseTypeDefinition(// $NON-NLS-1$
    xsdSchema.resolveComplexTypeDefinition(xsdSchema.getSchemaForSchemaNamespace(), "anyType"));
    XSDParticle xsdParticle2 = factory.createXSDParticle();
    xsdComplexTypeDef2.setContent(xsdParticle2);
    XSDModelGroup xsdModelGroup2 = factory.createXSDModelGroup();
    xsdParticle2.setContent(xsdModelGroup2);
    XSDParticle childParticle_2 = factory.createXSDParticle();
    XSDElementDeclaration childElement_2 = factory.createXSDElementDeclaration();
    childElement_2.setName(element1);
    childParticle_2.setContent(childElement_2);
    xsdModelGroup2.getContents().add(childParticle_2);
    xsdSchema.getContents().add(xsdComplexTypeDef2);
    // 
    topParent = Util.getTopParent(childElement1);
    assertNotNull(topParent);
    assertTrue(topParent.size() == 2);
    // 
    topParent = Util.getTopParent(childElement_2);
    assertNull(topParent);
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema) Test(org.junit.Test)

Example 24 with XSDIdentityConstraintDefinition

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

the class XSDUtilTest method testGetKeyFields.

@Test
public void testGetKeyFields() throws Exception {
    XSDFactory factory = XSDFactory.eINSTANCE;
    // $NON-NLS-1$
    String conceptName = "Product";
    // $NON-NLS-1$ //$NON-NLS-2$
    String[] fields = { "Id", "code" };
    XSDElementDeclaration concept = factory.createXSDElementDeclaration();
    concept.setName(conceptName);
    XSDIdentityConstraintDefinition ideCDef = factory.createXSDIdentityConstraintDefinition();
    XSDXPathDefinition xpathDefinition1 = factory.createXSDXPathDefinition();
    xpathDefinition1.setValue(fields[0]);
    ideCDef.getFields().add(xpathDefinition1);
    concept.getIdentityConstraintDefinitions().add(ideCDef);
    List<String> keyFields = XSDUtil.getKeyFields(concept);
    assertTrue(keyFields.isEmpty());
    // 
    ideCDef.setName(conceptName);
    XSDXPathDefinition xpathDefinition2 = factory.createXSDXPathDefinition();
    xpathDefinition2.setValue(fields[1]);
    ideCDef.getFields().add(xpathDefinition2);
    keyFields = XSDUtil.getKeyFields(concept);
    assertTrue(keyFields.size() == 2);
    assertTrue(keyFields.contains(fields[0]));
    assertTrue(keyFields.contains(fields[1]));
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) Test(org.junit.Test)

Example 25 with XSDIdentityConstraintDefinition

use of org.eclipse.xsd.XSDIdentityConstraintDefinition 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)

Aggregations

XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)56 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)38 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)32 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)21 ArrayList (java.util.ArrayList)20 XSDParticle (org.eclipse.xsd.XSDParticle)19 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)18 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)18 Iterator (java.util.Iterator)15 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)14 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)13 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)13 XSDFactory (org.eclipse.xsd.XSDFactory)13 XSDSchema (org.eclipse.xsd.XSDSchema)13 EList (org.eclipse.emf.common.util.EList)12 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)11 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)10 XSDTerm (org.eclipse.xsd.XSDTerm)10 Element (org.w3c.dom.Element)10 TreeObject (com.amalto.workbench.models.TreeObject)9