Search in sources :

Example 6 with XSDAttributeDeclaration

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

the class XSDAttributeUseAdapter method getTextForAttributeUse.

public String getTextForAttributeUse(XSDAttributeUse attributeUse, boolean showType) {
    XSDAttributeDeclaration ad = attributeUse.getAttributeDeclaration();
    StringBuffer result = new StringBuffer();
    result.append(getTextForAttribute(ad, showType));
    /*
    if (xsdAttributeUse.isSetConstraint())
    {
      if (result.length() != 0)
      {
        result.append("  ");
      }
      result.append('<');
      result.append(xsdAttributeUse.getConstraint());
      result.append("=\"");
      result.append(xsdAttributeUse.getLexicalValue());
      result.append("\">");
    }
    */
    return result.toString();
}
Also used : XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Example 7 with XSDAttributeDeclaration

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

the class XSDBaseAttributeAdapter method getName.

public String getName() {
    XSDAttributeDeclaration resolvedAttributeDeclaration = getResolvedXSDAttributeDeclaration();
    String name = resolvedAttributeDeclaration.getName();
    // $NON-NLS-1$
    return (name == null) ? "" : name;
}
Also used : XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Example 8 with XSDAttributeDeclaration

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

the class AddXSDAttributeDeclarationCommand method execute.

public void execute() {
    XSDAttributeDeclaration attribute = XSDFactory.eINSTANCE.createXSDAttributeDeclaration();
    try {
        if (parent == null) {
            beginRecording(xsdComplexTypeDefinition.getElement());
            if (!isReference) {
                // $NON-NLS-1$
                attribute.setName(getNewName(nameToAdd == null ? "NewAttribute" : nameToAdd));
                // $NON-NLS-1$
                attribute.setTypeDefinition(xsdComplexTypeDefinition.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("string"));
            } else {
                attribute.setResolvedAttributeDeclaration(setGlobalAttributeReference(xsdComplexTypeDefinition.getSchema()));
            }
            XSDAttributeUse attributeUse = XSDFactory.eINSTANCE.createXSDAttributeUse();
            attributeUse.setAttributeDeclaration(attribute);
            attributeUse.setContent(attribute);
            if (xsdComplexTypeDefinition.getAttributeContents() != null) {
                index = getInsertionIndex();
                if (index >= 0 && index < xsdComplexTypeDefinition.getAttributeContents().size()) {
                    xsdComplexTypeDefinition.getAttributeContents().add(index, attributeUse);
                } else {
                    xsdComplexTypeDefinition.getAttributeContents().add(attributeUse);
                }
                formatChild(xsdComplexTypeDefinition.getElement());
            }
        } else {
            beginRecording(parent.getElement());
            if (parent instanceof XSDSchema) {
                XSDSchema xsdSchema = (XSDSchema) parent;
                attribute = createGlobalXSDAttributeDeclaration(xsdSchema);
            } else if (parent instanceof XSDAttributeGroupDefinition) {
                if (!isReference) {
                    // $NON-NLS-1$
                    attribute.setTypeDefinition(parent.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("string"));
                    List list = new ArrayList();
                    Iterator i = ((XSDAttributeGroupDefinition) parent).getResolvedAttributeGroupDefinition().getAttributeUses().iterator();
                    while (i.hasNext()) {
                        XSDAttributeUse use = (XSDAttributeUse) i.next();
                        list.add(use.getAttributeDeclaration());
                    }
                    // $NON-NLS-1$
                    attribute.setName(XSDCommonUIUtils.createUniqueElementName("NewAttribute", list));
                } else {
                    attribute.setResolvedAttributeDeclaration(setGlobalAttributeReference(parent.getSchema()));
                }
                XSDAttributeUse attributeUse = XSDFactory.eINSTANCE.createXSDAttributeUse();
                attributeUse.setAttributeDeclaration(attribute);
                attributeUse.setContent(attribute);
                index = getInsertionIndex();
                if (index >= 0 && index < (((XSDAttributeGroupDefinition) parent).getResolvedAttributeGroupDefinition().getContents().size())) {
                    ((XSDAttributeGroupDefinition) parent).getResolvedAttributeGroupDefinition().getContents().add(index, attributeUse);
                } else {
                    ((XSDAttributeGroupDefinition) parent).getResolvedAttributeGroupDefinition().getContents().add(attributeUse);
                }
                formatChild(parent.getElement());
            }
        }
    } finally {
        endRecording();
    }
    addedXSDConcreteComponent = attribute;
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDSchema(org.eclipse.xsd.XSDSchema) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition)

Example 9 with XSDAttributeDeclaration

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

the class AddXSDAttributeDeclarationCommand method setGlobalAttributeReference.

protected XSDAttributeDeclaration setGlobalAttributeReference(XSDSchema xsdSchema) {
    List list = xsdSchema.getAttributeDeclarations();
    XSDAttributeDeclaration referencedAttribute = null;
    boolean isUserDefined = false;
    for (Iterator i = list.iterator(); i.hasNext(); ) {
        Object obj = i.next();
        if (obj instanceof XSDAttributeDeclaration) {
            XSDAttributeDeclaration attr = (XSDAttributeDeclaration) obj;
            if (!XSDConstants.SCHEMA_INSTANCE_URI_2001.equals(attr.getTargetNamespace())) {
                referencedAttribute = attr;
                isUserDefined = true;
                break;
            }
        }
    }
    if (!isUserDefined) {
        referencedAttribute = createGlobalXSDAttributeDeclaration(xsdSchema);
        // $NON-NLS-1$
        Text textNode = xsdSchema.getDocument().createTextNode("\n");
        xsdSchema.getElement().appendChild(textNode);
        xsdSchema.getContents().add(referencedAttribute);
    }
    return referencedAttribute;
}
Also used : Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Text(org.w3c.dom.Text) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Example 10 with XSDAttributeDeclaration

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

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