Search in sources :

Example 66 with XSDTypeDefinition

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

the class SimpleTypeInputDialog method modifyText.

public void modifyText(ModifyEvent e) {
    getButton(IDialogConstants.OK_ID).setEnabled(true);
    // $NON-NLS-1$
    infoLabel.setText("");
    String type = elemPanel.getText();
    if (// $NON-NLS-1$
    Pattern.compile("^\\s+\\w+\\s*").matcher(type).matches() || type.trim().replaceAll("\\s", "").length() != type.trim().length()) {
        // $NON-NLS-1$//$NON-NLS-2$
        infoLabel.setText(Messages.SimpleTypeInputDialog_infoLabelText);
        getButton(IDialogConstants.OK_ID).setEnabled(false);
        return;
    }
    type = type.trim();
    if (!XSDUtil.isValidatedXSDName(type)) {
        infoLabel.setText(Messages.InvalidName_Message);
        getButton(IDialogConstants.OK_ID).setEnabled(false);
        return;
    }
    for (XSDTypeDefinition simpType : xsdSchema.getTypeDefinitions()) {
        String typeToCompare = simpType.getName();
        // $NON-NLS-1$
        int delimiter = type.indexOf(" : ");
        if (delimiter != -1) {
            type = type.substring(0, delimiter);
        }
        if (typeToCompare.equals(type)) {
            if (caller instanceof XSDNewSimpleTypeDefinition) {
                infoLabel.setText(Messages.SimpleTypeInputDialog_SameName);
                getButton(IDialogConstants.OK_ID).setEnabled(false);
            } else if ((caller instanceof XSDChangeToSimpleTypeAction || caller instanceof XSDChangeBaseTypeAction) && simpType instanceof XSDComplexTypeDefinition) {
                infoLabel.setText(Messages.SimpleTypeInputDialog_SameName);
                getButton(IDialogConstants.OK_ID).setEnabled(false);
            }
            return;
        }
    }
}
Also used : XSDNewSimpleTypeDefinition(com.amalto.workbench.actions.XSDNewSimpleTypeDefinition) XSDChangeBaseTypeAction(com.amalto.workbench.actions.XSDChangeBaseTypeAction) XSDChangeToSimpleTypeAction(com.amalto.workbench.actions.XSDChangeToSimpleTypeAction) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 67 with XSDTypeDefinition

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

the class MatchRuleSelectionFilter method check.

public FilterResult check(Object obj) {
    if (obj instanceof XSDParticle) {
        XSDParticle particle = (XSDParticle) obj;
        int maxOccurs = particle.getMaxOccurs();
        if (maxOccurs > 1 || maxOccurs == -1) {
            return FilterResult.DISABLE;
        }
        XSDTerm term = particle.getTerm();
        if (term instanceof XSDElementDeclaration) {
            XSDElementDeclaration element = ((XSDElementDeclaration) term);
            XSDTypeDefinition type = element.getType();
            if (type instanceof XSDSimpleTypeDefinition) {
                return FilterResult.ENABLE;
            }
        }
    }
    return FilterResult.DISABLE;
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDTerm(org.eclipse.xsd.XSDTerm) XSDParticle(org.eclipse.xsd.XSDParticle) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 68 with XSDTypeDefinition

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

the class DataModelMainPage method validateType.

private void validateType() throws IllegalAccessException {
    HashMap<String, Boolean> typeCntMap = new HashMap<String, Boolean>();
    EList<XSDTypeDefinition> types = xsdSchema.getTypeDefinitions();
    // $NON-NLS-1$
    String tail = "";
    for (XSDTypeDefinition type : types) {
        if (type instanceof XSDComplexTypeDefinition) {
            tail = Messages.ComplexText;
        } else {
            tail = Messages.SimpleText;
        }
        if (typeCntMap.get(type.getName() + tail + type.getTargetNamespace()) == Boolean.TRUE) {
        }
        typeCntMap.put(type.getName() + tail + type.getTargetNamespace(), Boolean.TRUE);
    }
}
Also used : HashMap(java.util.HashMap) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 69 with XSDTypeDefinition

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

the class TreeExpandHelper method getExpandedTypeElements.

private Object[] getExpandedTypeElements(DataModelMainPage mainPage) {
    TreeViewer typesViewer = mainPage.getTypesViewer();
    SchemaTreeContentProvider contentProvider = (SchemaTreeContentProvider) typesViewer.getContentProvider();
    Object[] xsdDeclarations = getChildren(contentProvider.getXsdSchema(), contentProvider);
    // 
    List<Object> result = new ArrayList<Object>();
    // 
    Deque<ExpandInfoNode> nodeStack = new LinkedList<ExpandInfoNode>();
    // 
    Deque<Object> elementStack = new LinkedList<Object>();
    // record entities
    Map<ExpandInfoNode, XSDTypeDefinition> expandedRoots = new HashMap<ExpandInfoNode, XSDTypeDefinition>();
    for (Object obj : xsdDeclarations) {
        XSDTypeDefinition type = (XSDTypeDefinition) obj;
        String name = type.getName();
        for (ExpandInfoNode node : expandedTypes) {
            if (name.equals(node.name)) {
                expandedRoots.put(node, type);
                result.add(type);
                // /
                nodeStack.add(node);
                // /
                elementStack.add(type);
                break;
            }
        }
    }
    while (!nodeStack.isEmpty() && !elementStack.isEmpty()) {
        ExpandInfoNode node = nodeStack.pollFirst();
        Object element = elementStack.pollFirst();
        List<ExpandInfoNode> nodes = node.childs;
        Object[] elementChildren = getChildren(element, contentProvider);
        if (nodes != null && nodes.size() > 0 && elementChildren != null) {
            Map<ExpandInfoNode, Object> nodeElementPairs = getNodeElementPairs(elementChildren, nodes);
            for (ExpandInfoNode node2 : nodeElementPairs.keySet()) {
                nodeStack.add(node2);
                elementStack.add(nodeElementPairs.get(node2));
                result.add(nodeElementPairs.get(node2));
            }
        }
    }
    return result.toArray();
}
Also used : HashMap(java.util.HashMap) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) SchemaTreeContentProvider(com.amalto.workbench.providers.datamodel.SchemaTreeContentProvider)

Example 70 with XSDTypeDefinition

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

the class XPathTreeContentProvider method getChildren.

@Override
public Object[] getChildren(Object parent) {
    if (parent instanceof XSDSchema) {
        EList xsdElementDeclarations = xsdSchema.getElementDeclarations();
        return filterOutDuplicatedElems(xsdElementDeclarations);
    }
    if (parent instanceof XSDAttributeGroupDefinition) {
        XSDAttributeGroupDefinition attributeGroupDefinition = (XSDAttributeGroupDefinition) parent;
        if (// a ref
        attributeGroupDefinition.getContents().size() == 0)
            attributeGroupDefinition = attributeGroupDefinition.getResolvedAttributeGroupDefinition();
        return attributeGroupDefinition.getContents().toArray(new Object[attributeGroupDefinition.getContents().size()]);
    }
    if (parent instanceof XSDParticle) {
        // a particle inside a choice or sequence or whatever
        XSDParticle xsdParticle = (XSDParticle) parent;
        return getXSDParticleChildren(xsdParticle);
    }
    if (parent instanceof XSDModelGroup) {
        XSDModelGroup modelGroup = ((XSDModelGroup) parent);
        EList list = modelGroup.getContents();
        return list.toArray(new Object[list.size()]);
    }
    if (parent instanceof XSDSimpleTypeDefinition) {
        XSDSimpleTypeDefinition std = (XSDSimpleTypeDefinition) parent;
        if (std.getVariety().equals(XSDVariety.ATOMIC_LITERAL)) {
            ArrayList list = new ArrayList();
            // add Base Type if not a pre-defined type
            if (!std.getSchema().getSchemaForSchema().getTypeDefinitions().contains(std))
                list.add(std.getBaseTypeDefinition());
            list.addAll(std.getFacetContents());
            return list.toArray(new Object[list.size()]);
        }
        if (std.getVariety().equals(XSDVariety.LIST_LITERAL)) {
            // FIXME: How do we indicate it is a LIST?
            return new XSDSimpleTypeDefinition[] { std.getBaseTypeDefinition() };
        }
        if (std.getVariety().equals(XSDVariety.UNION_LITERAL))
            return std.getMemberTypeDefinitions().toArray(new XSDSimpleTypeDefinition[std.getMemberTypeDefinitions().size()]);
    // return new Object[]{std.getBaseTypeDefinition()};
    }
    if (parent instanceof XSDElementDeclaration) {
        // abstract elements do not have children
        if (((XSDElementDeclaration) parent).isAbstract())
            return new Object[0];
        ArrayList<Object> list = new ArrayList<Object>();
        // handle extensions and restrictions directly
        XSDTypeDefinition typeDefinition = ((XSDElementDeclaration) parent).getTypeDefinition();
        if (typeDefinition instanceof XSDComplexTypeDefinition) {
            list.addAll(getComplexTypeDefinitionChildren((XSDComplexTypeDefinition) typeDefinition));
        } else {
            list.add(((XSDElementDeclaration) parent).getTypeDefinition());
        }
        // }
        return list.toArray(new Object[list.size()]);
    }
    if (parent instanceof XSDIdentityConstraintDefinition) {
        ArrayList list = new ArrayList();
        return list.toArray(new Object[list.size()]);
    }
    if (parent instanceof Element) {
        // appinfos
        return new Object[0];
    }
    return new Object[0];
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) EList(org.eclipse.emf.common.util.EList) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) TreeObject(com.amalto.workbench.models.TreeObject) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema)

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