Search in sources :

Example 11 with XSDEnumerationFacet

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

the class XSDEnumerationFacetSection method doHandleEvent.

public void doHandleEvent(Event event) {
    if (event.widget == valueText) {
        if (!valueText.getEditable())
            return;
        String value = valueText.getText();
        if (input instanceof XSDEnumerationFacet) {
            XSDEnumerationFacet xsdEnumeration = (XSDEnumerationFacet) input;
            Command command = null;
            command = new SetXSDFacetValueCommand(Messages._UI_ACTION_CHANGE_ENUMERATION_VALUE, xsdEnumeration, value);
            if (command != null && getCommandStack() != null) {
                getCommandStack().execute(command);
                valueText.setText(value);
            }
        }
    }
}
Also used : XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) SetXSDFacetValueCommand(org.eclipse.wst.xsd.ui.internal.common.commands.SetXSDFacetValueCommand) Command(org.eclipse.gef.commands.Command) SetXSDFacetValueCommand(org.eclipse.wst.xsd.ui.internal.common.commands.SetXSDFacetValueCommand)

Example 12 with XSDEnumerationFacet

use of org.eclipse.xsd.XSDEnumerationFacet in project tmdm-common by Talend.

the class MetadataRepository method createFieldMetadata.

// TODO Refactor!
private FieldMetadata createFieldMetadata(XSDElementDeclaration element, ComplexTypeMetadata containingType, int minOccurs, int maxOccurs) {
    String fieldName = element.getName();
    if (maxOccurs > 0 && minOccurs > maxOccurs) {
        // Eclipse XSD does not check this
        throw new IllegalArgumentException("Can not parse information on field '" + element.getQName() + "' of type '" + containingType + "' (maxOccurs > minOccurs)");
    }
    boolean isMany = maxOccurs == -1 || maxOccurs > 1;
    XmlSchemaAnnotationProcessorState state = new XmlSchemaAnnotationProcessorState();
    try {
        XSDAnnotation annotation = element.getAnnotation();
        for (XmlSchemaAnnotationProcessor processor : XML_ANNOTATIONS_PROCESSORS) {
            processor.process(this, containingType, annotation, state);
        }
    } catch (Exception e) {
        throw new RuntimeException("Annotation processing exception while parsing info for field '" + fieldName + "' in type '" + containingType.getName() + "'", e);
    }
    boolean isMandatory = minOccurs > 0;
    boolean isContained = false;
    boolean isReference = state.isReference();
    boolean fkIntegrity = state.isFkIntegrity();
    boolean fkIntegrityOverride = state.isFkIntegrityOverride();
    List<FieldMetadata> foreignKeyInfo = state.getForeignKeyInfo();
    String foreignKeyInfoFormat = state.getForeignKeyInfoFormat();
    TypeMetadata fieldType = state.getFieldType();
    FieldMetadata referencedField = state.getReferencedField();
    TypeMetadata referencedType = state.getReferencedType();
    List<String> hideUsers = state.getHide();
    List<String> allowWriteUsers = state.getAllowWrite();
    List<String> workflowAccessRights = state.getWorkflowAccessRights();
    String visibilityRule = state.getVisibilityRule();
    XSDTypeDefinition schemaType = element.getType();
    if (schemaType instanceof XSDSimpleTypeDefinition) {
        XSDSimpleTypeDefinition simpleSchemaType = (XSDSimpleTypeDefinition) schemaType;
        XSDSimpleTypeDefinition content = simpleSchemaType.getBaseTypeDefinition();
        if (schemaType.getQName() != null) {
            fieldType = new SoftTypeRef(this, schemaType.getTargetNamespace(), schemaType.getName(), false);
        } else {
            // Null QNames may happen for anonymous types extending other types.
            fieldType = new SimpleTypeMetadata(targetNamespace, ANONYMOUS_PREFIX + String.valueOf(anonymousCounter++));
            if (content != null) {
                fieldType.addSuperType(new SoftTypeRef(this, content.getTargetNamespace(), content.getName(), false));
            }
        }
        setFieldData(simpleSchemaType, fieldType);
        fieldType.setData(XSD_LINE_NUMBER, XSDParser.getStartLine(element.getElement()));
        fieldType.setData(XSD_COLUMN_NUMBER, XSDParser.getStartColumn(element.getElement()));
        fieldType.setData(XSD_DOM_ELEMENT, element.getElement());
        fieldType.setData(MIN_OCCURS, minOccurs);
        fieldType.setData(MAX_OCCURS, maxOccurs);
        if (isReference) {
            ReferenceFieldMetadata referenceField = new ReferenceFieldMetadata(containingType, false, isMany, isMandatory, fieldName, (ComplexTypeMetadata) referencedType, referencedField, foreignKeyInfo, foreignKeyInfoFormat, fkIntegrity, fkIntegrityOverride, fieldType, allowWriteUsers, hideUsers, workflowAccessRights, state.getForeignKeyFilter(), visibilityRule);
            referenceField.setData(XSD_LINE_NUMBER, XSDParser.getStartLine(element.getElement()));
            referenceField.setData(XSD_COLUMN_NUMBER, XSDParser.getStartColumn(element.getElement()));
            referenceField.setData(XSD_ELEMENT, element);
            referenceField.setData(XSD_DOM_ELEMENT, element.getElement());
            referenceField.setData(MIN_OCCURS, minOccurs);
            referenceField.setData(MAX_OCCURS, maxOccurs);
            setLocalizedNames(referenceField, state.getLocaleToLabel());
            setLocalizedDescriptions(referenceField, state.getLocaleToDescription());
            setDefaultValueRule(referenceField, state.getDefaultValueRule());
            setFieldData(simpleSchemaType, referenceField);
            return referenceField;
        }
        if (content != null) {
            if (content.getFacets().size() > 0) {
                boolean isEnumeration = false;
                for (int i = 0; i < content.getFacets().size(); i++) {
                    XSDConstrainingFacet item = content.getFacets().get(i);
                    if (item instanceof XSDEnumerationFacet) {
                        isEnumeration = true;
                    }
                }
                if (isEnumeration) {
                    EnumerationFieldMetadata enumField = new EnumerationFieldMetadata(containingType, false, isMany, isMandatory, fieldName, fieldType, allowWriteUsers, hideUsers, workflowAccessRights, visibilityRule);
                    enumField.setData(XSD_LINE_NUMBER, XSDParser.getStartLine(element.getElement()));
                    enumField.setData(XSD_COLUMN_NUMBER, XSDParser.getStartColumn(element.getElement()));
                    enumField.setData(XSD_ELEMENT, element);
                    enumField.setData(XSD_DOM_ELEMENT, element.getElement());
                    enumField.setData(MIN_OCCURS, minOccurs);
                    enumField.setData(MAX_OCCURS, maxOccurs);
                    setLocalizedNames(enumField, state.getLocaleToLabel());
                    setLocalizedDescriptions(enumField, state.getLocaleToDescription());
                    setDefaultValueRule(enumField, state.getDefaultValueRule());
                    setFieldData(simpleSchemaType, enumField);
                    return enumField;
                } else {
                    FieldMetadata field = new SimpleTypeFieldMetadata(containingType, false, isMany, isMandatory, fieldName, fieldType, allowWriteUsers, hideUsers, workflowAccessRights, visibilityRule);
                    field.setData(XSD_LINE_NUMBER, XSDParser.getStartLine(element.getElement()));
                    field.setData(XSD_COLUMN_NUMBER, XSDParser.getStartColumn(element.getElement()));
                    field.setData(XSD_ELEMENT, element);
                    field.setData(XSD_DOM_ELEMENT, element.getElement());
                    field.setData(MIN_OCCURS, minOccurs);
                    field.setData(MAX_OCCURS, maxOccurs);
                    setLocalizedNames(field, state.getLocaleToLabel());
                    setLocalizedDescriptions(field, state.getLocaleToDescription());
                    setDefaultValueRule(field, state.getDefaultValueRule());
                    setFieldData(simpleSchemaType, field);
                    return field;
                }
            } else {
                FieldMetadata field = new SimpleTypeFieldMetadata(containingType, false, isMany, isMandatory, fieldName, fieldType, allowWriteUsers, hideUsers, workflowAccessRights, visibilityRule);
                field.setData(XSD_LINE_NUMBER, XSDParser.getStartLine(element.getElement()));
                field.setData(XSD_COLUMN_NUMBER, XSDParser.getStartColumn(element.getElement()));
                field.setData(XSD_ELEMENT, element);
                field.setData(XSD_DOM_ELEMENT, element.getElement());
                field.setData(MIN_OCCURS, minOccurs);
                field.setData(MAX_OCCURS, maxOccurs);
                setLocalizedNames(field, state.getLocaleToLabel());
                setLocalizedDescriptions(field, state.getLocaleToDescription());
                setDefaultValueRule(field, state.getDefaultValueRule());
                setFieldData(simpleSchemaType, field);
                return field;
            }
        }
    }
    if (fieldType == null) {
        String qName = element.getType() == null ? null : element.getType().getQName();
        if (qName != null) {
            TypeMetadata metadata = getType(element.getType().getTargetNamespace(), element.getType().getName());
            if (metadata != null) {
                fieldType = new SoftTypeRef(this, targetNamespace, schemaType.getName(), false);
                isContained = true;
            } else {
                if (schemaType instanceof XSDComplexTypeDefinition) {
                    fieldType = new SoftTypeRef(this, schemaType.getTargetNamespace(), schemaType.getName(), false);
                    isContained = true;
                } else {
                    throw new NotImplementedException("Support for '" + schemaType.getClass() + "'.");
                }
            }
        } else {
            // Ref & anonymous complex type
            isContained = true;
            XSDElementDeclaration refName = element.getResolvedElementDeclaration();
            if (schemaType != null) {
                fieldType = new ComplexTypeMetadataImpl(targetNamespace, ANONYMOUS_PREFIX + String.valueOf(anonymousCounter++), false);
                isContained = true;
            } else if (refName != null) {
                // Reference being an element, consider references as references to entity type.
                fieldType = new SoftTypeRef(this, refName.getTargetNamespace(), refName.getName(), true);
            } else {
                throw new NotImplementedException();
            }
        }
    }
    if (isContained) {
        ContainedTypeFieldMetadata containedField = new ContainedTypeFieldMetadata(containingType, isMany, isMandatory, fieldName, (ComplexTypeMetadata) fieldType, isReference, allowWriteUsers, hideUsers, workflowAccessRights, visibilityRule);
        containedField.setData(XSD_LINE_NUMBER, XSDParser.getStartLine(element.getElement()));
        containedField.setData(XSD_COLUMN_NUMBER, XSDParser.getStartColumn(element.getElement()));
        containedField.setData(XSD_ELEMENT, element);
        containedField.setData(XSD_DOM_ELEMENT, element.getElement());
        containedField.setData(MIN_OCCURS, minOccurs);
        containedField.setData(MAX_OCCURS, maxOccurs);
        if (fieldType.getName().startsWith(ANONYMOUS_PREFIX)) {
            currentTypeStack.push((ComplexTypeMetadata) containedField.getType());
            {
                XmlSchemaWalker.walk(schemaType, this);
            }
            currentTypeStack.pop();
        }
        setLocalizedNames(containedField, state.getLocaleToLabel());
        setLocalizedDescriptions(containedField, state.getLocaleToDescription());
        return containedField;
    } else {
        FieldMetadata field = new SimpleTypeFieldMetadata(containingType, false, isMany, isMandatory, fieldName, fieldType, allowWriteUsers, hideUsers, workflowAccessRights, visibilityRule);
        field.setData(XSD_LINE_NUMBER, XSDParser.getStartLine(element.getElement()));
        field.setData(XSD_COLUMN_NUMBER, XSDParser.getStartColumn(element.getElement()));
        field.setData(XSD_ELEMENT, element);
        field.setData(XSD_DOM_ELEMENT, element.getElement());
        field.setData(MIN_OCCURS, minOccurs);
        field.setData(MAX_OCCURS, maxOccurs);
        setLocalizedNames(field, state.getLocaleToLabel());
        setLocalizedDescriptions(field, state.getLocaleToDescription());
        return field;
    }
}
Also used : NotImplementedException(org.apache.commons.lang.NotImplementedException) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XmlSchemaAnnotationProcessorState(org.talend.mdm.commmon.metadata.annotation.XmlSchemaAnnotationProcessorState) XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) NotImplementedException(org.apache.commons.lang.NotImplementedException) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDConstrainingFacet(org.eclipse.xsd.XSDConstrainingFacet) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XmlSchemaAnnotationProcessor(org.talend.mdm.commmon.metadata.annotation.XmlSchemaAnnotationProcessor)

Example 13 with XSDEnumerationFacet

use of org.eclipse.xsd.XSDEnumerationFacet in project tmdm-common by Talend.

the class MetadataRepository method setFieldData.

private void setFieldData(XSDSimpleTypeDefinition simpleSchemaType, MetadataExtensible field) {
    EList<XSDConstrainingFacet> facets = simpleSchemaType.getFacetContents();
    List<String> enumerationList = new ArrayList<String>();
    for (XSDConstrainingFacet currentFacet : facets) {
        if (currentFacet instanceof XSDMaxLengthFacet) {
            field.setData(MetadataRepository.DATA_MAX_LENGTH, String.valueOf(((XSDMaxLengthFacet) currentFacet).getLexicalValue()));
        } else if (currentFacet instanceof XSDMinLengthFacet) {
            // this is the minLengthFacet
            field.setData(MetadataRepository.DATA_MIN_LENGTH, String.valueOf(((XSDMinLengthFacet) currentFacet).getLexicalValue()));
        } else if (currentFacet instanceof XSDLengthFacet) {
            // this is the lengthFacet
            field.setData(MetadataRepository.DATA_LENGTH, String.valueOf(((XSDLengthFacet) currentFacet).getValue()));
        } else if (currentFacet instanceof XSDTotalDigitsFacet) {
            // this is the totalDigits
            field.setData(MetadataRepository.DATA_TOTAL_DIGITS, String.valueOf(((XSDTotalDigitsFacet) currentFacet).getLexicalValue()));
        } else if (currentFacet instanceof XSDFractionDigitsFacet) {
            // this is the fractionDigits
            field.setData(MetadataRepository.DATA_FRACTION_DIGITS, String.valueOf(((XSDFractionDigitsFacet) currentFacet).getLexicalValue()));
        } else if (currentFacet instanceof XSDPatternFacet) {
            // this is the patternFacet
            field.setData(MetadataRepository.PATTERN, String.valueOf(((XSDPatternFacet) currentFacet).getLexicalValue()));
        } else if (currentFacet instanceof XSDMaxExclusiveFacet) {
            // this is the  maxExclusiveFacet
            field.setData(MetadataRepository.MAX_EXCLUSIVE, String.valueOf(((XSDMaxExclusiveFacet) currentFacet).getLexicalValue()));
        } else if (currentFacet instanceof XSDMinExclusiveFacet) {
            // this is the  minExclusiveFacet
            field.setData(MetadataRepository.MIN_EXCLUSIVE, String.valueOf(((XSDMinExclusiveFacet) currentFacet).getLexicalValue()));
        } else if (currentFacet instanceof XSDMaxInclusiveFacet) {
            // this is the  maxInclusiveFacet
            field.setData(MetadataRepository.MAX_INCLUSIVE, String.valueOf(((XSDMaxInclusiveFacet) currentFacet).getLexicalValue()));
        } else if (currentFacet instanceof XSDMinInclusiveFacet) {
            // this is the  minInclusiveFacet
            field.setData(MetadataRepository.MIN_INCLUSIVE, String.valueOf(((XSDMinInclusiveFacet) currentFacet).getLexicalValue()));
        } else if (currentFacet instanceof XSDEnumerationFacet) {
            // this is the  enumeration
            enumerationList.add(String.valueOf(((XSDEnumerationFacet) currentFacet).getLexicalValue()));
        }
    }
    field.setData(MetadataRepository.ENUMERATION_LIST, enumerationList);
}
Also used : XSDPatternFacet(org.eclipse.xsd.XSDPatternFacet) XSDMinInclusiveFacet(org.eclipse.xsd.XSDMinInclusiveFacet) XSDFractionDigitsFacet(org.eclipse.xsd.XSDFractionDigitsFacet) ArrayList(java.util.ArrayList) XSDLengthFacet(org.eclipse.xsd.XSDLengthFacet) XSDMaxExclusiveFacet(org.eclipse.xsd.XSDMaxExclusiveFacet) XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) XSDTotalDigitsFacet(org.eclipse.xsd.XSDTotalDigitsFacet) XSDConstrainingFacet(org.eclipse.xsd.XSDConstrainingFacet) XSDMinLengthFacet(org.eclipse.xsd.XSDMinLengthFacet) XSDMaxLengthFacet(org.eclipse.xsd.XSDMaxLengthFacet) XSDMinExclusiveFacet(org.eclipse.xsd.XSDMinExclusiveFacet) XSDMaxInclusiveFacet(org.eclipse.xsd.XSDMaxInclusiveFacet)

Example 14 with XSDEnumerationFacet

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

the class XSDComplexTypeDefinitionAdapter method getChildren.

public ITreeElement[] getChildren() {
    XSDComplexTypeDefinition xsdComplexTypeDefinition = getXSDComplexTypeDefinition();
    List list = new ArrayList();
    // Add attributes
    for (Iterator i = xsdComplexTypeDefinition.getAttributeContents().iterator(); i.hasNext(); ) {
        Object obj = i.next();
        if (obj instanceof XSDAttributeUse) {
            list.add(((XSDAttributeUse) obj).getAttributeDeclaration());
        } else if (obj instanceof XSDAttributeGroupDefinition) {
            getAttributeUses((XSDAttributeGroupDefinition) obj, list);
        }
    }
    // Add enumerations
    boolean canHaveEnumerations = xsdComplexTypeDefinition.getContentType() instanceof XSDSimpleTypeDefinition && XSDDerivationMethod.RESTRICTION_LITERAL.equals(xsdComplexTypeDefinition.getDerivationMethod());
    if (canHaveEnumerations) {
        Object contentType = getContentType();
        if (contentType != null) {
            for (Iterator iterator = ((XSDSimpleTypeDefinition) contentType).getEnumerationFacets().iterator(); iterator.hasNext(); ) {
                XSDEnumerationFacet enumerationFacet = (XSDEnumerationFacet) iterator.next();
                list.add(enumerationFacet);
            }
        }
    }
    XSDWildcard anyAttr = xsdComplexTypeDefinition.getAttributeWildcard();
    if (anyAttr != null)
        list.add(anyAttr);
    // get immediate XSD Model Group of this complex type
    if (xsdComplexTypeDefinition.getContent() != null) {
        XSDComplexTypeContent xsdComplexTypeContent = xsdComplexTypeDefinition.getContent();
        if (xsdComplexTypeContent instanceof XSDParticle) {
            XSDParticleContent particleContent = ((XSDParticle) xsdComplexTypeContent).getContent();
            if (particleContent instanceof XSDModelGroup) {
                list.add(particleContent);
            }
        }
    }
    // get inherited XSD Model Group of this complex type
    boolean showInheritedContent = XSDEditorPlugin.getPlugin().getShowInheritedContent();
    if (showInheritedContent) {
        XSDTypeDefinition typeDef = xsdComplexTypeDefinition.getBaseTypeDefinition();
        if (typeDef instanceof XSDComplexTypeDefinition) {
            XSDComplexTypeDefinition baseCT = (XSDComplexTypeDefinition) typeDef;
            if (baseCT.getTargetNamespace() != null && !baseCT.getTargetNamespace().equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001)) {
                if (baseCT.getContent() != null) {
                    XSDComplexTypeContent xsdComplexTypeContent = baseCT.getContent();
                    if (xsdComplexTypeContent instanceof XSDParticle) {
                        XSDParticleContent particleContent = ((XSDParticle) xsdComplexTypeContent).getContent();
                        if (particleContent instanceof XSDModelGroup) {
                            list.add(particleContent);
                        }
                    }
                }
            }
        }
    }
    List adapterList = new ArrayList();
    populateAdapterList(list, adapterList);
    return (ITreeElement[]) adapterList.toArray(new ITreeElement[0]);
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) ArrayList(java.util.ArrayList) XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDParticleContent(org.eclipse.xsd.XSDParticleContent) ITreeElement(org.eclipse.wst.xsd.ui.internal.adt.outline.ITreeElement) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) IADTObject(org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 15 with XSDEnumerationFacet

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

the class DeleteCommand method execute.

public void execute() {
    XSDVisitor visitor = new XSDVisitor() {

        public void visitElementDeclaration(org.eclipse.xsd.XSDElementDeclaration element) {
            if (element.getTypeDefinition() == target) {
                // $NON-NLS-1$
                XSDSimpleTypeDefinition type = target.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("string");
                element.setTypeDefinition(type);
            }
            super.visitElementDeclaration(element);
        }
    };
    XSDConcreteComponent parent = target.getContainer();
    XSDSchema schema = target.getSchema();
    try {
        beginRecording(parent.getElement());
        boolean doCleanup = false;
        if (target instanceof XSDModelGroup || target instanceof XSDElementDeclaration || target instanceof XSDModelGroupDefinition) {
            doCleanup = true;
            if (parent instanceof XSDParticle) {
                if (parent.getContainer() instanceof XSDModelGroup) {
                    XSDModelGroup modelGroup = (XSDModelGroup) ((XSDParticle) parent).getContainer();
                    modelGroup.getContents().remove(parent);
                } else if (parent.getContainer() instanceof XSDComplexTypeDefinition) {
                    XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) parent.getContainer();
                    complexType.setContent(null);
                }
            } else if (parent instanceof XSDSchema) {
                visitor.visitSchema(target.getSchema());
                ((XSDSchema) parent).getContents().remove(target);
            } else if (parent instanceof XSDRedefine) {
                Object adapter = target.eAdapters().get(0);
                if (adapter instanceof XSDModelGroupDefinitionAdapter) {
                    ((XSDModelGroupDefinitionAdapter) adapter).setReadOnly(true);
                    ((XSDModelGroupDefinitionAdapter) adapter).setChangeReadOnlyField(true);
                }
                ((XSDRedefine) parent).getContents().remove(target);
            }
        } else if (target instanceof XSDAttributeDeclaration) {
            doCleanup = true;
            if (parent instanceof XSDAttributeUse) {
                EObject obj = parent.eContainer();
                XSDComplexTypeDefinition complexType = null;
                while (obj != null) {
                    if (obj instanceof XSDComplexTypeDefinition) {
                        complexType = (XSDComplexTypeDefinition) obj;
                        break;
                    }
                    obj = obj.eContainer();
                }
                if (complexType != null) {
                    complexType.getAttributeContents().remove(parent);
                }
                if (parent.getContainer() instanceof XSDAttributeGroupDefinition) {
                    XSDAttributeGroupDefinition attrGroup = (XSDAttributeGroupDefinition) parent.getContainer();
                    attrGroup.getContents().remove(parent);
                }
            } else if (parent instanceof XSDSchema) {
                visitor.visitSchema(target.getSchema());
                ((XSDSchema) parent).getContents().remove(target);
            }
        } else if (target instanceof XSDAttributeGroupDefinition && parent instanceof XSDComplexTypeDefinition) {
            doCleanup = true;
            ((XSDComplexTypeDefinition) parent).getAttributeContents().remove(target);
        } else if (target instanceof XSDEnumerationFacet) {
            XSDEnumerationFacet enumerationFacet = (XSDEnumerationFacet) target;
            enumerationFacet.getSimpleTypeDefinition().getFacetContents().remove(enumerationFacet);
        } else if (target instanceof XSDWildcard) {
            if (parent instanceof XSDParticle) {
                if (parent.getContainer() instanceof XSDModelGroup) {
                    XSDModelGroup modelGroup = (XSDModelGroup) ((XSDParticle) parent).getContainer();
                    modelGroup.getContents().remove(parent);
                }
            } else if (parent instanceof XSDComplexTypeDefinition) {
                ((XSDComplexTypeDefinition) parent).setAttributeWildcardContent(null);
            } else if (parent instanceof XSDAttributeGroupDefinition) {
                ((XSDAttributeGroupDefinition) parent).setAttributeWildcardContent(null);
            }
        } else if (target instanceof XSDTypeDefinition && parent instanceof XSDElementDeclaration) {
            doCleanup = true;
            ((XSDElementDeclaration) parent).setTypeDefinition(target.resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "string"));
        } else {
            if (parent instanceof XSDSchema) {
                doCleanup = true;
                visitor.visitSchema(target.getSchema());
                ((XSDSchema) parent).getContents().remove(target);
            } else if (parent instanceof XSDRedefine) {
                doCleanup = false;
                EList contents = ((XSDRedefine) parent).getContents();
                Object adapter = target.eAdapters().get(0);
                if (adapter instanceof XSDComplexTypeDefinitionAdapter) {
                    ((XSDComplexTypeDefinitionAdapter) adapter).setReadOnly(true);
                    ((XSDComplexTypeDefinitionAdapter) adapter).setChangeReadOnlyField(true);
                } else if (adapter instanceof XSDSimpleTypeDefinitionAdapter) {
                    ((XSDSimpleTypeDefinitionAdapter) adapter).setReadOnly(true);
                    ((XSDSimpleTypeDefinitionAdapter) adapter).setChangeReadOnlyField(true);
                } else if (adapter instanceof XSDAttributeGroupDefinitionAdapter) {
                    ((XSDAttributeGroupDefinitionAdapter) adapter).setReadOnly(true);
                    ((XSDAttributeGroupDefinitionAdapter) adapter).setChangeReadOnlyField(true);
                }
                contents.remove(target);
            }
        }
        if (doCleanup)
            XSDDirectivesManager.removeUnusedXSDImports(schema);
    } finally {
        endRecording();
    }
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDRedefine(org.eclipse.xsd.XSDRedefine) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDVisitor(org.eclipse.wst.xsd.ui.internal.adapters.XSDVisitor) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDSimpleTypeDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDSimpleTypeDefinitionAdapter) XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) EObject(org.eclipse.emf.ecore.EObject) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema) XSDComplexTypeDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDComplexTypeDefinitionAdapter) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDAttributeGroupDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeGroupDefinitionAdapter) XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) EList(org.eclipse.emf.common.util.EList) XSDModelGroupDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDModelGroupDefinitionAdapter) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) EObject(org.eclipse.emf.ecore.EObject) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Aggregations

XSDEnumerationFacet (org.eclipse.xsd.XSDEnumerationFacet)17 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)10 List (java.util.List)8 ArrayList (java.util.ArrayList)7 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)7 Iterator (java.util.Iterator)6 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)5 XSDParticle (org.eclipse.xsd.XSDParticle)5 XSDPatternFacet (org.eclipse.xsd.XSDPatternFacet)5 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)4 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)4 EObject (org.eclipse.emf.ecore.EObject)3 AddEnumerationsCommand (org.eclipse.wst.xsd.ui.internal.common.commands.AddEnumerationsCommand)3 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)3 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)3 XSDFractionDigitsFacet (org.eclipse.xsd.XSDFractionDigitsFacet)3 XSDLengthFacet (org.eclipse.xsd.XSDLengthFacet)3 XSDMaxExclusiveFacet (org.eclipse.xsd.XSDMaxExclusiveFacet)3 XSDMaxInclusiveFacet (org.eclipse.xsd.XSDMaxInclusiveFacet)3 XSDMaxLengthFacet (org.eclipse.xsd.XSDMaxLengthFacet)3