Search in sources :

Example 81 with XSDParticle

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

the class XSDAnnotationsStructure method setAutoExpand.

/**
 **************************************************************************
 * Auto Expand
 * @throws Exception
 ***************************************************************************
 */
public boolean setAutoExpand(String value) throws Exception {
    if (!(declaration.getTypeDefinition() instanceof XSDComplexTypeDefinition)) {
        return false;
    }
    XSDSchema xsd = schema != null ? schema : declaration.getSchema();
    // $NON-NLS-1$
    String auto = "X_AutoExpand";
    String xsdString = Util.nodeToString(xsd.getDocument().getDocumentElement());
    ArrayList<Object> objs = Util.getAllComplexTypeChildren(declaration);
    for (Object obj : objs) {
        if (obj instanceof XSDElementDeclaration || obj instanceof XSDParticle) {
            boolean isImported = false;
            if (obj instanceof XSDParticle) {
                XSDParticle particle = (XSDParticle) obj;
                if (particle.getTerm() instanceof XSDElementDeclaration) {
                    XSDElementDeclaration decl = (XSDElementDeclaration) particle.getTerm();
                    if (Util.IsAImporedElement(decl, xsdString)) {
                        XSDTypeDefinition typeDef = decl.getTypeDefinition();
                        if (Util.IsAImporedElement(typeDef, xsdString)) {
                            isImported = true;
                        }
                    }
                }
            } else if (obj instanceof XSDElementDeclaration) {
                XSDElementDeclaration decl = (XSDElementDeclaration) obj;
                if (Util.IsAImporedElement(decl, xsdString)) {
                    isImported = true;
                }
            }
            if (!isImported) {
                XSDAnnotationsStructure annotion = new XSDAnnotationsStructure((XSDComponent) obj);
                annotion.setAppInfo(auto, value, true);
            }
        }
    }
    return true;
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 82 with XSDParticle

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

the class XSDAnnotationsStructure method setAccessRole.

/**
 **************************************************************************
 * WRITE ACCESS
 *
 * @throws XtentisException
 ***************************************************************************
 */
public boolean setAccessRole(Collection<String> roles, boolean recursive, IStructuredContentProvider provider, String access) throws Exception {
    XSDSchema xsd = schema != null ? schema : declaration.getSchema();
    String xsdString = Util.nodeToString(xsd.getDocument().getDocumentElement());
    if (recursive) {
        ArrayList<Object> objList = new ArrayList<Object>();
        XSDComponent component = declaration;
        if (declaration == null) {
            component = this.componet;
        }
        Object[] objs = Util.getAllObject(component, objList, provider);
        while (objs.length > 0) {
            Object[] objCpys = objs;
            for (Object obj : objCpys) {
                if (obj instanceof XSDElementDeclaration || obj instanceof XSDParticle) {
                    boolean isImported = false;
                    if (obj instanceof XSDParticle) {
                        XSDParticle particle = (XSDParticle) obj;
                        if (particle.getTerm() instanceof XSDElementDeclaration) {
                            XSDElementDeclaration decl = (XSDElementDeclaration) particle.getTerm();
                            if (Util.IsAImporedElement(decl, xsdString)) {
                                XSDTypeDefinition typeDef = decl.getTypeDefinition();
                                if (Util.IsAImporedElement(typeDef, xsdString)) {
                                    isImported = true;
                                }
                            }
                        }
                    } else if (obj instanceof XSDElementDeclaration) {
                        XSDElementDeclaration decl = (XSDElementDeclaration) obj;
                        if (Util.IsAImporedElement(decl, xsdString)) {
                            isImported = true;
                        }
                    }
                    if (!isImported) {
                        XSDAnnotationsStructure annotion = new XSDAnnotationsStructure((XSDComponent) obj);
                        // see 7993, if UUID/AUTO_INCREMENT ,should not add write access
                        if (obj instanceof XSDParticle) {
                            XSDParticle o = (XSDParticle) obj;
                            // String name=Util.getFirstTextNode(o.getElement(), "@name");
                            // $NON-NLS-1$
                            String type = Util.getFirstTextNode(o.getElement(), "@type");
                            if (EUUIDCustomType.AUTO_INCREMENT.equals(type) || EUUIDCustomType.UUID.equals(type)) {
                                objList.remove(obj);
                                objs = objList.toArray();
                                continue;
                            }
                        }
                        // X_Write
                        annotion.removeAppInfos(access);
                        for (Iterator<String> iter = roles.iterator(); iter.hasNext(); ) {
                            String role = iter.next();
                            annotion.addAppInfo(access, role);
                        }
                    }
                }
                objList.remove(obj);
                objs = objList.toArray();
            }
        }
        return setAccessRole(roles, access);
    } else {
        if (Util.IsAImporedElement(declaration, xsdString)) {
            return false;
        }
        return setAccessRole(roles, access);
    }
}
Also used : ArrayList(java.util.ArrayList) XSDComponent(org.eclipse.xsd.XSDComponent) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 83 with XSDParticle

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

the class XSDGenerateHTML method printParticle.

/**
 * Print a particle with markup for the document.
 *
 * @param xsdParticle a particle.
 * @param rootElementDeclarationMarkup the markup.
 */
public void printParticle(XSDParticle xsdParticle, String rootElementDeclarationMarkup) {
    int minOccurs = xsdParticle.getMinOccurs();
    int maxOccurs = xsdParticle.getMaxOccurs();
    XSDTerm xsdTerm = xsdParticle.getTerm();
    if (xsdTerm instanceof XSDElementDeclaration) {
        XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration) xsdTerm;
        String elementDeclarationName = xsdElementDeclaration.getName();
        String elementDeclarationMarkup = null;
        if (rootElementDeclarationMarkup == null) {
            elementDeclarationMarkup = getElementDeclarationMarkup(elementDeclarationName);
        }
        if (elementDeclarationMarkup != null) {
            // $NON-NLS-1$
            System.out.print("<span class='");
            System.out.print(elementDeclarationMarkup);
            // $NON-NLS-1$
            System.out.print("'>");
        }
        // $NON-NLS-1$ //$NON-NLS-2$
        System.out.print("<a href='#" + getLocalAnchor(xsdElementDeclaration) + "'>");
        System.out.print(elementDeclarationName.charAt(0));
        // $NON-NLS-1$
        System.out.print("</a>");
        System.out.print(elementDeclarationName.substring(1));
        if (elementDeclarationMarkup != null) {
            // $NON-NLS-1$
            System.out.print("</span>");
        }
        if (minOccurs == 0) {
            if (maxOccurs == 1) {
                // $NON-NLS-1$
                System.out.print("?");
            } else {
                // $NON-NLS-1$
                System.out.print("*");
            }
        } else if (maxOccurs == -1) {
            // $NON-NLS-1$
            System.out.print("+");
        }
    } else if (xsdTerm instanceof XSDModelGroup) {
        XSDModelGroup xsdModelGroup = (XSDModelGroup) xsdTerm;
        List particles = xsdModelGroup.getParticles();
        boolean isRedundant = particles.size() == 1 && minOccurs == 1 && maxOccurs == 1 && ((XSDParticle) particles.get(0)).getTerm() instanceof XSDModelGroup;
        if (!isRedundant) {
            // ) //$NON-NLS-1$
            System.out.print("(");
        }
        String separator = // $NON-NLS-1$
        XSDCompositor.CHOICE_LITERAL == xsdModelGroup.getCompositor() ? // $NON-NLS-1$
        " | " : // $NON-NLS-1$ //$NON-NLS-2$
        XSDCompositor.SEQUENCE_LITERAL == xsdModelGroup.getCompositor() ? ",  " : "  &  ";
        for (Iterator i = xsdModelGroup.getParticles().iterator(); i.hasNext(); ) {
            XSDParticle childParticle = (XSDParticle) i.next();
            printParticle(childParticle, rootElementDeclarationMarkup);
            if (i.hasNext()) {
                System.out.print(separator);
            }
        }
        if (!isRedundant) {
            // (
            // $NON-NLS-1$
            System.out.print(")");
            if (minOccurs == 0) {
                if (maxOccurs == 1) {
                    // $NON-NLS-1$
                    System.out.print("?");
                } else {
                    // $NON-NLS-1$
                    System.out.print("*");
                }
            } else if (maxOccurs == -1) {
                // $NON-NLS-1$
                System.out.print("+");
            }
        }
    } else if (xsdTerm instanceof XSDWildcard) {
        // $NON-NLS-1$
        System.out.print("<em>{any}</em>");
    }
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Iterator(java.util.Iterator) XSDTerm(org.eclipse.xsd.XSDTerm) XSDWildcard(org.eclipse.xsd.XSDWildcard) List(java.util.List) ArrayList(java.util.ArrayList) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 84 with XSDParticle

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

the class XSDParser method processParticle.

public void processParticle(XSDParticle xsdParticle, String ident) {
    int minOccurs = xsdParticle.getMinOccurs();
    int maxOccurs = xsdParticle.getMaxOccurs();
    XSDTerm xsdTerm = xsdParticle.getTerm();
    if (xsdTerm instanceof XSDElementDeclaration) {
        XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration) xsdTerm;
        String elementDeclarationName = xsdElementDeclaration.getName();
        System.out.print(elementDeclarationName);
        if (minOccurs == 0) {
            if (maxOccurs == 1) {
                // $NON-NLS-1$
                System.out.print("?");
            } else {
                // $NON-NLS-1$
                System.out.print("*");
            }
        } else if (maxOccurs == -1) {
            // $NON-NLS-1$
            System.out.print("+");
        }
        System.out.println(// $NON-NLS-1$
        "  -- root Container: " + ((XSDParticle) xsdElementDeclaration.getContainer()).getTerm().getClass().getName());
    } else if (xsdTerm instanceof XSDModelGroup) {
        XSDModelGroup xsdModelGroup = (XSDModelGroup) xsdTerm;
        List particles = xsdModelGroup.getParticles();
        String separator = // $NON-NLS-1$
        XSDCompositor.CHOICE_LITERAL == xsdModelGroup.getCompositor() ? // $NON-NLS-1$
        "|" : // $NON-NLS-1$ //$NON-NLS-2$
        XSDCompositor.SEQUENCE_LITERAL == xsdModelGroup.getCompositor() ? "&" : "a";
        for (Iterator it = particles.iterator(); it.hasNext(); ) {
            XSDParticle childParticle = (XSDParticle) it.next();
            // $NON-NLS-1$ //$NON-NLS-2$
            System.out.print(ident + "[" + separator + "]");
            // $NON-NLS-1$
            processParticle(childParticle, ident + "    ");
        }
        if (minOccurs == 0) {
            if (maxOccurs == 1) {
                // $NON-NLS-1$
                System.out.print("?");
            } else {
                // $NON-NLS-1$
                System.out.print("*");
            }
        } else if (maxOccurs == -1) {
            // $NON-NLS-1$
            System.out.print("+");
        }
        System.out.println();
    } else if (xsdTerm instanceof XSDWildcard) {
        // $NON-NLS-1$
        System.out.print("<em>{any}</em>");
    }
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Iterator(java.util.Iterator) XSDTerm(org.eclipse.xsd.XSDTerm) XSDWildcard(org.eclipse.xsd.XSDWildcard) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) List(java.util.List) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 85 with XSDParticle

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

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