Search in sources :

Example 1 with XSDConstrainingFacet

use of org.eclipse.xsd.XSDConstrainingFacet in project tmdm-studio-se by Talend.

the class XSDChangeBaseTypeAction method doAction.

@Override
public IStatus doAction() {
    try {
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        XSDSimpleTypeDefinition typedef = (XSDSimpleTypeDefinition) selection.getFirstElement();
        // Cannot change the simple type definition of built in type
        // if (schema.getSchemaForSchemaNamespace().equals(typedef.getTargetNamespace())) return
        // Status.CANCEL_STATUS;
        // build list of custom types and built in types
        ArrayList customTypes = new ArrayList();
        for (Object element : schema.getTypeDefinitions()) {
            XSDTypeDefinition type = (XSDTypeDefinition) element;
            if (type instanceof XSDSimpleTypeDefinition) {
                if (type.getTargetNamespace() != null && !type.getTargetNamespace().equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001) || type.getTargetNamespace() == null) {
                    customTypes.add(type.getName());
                }
            }
        }
        List builtInTypes = XSDUtil.getBuiltInTypes();
        // can't change builtin's base type
        if (builtInTypes.contains(typedef.getName())) {
            return Status.CANCEL_STATUS;
        }
        dialog = new SimpleTypeInputDialog(this, page.getSite().getShell(), schema, Messages.XSDChangeBaseTypeAction_DialogTitle, customTypes, builtInTypes, typedef.getBaseTypeDefinition().getName());
        dialog.setBlockOnOpen(true);
        int ret = dialog.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        // backup current Base Type
        XSDTypeDefinition current = typedef.getBaseTypeDefinition();
        // set new one
        if (builtIn) {
            typedef.setBaseTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), typeName));
        } else {
            // check if simple type definition already exists
            XSDSimpleTypeDefinition std = schema.resolveSimpleTypeDefinition(typeName);
            if (!schema.getTypeDefinitions().contains(std)) {
                // $NON-NLS-1$
                std.setBaseTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), "string"));
                schema.getContents().add(std);
            }
            typedef.setBaseTypeDefinition(std);
        }
        // remove current facets
        typedef.getFacetContents().removeAll(typedef.getFacetContents());
        typedef.updateElement();
        if (builtIn) {
            EList<XSDConstrainingFacet> constrainFacts = typedef.getBaseTypeDefinition().getFacetContents();
            for (XSDConstrainingFacet fact : constrainFacts) {
                if (fact instanceof XSDPatternFacet) {
                    XSDPatternFacet newFact = XSDSchemaBuildingTools.getXSDFactory().createXSDPatternFacet();
                    newFact.setLexicalValue(((XSDPatternFacet) fact).getLexicalValue());
                    typedef.getFacetContents().add(newFact);
                }
            }
            typedef.updateElement();
        }
        // remove current if no more in use
        // if ( (current.getName()!=null) && //anonymous type
        // (!schema.getSchemaForSchemaNamespace().equals(current.getTargetNamespace()))
        // ){
        // List eut =Util.findElementsUsingType(schema, current.getTargetNamespace(), current.getName());
        // if (eut.size()==0)
        // schema.getContents().remove(current);
        // }
        page.refresh();
        page.markDirty();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDChangeBaseTypeAction_ErrorMsg1, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : XSDPatternFacet(org.eclipse.xsd.XSDPatternFacet) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) ArrayList(java.util.ArrayList) XSDConstrainingFacet(org.eclipse.xsd.XSDConstrainingFacet) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) List(java.util.List) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SimpleTypeInputDialog(com.amalto.workbench.dialogs.SimpleTypeInputDialog) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 2 with XSDConstrainingFacet

use of org.eclipse.xsd.XSDConstrainingFacet 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 3 with XSDConstrainingFacet

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

the class MetadataRepository method visitSimpleType.

@Override
public void visitSimpleType(XSDSimpleTypeDefinition type) {
    String typeName = type.getName();
    TypeMetadata typeMetadata = getNonInstantiableType(targetNamespace, typeName);
    if (typeMetadata == null) {
        typeMetadata = new SimpleTypeMetadata(targetNamespace, typeName);
    }
    List<TypeMetadata> superTypes = new LinkedList<TypeMetadata>();
    if (typeName == null) {
        // Anonymous simple type (expects this is a restriction of a simple type or fails).
        XSDSimpleTypeDefinition baseTypeDefinition = type.getBaseTypeDefinition();
        if (baseTypeDefinition != null) {
            typeName = baseTypeDefinition.getName();
        } else {
            throw new NotImplementedException("Support for " + type);
        }
    } else {
        // Simple type might inherit from other simple types (i.e. UUID from string).
        XSDSimpleTypeDefinition baseType = type.getBaseTypeDefinition();
        if (baseType != null && baseType.getName() != null) {
            superTypes.add(new SoftTypeRef(this, baseType.getTargetNamespace(), baseType.getName(), false));
            EList<XSDConstrainingFacet> facets = type.getFacetContents();
            for (XSDConstrainingFacet currentFacet : facets) {
                if (currentFacet instanceof XSDMaxLengthFacet) {
                    typeMetadata.setData(MetadataRepository.DATA_MAX_LENGTH, String.valueOf(((XSDMaxLengthFacet) currentFacet).getValue()));
                } else if (currentFacet instanceof XSDLengthFacet) {
                    typeMetadata.setData(MetadataRepository.DATA_MAX_LENGTH, String.valueOf(((XSDLengthFacet) currentFacet).getValue()));
                } else if (currentFacet instanceof XSDTotalDigitsFacet) {
                    // this is the totalDigits
                    typeMetadata.setData(MetadataRepository.DATA_TOTAL_DIGITS, String.valueOf(((XSDTotalDigitsFacet) currentFacet).getValue()));
                } else if (currentFacet instanceof XSDFractionDigitsFacet) {
                    // this is the fractionDigits
                    typeMetadata.setData(MetadataRepository.DATA_FRACTION_DIGITS, String.valueOf(((XSDFractionDigitsFacet) currentFacet).getValue()));
                } else if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Ignore simple type facet on type '" + typeName + "': " + currentFacet);
                }
            }
        }
    }
    if (getNonInstantiableType(targetNamespace, typeName) == null) {
        for (TypeMetadata superType : superTypes) {
            typeMetadata.addSuperType(superType);
        }
        addTypeMetadata(typeMetadata);
    }
}
Also used : XSDFractionDigitsFacet(org.eclipse.xsd.XSDFractionDigitsFacet) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) NotImplementedException(org.apache.commons.lang.NotImplementedException) LinkedList(java.util.LinkedList) XSDLengthFacet(org.eclipse.xsd.XSDLengthFacet) XSDTotalDigitsFacet(org.eclipse.xsd.XSDTotalDigitsFacet) XSDConstrainingFacet(org.eclipse.xsd.XSDConstrainingFacet) XSDMaxLengthFacet(org.eclipse.xsd.XSDMaxLengthFacet)

Example 4 with XSDConstrainingFacet

use of org.eclipse.xsd.XSDConstrainingFacet 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 5 with XSDConstrainingFacet

use of org.eclipse.xsd.XSDConstrainingFacet in project tmdm-studio-se by Talend.

the class SimpleTypeFacetCommitHandlerHelper_StringArrayFacet method doCommit.

@Override
protected boolean doCommit(String facetName) throws CommitException {
    String newValue = (String) commitHandler.getCommitedObj().getFacetValue(facetName);
    String oldValue = getOldFacetValue();
    if ((newValue == null && oldValue == null) || (oldValue != null && oldValue.equals(newValue)) || (newValue != null && newValue.equals(oldValue))) {
        return false;
    }
    if (oldValue != null) {
        commitHandler.getCommitedObj().getXSDSimpleType().getFacetContents().removeAll(Arrays.asList(commitHandler.getOldFacets()));
    }
    if (newValue != null && !newValue.trim().isEmpty()) {
        XSDConstrainingFacet f = commitHandler.creatNewFacet();
        // $NON-NLS-1$
        f.setLexicalValue("" + newValue);
        commitHandler.getCommitedObj().getXSDSimpleType().getFacetContents().add(f);
    }
    return true;
}
Also used : XSDConstrainingFacet(org.eclipse.xsd.XSDConstrainingFacet)

Aggregations

XSDConstrainingFacet (org.eclipse.xsd.XSDConstrainingFacet)5 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)3 ArrayList (java.util.ArrayList)2 NotImplementedException (org.apache.commons.lang.NotImplementedException)2 XSDEnumerationFacet (org.eclipse.xsd.XSDEnumerationFacet)2 XSDFractionDigitsFacet (org.eclipse.xsd.XSDFractionDigitsFacet)2 XSDLengthFacet (org.eclipse.xsd.XSDLengthFacet)2 XSDMaxLengthFacet (org.eclipse.xsd.XSDMaxLengthFacet)2 XSDPatternFacet (org.eclipse.xsd.XSDPatternFacet)2 XSDTotalDigitsFacet (org.eclipse.xsd.XSDTotalDigitsFacet)2 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)2 SimpleTypeInputDialog (com.amalto.workbench.dialogs.SimpleTypeInputDialog)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 EList (org.eclipse.emf.common.util.EList)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)1 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)1 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)1 XSDMaxExclusiveFacet (org.eclipse.xsd.XSDMaxExclusiveFacet)1