Search in sources :

Example 6 with XSDParticleContent

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

the class TypesLabelProvider method getText.

@Override
public String getText(Object obj) {
    if (obj instanceof XSDElementDeclaration) {
        String name = ((XSDElementDeclaration) obj).getName();
        if (((XSDElementDeclaration) obj).isAbstract()) {
            name += Messages.TypesLabelProvider_0;
        }
        String tail = ((XSDElementDeclaration) obj).getTargetNamespace() == null ? "" : // $NON-NLS-1$//$NON-NLS-2$
        " : " + ((XSDElementDeclaration) obj).getTargetNamespace();
        return name + tail;
    }
    if (obj instanceof XSDParticle) {
        XSDParticle xsdParticle = (XSDParticle) obj;
        XSDParticleContent content = xsdParticle.getContent();
        XSDTerm xsdTerm = xsdParticle.getTerm();
        // $NON-NLS-1$
        String name = "";
        if (content instanceof XSDElementDeclaration) {
            XSDElementDeclaration decl = (XSDElementDeclaration) content;
            // $NON-NLS-1$
            name += (decl.getName() == null ? "" : decl.getName());
            if (decl.getTypeDefinition() == null) {
                // $NON-NLS-1$//$NON-NLS-2$
                name += " [" + ((XSDElementDeclaration) xsdTerm).getName() + "]";
            }
        } else if (content instanceof XSDModelGroup) {
            // System.out.println("SHOULD NOT HAPPEN????");
            if (xsdParticle.getContainer() instanceof XSDComplexTypeDefinition) {
                String ctdName = ((XSDComplexTypeDefinition) xsdParticle.getContainer()).getName();
                // $NON-NLS-1$
                name = (ctdName != null ? ctdName : "");
            }
        /*
                 * int type = ((XSDModelGroup)xsdTerm).getCompositor().getValue(); switch (type) { case
                 * XSDCompositor.ALL: name= ""; break; case XSDCompositor.CHOICE: name= ""; break; case
                 * XSDCompositor.SEQUENCE: name= ""; break; }
                 */
        } else {
            // $NON-NLS-1$
            name = "[Any]";
        }
        if (!((xsdParticle.getMinOccurs() == 1) && (xsdParticle.getMaxOccurs() == 1))) {
            // $NON-NLS-1$
            name += "  [";
            name += xsdParticle.getMinOccurs();
            // $NON-NLS-1$
            name += "...";
            // $NON-NLS-1$//$NON-NLS-2$
            name += (xsdParticle.getMaxOccurs() == -1) ? "many" : "" + xsdParticle.getMaxOccurs();
            // $NON-NLS-1$
            name += "]";
        }
        return name;
    }
    if (obj instanceof XSDSimpleTypeDefinition) {
        return getSimpleTypeDefinition((XSDSimpleTypeDefinition) obj);
    }
    if (obj instanceof XSDComplexTypeDefinition) {
        return getComplexTypeDefinition((XSDComplexTypeDefinition) obj);
    }
    if (obj instanceof XSDModelGroup) {
        // return the name of the complex type definition
        XSDParticle particle = (XSDParticle) (((XSDModelGroup) obj).getContainer());
        XSDComplexTypeDefinition complexTypeDefinition = (XSDComplexTypeDefinition) particle.getContainer();
        String name = complexTypeDefinition.getName();
        if (name == null) {
            // $NON-NLS-1$
            name = "";
        }
        // return the occurrence
        if (!((particle.getMinOccurs() == 1) && (particle.getMaxOccurs() == 1))) {
            // $NON-NLS-1$
            name += "  [";
            name += particle.getMinOccurs();
            // $NON-NLS-1$
            name += "...";
            // $NON-NLS-1$//$NON-NLS-2$
            name += (particle.getMaxOccurs() == -1) ? "many" : "" + particle.getMaxOccurs();
            // $NON-NLS-1$
            name += "]";
        }
        XSDTypeDefinition extendType = complexTypeDefinition.getBaseTypeDefinition();
        // $NON-NLS-1$
        String extendTypeName = "";
        if (extendType != null && extendType != complexTypeDefinition && !"anyType".equals(extendType.getName())) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            extendTypeName = ":" + extendType.getName();
        }
        return name + extendTypeName;
    }
    if (obj instanceof XSDFacet) {
        // $NON-NLS-1$
        return ((XSDFacet) obj).getFacetName() + ": " + ((XSDFacet) obj).getLexicalValue();
    }
    if (obj instanceof XSDIdentityConstraintDefinition) {
        return ((XSDIdentityConstraintDefinition) obj).getName();
    }
    if (obj instanceof XSDXPathDefinition) {
        XSDXPathDefinition xpath = (XSDXPathDefinition) obj;
        return xpath.getValue();
    }
    if (obj instanceof XSDAttributeGroupDefinition) {
        XSDAttributeGroupDefinition attributeGroupDefinition = (XSDAttributeGroupDefinition) obj;
        // $NON-NLS-1$
        String name = (attributeGroupDefinition.getName() == null ? "" : attributeGroupDefinition.getName());
        if (attributeGroupDefinition.getContents().size() == 0) {
            // $NON-NLS-1$//$NON-NLS-2$
            name += " [" + attributeGroupDefinition.getResolvedAttributeGroupDefinition().getName() + "]";
        }
        return name;
    }
    if (obj instanceof XSDAttributeUse) {
        XSDAttributeUse attributeUse = (XSDAttributeUse) obj;
        String name = attributeUse.getAttributeDeclaration().getName();
        if (name == null) {
            // $NON-NLS-1$//$NON-NLS-2$
            name = " [" + attributeUse.getAttributeDeclaration().getResolvedAttributeDeclaration().getName() + "]";
        }
        return name;
    }
    if (obj instanceof XSDAnnotation) {
        // $NON-NLS-1$
        return "Annotations";
    }
    if (obj instanceof Element) {
        try {
            Element e = (Element) obj;
            if (e.getLocalName().equals("documentation")) {
                // $NON-NLS-1$
                return Messages.TypesLabelProvider_1 + e.getChildNodes().item(0).getNodeValue();
            } 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 Util.iso2lang.get(source.substring(8).toLowerCase()) + Messages.TypesLabelProvider_2 + e.getChildNodes().item(0).getNodeValue();
                    } else if (source.equals("X_ForeignKey")) {
                        // $NON-NLS-1$
                        return Messages.TypesLabelProvider_3 + e.getChildNodes().item(0).getNodeValue();
                    } else if (source.equals("X_ForeignKey_NotSep")) {
                        // $NON-NLS-1$
                        Boolean v = Boolean.valueOf(e.getChildNodes().item(0).getNodeValue());
                        return Messages.SimpleXpathInputDialog_sepFkTabPanel + Messages.TypesLabelProvider_4 + v;
                    } else if (source.equals("X_ForeignKeyInfo")) {
                        // $NON-NLS-1$
                        return Messages.TypesLabelProvider_5 + e.getChildNodes().item(0).getNodeValue();
                    } else if (source.equals("X_ForeignKey_Filter")) {
                        // $NON-NLS-1$
                        return Messages.TypesLabelProvider_6 + e.getChildNodes().item(0).getNodeValue();
                    } else if (source.equals("X_SourceSystem")) {
                        // $NON-NLS-1$
                        return Messages.TypesLabelProvider_7 + e.getChildNodes().item(0).getNodeValue();
                    } else if (source.equals("X_TargetSystem")) {
                        // $NON-NLS-1$
                        return Messages.TypesLabelProvider_8 + e.getChildNodes().item(0).getNodeValue();
                    } else if (source.startsWith("X_Description_")) {
                        // $NON-NLS-1$
                        return Util.iso2lang.get(source.substring(14).toLowerCase()) + Messages.TypesLabelProvider_9 + e.getChildNodes().item(0).getNodeValue();
                    } else if (source.equals("X_Write")) {
                        // $NON-NLS-1$
                        return Messages.TypesLabelProvider_10 + e.getChildNodes().item(0).getNodeValue();
                    } else if (source.equals("X_Deny_Create")) {
                        // $NON-NLS-1$
                        return Messages.TypesLabelProvider_11 + e.getChildNodes().item(0).getNodeValue();
                    } else if (source.equals("X_Deny_LogicalDelete")) {
                        // $NON-NLS-1$
                        return Messages.TypesLabelProvider_12 + e.getChildNodes().item(0).getNodeValue();
                    } else if (source.equals("X_Deny_PhysicalDelete")) {
                        // $NON-NLS-1$
                        return Messages.TypesLabelProvider_13 + e.getChildNodes().item(0).getNodeValue();
                    } else if (source.equals("X_Hide")) {
                        // $NON-NLS-1$
                        return Messages.TypesLabelProvider_14 + e.getChildNodes().item(0).getNodeValue();
                    } else if (source.equals("X_AutoExpand")) {
                        // $NON-NLS-1$
                        return Messages.TypesLabelProvider_15 + e.getChildNodes().item(0).getNodeValue();
                    } else if (source.equals("X_Retrieve_FKinfos")) {
                        // $NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_23, e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_FKIntegrity")) {
                        // $NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_24, e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_FKIntegrity_Override")) {
                        // $NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_25, e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_Workflow")) {
                        // $NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_16, e.getChildNodes().item(0).getNodeValue());
                    }
                    if (source.equals("X_ForeignKey_Filter")) {
                        // $NON-NLS-1$
                        String nodeValue = e.getChildNodes().item(0).getNodeValue();
                        if (nodeValue.startsWith("$CFFP:")) {
                            // $NON-NLS-1$
                            nodeValue = StringEscapeUtils.unescapeXml(nodeValue).substring(6);
                        }
                        return Messages.bind(Messages.XSDTreeLabelProvider_26, nodeValue);
                    } else {
                        // $NON-NLS-1$
                        return source + ": " + Util.nodeToString((Element) obj);
                    }
                } else {
                    return Util.nodeToString((Element) obj);
                }
            } else {
                return Util.nodeToString((Element) obj);
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
    if (obj == null) {
        // $NON-NLS-1$
        return "NULL";
    }
    // $NON-NLS-1$//$NON-NLS-2$
    return "?? " + obj.getClass().getName() + " : " + obj.toString();
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) Element(org.w3c.dom.Element) XSDParticleContent(org.eclipse.xsd.XSDParticleContent) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) XSDFacet(org.eclipse.xsd.XSDFacet) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDTerm(org.eclipse.xsd.XSDTerm) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 7 with XSDParticleContent

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

the class XSDUtil method isPrimaryKeyElement.

public static boolean isPrimaryKeyElement(XSDParticle particle) {
    if (isSimpleTypeElement(particle)) {
        Map<XSDElementDeclaration, List<XSDComplexTypeDefinition>> entityMapComplexTypes = buildEntityUsedComplexTypeMap((XSDSchema) particle.getRootContainer());
        Iterator<XSDElementDeclaration> iterator = entityMapComplexTypes.keySet().iterator();
        while (iterator.hasNext()) {
            XSDElementDeclaration concept = iterator.next();
            List<String> keyFields = getKeyFields(concept);
            if (keyFields.contains(((XSDElementDeclaration) particle.getTerm()).getName())) {
                List<XSDComplexTypeDefinition> ctypes = entityMapComplexTypes.get(concept);
                for (XSDComplexTypeDefinition ctype : ctypes) {
                    XSDComplexTypeContent ctypeContent = ctype.getContent();
                    if (ctypeContent instanceof XSDParticle) {
                        XSDParticle typeParticle = (XSDParticle) ctypeContent;
                        XSDParticleContent particleContent = typeParticle.getContent();
                        if (particleContent instanceof XSDModelGroup) {
                            XSDModelGroup particleGroup = (XSDModelGroup) particleContent;
                            if (particleGroup.getContents().contains(particle)) {
                                return true;
                            }
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDParticleContent(org.eclipse.xsd.XSDParticleContent) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) NodeList(org.w3c.dom.NodeList) EList(org.eclipse.emf.common.util.EList) List(java.util.List) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 8 with XSDParticleContent

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

the class XSDUtil method isFirstLevelChild.

public static boolean isFirstLevelChild(XSDParticle particle) {
    XSDSchema schema = (XSDSchema) particle.getRootContainer();
    Map<XSDElementDeclaration, List<XSDComplexTypeDefinition>> entityMapComplexTypes = buildEntityUsedComplexTypeMap(schema);
    Iterator<XSDElementDeclaration> iterator = entityMapComplexTypes.keySet().iterator();
    while (iterator.hasNext()) {
        XSDElementDeclaration concept = iterator.next();
        List<XSDComplexTypeDefinition> ctypes = entityMapComplexTypes.get(concept);
        for (XSDComplexTypeDefinition ctype : ctypes) {
            XSDComplexTypeContent ctypeContent = ctype.getContent();
            if (ctypeContent instanceof XSDParticle) {
                XSDParticle typeParticle = (XSDParticle) ctypeContent;
                XSDParticleContent particleContent = typeParticle.getContent();
                if (particleContent instanceof XSDModelGroup) {
                    XSDModelGroup particleGroup = (XSDModelGroup) particleContent;
                    if (particleGroup.getContents().contains(particle)) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDParticleContent(org.eclipse.xsd.XSDParticleContent) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) NodeList(org.w3c.dom.NodeList) EList(org.eclipse.emf.common.util.EList) List(java.util.List) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 9 with XSDParticleContent

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

the class XSDUtilTest method testGetAnnotationValue.

@Test
public void testGetAnnotationValue() throws Exception {
    // $NON-NLS-1$
    String fileName = "Product_0.1.xsd";
    // $NON-NLS-1$
    String elementName = "Family";
    // $NON-NLS-1$
    String fk = "Store/Id";
    String xsdString = TestUtil.readTestResource(XSDUtilTest.this.getClass(), fileName);
    assertNotNull(xsdString);
    XSDSchema xsdSchema = Util.getXSDSchema(xsdString);
    for (XSDElementDeclaration element : xsdSchema.getElementDeclarations()) {
        XSDTypeDefinition typeDefinition = element.getTypeDefinition();
        if (typeDefinition instanceof XSDComplexTypeDefinition) {
            XSDComplexTypeContent xsdComplexTypeContent = ((XSDComplexTypeDefinition) typeDefinition).getContent();
            if (xsdComplexTypeContent instanceof XSDParticle) {
                XSDParticleContent content = ((XSDParticle) xsdComplexTypeContent).getContent();
                if (content instanceof XSDModelGroup) {
                    for (XSDParticle particle : ((XSDModelGroup) content).getParticles()) {
                        XSDTerm term = particle.getTerm();
                        if (term instanceof XSDElementDeclaration) {
                            XSDElementDeclaration elementDeclaration = (XSDElementDeclaration) term;
                            if (elementDeclaration.getName().equals(elementName)) {
                                String value = XSDUtil.getAnnotationValue(elementDeclaration, X_FOREIGN_KEY);
                                assertEquals(fk, value);
                                return;
                            }
                        }
                    }
                }
            }
        }
    }
    fail();
}
Also used : XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDParticleContent(org.eclipse.xsd.XSDParticleContent) XSDTerm(org.eclipse.xsd.XSDTerm) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) Test(org.junit.Test)

Example 10 with XSDParticleContent

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

the class XSDUtilTest method testIsEntity.

@Test
public void testIsEntity() throws Exception {
    // $NON-NLS-1$
    String fileName = "Product_0.1.xsd";
    // $NON-NLS-1$
    String elementName = "Product";
    String xsdString = TestUtil.readTestResource(XSDUtilTest.this.getClass(), fileName);
    assertNotNull(xsdString);
    XSDSchema xsdSchema = Util.getXSDSchema(xsdString);
    XSDElementDeclaration decl = null;
    for (XSDElementDeclaration element : xsdSchema.getElementDeclarations()) {
        if (element.getName().equals(elementName)) {
            decl = element;
        }
        assertTrue(XSDUtil.isEntity(element));
    }
    if (decl != null) {
        XSDComplexTypeDefinition ctypeDefinition = (XSDComplexTypeDefinition) decl.getTypeDefinition();
        XSDComplexTypeContent content = ctypeDefinition.getContent();
        if (content instanceof XSDParticle) {
            XSDParticle xsdParticle = (XSDParticle) content;
            XSDParticleContent particleContent = xsdParticle.getContent();
            if (particleContent instanceof XSDModelGroup) {
                XSDModelGroup modelGroup = (XSDModelGroup) particleContent;
                EList<XSDParticle> contents = modelGroup.getContents();
                for (XSDParticle particle : contents) {
                    if (particle.getContent() instanceof XSDElementDeclaration) {
                        assertFalse(XSDUtil.isEntity(particle.getContent()));
                    }
                }
            }
        }
    }
}
Also used : XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDParticleContent(org.eclipse.xsd.XSDParticleContent) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema) Test(org.junit.Test)

Aggregations

XSDParticle (org.eclipse.xsd.XSDParticle)17 XSDParticleContent (org.eclipse.xsd.XSDParticleContent)17 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)12 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)10 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)9 XSDComplexTypeContent (org.eclipse.xsd.XSDComplexTypeContent)8 XSDSchema (org.eclipse.xsd.XSDSchema)6 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)6 List (java.util.List)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 Iterator (java.util.Iterator)3 EList (org.eclipse.emf.common.util.EList)3 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)3 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)3 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)3 XSDTerm (org.eclipse.xsd.XSDTerm)3 Element (org.w3c.dom.Element)3 LinkedList (java.util.LinkedList)2 IADTObject (org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject)2