Search in sources :

Example 26 with XSDAttributeDeclaration

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

the class XSDVisitor method visitSchema.

public void visitSchema(XSDSchema schema) {
    this.schema = schema;
    for (Iterator iterator = schema.getAttributeDeclarations().iterator(); iterator.hasNext(); ) {
        XSDAttributeDeclaration attr = (XSDAttributeDeclaration) iterator.next();
        visitAttributeDeclaration(attr);
    }
    for (Iterator iterator = schema.getTypeDefinitions().iterator(); iterator.hasNext(); ) {
        XSDTypeDefinition type = (XSDTypeDefinition) iterator.next();
        visitTypeDefinition(type);
    }
    for (Iterator iterator = schema.getElementDeclarations().iterator(); iterator.hasNext(); ) {
        XSDElementDeclaration element = (XSDElementDeclaration) iterator.next();
        visitElementDeclaration(element);
    }
    for (Iterator iterator = schema.getIdentityConstraintDefinitions().iterator(); iterator.hasNext(); ) {
        XSDIdentityConstraintDefinition identityConstraint = (XSDIdentityConstraintDefinition) iterator.next();
        visitIdentityConstraintDefinition(identityConstraint);
    }
    for (Iterator iterator = schema.getModelGroupDefinitions().iterator(); iterator.hasNext(); ) {
        XSDModelGroupDefinition modelGroup = (XSDModelGroupDefinition) iterator.next();
        visitModelGroupDefinition(modelGroup);
    }
    for (Iterator iterator = schema.getAttributeGroupDefinitions().iterator(); iterator.hasNext(); ) {
        XSDAttributeGroupDefinition attributeGroup = (XSDAttributeGroupDefinition) iterator.next();
        visitAttributeGroupDefinition(attributeGroup);
    }
    for (Iterator iterator = schema.getNotationDeclarations().iterator(); iterator.hasNext(); ) {
        XSDNotationDeclaration element = (XSDNotationDeclaration) iterator.next();
        visitNotationDeclaration(element);
    }
}
Also used : XSDNotationDeclaration(org.eclipse.xsd.XSDNotationDeclaration) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Iterator(java.util.Iterator) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition)

Example 27 with XSDAttributeDeclaration

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

the class TypesHelper method getGlobalAttributes.

public java.util.List getGlobalAttributes() {
    Vector items = new Vector();
    if (xsdSchema != null) {
        updateExternalImportGlobals();
        if (xsdSchema.getAttributeDeclarations() != null) {
            Iterator i = xsdSchema.getAttributeDeclarations().iterator();
            while (i.hasNext()) {
                XSDAttributeDeclaration attributeDeclaration = (XSDAttributeDeclaration) i.next();
                if (attributeDeclaration.getTargetNamespace() == null || (attributeDeclaration.getTargetNamespace() != null && !attributeDeclaration.getTargetNamespace().equals(XSDConstants.SCHEMA_INSTANCE_URI_2001))) {
                    String name = attributeDeclaration.getQName(xsdSchema);
                    if (name != null) {
                        items.add(name);
                    }
                }
            }
        }
        // items = addExternalImportedAttributes(items);
        items = (Vector) sortList(items);
    }
    return items;
}
Also used : Iterator(java.util.Iterator) Vector(java.util.Vector) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Example 28 with XSDAttributeDeclaration

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

the class AddXSDAttributeDeclarationAction method run.

public void run() {
    Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
    if (selection instanceof XSDBaseAdapter) {
        selection = ((XSDBaseAdapter) selection).getTarget();
        if (selection instanceof XSDAttributeDeclaration) {
            selection = ((XSDAttributeDeclaration) selection).getContainer();
        }
    }
    AddXSDAttributeDeclarationCommand command = null;
    if (selection instanceof XSDComplexTypeDefinition) {
        command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, (XSDComplexTypeDefinition) selection);
        command.setReference(isReference);
        getCommandStack().execute(command);
    } else if (selection instanceof XSDAttributeUse) {
        XSDAttributeUse xsdAttributeUse = (XSDAttributeUse) selection;
        XSDConcreteComponent parent = null;
        XSDComplexTypeDefinition ct = null;
        XSDAttributeGroupDefinition group = null;
        for (parent = xsdAttributeUse.getContainer(); parent != null; ) {
            if (parent instanceof XSDComplexTypeDefinition) {
                ct = (XSDComplexTypeDefinition) parent;
                break;
            } else if (parent instanceof XSDAttributeGroupDefinition) {
                group = (XSDAttributeGroupDefinition) parent;
                break;
            }
            parent = parent.getContainer();
        }
        if (ct != null) {
            XSDAttributeUse sel = (XSDAttributeUse) selection;
            int index = ct.getAttributeContents().indexOf(sel);
            command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, ct, getId(), index);
            command.setReference(isReference);
            getCommandStack().execute(command);
        } else if (group != null) {
            XSDAttributeUse sel = (XSDAttributeUse) selection;
            int index = group.eContents().indexOf(sel);
            command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, group, getId(), index);
            command.setReference(isReference);
            getCommandStack().execute(command);
        }
    } else if (selection instanceof XSDAttributeGroupDefinition) {
        command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, (XSDAttributeGroupDefinition) selection);
        command.setReference(isReference);
        getCommandStack().execute(command);
    } else if (selection instanceof XSDSchema) {
        command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, (XSDSchema) selection);
        getCommandStack().execute(command);
    }
    if (command != null) {
        addedComponent = command.getAddedComponent();
        Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent);
        selectAddedComponent(adapter);
    }
}
Also used : AddXSDAttributeDeclarationCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDAttributeDeclarationCommand) XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) Adapter(org.eclipse.emf.common.notify.Adapter) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 29 with XSDAttributeDeclaration

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

the class AddExtensionsComponentDialog method buildInput.

private static List buildInput(XSDSchema xsdSchema) {
    if (xsdSchema == null)
        return null;
    List elements = xsdSchema.getElementDeclarations();
    List attributes = xsdSchema.getAttributeDeclarations();
    String targetNamespace = xsdSchema.getTargetNamespace();
    // For safety purpose: We don't append 'attributes' to 'elements'
    // ArrayStoreException(or similar one) may occur
    List allItems = new ArrayList(attributes.size() + elements.size());
    {
        // only add non-imported elements here. (trung)
        for (int i = 0; i < elements.size(); i++) {
            XSDElementDeclaration currentElement = (XSDElementDeclaration) elements.get(i);
            if (currentElement.getTargetNamespace() != null) {
                if (currentElement.getTargetNamespace().equals(targetNamespace))
                    allItems.add(currentElement);
            } else {
                if (targetNamespace == null)
                    allItems.add(currentElement);
            }
        }
        // only add non-imported elements here. (trung)
        for (int i = 0; i < attributes.size(); i++) {
            XSDAttributeDeclaration currentAttribute = (XSDAttributeDeclaration) attributes.get(i);
            if (currentAttribute.getTargetNamespace() != null) {
                if (currentAttribute.isGlobal() && currentAttribute.getTargetNamespace().equals(targetNamespace))
                    allItems.add(currentAttribute);
            } else {
                if (targetNamespace == null)
                    allItems.add(currentAttribute);
            }
        }
    }
    return allItems;
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Example 30 with XSDAttributeDeclaration

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

the class AddXSDAttributeGroupDefinitionCommand method updateNames.

private void updateNames(XSDComplexTypeDefinition ct) {
    Iterator iter = ct.getAttributeContents().iterator();
    while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof XSDAttributeUse) {
            XSDAttributeUse use = (XSDAttributeUse) obj;
            XSDAttributeDeclaration attr = use.getAttributeDeclaration();
            String attrName = attr.getName();
            if (attrName != null) {
                names.add(attrName);
            }
        }
    }
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) Iterator(java.util.Iterator) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Aggregations

XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)49 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)27 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)18 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)17 Iterator (java.util.Iterator)16 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)16 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)15 XSDSchema (org.eclipse.xsd.XSDSchema)15 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)14 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)13 List (java.util.List)10 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)10 XSDModelGroupDefinition (org.eclipse.xsd.XSDModelGroupDefinition)9 ArrayList (java.util.ArrayList)8 Element (org.w3c.dom.Element)8 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)7 XSDParticle (org.eclipse.xsd.XSDParticle)7 XSDNamedComponent (org.eclipse.xsd.XSDNamedComponent)6 XSDWildcard (org.eclipse.xsd.XSDWildcard)6 EList (org.eclipse.emf.common.util.EList)5