Search in sources :

Example 1 with XSDTypeDefinition

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

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

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

the class NewConceptOrElementDialog method validateType.

private void validateType(String typeName, boolean forConcept) {
    getButton(IDialogConstants.OK_ID).setEnabled(true);
    // $NON-NLS-1$
    infoLabel.setText("");
    for (XSDTypeDefinition specType : schema.getTypeDefinitions()) {
        if (forConcept && specType instanceof XSDSimpleTypeDefinition) {
            continue;
        } else if (!forConcept && specType instanceof XSDComplexTypeDefinition) {
            continue;
        }
        String typeToCompare = typeName;
        // $NON-NLS-1$
        int delimiter = typeToCompare.indexOf(" : ");
        if (delimiter != -1) {
            typeToCompare = typeToCompare.substring(0, delimiter);
        }
        if (typeToCompare.equals(specType.getName())) {
            infoLabel.setText(Messages.NewConceptOrElementDialog_SameTypeNameAlreadyExists);
            getButton(IDialogConstants.OK_ID).setEnabled(false);
            return;
        }
    }
}
Also used : XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 4 with XSDTypeDefinition

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

Example 5 with XSDTypeDefinition

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

the class Util method getComplexTypes.

public static List<XSDComplexTypeDefinition> getComplexTypes(XSDSchema xsd) {
    EList<XSDTypeDefinition> contents = xsd.getTypeDefinitions();
    List<XSDComplexTypeDefinition> complexs = new ArrayList<XSDComplexTypeDefinition>();
    for (XSDTypeDefinition type : contents) {
        if (type instanceof XSDComplexTypeDefinition) {
            boolean exist = false;
            for (XSDComplexTypeDefinition xsdEl : complexs) {
                if (xsdEl.getName().equals(type.getName()) && xsdEl.getTargetNamespace() != null && type.getTargetNamespace() != null && xsdEl.getTargetNamespace().equals(type.getTargetNamespace())) {
                    exist = true;
                    break;
                } else if (xsdEl.getTargetNamespace() == null && type.getTargetNamespace() == null && xsdEl.getName().equals(type.getName())) {
                    exist = true;
                    break;
                }
            }
            if (!exist && ((type.getTargetNamespace() != null && !type.getTargetNamespace().equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001)) || type.getTargetNamespace() == null)) {
                complexs.add((XSDComplexTypeDefinition) type);
            }
        }
    }
    return complexs;
}
Also used : ArrayList(java.util.ArrayList) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Aggregations

XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)119 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)66 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)57 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)46 ArrayList (java.util.ArrayList)39 XSDParticle (org.eclipse.xsd.XSDParticle)36 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)32 Iterator (java.util.Iterator)26 XSDSchema (org.eclipse.xsd.XSDSchema)26 List (java.util.List)22 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)17 EList (org.eclipse.emf.common.util.EList)16 TreeObject (com.amalto.workbench.models.TreeObject)14 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)14 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)13 XSDTerm (org.eclipse.xsd.XSDTerm)13 XSDFactory (org.eclipse.xsd.XSDFactory)12 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)11 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)10 XSDComplexTypeContent (org.eclipse.xsd.XSDComplexTypeContent)10