Search in sources :

Example 51 with XSDTypeDefinition

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

the class XSDImpl method isTypeDerivedFrom.

/**
 * Adapted from protected static boolean isTypeDerivedFrom(XSDTypeDefinition
 * typedef, String namespace, String localName) in class XSDSchemaQueryTools
 * found in org.eclipse.xsd plugin.
 *
 * Recursive worker method to find typeDefinitions that derive from a named
 * type.
 *
 * @see #findTypesDerivedFrom(XSDSchema, String, String)
 * @param typeDef
 *          to see if it's derived from
 * @param namespace
 *          for the type derived from
 * @param localName
 *          for the type derived from
 * @return true if it is; false otherwise
 */
protected static boolean isTypeDerivedFrom(XSDTypeDefinition typedef, String namespace, String localName) {
    // Walk the baseTypes from this typedef seeing if any
    // of them match the requested one
    XSDTypeDefinition baseType = typedef.getBaseType();
    if (baseType == null) {
        // typedef is a root type like xsd:anyType, so it has no base
        return false;
    }
    // As this convenience method if our parameters match
    if (baseType.hasNameAndTargetNamespace(localName, namespace)) {
        return true;
    }
    XSDTypeDefinition rootType = typedef.getRootType();
    if (rootType == baseType) {
        // If we've hit the root, we aren't derived from it
        return false;
    } else {
        // This method should be replaced with     XSDConstants.isOrIsDerivedFrom(baseType, localName, namespace);
        if (rootType.isCircular()) {
            return true;
        }
        // Otherwise continue to traverse upwards
        return isTypeDerivedFrom(baseType, namespace, localName);
    }
}
Also used : XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 52 with XSDTypeDefinition

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

the class XSDElementDeclarationSection method fillTypesCombo.

private void fillTypesCombo() {
    IEditorPart editor = getActiveEditor();
    ComponentReferenceEditManager manager = (ComponentReferenceEditManager) editor.getAdapter(XSDTypeReferenceEditManager.class);
    if (manager != null) {
        ComponentSpecification[] items = manager.getQuickPicks();
        typeCombo.removeAll();
        typeCombo.add(Messages._UI_COMBO_BROWSE);
        typeCombo.add(Messages._UI_COMBO_NEW);
        for (int i = 0; i < items.length; i++) {
            typeCombo.add(items[i].getName());
        }
        // Add the current Type of this element if needed
        XSDElementDeclaration namedComponent = ((XSDElementDeclaration) input).getResolvedElementDeclaration();
        XSDTypeDefinition td = namedComponent.getType();
        if (td != null) {
            String currentTypeName = td.getQName(xsdSchema);
            if (// anonymous type
            currentTypeName == null)
                currentTypeName = "**Anonymous**";
            ComponentSpecification ret = getComponentSpecFromQuickPickForValue(currentTypeName, manager);
            if (// not in quickPick
            ret == null && currentTypeName != null) {
                typeCombo.add(currentTypeName);
            }
        }
    }
}
Also used : XSDTypeReferenceEditManager(org.eclipse.wst.xsd.ui.internal.editor.XSDTypeReferenceEditManager) ComponentSpecification(org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ComponentReferenceEditManager(org.eclipse.wst.xsd.ui.internal.adt.edit.ComponentReferenceEditManager) IEditorPart(org.eclipse.ui.IEditorPart) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 53 with XSDTypeDefinition

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

the class XSDFacetSection method updateInput.

private void updateInput() {
    previousPrimitiveType = currentPrimitiveType;
    if (input instanceof XSDFeature) {
        xsdFeature = (XSDFeature) input;
        typeDefinition = xsdFeature.getResolvedFeature().getType();
        XSDTypeDefinition anonymousTypeDefinition = null;
        if (xsdFeature instanceof XSDElementDeclaration) {
            xsdElementDeclaration = (XSDElementDeclaration) xsdFeature;
            anonymousTypeDefinition = xsdElementDeclaration.getResolvedElementDeclaration().getAnonymousTypeDefinition();
        } else if (xsdFeature instanceof XSDAttributeDeclaration) {
            xsdAttributeDeclaration = (XSDAttributeDeclaration) xsdFeature;
            anonymousTypeDefinition = xsdAttributeDeclaration.getResolvedAttributeDeclaration().getAnonymousTypeDefinition();
        }
        if (typeDefinition instanceof XSDSimpleTypeDefinition) {
            xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition) typeDefinition;
        }
        if (anonymousTypeDefinition instanceof XSDSimpleTypeDefinition) {
            xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition) anonymousTypeDefinition;
        }
        if (xsdSimpleTypeDefinition != null) {
            if (!XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001.equals(xsdSimpleTypeDefinition.getTargetNamespace())) {
                XSDSimpleTypeDefinition basePrimitiveType = xsdSimpleTypeDefinition.getBaseTypeDefinition();
                String basePrimitiveTypeString = basePrimitiveType != null ? basePrimitiveType.getName() : "";
                currentPrimitiveType = basePrimitiveType;
                // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                titleString = Messages._UI_LABEL_TYPE + (anonymousTypeDefinition != null ? "(" + xsdFeature.getResolvedFeature().getName() + "Type)" : xsdSimpleTypeDefinition.getName()) + " , " + Messages._UI_LABEL_BASE + ": " + basePrimitiveTypeString;
            } else {
                currentPrimitiveType = xsdSimpleTypeDefinition;
                titleString = Messages._UI_LABEL_TYPE + (anonymousTypeDefinition != null ? "(" + xsdFeature.getResolvedFeature().getName() + "Type)" : xsdSimpleTypeDefinition.getName());
            }
        }
    } else if (input instanceof XSDSimpleTypeDefinition) {
        xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition) input;
        currentPrimitiveType = xsdSimpleTypeDefinition;
        // $NON-NLS-1$ //$NON-NLS-2$
        titleString = Messages._UI_LABEL_TYPE + (xsdSimpleTypeDefinition.getName() == null ? "(localType)" : xsdSimpleTypeDefinition.getName()) + " , " + Messages._UI_LABEL_BASE + ": " + xsdSimpleTypeDefinition.getBaseTypeDefinition().getName();
    }
}
Also used : XSDFeature(org.eclipse.xsd.XSDFeature) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 54 with XSDTypeDefinition

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

the class XSDCommonUIUtils method getInputXSDAnnotation.

public static XSDAnnotation getInputXSDAnnotation(XSDConcreteComponent input, boolean createIfNotExist) {
    XSDAnnotation xsdAnnotation = null;
    XSDFactory factory = XSDFactory.eINSTANCE;
    if (input instanceof XSDAttributeDeclaration) {
        XSDAttributeDeclaration xsdComp = (XSDAttributeDeclaration) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDAttributeGroupDefinition) {
        XSDAttributeGroupDefinition xsdComp = (XSDAttributeGroupDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDElementDeclaration) {
        XSDElementDeclaration xsdComp = (XSDElementDeclaration) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDNotationDeclaration) {
        XSDNotationDeclaration xsdComp = (XSDNotationDeclaration) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDXPathDefinition) {
        XSDXPathDefinition xsdComp = (XSDXPathDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDModelGroup) {
        XSDModelGroup xsdComp = (XSDModelGroup) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDModelGroupDefinition) {
        XSDModelGroupDefinition xsdComp = (XSDModelGroupDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDIdentityConstraintDefinition) {
        XSDIdentityConstraintDefinition xsdComp = (XSDIdentityConstraintDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDWildcard) {
        XSDWildcard xsdComp = (XSDWildcard) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDSchema) {
        XSDSchema xsdComp = (XSDSchema) input;
        List list = xsdComp.getAnnotations();
        if (list.size() > 0) {
            xsdAnnotation = (XSDAnnotation) list.get(0);
        } else {
            if (createIfNotExist && xsdAnnotation == null) {
                xsdAnnotation = factory.createXSDAnnotation();
                if (xsdComp.getContents() != null) {
                    xsdComp.getContents().add(0, xsdAnnotation);
                }
            }
        }
        return xsdAnnotation;
    } else if (input instanceof XSDFacet) {
        XSDFacet xsdComp = (XSDFacet) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDTypeDefinition) {
        XSDTypeDefinition xsdComp = (XSDTypeDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDInclude) {
        XSDInclude xsdComp = (XSDInclude) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDImport) {
        XSDImport xsdComp = (XSDImport) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDRedefine) {
        XSDRedefine xsdComp = (XSDRedefine) input;
        List contents = xsdComp.getContents();
        for (int i = 0; i < contents.size(); i++) {
            Object content = contents.get(i);
            if (content instanceof XSDAnnotation) {
                xsdAnnotation = (XSDAnnotation) content;
                break;
            }
        }
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            contents.add(0, xsdAnnotation);
        }
        return xsdAnnotation;
    } else if (input instanceof XSDAnnotation) {
        xsdAnnotation = (XSDAnnotation) input;
    }
    if (createIfNotExist) {
        formatAnnotation(xsdAnnotation);
    }
    return xsdAnnotation;
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDRedefine(org.eclipse.xsd.XSDRedefine) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDNotationDeclaration(org.eclipse.xsd.XSDNotationDeclaration) XSDFacet(org.eclipse.xsd.XSDFacet) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) EObject(org.eclipse.emf.ecore.EObject) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDImport(org.eclipse.xsd.XSDImport) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDSchema(org.eclipse.xsd.XSDSchema) XSDInclude(org.eclipse.xsd.XSDInclude)

Example 55 with XSDTypeDefinition

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

the class TypesHelper method getUserSimpleTypes.

public java.util.List getUserSimpleTypes() {
    Vector items = new Vector();
    if (xsdSchema != null) {
        updateExternalImportGlobals();
        Iterator i = xsdSchema.getTypeDefinitions().iterator();
        while (i.hasNext()) {
            XSDTypeDefinition typeDefinition = (XSDTypeDefinition) i.next();
            if (typeDefinition instanceof XSDSimpleTypeDefinition) {
                items.add(typeDefinition);
            // items.add(typeDefinition.getQName(xsdSchema));
            }
        }
    // We need to add the anyType
    // items.add(getPrefix(xsdSchema.getSchemaForSchemaNamespace(), true) + "anyType");
    // items = addExternalImportedUserSimpleTypes(items);
    // items = (Vector) sortList(items);
    }
    return items;
}
Also used : XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) Iterator(java.util.Iterator) Vector(java.util.Vector) 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