Search in sources :

Example 91 with XSDParticle

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

the class Util method isReferrenced.

private static boolean isReferrenced(XSDElementDeclaration element, XSDElementDeclaration term) {
    if (element == term) {
        return true;
    }
    if (term.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
        XSDComplexTypeContent fromcomplexType = ((XSDComplexTypeDefinition) term.getTypeDefinition()).getContent();
        if (fromcomplexType instanceof XSDParticle) {
            XSDParticle particle = (XSDParticle) fromcomplexType;
            if (particle.getTerm() instanceof XSDModelGroup) {
                XSDModelGroup modelGroup = ((XSDModelGroup) particle.getTerm());
                EList<?> fromlist = modelGroup.getContents();
                for (Object obj : fromlist) {
                    XSDTerm t = ((XSDParticle) obj).getTerm();
                    if (t == element) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDTerm(org.eclipse.xsd.XSDTerm) XObject(com.sun.org.apache.xpath.internal.objects.XObject) TreeObject(com.amalto.workbench.models.TreeObject) EObject(org.eclipse.emf.ecore.EObject) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 92 with XSDParticle

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

the class Util method getComplexTypeDefinitionChildren.

public static ArrayList<Object> getComplexTypeDefinitionChildren(XSDComplexTypeDefinition complexTypeDefinition, boolean ignoreRestriction) {
    XSDComplexTypeContent xsdComplexTypeContent = complexTypeDefinition.getContent();
    ArrayList<Object> list = new ArrayList<Object>();
    // Now determine whether ref. If ref look at the base Type definition
    XSDTypeDefinition baseTypeDefinition = complexTypeDefinition.getBaseTypeDefinition();
    if (xsdComplexTypeContent == null) {
        XSDTypeDefinition typeDefinition = baseTypeDefinition;
        // 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();
    }
    // check if we are extending a complex Definition
    if ("extension".equals(complexTypeDefinition.getDerivationMethod().getName())) {
        if (baseTypeDefinition instanceof XSDComplexTypeDefinition && baseTypeDefinition != complexTypeDefinition) {
            String name = ((XSDComplexTypeDefinition) baseTypeDefinition).getDerivationMethod().getName();
            if (name.equals("restriction") || ignoreRestriction) {
                // $NON-NLS-1$
                list.addAll(getComplexTypeDefinitionChildren((XSDComplexTypeDefinition) baseTypeDefinition, ignoreRestriction));
            // 
            }
        }
    }
    // Attributes
    if (complexTypeDefinition.getAttributeContents() != null) {
        list.addAll(complexTypeDefinition.getAttributeContents());
    }
    // Annotations
    if (complexTypeDefinition.getAnnotations() != null) {
        list.addAll(complexTypeDefinition.getAnnotations());
    }
    // 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) {
        // log.info("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) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) ArrayList(java.util.ArrayList) XObject(com.sun.org.apache.xpath.internal.objects.XObject) TreeObject(com.amalto.workbench.models.TreeObject) EObject(org.eclipse.emf.ecore.EObject) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 93 with XSDParticle

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

the class SelectXPathComposite method getXpath.

private String getXpath() {
    // $NON-NLS-1$
    String path = "";
    // $NON-NLS-1$
    String totalXpath = "";
    TreeItem item;
    TreeItem[] items = tvXPath.getTree().getSelection();
    for (int i = 0; i < items.length; i++) {
        item = items[i];
        XSDConcreteComponent component = (XSDConcreteComponent) item.getData();
        if (!(component instanceof XSDParticle) && !(component instanceof XSDElementDeclaration)) {
            continue;
        }
        do {
            component = (XSDConcreteComponent) item.getData();
            if (component instanceof XSDParticle) {
                if (((XSDParticle) component).getTerm() instanceof XSDElementDeclaration) {
                    // $NON-NLS-1$
                    path = "/" + ((XSDElementDeclaration) ((XSDParticle) component).getTerm()).getName() + path;
                }
            } else if (component instanceof XSDElementDeclaration) {
                // $NON-NLS-1$//$NON-NLS-2$
                path = (isAbsolutePath ? "/" : "") + ((XSDElementDeclaration) component).getName() + path;
            }
            item = item.getParentItem();
        } while (item != null);
        if (i == 0) {
            totalXpath = path;
        } else {
            // $NON-NLS-1$
            totalXpath += "&" + path;
        }
        // $NON-NLS-1$
        path = "";
    }
    // for(i=0
    if (context != null && conceptName != null) {
        if (totalXpath.equals(conceptName)) {
            // $NON-NLS-1$
            totalXpath = totalXpath.replaceAll(conceptName, "/");
        } else {
            // $NON-NLS-1$//$NON-NLS-2$
            totalXpath = totalXpath.replaceAll(conceptName + "/", "");
        }
        if (totalXpath.equals(context) || totalXpath.equals(context.replaceAll(conceptName + "/", ""))) {
            // $NON-NLS-1$//$NON-NLS-2$
            // $NON-NLS-1$
            totalXpath = ".";
        }
        if (// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
        totalXpath.indexOf('/') == -1 && !totalXpath.equals(".") && !"/".equals(totalXpath) && !"/".equals(context) && !context.equals(conceptName)) {
            // $NON-NLS-1$
            totalXpath = "../" + totalXpath;
        }
    }
    return totalXpath;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) TreeItem(org.eclipse.swt.widgets.TreeItem) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 94 with XSDParticle

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

the class UtilTest method testGetComponentName.

@Test
public void testGetComponentName() {
    // $NON-NLS-1$ //$NON-NLS-2$
    String prefix = "name=\"", suffix = "\"";
    String[] objNames = { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    "product_elementdeclaration", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    "product_particle", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    "p_complextype", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    "p_simpletype", "product_identityconstraintdef", // $NON-NLS-1$ //$NON-NLS-2$
    "p_xpathdef" };
    String[] expectedObjNames = new String[objNames.length];
    for (int i = 0; i < objNames.length - 1; i++) {
        expectedObjNames[i] = prefix + objNames[i] + suffix;
    }
    // $NON-NLS-1$
    expectedObjNames[objNames.length - 1] = "xpath=\"" + objNames[objNames.length - 1] + suffix;
    XSDFactory factory = XSDFactory.eINSTANCE;
    try {
        XSDElementDeclaration xsdElementDeclaration = factory.createXSDElementDeclaration();
        xsdElementDeclaration.setName(objNames[0]);
        XSDParticle xsdParticle = factory.createXSDParticle();
        XSDElementDeclaration xsdParticleDeclaration = factory.createXSDElementDeclaration();
        xsdParticleDeclaration.setName(objNames[1]);
        xsdParticle.setTerm(xsdParticleDeclaration);
        XSDComplexTypeDefinition xsdComplexTypeDefinition = factory.createXSDComplexTypeDefinition();
        xsdComplexTypeDefinition.setName(objNames[2]);
        XSDSimpleTypeDefinition xsdSimpleTypeDefinition = factory.createXSDSimpleTypeDefinition();
        xsdSimpleTypeDefinition.setName(objNames[3]);
        XSDIdentityConstraintDefinition xsdIdConsDef = factory.createXSDIdentityConstraintDefinition();
        xsdIdConsDef.setName(objNames[4]);
        XSDXPathDefinition xsdPathDefinition = factory.createXSDXPathDefinition();
        xsdPathDefinition.setValue(objNames[5]);
        String name = Util.getComponentName(xsdElementDeclaration);
        assertEquals(expectedObjNames[0], name);
        name = Util.getComponentName(xsdParticle);
        assertEquals(expectedObjNames[1], name);
        name = Util.getComponentName(xsdComplexTypeDefinition);
        assertEquals(expectedObjNames[2], name);
        name = Util.getComponentName(xsdSimpleTypeDefinition);
        assertEquals(expectedObjNames[3], name);
        name = Util.getComponentName(xsdIdConsDef);
        assertEquals(expectedObjNames[4], name);
        name = Util.getComponentName(xsdPathDefinition);
        assertEquals(expectedObjNames[5], name);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Test(org.junit.Test)

Example 95 with XSDParticle

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

the class UtilTest method testGetParticleReferenceName.

@Test
public void testGetParticleReferenceName() {
    XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) schema.getElementDeclarations().get(0).getTypeDefinition();
    XSDModelGroup group = (XSDModelGroup) ((XSDParticle) complexType.getContent()).getTerm();
    XSDParticle curXSDParticle = group.getParticles().get(0);
    String name = Util.getParticleReferenceName(curXSDParticle);
    // $NON-NLS-1$
    assertEquals(name, "");
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) Test(org.junit.Test)

Aggregations

XSDParticle (org.eclipse.xsd.XSDParticle)146 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)103 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)93 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)75 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)36 ArrayList (java.util.ArrayList)34 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)34 XSDTerm (org.eclipse.xsd.XSDTerm)31 XSDFactory (org.eclipse.xsd.XSDFactory)27 XSDComplexTypeContent (org.eclipse.xsd.XSDComplexTypeContent)24 XSDSchema (org.eclipse.xsd.XSDSchema)24 Test (org.junit.Test)23 Iterator (java.util.Iterator)21 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)21 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)19 EList (org.eclipse.emf.common.util.EList)17 XSDParticleContent (org.eclipse.xsd.XSDParticleContent)17 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)16 Element (org.w3c.dom.Element)16 List (java.util.List)15