Search in sources :

Example 1 with XSDParticle

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

the class ComplexTypeInputDialogR method valid.

private boolean valid() {
    elementName = elementNameText.getText().trim();
    if (((elementName == null) || ("".equals(elementName)))) {
        // $NON-NLS-1$
        MessageDialog.openError(this.getShell(), Messages._Error, Messages._BusinessNameCannotEmpty);
        setReturnCode(-1);
        elementNameText.setFocus();
        return false;
    }
    if (elementName.replaceAll("\\s", "").length() != elementName.length()) {
        // $NON-NLS-1$//$NON-NLS-2$
        MessageDialog.openError(this.getShell(), Messages._Error, Messages._BusinessNameCannotContainEmpty);
        setReturnCode(-1);
        elementNameText.setFocus();
        return false;
    }
    if ("".equals(minOccursText.getText()) && "".equals(maxOccursText.getText())) {
        // $NON-NLS-1$//$NON-NLS-2$
        minOccurs = 1;
        maxOccurs = 1;
        return false;
    }
    try {
        minOccurs = Integer.parseInt(minOccursText.getText());
    } catch (Exception e1) {
        MessageDialog.openError(this.getShell(), Messages._Error, Messages._MinNoLessThanZero);
        setReturnCode(-1);
        minOccursText.setFocus();
        return false;
    }
    if (minOccurs < 0) {
        MessageDialog.openError(this.getShell(), Messages._Error, Messages._MinNoLessThanZero);
        setReturnCode(-1);
        minOccursText.setFocus();
        return false;
    }
    if ("".equals(maxOccursText.getText())) {
        // $NON-NLS-1$
        maxOccurs = -1;
    } else {
        try {
            maxOccurs = Integer.parseInt(maxOccursText.getText());
        } catch (Exception e2) {
            MessageDialog.openError(this.getShell(), Messages._Error, Messages._MaxOccBeNum);
            setReturnCode(-1);
            maxOccursText.setFocus();
            return false;
        }
        if ((maxOccurs < minOccurs) || (maxOccurs <= 0)) {
            maxOccurs = -1;
        }
    }
    // get position of the selected particle in the container
    for (Iterator<XSDParticle> iter = group.getContents().iterator(); iter.hasNext(); ) {
        XSDParticle p = iter.next();
        if (p.getTerm() instanceof XSDElementDeclaration) {
            XSDElementDeclaration thisDecl = (XSDElementDeclaration) p.getTerm();
            if (thisDecl.getName().equals(elementName)) {
                MessageDialog.openError(getShell(), Messages._Error, Messages.bind(Messages._BusinessEle, elementName));
                return false;
            }
        }
    }
    // for
    String typeName = getTypeName();
    if (!"".equals(typeName)) {
        // $NON-NLS-1$
        EList<XSDTypeDefinition> list = xsdSchema.getTypeDefinitions();
        for (Iterator<XSDTypeDefinition> iter = list.iterator(); iter.hasNext(); ) {
            XSDTypeDefinition td = iter.next();
            if (td.getName().equals(typeName)) {
                if (td instanceof XSDSimpleTypeDefinition) {
                    MessageDialog.openError(getShell(), Messages._Error, Messages.bind(Messages._ThisType, typeName));
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 2 with XSDParticle

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

the class DOMViewDialog method collectKeyWords.

private void collectKeyWords(XSDElementDeclaration elementDeclaration, Set<String> keys) {
    String elementName = elementDeclaration.getName();
    keys.add(elementName);
    XSDTypeDefinition typeDefinition = elementDeclaration.getType();
    if (typeDefinition instanceof XSDComplexTypeDefinition) {
        XSDParticle particle = (XSDParticle) ((XSDComplexTypeDefinition) typeDefinition).getContent();
        XSDTerm term = particle.getTerm();
        if (term instanceof XSDModelGroup) {
            EList<XSDParticle> particles = ((XSDModelGroup) term).getContents();
            for (XSDParticle p : particles) {
                XSDTerm childTerm = p.getTerm();
                if (childTerm instanceof XSDElementDeclaration) {
                    collectKeyWords((XSDElementDeclaration) childTerm, keys);
                }
            }
        }
    }
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDTerm(org.eclipse.xsd.XSDTerm) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 3 with XSDParticle

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

the class XpathSelectDialog method getXpath.

private String getXpath(StructuredSelection sel) {
    // $NON-NLS-1$
    String path = "";
    // $NON-NLS-1$
    String totalXpath = "";
    TreeItem item;
    TreeItem[] items = domViewer.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 4 with XSDParticle

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

the class ComplexTypeWrapper method changeGroupType.

public boolean changeGroupType() {
    XSDParticle groupParticle = (XSDParticle) curXSDComplexType.getContent();
    XSDModelGroup group = (XSDModelGroup) groupParticle.getContent();
    if (group.getCompositor().equals(newGroupType))
        return false;
    group.setCompositor(newGroupType);
    group.updateElement();
    return true;
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 5 with XSDParticle

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

the class Util method getChildElements.

public static Map<String, XSDParticle> getChildElements(String parentxpath, XSDComplexTypeDefinition ctype, boolean onlyTopLevel, final Set<Object> visited) throws Exception {
    if (visited == null || ctype == null) {
        throw new IllegalArgumentException();
    }
    if (parentxpath == null) {
        // $NON-NLS-1$
        parentxpath = "";
    }
    Map<String, XSDParticle> childElements = new HashMap<String, XSDParticle>();
    XSDTypeDefinition baseType = ctype.getBaseType();
    if (!visited.contains(ctype)) {
        visited.add(ctype);
        if (baseType instanceof XSDComplexTypeDefinition && baseType != ctype) {
            XSDComplexTypeDefinition cmpType = (XSDComplexTypeDefinition) baseType;
            childElements.putAll(getChildElements(parentxpath, cmpType, onlyTopLevel, visited));
        }
        childElements.putAll(getComplexChilds(parentxpath, ctype, onlyTopLevel, visited));
    }
    return childElements;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

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