Search in sources :

Example 6 with XSDLengthFacet

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

use of org.eclipse.xsd.XSDLengthFacet 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 8 with XSDLengthFacet

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

the class UpdateStringLengthFacetCommand method execute.

public void execute() {
    try {
        beginRecording(xsdSimpleType.getElement());
        XSDLengthFacet lengthFacet = xsdSimpleType.getEffectiveLengthFacet();
        XSDMinLengthFacet minLengthFacet = xsdSimpleType.getEffectiveMinLengthFacet();
        XSDMaxLengthFacet maxLengthFacet = xsdSimpleType.getEffectiveMaxLengthFacet();
        String currentLength = null, currentMin = null, currentMax = null;
        if (lengthFacet != null) {
            currentLength = lengthFacet.getLexicalValue();
        }
        if (minLengthFacet != null) {
            currentMin = minLengthFacet.getLexicalValue();
        }
        if (maxLengthFacet != null) {
            currentMax = maxLengthFacet.getLexicalValue();
        }
        if (doUpdateMax && !doUpdateMin) {
            if (maxLengthFacet != null) {
                if (max != null) {
                    if (max.equals(currentMin)) {
                        lengthFacet = XSDFactory.eINSTANCE.createXSDLengthFacet();
                        lengthFacet.setLexicalValue(max);
                        xsdSimpleType.getFacetContents().add(lengthFacet);
                        xsdSimpleType.getFacetContents().remove(maxLengthFacet);
                        xsdSimpleType.getFacetContents().remove(minLengthFacet);
                    } else {
                        if (lengthFacet != null) {
                            xsdSimpleType.getFacetContents().remove(lengthFacet);
                        }
                        if (minLengthFacet == null && currentLength != null) {
                            minLengthFacet = XSDFactory.eINSTANCE.createXSDMinLengthFacet();
                            minLengthFacet.setLexicalValue(currentLength);
                            xsdSimpleType.getFacetContents().add(minLengthFacet);
                        }
                        maxLengthFacet.setLexicalValue(max);
                    }
                } else {
                    xsdSimpleType.getFacetContents().remove(maxLengthFacet);
                }
            } else {
                if (currentMin != null && currentMin.equals(max)) {
                    if (lengthFacet == null) {
                        lengthFacet = XSDFactory.eINSTANCE.createXSDLengthFacet();
                        xsdSimpleType.getFacetContents().add(lengthFacet);
                    }
                    lengthFacet.setLexicalValue(max);
                    xsdSimpleType.getFacetContents().remove(minLengthFacet);
                } else if (currentLength != null && !currentLength.equals(max)) {
                    xsdSimpleType.getFacetContents().remove(lengthFacet);
                    if (max != null) {
                        maxLengthFacet = XSDFactory.eINSTANCE.createXSDMaxLengthFacet();
                        maxLengthFacet.setLexicalValue(max);
                        xsdSimpleType.getFacetContents().add(maxLengthFacet);
                    }
                    minLengthFacet = XSDFactory.eINSTANCE.createXSDMinLengthFacet();
                    minLengthFacet.setLexicalValue(currentLength);
                    xsdSimpleType.getFacetContents().add(minLengthFacet);
                } else {
                    if (lengthFacet != null) {
                        xsdSimpleType.getFacetContents().remove(lengthFacet);
                        minLengthFacet = XSDFactory.eINSTANCE.createXSDMinLengthFacet();
                        minLengthFacet.setLexicalValue(currentLength);
                        xsdSimpleType.getFacetContents().add(minLengthFacet);
                    }
                    maxLengthFacet = XSDFactory.eINSTANCE.createXSDMaxLengthFacet();
                    maxLengthFacet.setLexicalValue(max);
                    xsdSimpleType.getFacetContents().add(maxLengthFacet);
                }
            }
        } else if (!doUpdateMax && doUpdateMin) {
            if (minLengthFacet != null) {
                if (min != null) {
                    if (min.equals(currentMax)) {
                        lengthFacet = XSDFactory.eINSTANCE.createXSDLengthFacet();
                        lengthFacet.setLexicalValue(min);
                        xsdSimpleType.getFacetContents().add(lengthFacet);
                        xsdSimpleType.getFacetContents().remove(maxLengthFacet);
                        xsdSimpleType.getFacetContents().remove(minLengthFacet);
                    } else {
                        if (lengthFacet != null) {
                            xsdSimpleType.getFacetContents().remove(lengthFacet);
                        }
                        if (maxLengthFacet == null && currentLength != null) {
                            maxLengthFacet = XSDFactory.eINSTANCE.createXSDMaxLengthFacet();
                            maxLengthFacet.setLexicalValue(currentLength);
                            xsdSimpleType.getFacetContents().add(maxLengthFacet);
                        }
                        minLengthFacet.setLexicalValue(min);
                    }
                } else {
                    xsdSimpleType.getFacetContents().remove(minLengthFacet);
                }
            } else {
                if (currentMax != null && currentMax.equals(min)) {
                    if (lengthFacet == null) {
                        lengthFacet = XSDFactory.eINSTANCE.createXSDLengthFacet();
                        xsdSimpleType.getFacetContents().add(lengthFacet);
                    }
                    lengthFacet.setLexicalValue(min);
                    xsdSimpleType.getFacetContents().remove(maxLengthFacet);
                } else if (currentLength != null && !currentLength.equals(min)) {
                    xsdSimpleType.getFacetContents().remove(lengthFacet);
                    if (min != null) {
                        minLengthFacet = XSDFactory.eINSTANCE.createXSDMinLengthFacet();
                        minLengthFacet.setLexicalValue(min);
                        xsdSimpleType.getFacetContents().add(minLengthFacet);
                    }
                    maxLengthFacet = XSDFactory.eINSTANCE.createXSDMaxLengthFacet();
                    maxLengthFacet.setLexicalValue(currentLength);
                    xsdSimpleType.getFacetContents().add(maxLengthFacet);
                } else {
                    minLengthFacet = XSDFactory.eINSTANCE.createXSDMinLengthFacet();
                    minLengthFacet.setLexicalValue(min);
                    xsdSimpleType.getFacetContents().add(minLengthFacet);
                    if (lengthFacet != null) {
                        xsdSimpleType.getFacetContents().remove(lengthFacet);
                        maxLengthFacet = XSDFactory.eINSTANCE.createXSDMaxLengthFacet();
                        maxLengthFacet.setLexicalValue(currentLength);
                        xsdSimpleType.getFacetContents().add(maxLengthFacet);
                    }
                }
            }
        }
        formatChild(xsdSimpleType.getElement());
    } finally {
        endRecording();
    }
}
Also used : XSDLengthFacet(org.eclipse.xsd.XSDLengthFacet) XSDMinLengthFacet(org.eclipse.xsd.XSDMinLengthFacet) XSDMaxLengthFacet(org.eclipse.xsd.XSDMaxLengthFacet)

Aggregations

XSDLengthFacet (org.eclipse.xsd.XSDLengthFacet)8 XSDMaxLengthFacet (org.eclipse.xsd.XSDMaxLengthFacet)7 XSDMinLengthFacet (org.eclipse.xsd.XSDMinLengthFacet)6 XSDFractionDigitsFacet (org.eclipse.xsd.XSDFractionDigitsFacet)4 XSDMaxExclusiveFacet (org.eclipse.xsd.XSDMaxExclusiveFacet)4 XSDMaxInclusiveFacet (org.eclipse.xsd.XSDMaxInclusiveFacet)4 XSDMinExclusiveFacet (org.eclipse.xsd.XSDMinExclusiveFacet)4 XSDMinInclusiveFacet (org.eclipse.xsd.XSDMinInclusiveFacet)4 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)4 XSDTotalDigitsFacet (org.eclipse.xsd.XSDTotalDigitsFacet)4 XSDEnumerationFacet (org.eclipse.xsd.XSDEnumerationFacet)3 ArrayList (java.util.ArrayList)2 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)2 XSDConstrainingFacet (org.eclipse.xsd.XSDConstrainingFacet)2 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)2 XSDParticle (org.eclipse.xsd.XSDParticle)2 XSDPatternFacet (org.eclipse.xsd.XSDPatternFacet)2 XSDWhiteSpaceFacet (org.eclipse.xsd.XSDWhiteSpaceFacet)2 FacetsListInputDialog (com.amalto.workbench.dialogs.FacetsListInputDialog)1 BigDecimal (java.math.BigDecimal)1