Search in sources :

Example 56 with XSDTypeDefinition

use of org.eclipse.xsd.XSDTypeDefinition in project webtools.sourceediting by eclipse.

the class TypesHelper method getBuiltInTypeNamesList2.

// issue (cs) do we still need this?  it can likely be remove now
// was used for content assist but I don't think we really need it
public java.util.List getBuiltInTypeNamesList2() {
    List result = new ArrayList();
    if (xsdSchema != null) {
        List prefixes = getPrefixesForNamespace(xsdSchema.getSchemaForSchemaNamespace());
        XSDSchema schemaForSchema = XSDSchemaImpl.getSchemaForSchema(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
        for (Iterator i = schemaForSchema.getSimpleTypeIdMap().values().iterator(); i.hasNext(); ) {
            XSDTypeDefinition td = (XSDTypeDefinition) i.next();
            String localName = td.getName();
            String prefix = prefixes.size() > 0 ? (String) prefixes.get(0) : null;
            String prefixedName = (prefix != null && prefix.length() > 0) ? prefix + ":" + localName : localName;
            result.add(prefixedName);
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) XSDSchema(org.eclipse.xsd.XSDSchema) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 57 with XSDTypeDefinition

use of org.eclipse.xsd.XSDTypeDefinition in project webtools.sourceediting by eclipse.

the class TypesHelper method getBuiltInTypeNamesList.

// TODO This method and it's very similar getBuiltInTypeNamesList2 should
// be reviewed and combined if possible. Both seem to be used from
// XSDModelQueryExtension for content assist purposes.
public java.util.List getBuiltInTypeNamesList() {
    List items = new ArrayList();
    if (xsdSchema != null) {
        String prefix = xsdSchema.getSchemaForSchemaQNamePrefix();
        if (xsdSchema != null) {
            XSDSchema schemaForSchema = XSDSchemaImpl.getSchemaForSchema(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
            for (Iterator i = schemaForSchema.getSimpleTypeIdMap().values().iterator(); i.hasNext(); ) {
                XSDTypeDefinition td = (XSDTypeDefinition) i.next();
                String localName = td.getName();
                String prefixedName = (prefix != null && prefix.length() > 0) ? prefix + ":" + localName : localName;
                items.add(prefixedName);
            }
        }
    }
    return items;
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) XSDSchema(org.eclipse.xsd.XSDSchema) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 58 with XSDTypeDefinition

use of org.eclipse.xsd.XSDTypeDefinition in project webtools.sourceediting by eclipse.

the class OpenOnSelectionHelper method openOnGlobalReference.

public XSDNamedComponent openOnGlobalReference(XSDConcreteComponent comp) {
    XSDSchema schema = xsdSchema;
    String name = null;
    String namespace = null;
    if (comp instanceof XSDNamedComponent) {
        name = ((XSDNamedComponent) comp).getName();
        namespace = ((XSDNamedComponent) comp).getTargetNamespace();
    }
    if (name == null) {
        // For Anonymous types, just show the element
        if (comp instanceof XSDTypeDefinition) {
            XSDTypeDefinition type = (XSDTypeDefinition) comp;
            comp = type.getContainer();
            if (comp instanceof XSDNamedComponent) {
                name = ((XSDNamedComponent) comp).getName();
                namespace = ((XSDNamedComponent) comp).getTargetNamespace();
            }
        }
    }
    if (schema == null || name == null) {
        return null;
    }
    List objects = null;
    if (comp instanceof XSDElementDeclaration) {
        objects = schema.getElementDeclarations();
    } else if (comp instanceof XSDTypeDefinition) {
        objects = schema.getTypeDefinitions();
    } else if (comp instanceof XSDAttributeGroupDefinition) {
        objects = schema.getAttributeGroupDefinitions();
    } else if (comp instanceof XSDIdentityConstraintDefinition) {
        objects = schema.getIdentityConstraintDefinitions();
    } else if (comp instanceof XSDModelGroupDefinition) {
        objects = schema.getModelGroupDefinitions();
    } else if (comp instanceof XSDAttributeDeclaration) {
        objects = schema.getAttributeDeclarations();
    }
    if (objects != null) {
        if (namespace != null) {
            // First, look for a namespace and name match
            for (Iterator iter = objects.iterator(); iter.hasNext(); ) {
                XSDNamedComponent namedComp = (XSDNamedComponent) iter.next();
                String targetNamespace = namedComp.getTargetNamespace();
                if (namedComp.getName().equals(name) && targetNamespace != null && targetNamespace.equals(namespace)) {
                    revealObject(namedComp);
                    return namedComp;
                }
            }
        }
        // Next, look for just a name match
        for (Iterator iter = objects.iterator(); iter.hasNext(); ) {
            XSDNamedComponent namedComp = (XSDNamedComponent) iter.next();
            if (namedComp.getName().equals(name)) {
                revealObject(namedComp);
                return namedComp;
            }
        }
    }
    return null;
}
Also used : XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Iterator(java.util.Iterator) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) List(java.util.List) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDSchema(org.eclipse.xsd.XSDSchema) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition)

Example 59 with XSDTypeDefinition

use of org.eclipse.xsd.XSDTypeDefinition in project webtools.sourceediting by eclipse.

the class OpenOnSelectionHelper method openOnSelection.

public boolean openOnSelection() {
    List selectedNodes = null;
    ISelection selection = textEditor.getSelectionProvider().getSelection();
    if (selection instanceof IStructuredSelection) {
        selectedNodes = ((IStructuredSelection) selection).toList();
    }
    if (selectedNodes != null && !selectedNodes.isEmpty()) {
        for (Iterator i = selectedNodes.iterator(); i.hasNext(); ) {
            Object obj = i.next();
            if (xsdSchema != null) {
                XSDConcreteComponent xsdComp = xsdSchema.getCorrespondingComponent((Node) obj);
                XSDConcreteComponent objectToReveal = null;
                if (xsdComp instanceof XSDElementDeclaration) {
                    XSDElementDeclaration elementDecl = (XSDElementDeclaration) xsdComp;
                    if (elementDecl.isElementDeclarationReference()) {
                        objectToReveal = elementDecl.getResolvedElementDeclaration();
                    } else {
                        XSDConcreteComponent typeDef = null;
                        if (elementDecl.getAnonymousTypeDefinition() == null) {
                            typeDef = elementDecl.getTypeDefinition();
                        }
                        XSDConcreteComponent subGroupAffiliation = elementDecl.getSubstitutionGroupAffiliation();
                        if (typeDef != null && subGroupAffiliation != null) {
                            // then jump to that, otherwise just go to the typeDef.
                            if (obj instanceof Attr && ((Attr) obj).getLocalName().equals(XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE)) {
                                objectToReveal = subGroupAffiliation;
                            } else {
                                // if we fail, set the substitution group as the object to reveal as a backup plan.
                                if (revealObject(typeDef)) {
                                    return true;
                                } else {
                                    objectToReveal = subGroupAffiliation;
                                }
                            }
                        } else {
                            // one or more of these is null.  If the typeDef is non-null, use it.  Otherwise
                            // try and use the substitution group
                            objectToReveal = typeDef != null ? typeDef : subGroupAffiliation;
                        }
                    }
                } else if (xsdComp instanceof XSDModelGroupDefinition) {
                    XSDModelGroupDefinition elementDecl = (XSDModelGroupDefinition) xsdComp;
                    if (elementDecl.isModelGroupDefinitionReference()) {
                        objectToReveal = elementDecl.getResolvedModelGroupDefinition();
                    }
                } else if (xsdComp instanceof XSDAttributeDeclaration) {
                    XSDAttributeDeclaration attrDecl = (XSDAttributeDeclaration) xsdComp;
                    if (attrDecl.isAttributeDeclarationReference()) {
                        objectToReveal = attrDecl.getResolvedAttributeDeclaration();
                    } else if (attrDecl.getAnonymousTypeDefinition() == null) {
                        objectToReveal = attrDecl.getTypeDefinition();
                    }
                } else if (xsdComp instanceof XSDAttributeGroupDefinition) {
                    XSDAttributeGroupDefinition attrGroupDef = (XSDAttributeGroupDefinition) xsdComp;
                    if (attrGroupDef.isAttributeGroupDefinitionReference()) {
                        objectToReveal = attrGroupDef.getResolvedAttributeGroupDefinition();
                    }
                } else if (xsdComp instanceof XSDIdentityConstraintDefinition) {
                    XSDIdentityConstraintDefinition idConstraintDef = (XSDIdentityConstraintDefinition) xsdComp;
                    if (idConstraintDef.getReferencedKey() != null) {
                        objectToReveal = idConstraintDef.getReferencedKey();
                    }
                } else if (xsdComp instanceof XSDSimpleTypeDefinition) {
                    XSDSimpleTypeDefinition typeDef = (XSDSimpleTypeDefinition) xsdComp;
                    objectToReveal = typeDef.getItemTypeDefinition();
                    if (objectToReveal == null) {
                        // if itemType attribute is not set, then check for memberType
                        List memberTypes = typeDef.getMemberTypeDefinitions();
                        if (memberTypes != null && memberTypes.size() > 0) {
                            objectToReveal = (XSDConcreteComponent) memberTypes.get(0);
                        }
                    }
                } else if (xsdComp instanceof XSDTypeDefinition) {
                    XSDTypeDefinition typeDef = (XSDTypeDefinition) xsdComp;
                    objectToReveal = typeDef.getBaseType();
                } else if (xsdComp instanceof XSDSchemaDirective) {
                    XSDSchemaDirective directive = (XSDSchemaDirective) xsdComp;
                    // String schemaLocation = URIHelper.removePlatformResourceProtocol(directive.getResolvedSchema().getSchemaLocation());
                    // openXSDEditor(schemaLocation);
                    // return false;
                    objectToReveal = directive.getResolvedSchema();
                }
                // now reveal the object if this isn't null
                if (objectToReveal != null) {
                    return revealObject(objectToReveal);
                }
            }
        }
    }
    return false;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Attr(org.w3c.dom.Attr) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDSchemaDirective(org.eclipse.xsd.XSDSchemaDirective) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ISelection(org.eclipse.jface.viewers.ISelection) Iterator(java.util.Iterator) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) List(java.util.List) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Example 60 with XSDTypeDefinition

use of org.eclipse.xsd.XSDTypeDefinition in project webtools.sourceediting by eclipse.

the class XSDChildUtility method getImmediateDerivedTypes.

public static List getImmediateDerivedTypes(XSDComplexTypeDefinition complexType) {
    ArrayList typesDerivedFrom = new ArrayList();
    // A handy convenience method quickly gets all
    // typeDefinitions within our schema; note that
    // whether or not this returns types in included,
    // imported, or redefined schemas is subject to change
    List typedefs = complexType.getSchema().getTypeDefinitions();
    for (Iterator iter = typedefs.iterator(); iter.hasNext(); ) {
        XSDTypeDefinition typedef = (XSDTypeDefinition) iter.next();
        // of them match the requested one
        if (complexType.equals(typedef.getBaseType())) {
            // We found it, return the original one and continue
            typesDerivedFrom.add(typedef);
        }
    }
    return typesDerivedFrom;
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) 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