Search in sources :

Example 1 with XSDComplexTypeContent

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

the class XSDParser method loadAndPrint.

/**
 * Load the XML Schema file and print the documentation based on it.
 *
 * @param xsdFile the name of an XML Schema file.
 */
public void loadAndPrint(String xsd) throws Exception {
    // XSDFactory xsdFactory = XSDFactory.eINSTANCE;
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    documentBuilderFactory.setNamespaceAware(true);
    documentBuilderFactory.setValidating(false);
    InputSource source = new InputSource(new StringReader(xsd));
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    Document document = documentBuilder.parse(source);
    XSDSchema xsdSchema = XSDSchemaImpl.createSchema(document.getDocumentElement());
    // Create a resource set and load the main schema file into it.
    // 
    /*
         * ResourceSet resourceSet = new ResourceSetImpl(); XSDResourceImpl xsdResource = (XSDResourceImpl) resourceSet
         * .getResource(URI.createFileURI(xsdFile), true);
         * 
         * XSDResourceImpl res = new XSDResourceImpl();
         * 
         * XSDSchema xsdSchema = xsdResource.getSchema();
         */
    // $NON-NLS-1$
    String elementContentHeaderDocumentation = getContentDocumentation("element-header");
    if (elementContentHeaderDocumentation != null) {
        System.out.println(elementContentHeaderDocumentation);
    }
    List all = new ArrayList(xsdSchema.getElementDeclarations());
    for (Iterator iter = all.iterator(); iter.hasNext(); ) {
        XSDElementDeclaration concept = (XSDElementDeclaration) iter.next();
        // $NON-NLS-1$ //$NON-NLS-2$
        System.out.println("CONCEPT: " + concept.getName() + "-- " + concept.getContainer().getClass().getName());
        // name of the concept in English
        XSDAnnotation annotation = concept.getAnnotation();
        if (annotation != null) {
            EList list = annotation.getApplicationInformation();
            for (Iterator iterator = list.iterator(); iterator.hasNext(); ) {
                Element appinfo = (Element) iterator.next();
                // $NON-NLS-1$
                String language = appinfo.getAttribute("source");
                if ("EN".equals(language.toUpperCase())) {
                    // $NON-NLS-1$
                    if (appinfo.getFirstChild() != null)
                        // $NON-NLS-1$
                        System.out.println("     " + appinfo.getFirstChild().getNodeValue());
                }
            }
        }
        // children
        XSDTypeDefinition typedef = concept.getTypeDefinition();
        if (typedef instanceof XSDComplexTypeDefinition) {
            XSDComplexTypeContent xsdContent = ((XSDComplexTypeDefinition) typedef).getContent();
            XSDParticle xsdParticle = (XSDParticle) xsdContent;
            // $NON-NLS-1$
            String ident = "    ";
            processParticle(xsdParticle, ident);
        }
    }
// for elements
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) EList(org.eclipse.emf.common.util.EList) DocumentBuilder(javax.xml.parsers.DocumentBuilder) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) StringReader(java.io.StringReader) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) List(java.util.List) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 2 with XSDComplexTypeContent

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

the class XSDPasteConceptAction method addAnnotationForXSDElementDeclaration.

public void addAnnotationForXSDElementDeclaration(XSDElementDeclaration fromElem, XSDElementDeclaration toElem) {
    if (fromElem.getAnnotation() != null) {
        // toElem.setAnnotation(cloneXSDAnnotation(toElem.getAnnotation(),fromElem.getAnnotation()));
        XSDAnnotationsStructure struc = new XSDAnnotationsStructure(toElem);
        addAnnotion(struc, fromElem.getAnnotation());
    }
    if (fromElem.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
        XSDComplexTypeContent fromcomplexType = ((XSDComplexTypeDefinition) fromElem.getTypeDefinition()).getContent();
        // in this situation,if not copy the complex type, the type change to simple type
        if (this.typeList.containsKey(toElem.getTypeDefinition().getName())) {
            this.copyTypeSet.add(this.typeList.get(toElem.getTypeDefinition().getName()));
        }
        if (toElem.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
            XSDComplexTypeContent tocomplexType = ((XSDComplexTypeDefinition) toElem.getTypeDefinition()).getContent();
            if (fromcomplexType instanceof XSDParticle) {
                XSDParticle fromxsdParticle = (XSDParticle) fromcomplexType;
                XSDParticle toxsdParticle = (XSDParticle) tocomplexType;
                if (fromxsdParticle.getTerm() instanceof XSDModelGroup) {
                    XSDModelGroup frommodelGroup = ((XSDModelGroup) fromxsdParticle.getTerm());
                    XSDModelGroup tomodelGroup = ((XSDModelGroup) toxsdParticle.getTerm());
                    EList<XSDParticle> fromlist = frommodelGroup.getContents();
                    EList<XSDParticle> tolist = tomodelGroup.getContents();
                    Iterator<XSDParticle> toIt = tolist.iterator();
                    for (XSDParticle fromel : fromlist.toArray(new XSDParticle[fromlist.size()])) {
                        XSDParticle toel = toIt.next();
                        XSDTerm totm = toel.getTerm();
                        XSDTerm fromtm = fromel.getTerm();
                        if (fromtm instanceof XSDElementDeclaration) {
                            XSDAnnotation fromannotation = ((XSDElementDeclaration) fromtm).getAnnotation();
                            if (fromannotation != null) {
                                // ((XSDElementDeclaration)
                                // totm).setAnnotation(cloneXSDAnnotation(((XSDElementDeclaration)
                                // totm).getAnnotation(),fromannotation));
                                XSDAnnotationsStructure struc = new XSDAnnotationsStructure(totm);
                                if (((XSDElementDeclaration) totm).getType() != null) {
                                    addAnnotion(struc, fromannotation);
                                } else {
                                    MessageDialog.openInformation(page.getSite().getShell(), Messages.Warning, Messages.bind(Messages.XSDPasteConceptAction_Information, fromElem.getName()));
                                    return;
                                }
                            }
                            if (((XSDElementDeclaration) totm).getType() != null && this.typeList.containsKey(((XSDElementDeclaration) totm).getType().getName())) {
                                this.copyTypeSet.add(this.typeList.get(((XSDElementDeclaration) totm).getType().getName()));
                            }
                            addAnnotationForXSDElementDeclaration((XSDElementDeclaration) fromtm, (XSDElementDeclaration) totm);
                        }
                    }
                }
            }
        }
    } else {
        String simpleType = fromElem.getTypeDefinition().getName();
        if (this.typeList.containsKey(simpleType)) {
            this.copyTypeSet.add(fromElem.getTypeDefinition());
        }
    }
}
Also used : XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDTerm(org.eclipse.xsd.XSDTerm) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 3 with XSDComplexTypeContent

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

the class XPathTreeContentProvider method getComplexTypeDefinitionChildren.

private ArrayList<Object> getComplexTypeDefinitionChildren(XSDComplexTypeDefinition complexTypeDefinition) {
    // System.out.println("getComplexTypeDefinitionChildren "+complexTypeDefinition+": "+complexTypeDefinition.getContent());
    // System.out.println(
    // "getComplexTypeDefinitionChildren BASE TYPE "+
    // complexTypeDefinition.getBaseTypeDefinition().getName()+" : "+
    // complexTypeDefinition.getDerivationMethod().getName()
    // );
    XSDComplexTypeContent xsdComplexTypeContent = complexTypeDefinition.getContent();
    ArrayList<Object> list = new ArrayList<Object>();
    // Now determine whether ref. If ref look at the base Type definition
    if (xsdComplexTypeContent == null) {
        XSDTypeDefinition typeDefinition = complexTypeDefinition.getBaseTypeDefinition();
        // if a simple type return the simple type
        if (typeDefinition instanceof XSDSimpleTypeDefinition) {
            list.add(typeDefinition);
            return list;
        } else {
        }
        // it is a complex Type
        xsdComplexTypeContent = ((XSDComplexTypeDefinition) typeDefinition).getContent();
    }
    // Attributes
    if (complexTypeDefinition.getAttributeContents() != null) {
        list.addAll(complexTypeDefinition.getAttributeContents());
        // XSDTypeDefinition baseTypeDef = complexTypeDefinition.getBaseTypeDefinition();
        // while (baseTypeDef instanceof XSDComplexTypeDefinition
        // && (baseTypeDef.getTargetNamespace() == null || !baseTypeDef.getTargetNamespace().equals(
        // XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001))) {
        // XSDComplexTypeDefinition parentType = (XSDComplexTypeDefinition) baseTypeDef;
        // list.addAll(((XSDComplexTypeDefinition) baseTypeDef).getAttributeContents());
        // list.addAll(getComplexTypeDefinitionChildren(parentType));
        // baseTypeDef = baseTypeDef.getBaseType();
        // }
        list.addAll(Util.getComplexTypeDefinitionChildren(complexTypeDefinition, true));
        list.removeAll(complexTypeDefinition.getAnnotations());
        return list;
    }
    // simple type return the simple type
    if (xsdComplexTypeContent instanceof XSDSimpleTypeDefinition) {
        list.add(xsdComplexTypeContent);
        return list;
    }
    // // xsd Particle: we have a model group
    // if (xsdComplexTypeContent instanceof XSDParticle) {
    // // System.out.println("Model Group?: "+((XSDParticle)xsdComplexTypeContent).getTerm());
    // if (((XSDParticle) xsdComplexTypeContent).getTerm() instanceof XSDModelGroup) {
    // // return the model group
    // list.add(((XSDParticle) xsdComplexTypeContent).getTerm());
    // return list;
    // } else { // wild card or element declaration '?)
    // list.add(((XSDParticle) xsdComplexTypeContent).getTerm());
    // return list;
    // }
    // }
    // what else could it be ?
    list.add(xsdComplexTypeContent);
    return list;
}
Also used : XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) ArrayList(java.util.ArrayList) TreeObject(com.amalto.workbench.models.TreeObject) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 4 with XSDComplexTypeContent

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

the class TypesContentProvider method getChildren.

public Object[] getChildren(Object parent) {
    if (parent instanceof XSDSchema) {
        EList xsdElementDeclarations = xsdSchema.getTypeDefinitions();
        List<XSDTypeDefinition> list = new ArrayList<XSDTypeDefinition>();
        for (XSDTypeDefinition el : (XSDTypeDefinition[]) xsdElementDeclarations.toArray(new XSDTypeDefinition[xsdElementDeclarations.size()])) {
            // if( el instanceof XSDComplexTypeDefinition){
            boolean exist = false;
            for (XSDTypeDefinition type : list) {
                if (type.getName().equals(el.getName()) && type.getTargetNamespace() != null && el.getTargetNamespace() != null && type.getTargetNamespace().equals(el.getTargetNamespace())) {
                    exist = true;
                    break;
                } else if (type.getName().equals(el.getName()) && type.getTargetNamespace() == null && el.getTargetNamespace() == null) {
                    exist = true;
                    break;
                }
            }
            if (!exist && (el.getTargetNamespace() != null && !el.getTargetNamespace().equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001)) || el.getTargetNamespace() == null) {
                list.add(el);
            }
        // }
        }
        // }
        return list.toArray(new XSDTypeDefinition[list.size()]);
    // return xsdElementDeclarations.toArray(new XSDTypeDefinition[xsdElementDeclarations.size()] );
    }
    if (parent instanceof XSDAttributeGroupDefinition) {
        XSDAttributeGroupDefinition attributeGroupDefinition = (XSDAttributeGroupDefinition) parent;
        if (// a ref
        attributeGroupDefinition.getContents().size() == 0)
            attributeGroupDefinition = attributeGroupDefinition.getResolvedAttributeGroupDefinition();
        return attributeGroupDefinition.getContents().toArray(new Object[attributeGroupDefinition.getContents().size()]);
    }
    if (parent instanceof XSDParticle) {
        // a particle inside a choice or sequence or whatever
        XSDParticle xsdParticle = (XSDParticle) parent;
        return getXSDParticleChildren(xsdParticle);
    }
    if (parent instanceof XSDTypeDefinition) {
        if (parent instanceof XSDSimpleTypeDefinition) {
            XSDSimpleTypeDefinition std = (XSDSimpleTypeDefinition) parent;
            if (std.getVariety().equals(XSDVariety.ATOMIC_LITERAL)) {
                ArrayList list = new ArrayList();
                // add Base Type if not a pre-defined type
                if (std != null && std.getSchema() != null && std.getSchema().getSchemaForSchema() != null)
                    if (!std.getSchema().getSchemaForSchema().getTypeDefinitions().contains(std))
                        list.add(std.getBaseTypeDefinition());
                list.addAll(std.getFacetContents());
                return list.toArray(new Object[list.size()]);
            }
            if (std.getVariety().equals(XSDVariety.LIST_LITERAL)) {
                // FIXME: How do we indicate it is a LIST?
                return new XSDSimpleTypeDefinition[] { std.getBaseTypeDefinition() };
            }
            if (std.getVariety().equals(XSDVariety.UNION_LITERAL))
                return (XSDSimpleTypeDefinition[]) (std.getMemberTypeDefinitions().toArray(new XSDSimpleTypeDefinition[std.getMemberTypeDefinitions().size()]));
        // return new Object[]{std.getBaseTypeDefinition()};
        }
        if (parent instanceof XSDComplexTypeDefinition) {
            XSDComplexTypeContent xsdComplexTypeContent = ((XSDComplexTypeDefinition) parent).getContent();
            ArrayList<Object> list = new ArrayList<Object>();
            list.addAll(((XSDComplexTypeDefinition) parent).getAttributeContents());
            if (xsdComplexTypeContent == null) {
                XSDComplexTypeDefinition ctd = (XSDComplexTypeDefinition) parent;
                list.add(ctd.getBaseTypeDefinition());
                return list.toArray(new Object[list.size()]);
            } else {
                if (xsdComplexTypeContent instanceof XSDSimpleTypeDefinition) {
                    list.add(xsdComplexTypeContent);
                    return list.toArray(new Object[list.size()]);
                }
                if (xsdComplexTypeContent instanceof XSDParticle)
                    return getXSDParticleChildren((XSDParticle) xsdComplexTypeContent);
                // return children
                list.add(((XSDComplexTypeDefinition) parent).getContent());
                return list.toArray(new Object[list.size()]);
            }
        }
    }
    if (parent instanceof XSDModelGroup) {
        XSDModelGroup modelGroup = ((XSDModelGroup) parent);
        EList list = modelGroup.getContents();
        List<XSDParticle> ls = new ArrayList<XSDParticle>();
        if (filter != null && !filter.isAll()) {
            for (XSDParticle el : (XSDParticle[]) list.toArray(new XSDParticle[list.size()])) {
                XSDTerm tm = el.getTerm();
                if (tm instanceof XSDElementDeclaration) {
                    XSDAnnotation annotation = ((XSDElementDeclaration) tm).getAnnotation();
                    if (isInclude(annotation)) {
                        ls.add(el);
                    }
                }
            }
            return ls.toArray(new XSDParticle[ls.size()]);
        }
        return list.toArray(new Object[list.size()]);
    }
    if (parent instanceof XSDSimpleTypeDefinition) {
        XSDSimpleTypeDefinition std = (XSDSimpleTypeDefinition) parent;
        if (std.getVariety().equals(XSDVariety.ATOMIC_LITERAL)) {
            ArrayList list = new ArrayList();
            // add Base Type if not a pre-defined type
            if (!std.getSchema().getSchemaForSchema().getTypeDefinitions().contains(std))
                list.add(std.getBaseTypeDefinition());
            list.addAll(std.getFacetContents());
            return list.toArray(new Object[list.size()]);
        }
        if (std.getVariety().equals(XSDVariety.LIST_LITERAL)) {
            // FIXME: How do we indicate it is a LIST?
            return new XSDSimpleTypeDefinition[] { std.getBaseTypeDefinition() };
        }
        if (std.getVariety().equals(XSDVariety.UNION_LITERAL))
            return std.getMemberTypeDefinitions().toArray(new XSDSimpleTypeDefinition[std.getMemberTypeDefinitions().size()]);
    // return new Object[]{std.getBaseTypeDefinition()};
    }
    if (parent instanceof XSDIdentityConstraintDefinition) {
        ArrayList list = new ArrayList();
        if (filter != null && !filter.isAll()) {
        } else {
            list.add(((XSDIdentityConstraintDefinition) parent).getSelector());
            list.addAll(((XSDIdentityConstraintDefinition) parent).getFields());
        }
        return list.toArray(new Object[list.size()]);
    }
    if (parent instanceof XSDAnnotation) {
        ArrayList list = new ArrayList();
        if (filter != null && !filter.isAll()) {
        } else {
            XSDAnnotation annotation = (XSDAnnotation) parent;
            list.addAll(annotation.getUserInformation());
            list.addAll(annotation.getApplicationInformation());
        }
        return list.size() == 0 ? new Object[0] : list.toArray(new Object[list.size()]);
    }
    if (parent instanceof Element) {
        // appinfos
        return new Object[0];
    }
    return new Object[0];
}
Also used : XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) EList(org.eclipse.emf.common.util.EList) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDTerm(org.eclipse.xsd.XSDTerm) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) TreeObject(com.amalto.workbench.models.TreeObject) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 5 with XSDComplexTypeContent

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

Aggregations

XSDComplexTypeContent (org.eclipse.xsd.XSDComplexTypeContent)26 XSDParticle (org.eclipse.xsd.XSDParticle)24 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)22 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)20 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)16 ArrayList (java.util.ArrayList)10 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)10 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)9 XSDParticleContent (org.eclipse.xsd.XSDParticleContent)8 XSDTerm (org.eclipse.xsd.XSDTerm)8 EList (org.eclipse.emf.common.util.EList)7 XSDSchema (org.eclipse.xsd.XSDSchema)7 TreeObject (com.amalto.workbench.models.TreeObject)6 Iterator (java.util.Iterator)6 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)6 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)5 List (java.util.List)4 EObject (org.eclipse.emf.ecore.EObject)4 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)4 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)4