Java Examples for org.eclipse.xsd.XSDEnumerationFacet

The following java examples will help you to understand the usage of org.eclipse.xsd.XSDEnumerationFacet. These source code samples are taken from different open source projects.

Example 1
Project: turmeric-eclipse-master  File: XSDUtils.java View source code
/**
	 * process XSDSimpleTypeDefinition instance
	 * 
	 * @param complex
	 * @return
	 * @throws ImportTypeException
	 */
private ImportTypeModel processSimpleTypeDef(XSDSimpleTypeDefinition simple) throws ImportTypeException {
    TypeParamModel model = null;
    EList<XSDEnumerationFacet> enums = simple.getEnumerationFacets();
    if (enums == null || enums.size() == 0) {
        model = new SimpleTypeParamModel();
        SOAXSDTemplateSubType simpleType = SOAXSDTemplateSubType.SIMPLE;
        model.setTemplateCategory(simpleType);
        model.setTemplateName(getTemplateFile(simpleType));
    } else {
        EnumTypeParamModel enummodel = new EnumTypeParamModel();
        model = enummodel;
        SOAXSDTemplateSubType enumType = SOAXSDTemplateSubType.ENUM;
        model.setTemplateCategory(enumType);
        String templateFile = getTemplateFile(enumType);
        model.setTemplateName(templateFile);
        EnumTableModel[] enumItems = new EnumTableModel[enums.size()];
        for (int i = 0; i < enums.size(); i++) {
            XSDEnumerationFacet facet = enums.get(i);
            enumItems[i] = new EnumTableModel();
            enumItems[i].setEnumValue(facet.getLexicalValue());
            String description = getDescriptionFromAnnotation(facet.getAnnotation());
            enumItems[i].setEnumDesc(description);
        }
        enummodel.setEnumTableModel(enumItems);
    }
    String typeName = simple.getName();
    if (typeName == null) {
        typeName = "";
    }
    // String version = simple.getSchema().getVersion();
    XSDTypeDefinition typeDef = simple.getBaseType();
    String baseType = typeDef.getName();
    String namespace = simple.getTargetNamespace();
    String description = getDescriptionFromAnnotations(simple.getAnnotations());
    model.setTypeName(typeName);
    // model.setVersion(version);
    model.setBaseType(baseType);
    model.setDescription(description);
    model.setNamespace(namespace);
    ImportTypeModel importModel = new ImportTypeModel(model);
    return importModel;
}
Example 2
Project: webtools.sourceediting-master  File: XSDImpl.java View source code
private static void getEnumeratedValuesForSimpleType(XSDTypeDefinition type, List result) {
    List enumerationFacets = ((XSDSimpleTypeDefinition) type).getEnumerationFacets();
    for (Iterator i = enumerationFacets.iterator(); i.hasNext(); ) {
        XSDEnumerationFacet enumFacet = (XSDEnumerationFacet) i.next();
        List values = enumFacet.getValue();
        for (Iterator j = values.iterator(); j.hasNext(); ) {
            Object o = j.next();
            if (o != null) {
                if (!result.contains(o)) {
                    result.add(o.toString());
                }
            }
        }
    }
}
Example 3
Project: rinzo-xml-editor-master  File: XSDAttributeDefinition.java View source code
public Collection<String> getAcceptableValues() {
    Collection<String> result = new ArrayList<String>();
    for (Iterator iterator = this.attribute.getTypeDefinition().getFacetContents().iterator(); iterator.hasNext(); ) {
        Object next = iterator.next();
        if (next instanceof XSDEnumerationFacet) {
            XSDEnumerationFacet enumerationElement = (XSDEnumerationFacet) next;
            result.add(enumerationElement.getLexicalValue());
        }
    }
    return result;
}
Example 4
Project: teiid-designer-master  File: FacetHelper.java View source code
/**
     * Sets the core value of the specified facet. If facet cannot be properly modified to match fv, facets will be added or
     * removed as necessary to make it work. This occurs when a min or max value is changed from inclusive to exclusive, and when
     * dealing with patterns and enumerations.
     * 
     * @param facet
     * @param fv
     */
private static XSDConstrainingFacet setMainFacetValue(XSDSimpleTypeDefinition type, XSDConstrainingFacet facet, Object value) {
    int facetClassifierID = facet.eClass().getClassifierID();
    switch(facetClassifierID) {
        case XSDPackage.XSD_LENGTH_FACET:
            {
                XSDLengthFacet lf = (XSDLengthFacet) facet;
                if (value instanceof Integer) {
                    Integer i = (Integer) value;
                    lf.setLexicalValue(i.toString());
                } else if (value instanceof InclusiveInteger) {
                    InclusiveInteger ii = (InclusiveInteger) value;
                    lf.setLexicalValue(Integer.toString(ii.value));
                }
            // endif
            }
            break;
        case XSDPackage.XSD_MAX_LENGTH_FACET:
            {
                XSDMaxLengthFacet mf = (XSDMaxLengthFacet) facet;
                if (value instanceof Integer) {
                    Integer i = (Integer) value;
                    mf.setLexicalValue(i.toString());
                } else if (value instanceof InclusiveInteger) {
                    InclusiveInteger ii = (InclusiveInteger) value;
                    mf.setLexicalValue(Integer.toString(ii.value));
                }
            // endif
            }
            break;
        case XSDPackage.XSD_MIN_LENGTH_FACET:
            {
                XSDMinLengthFacet mf = (XSDMinLengthFacet) facet;
                if (value instanceof Integer) {
                    Integer i = (Integer) value;
                    mf.setLexicalValue(i.toString());
                } else if (value instanceof InclusiveInteger) {
                    InclusiveInteger ii = (InclusiveInteger) value;
                    mf.setLexicalValue(Integer.toString(ii.value));
                }
            // endif
            }
            break;
        case XSDPackage.XSD_PATTERN_FACET:
            {
                XSDPatternFacet pf = (XSDPatternFacet) facet;
                pf.setLexicalValue((String) value);
            }
            break;
        case XSDPackage.XSD_ENUMERATION_FACET:
            {
                XSDEnumerationFacet ef = (XSDEnumerationFacet) facet;
                ef.setLexicalValue((String) value);
            }
            break;
        case XSDPackage.XSD_WHITE_SPACE_FACET:
            {
                XSDWhiteSpaceFacet wf = (XSDWhiteSpaceFacet) facet;
                if (value instanceof String) {
                    String white = (String) value;
                    wf.setLexicalValue(white);
                }
            // endif
            }
            break;
        case XSDPackage.XSD_MIN_EXCLUSIVE_FACET:
        case XSDPackage.XSD_MIN_INCLUSIVE_FACET:
            {
                XSDMinFacet mf = (XSDMinFacet) facet;
                if (value instanceof Integer) {
                    Integer i = (Integer) value;
                    mf.setLexicalValue(i.toString());
                } else if (value instanceof InclusiveInteger) {
                    InclusiveInteger ii = (InclusiveInteger) value;
                    if (ii.isInclusive == mf.isInclusive()) {
                        // same inclusive types, don't need to do anything crazy
                        mf.setLexicalValue(Integer.toString(ii.value));
                    } else {
                        XSDMinFacet mf2;
                        if (ii.isInclusive) {
                            mf2 = XSDFactory.eINSTANCE.createXSDMinInclusiveFacet();
                        } else {
                            mf2 = XSDFactory.eINSTANCE.createXSDMinExclusiveFacet();
                        }
                        // endif
                        mf2.setLexicalValue(Integer.toString(ii.value));
                        try {
                            // remove old:
                            ModelerCore.getModelEditor().removeValue(type, mf, type.getFacetContents());
                            // add the copy:
                            ModelerCore.getModelEditor().addValue(type, mf2, type.getFacetContents());
                            // update the return value:
                            facet = mf2;
                        } catch (ModelerCoreException err) {
                            ModelerXsdUiConstants.Util.log(err);
                        }
                        return mf2;
                    }
                // endif -- same inclusive
                }
            // endif -- integer or iinteger
            }
            break;
        case XSDPackage.XSD_MAX_EXCLUSIVE_FACET:
        case XSDPackage.XSD_MAX_INCLUSIVE_FACET:
            {
                XSDMaxFacet mf = (XSDMaxFacet) facet;
                if (value instanceof Integer) {
                    Integer i = (Integer) value;
                    mf.setLexicalValue(i.toString());
                } else if (value instanceof InclusiveInteger) {
                    InclusiveInteger ii = (InclusiveInteger) value;
                    if (ii.isInclusive == mf.isInclusive()) {
                        // same inclusive types, don't need to do anything crazy
                        mf.setLexicalValue(Integer.toString(ii.value));
                    } else {
                        XSDMaxFacet mf2;
                        if (ii.isInclusive) {
                            mf2 = XSDFactory.eINSTANCE.createXSDMaxInclusiveFacet();
                        } else {
                            mf2 = XSDFactory.eINSTANCE.createXSDMaxExclusiveFacet();
                        }
                        // endif
                        mf2.setLexicalValue(Integer.toString(ii.value));
                        try {
                            // remove old:
                            ModelerCore.getModelEditor().removeValue(type, mf, type.getFacetContents());
                            // add the copy:
                            ModelerCore.getModelEditor().addValue(type, mf2, type.getFacetContents());
                            // update the return value:
                            facet = mf2;
                        } catch (ModelerCoreException err) {
                            ModelerXsdUiConstants.Util.log(err);
                        }
                        return mf2;
                    }
                // endif -- same inclusive
                }
            // endif -- integer or iinteger
            }
            break;
        case XSDPackage.XSD_FRACTION_DIGITS_FACET:
            {
                XSDFractionDigitsFacet ff = (XSDFractionDigitsFacet) facet;
                if (value instanceof Integer) {
                    Integer i = (Integer) value;
                    ff.setLexicalValue(i.toString());
                } else if (value instanceof InclusiveInteger) {
                    InclusiveInteger ii = (InclusiveInteger) value;
                    ff.setLexicalValue(Integer.toString(ii.value));
                }
            // endif
            }
            break;
        case XSDPackage.XSD_TOTAL_DIGITS_FACET:
            {
                XSDTotalDigitsFacet tf = (XSDTotalDigitsFacet) facet;
                if (value instanceof Integer) {
                    Integer i = (Integer) value;
                    tf.setLexicalValue(i.toString());
                } else if (value instanceof InclusiveInteger) {
                    InclusiveInteger ii = (InclusiveInteger) value;
                    tf.setLexicalValue(Integer.toString(ii.value));
                }
            // endif
            }
            break;
        default:
            ModelerXsdUiConstants.Util.log(ModelerXsdUiConstants.Util.getString(ERROR_KEY_UNUSABLE_FACET, facet));
            break;
    }
    return facet;
}
Example 5
Project: org.eclipse.wst.sse.sieditor-master  File: SetBaseTypeCommand.java View source code
private void updateSimpleTypeFacets(final XSDSimpleTypeDefinition type, final XSDSimpleTypeDefinition baseType) {
    final List<XSDConstrainingFacet> facets = type.getFacetContents();
    if (!getSimpleTypeFacets().areLengthFacetsSupported(baseType)) {
        removeFacet(facets, type.getLengthFacet());
        removeFacet(facets, type.getMinLengthFacet());
        removeFacet(facets, type.getMaxLengthFacet());
    }
    if (!getSimpleTypeFacets().areInclusiveFacetsSupported(baseType)) {
        removeFacet(facets, type.getMinInclusiveFacet());
        removeFacet(facets, type.getMaxInclusiveFacet());
    }
    if (!getSimpleTypeFacets().areExclusiveFacetsSupported(baseType)) {
        removeFacet(facets, type.getMinExclusiveFacet());
        removeFacet(facets, type.getMaxExclusiveFacet());
    }
    if (!getSimpleTypeFacets().isFractionDigitsFacetSupported(baseType)) {
        removeFacet(facets, type.getFractionDigitsFacet());
    }
    if (!getSimpleTypeFacets().isTotalDigitsFacetSupported(baseType)) {
        removeFacet(facets, type.getTotalDigitsFacet());
    }
    if (!getSimpleTypeFacets().isEnumerationFacetSupported(baseType)) {
        for (final Iterator<XSDConstrainingFacet> it = facets.iterator(); it.hasNext(); ) {
            if (it.next() instanceof XSDEnumerationFacet) {
                it.remove();
            }
        }
    }
    if (!getSimpleTypeFacets().isWhitespaceFacetSupported(baseType)) {
        removeFacet(facets, type.getWhiteSpaceFacet());
    }
}
Example 6
Project: geotools_trunk-master  File: ParseExecutor.java View source code
/**
     * Pre-parses the instance compontent checking the following:
     * <p>
     *
     * </p>
     * @param instance
     */
protected Object preParse(InstanceComponent instance) {
    // we only preparse text, so simple types
    XSDSimpleTypeDefinition type = null;
    if (instance.getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
        type = (XSDSimpleTypeDefinition) instance.getTypeDefinition();
    } else {
        XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) instance.getTypeDefinition();
        if (complexType.getContentType() instanceof XSDSimpleTypeDefinition) {
            type = (XSDSimpleTypeDefinition) complexType.getContentType();
        }
    }
    String text = instance.getText();
    if (type != null) {
        //first base on variety
        if (type.getVariety() == XSDVariety.LIST_LITERAL) {
            //list, whiteSpace is fixed to "COLLAPSE 
            text = Whitespace.COLLAPSE.preparse(text);
            //lists are seperated by spaces
            String[] list = text.split(" +");
            // 4. enumeration
            if (type.getLengthFacet() != null) {
                XSDLengthFacet length = type.getLengthFacet();
                if (list.length != length.getValue()) {
                //validation exception
                }
            }
            if (type.getMaxLengthFacet() != null) {
                XSDMaxLengthFacet length = type.getMaxLengthFacet();
                if (list.length > length.getValue()) {
                //validation exception
                }
            }
            if (type.getMinLengthFacet() != null) {
                XSDMinLengthFacet length = type.getMinLengthFacet();
                if (list.length < length.getValue()) {
                //validation exception
                }
            }
            if (!type.getEnumerationFacets().isEmpty()) {
                //gather up all teh possible values
                Set values = new HashSet();
                for (Iterator e = type.getEnumerationFacets().iterator(); e.hasNext(); ) {
                    XSDEnumerationFacet enumeration = (XSDEnumerationFacet) e.next();
                    for (Iterator v = enumeration.getValue().iterator(); v.hasNext(); ) {
                        values.add(v.next());
                    }
                }
                for (int i = 0; i < list.length; i++) {
                    if (!values.contains(list[i])) {
                    //validation exception
                    }
                }
            }
            //now we must parse the items up
            final XSDSimpleTypeDefinition itemType = type.getItemTypeDefinition();
            List parsed = new ArrayList();
            //create a pseudo declaration
            final XSDElementDeclaration element = XSDFactory.eINSTANCE.createXSDElementDeclaration();
            element.setTypeDefinition(itemType);
            if (instance.getName() != null) {
                element.setName(instance.getName());
            }
            if (instance.getNamespace() != null) {
                element.setTargetNamespace(instance.getNamespace());
            }
            //create a new instance of the specified type
            InstanceComponentImpl theInstance = new InstanceComponentImpl() {

                public XSDTypeDefinition getTypeDefinition() {
                    return itemType;
                }

                public XSDNamedComponent getDeclaration() {
                    return element;
                }

                ;
            };
            for (int i = 0; i < list.length; i++) {
                theInstance.setText(list[i]);
                //perform the parse
                ParseExecutor executor = new ParseExecutor(theInstance, null, context, parser);
                parser.getBindingWalker().walk(element, executor, context);
                parsed.add(executor.getValue());
            }
            return parsed;
        } else if (type.getVariety() == XSDVariety.UNION_LITERAL) {
            // datatypes
            return text;
        } else {
            //walk through the facets and preparse as necessary 
            for (Iterator f = type.getFacets().iterator(); f.hasNext(); ) {
                XSDFacet facet = (XSDFacet) f.next();
                //white space
                if (facet instanceof XSDWhiteSpaceFacet) {
                    XSDWhiteSpaceFacet whitespace = (XSDWhiteSpaceFacet) facet;
                    if (whitespace.getValue() == XSDWhiteSpace.REPLACE_LITERAL) {
                        text = Whitespace.REPLACE.preparse(text);
                    }
                    if (whitespace.getValue() == XSDWhiteSpace.COLLAPSE_LITERAL) {
                        text = Whitespace.COLLAPSE.preparse(text);
                    }
                    if (whitespace.getValue() == XSDWhiteSpace.PRESERVE_LITERAL) {
                    //do nothing
                    }
                }
            }
            return text;
        }
    } else {
        // for mixed
        if (instance.getTypeDefinition() instanceof XSDComplexTypeDefinition && ((XSDComplexTypeDefinition) instance.getTypeDefinition()).isMixed()) {
            //collape the text
            text = Whitespace.COLLAPSE.preparse(text);
        }
    }
    return text;
}
Example 7
Project: org.eclipse.bpel-master  File: XSD2XMLGenerator.java View source code
/**
		 * This was stolen directly from XSDImpl. It builds a list of the enumeration
		 * values for the given XSD type definition.
		 * 
		 * @param type - an XSD type definition (presumably determined from a CMNode)
		 * @param result - List to which we will add our results
		 */
public void getEnumeratedValuesForSimpleType(XSDTypeDefinition type, List result) {
    List enumerationFacets = ((XSDSimpleTypeDefinition) type).getEnumerationFacets();
    for (Iterator i = enumerationFacets.iterator(); i.hasNext(); ) {
        XSDEnumerationFacet enumFacet = (XSDEnumerationFacet) i.next();
        List values = enumFacet.getValue();
        for (Iterator j = values.iterator(); j.hasNext(); ) {
            Object o = j.next();
            if (o != null) {
                if (!result.contains(o)) {
                    result.add(o.toString());
                }
            }
        }
    }
}
Example 8
Project: tmdm-studio-se-master  File: DataModelMainPage.java View source code
private int getElementType(Object decl) {
    if (Util.getParent(decl) == decl) {
        if (Util.checkConcept((XSDElementDeclaration) decl)) {
            return 0;
        }
        return 1;
    }
    if (decl instanceof XSDComplexTypeDefinition) {
        return 2;
    }
    if (decl instanceof XSDIdentityConstraintDefinition) {
        return 3;
    }
    if (decl instanceof XSDXPathDefinition) {
        return 4;
    }
    if (decl instanceof XSDSimpleTypeDefinition) {
        return 5;
    }
    if (decl instanceof XSDAnnotation) {
        return 6;
    }
    if (decl instanceof XSDParticle) {
        return 7;
    }
    if (decl instanceof XSDModelGroup) {
        return 8;
    }
    if (decl instanceof XSDWhiteSpaceFacet) {
        return 201;
    }
    if (decl instanceof XSDLengthFacet) {
        return 202;
    }
    if (decl instanceof XSDMinLengthFacet) {
        return 203;
    }
    if (decl instanceof XSDMaxLengthFacet) {
        return 204;
    }
    if (decl instanceof XSDTotalDigitsFacet) {
        return 205;
    }
    if (decl instanceof XSDFractionDigitsFacet) {
        return 206;
    }
    if (decl instanceof XSDMaxInclusiveFacet) {
        return 207;
    }
    if (decl instanceof XSDMaxExclusiveFacet) {
        return 208;
    }
    if (decl instanceof XSDMinInclusiveFacet) {
        return 209;
    }
    if (decl instanceof XSDMinExclusiveFacet) {
        return 210;
    }
    if (decl instanceof XSDPatternFacet) {
        return 211;
    }
    if (decl instanceof XSDEnumerationFacet) {
        return 212;
    }
    if (decl instanceof Element) {
        Element e = (Element) decl;
        if (e.getLocalName().equals("appinfo")) {
        //$NON-NLS-1$
        }
        //$NON-NLS-1$
        String source = e.getAttribute("source");
        if (source != null) {
            if (source.startsWith("X_Label_")) {
                //$NON-NLS-1$
                return 101;
            } else if (source.equals("X_ForeignKey")) {
                //$NON-NLS-1$
                return 102;
            } else if (source.equals("X_ForeignKeyInfo")) {
                //$NON-NLS-1$
                return 103;
            } else if (source.equals("X_SourceSystem")) {
                //$NON-NLS-1$
                return 104;
            } else if (source.equals("X_TargetSystem")) {
                //$NON-NLS-1$
                return 105;
            } else if (source.startsWith("X_Description_")) {
                //$NON-NLS-1$
                return 106;
            } else if (source.equals("X_Write")) {
                //$NON-NLS-1$
                return 107;
            } else if (source.equals("X_Hide")) {
                //$NON-NLS-1$
                return 108;
            } else if (source.equals("X_Schematron")) {
                //$NON-NLS-1$
                return 109;
            } else if (source.startsWith("X_Facet_")) {
                //$NON-NLS-1$
                return 110;
            } else if (source.startsWith("X_Workflow")) {
                //$NON-NLS-1$
                return 111;
            } else if (source.startsWith("X_ForeignKey_Filter")) {
                //$NON-NLS-1$
                return 112;
            } else if (source.startsWith("X_Display_Format_")) {
                //$NON-NLS-1$
                return 113;
            } else if (source.equals("X_Lookup_Field")) {
                //$NON-NLS-1$
                return 114;
            } else if (source.equals("X_PrimaryKeyInfo")) {
                //$NON-NLS-1$
                return 115;
            } else if (source.equals("X_Visible_Rule")) {
                //$NON-NLS-1$
                return 116;
            } else if (source.equals("X_Default_Value_Rule")) {
                //$NON-NLS-1$
                return 117;
            } else if (source.equals("X_Deny_Create")) {
                //$NON-NLS-1$
                return 118;
            } else if (source.equals("X_Deny_PhysicalDelete")) {
                //$NON-NLS-1$
                return 119;
            } else if (source.equals("X_Deny_LogicalDelete")) {
                //$NON-NLS-1$
                return 120;
            } else if (source.equals("X_FKIntegrity")) {
                //$NON-NLS-1$
                return 121;
            } else if (source.equals("X_FKIntegrity_Override")) {
                //$NON-NLS-1$
                return 122;
            } else if (source.equals("X_ForeignKeyInfoFormat")) {
                //$NON-NLS-1$
                return 123;
            }
        }
    }
    return -1;
}
Example 9
Project: modeshape-master  File: XsdReader.java View source code
protected void processTypeFacets(XSDSimpleTypeDefinition type, Node typeNode, XSDTypeDefinition baseType) throws RepositoryException {
    if (baseType == null) {
        baseType = type.getBaseType();
    }
    if (baseType == type) {
        // The base type is the anytype ...
        baseType = type.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("http://www.w3.org/2001/XMLSchema", "anyType");
    }
    if (baseType != null) {
        typeNode.setProperty(XsdLexicon.BASE_TYPE_NAME, baseType.getName());
        typeNode.setProperty(XsdLexicon.BASE_TYPE_NAMESPACE, baseType.getTargetNamespace());
        setReference(typeNode, XsdLexicon.BASE_TYPE_REFERENCE, TYPE_DEFINITIONS, baseType.getTargetNamespace(), baseType.getName());
    }
    processFacet(type.getEffectiveMaxLengthFacet(), typeNode, XsdLexicon.MAX_LENGTH, PropertyType.LONG);
    processFacet(type.getMaxLengthFacet(), typeNode, XsdLexicon.MAX_LENGTH, PropertyType.LONG);
    processFacet(type.getEffectiveMinLengthFacet(), typeNode, XsdLexicon.MIN_LENGTH, PropertyType.LONG);
    processFacet(type.getMinLengthFacet(), typeNode, XsdLexicon.MIN_LENGTH, PropertyType.LONG);
    processFacet(type.getEffectiveMaxFacet(), typeNode, XsdLexicon.MAX_VALUE_EXCLUSIVE, PropertyType.LONG);
    processFacet(type.getMaxExclusiveFacet(), typeNode, XsdLexicon.MAX_VALUE_EXCLUSIVE, PropertyType.LONG);
    processFacet(type.getEffectiveMinFacet(), typeNode, XsdLexicon.MIN_VALUE_EXCLUSIVE, PropertyType.LONG);
    processFacet(type.getMinExclusiveFacet(), typeNode, XsdLexicon.MIN_VALUE_EXCLUSIVE, PropertyType.LONG);
    processFacet(type.getMaxInclusiveFacet(), typeNode, XsdLexicon.MAX_VALUE_INCLUSIVE, PropertyType.LONG);
    processFacet(type.getMinInclusiveFacet(), typeNode, XsdLexicon.MIN_VALUE_INCLUSIVE, PropertyType.LONG);
    processFacet(type.getEffectiveTotalDigitsFacet(), typeNode, XsdLexicon.TOTAL_DIGITS, PropertyType.LONG);
    processFacet(type.getTotalDigitsFacet(), typeNode, XsdLexicon.TOTAL_DIGITS, PropertyType.LONG);
    processFacet(type.getEffectiveFractionDigitsFacet(), typeNode, XsdLexicon.FRACTION_DIGITS, PropertyType.LONG);
    processFacet(type.getFractionDigitsFacet(), typeNode, XsdLexicon.FRACTION_DIGITS, PropertyType.LONG);
    processFacet(type.getEffectiveWhiteSpaceFacet(), typeNode, XsdLexicon.WHITESPACE, PropertyType.STRING);
    processFacet(type.getWhiteSpaceFacet(), typeNode, XsdLexicon.WHITESPACE, PropertyType.STRING);
    processFacet(type.getEffectivePatternFacet(), typeNode, XsdLexicon.PATTERN, PropertyType.STRING);
    @SuppressWarnings("unchecked") List<XSDPatternFacet> patternFacets = type.getPatternFacets();
    processFacetsList(patternFacets, typeNode, XsdLexicon.PATTERN);
    processFacet(type.getEffectiveEnumerationFacet(), typeNode, XsdLexicon.ENUMERATED_VALUES, PropertyType.STRING);
    @SuppressWarnings("unchecked") List<XSDEnumerationFacet> enumFacets = type.getEnumerationFacets();
    processFacetsList(enumFacets, typeNode, XsdLexicon.ENUMERATED_VALUES);
    @SuppressWarnings("unchecked") List<XSDSimpleFinal> finalFacets2 = type.getFinal();
    processEnumerators(finalFacets2, typeNode, XsdLexicon.FINAL);
    processAnnotation(type.getAnnotation(), typeNode);
}
Example 10
Project: mappingtools-master  File: XSDStructure.java View source code
//------------------------------------------------------------------------------------------------------
//                             Getting Enumeration values of simple types
//------------------------------------------------------------------------------------------------------
/**
          * @param simpleTypeName the name of a simple type
          * @return a list of its enumerated values, if it has any; otherwise an empty list
          * @throws MapperException if there is no such simple type
          */
public Vector<String> getSimpleTypeEnumeratedValues(String simpleTypeName) throws MapperException {
    Vector<String> values = new Vector<String>();
    XSDSimpleTypeDefinition theType = null;
    EList<XSDTypeDefinition> types = schema.getTypeDefinitions();
    for (Iterator<XSDTypeDefinition> it = types.iterator(); it.hasNext(); ) {
        XSDTypeDefinition next = it.next();
        if (theType == null) {
            if ((next instanceof XSDSimpleTypeDefinition) && (next.getName().equals(simpleTypeName)))
                theType = (XSDSimpleTypeDefinition) next;
            if ((theType != null) && (theType.getEnumerationFacets() != null)) {
                int size = theType.getEnumerationFacets().size();
                if (size > 0) {
                    for (Iterator<XSDEnumerationFacet> iu = theType.getEnumerationFacets().iterator(); iu.hasNext(); ) {
                        XSDEnumerationFacet facet = iu.next();
                        EList<Object> valueSet = facet.getValue();
                        if ((valueSet != null) && (valueSet.size() == 1)) {
                            Object value = valueSet.get(0);
                            if (value instanceof String)
                                values.add((String) value);
                        }
                    }
                }
            }
        }
    }
    if (theType == null)
        throw new MapperException("Simple type '" + simpleTypeName + "' not found.");
    return values;
}
Example 11
Project: geotools-tike-master  File: ParseExecutor.java View source code
/**
     * Pre-parses the instance compontent checking the following:
     * <p>
     *
     * </p>
     * @param instance
     */
protected Object preParse(InstanceComponent instance) {
    // we only preparse text, so simple types
    XSDSimpleTypeDefinition type = null;
    if (instance.getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
        type = (XSDSimpleTypeDefinition) instance.getTypeDefinition();
    } else {
        XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) instance.getTypeDefinition();
        if (complexType.getContentType() instanceof XSDSimpleTypeDefinition) {
            type = (XSDSimpleTypeDefinition) complexType.getContentType();
        }
    }
    String text = instance.getText();
    if (type != null) {
        //first base on variety
        if (type.getVariety() == XSDVariety.LIST_LITERAL) {
            //list, whiteSpace is fixed to "COLLAPSE 
            text = Whitespace.COLLAPSE.preparse(text);
            //lists are seperated by spaces
            String[] list = text.split(" +");
            // 4. enumeration
            if (type.getLengthFacet() != null) {
                XSDLengthFacet length = type.getLengthFacet();
                if (list.length != length.getValue()) {
                //validation exception
                }
            }
            if (type.getMaxLengthFacet() != null) {
                XSDMaxLengthFacet length = type.getMaxLengthFacet();
                if (list.length > length.getValue()) {
                //validation exception
                }
            }
            if (type.getMinLengthFacet() != null) {
                XSDMinLengthFacet length = type.getMinLengthFacet();
                if (list.length < length.getValue()) {
                //validation exception
                }
            }
            if (!type.getEnumerationFacets().isEmpty()) {
                //gather up all teh possible values
                Set values = new HashSet();
                for (Iterator e = type.getEnumerationFacets().iterator(); e.hasNext(); ) {
                    XSDEnumerationFacet enumeration = (XSDEnumerationFacet) e.next();
                    for (Iterator v = enumeration.getValue().iterator(); v.hasNext(); ) {
                        values.add(v.next());
                    }
                }
                for (int i = 0; i < list.length; i++) {
                    if (!values.contains(list[i])) {
                    //validation exception
                    }
                }
            }
            //now we must parse the items up
            final XSDSimpleTypeDefinition itemType = type.getItemTypeDefinition();
            List parsed = new ArrayList();
            for (int i = 0; i < list.length; i++) {
                //create a pseudo declaration
                final XSDElementDeclaration element = XSDFactory.eINSTANCE.createXSDElementDeclaration();
                element.setTypeDefinition(itemType);
                if (instance.getName() != null) {
                    element.setName(instance.getName());
                }
                if (instance.getNamespace() != null) {
                    element.setTargetNamespace(instance.getNamespace());
                }
                //create a new instance of the specified type
                InstanceComponentImpl theInstance = new InstanceComponentImpl() {

                    public XSDTypeDefinition getTypeDefinition() {
                        return itemType;
                    }

                    public XSDNamedComponent getDeclaration() {
                        return element;
                    }

                    ;
                };
                theInstance.setText(list[i]);
                //perform the parse
                ParseExecutor executor = new ParseExecutor(theInstance, null, context, parser);
                parser.getBindingWalker().walk(element, executor, context);
                parsed.add(executor.getValue());
            }
            return parsed;
        } else if (type.getVariety() == XSDVariety.UNION_LITERAL) {
            // datatypes
            return text;
        } else {
            //walk through the facets and preparse as necessary 
            for (Iterator f = type.getFacets().iterator(); f.hasNext(); ) {
                XSDFacet facet = (XSDFacet) f.next();
                //white space
                if (facet instanceof XSDWhiteSpaceFacet) {
                    XSDWhiteSpaceFacet whitespace = (XSDWhiteSpaceFacet) facet;
                    if (whitespace.getValue() == XSDWhiteSpace.REPLACE_LITERAL) {
                        text = Whitespace.REPLACE.preparse(text);
                    }
                    if (whitespace.getValue() == XSDWhiteSpace.COLLAPSE_LITERAL) {
                        text = Whitespace.COLLAPSE.preparse(text);
                    }
                    if (whitespace.getValue() == XSDWhiteSpace.PRESERVE_LITERAL) {
                    //do nothing
                    }
                }
            }
            return text;
        }
    } else {
        // for mixed
        if (instance.getTypeDefinition() instanceof XSDComplexTypeDefinition && ((XSDComplexTypeDefinition) instance.getTypeDefinition()).isMixed()) {
            //collape the text
            text = Whitespace.COLLAPSE.preparse(text);
        }
    }
    return text;
}
Example 12
Project: geotools-master  File: ParseExecutor.java View source code
/**
     * Pre-parses the instance compontent checking the following:
     * <p>
     *
     * </p>
     * @param instance
     */
protected Object preParse(InstanceComponent instance) {
    // we only preparse text, so simple types
    XSDSimpleTypeDefinition type = null;
    if (instance.getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
        type = (XSDSimpleTypeDefinition) instance.getTypeDefinition();
    } else {
        XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) instance.getTypeDefinition();
        if (complexType.getContentType() instanceof XSDSimpleTypeDefinition) {
            type = (XSDSimpleTypeDefinition) complexType.getContentType();
        }
    }
    String text = instance.getText();
    if (type != null) {
        //first base on variety
        if (type.getVariety() == XSDVariety.LIST_LITERAL) {
            //list, whiteSpace is fixed to "COLLAPSE 
            text = Whitespace.COLLAPSE.preparse(text);
            //lists are seperated by spaces
            String[] list = text.split(" +");
            // 4. enumeration
            if (type.getLengthFacet() != null) {
                XSDLengthFacet length = type.getLengthFacet();
                if (list.length != length.getValue()) {
                //validation exception
                }
            }
            if (type.getMaxLengthFacet() != null) {
                XSDMaxLengthFacet length = type.getMaxLengthFacet();
                if (list.length > length.getValue()) {
                //validation exception
                }
            }
            if (type.getMinLengthFacet() != null) {
                XSDMinLengthFacet length = type.getMinLengthFacet();
                if (list.length < length.getValue()) {
                //validation exception
                }
            }
            if (!type.getEnumerationFacets().isEmpty()) {
                //gather up all teh possible values
                Set values = new HashSet();
                for (Iterator e = type.getEnumerationFacets().iterator(); e.hasNext(); ) {
                    XSDEnumerationFacet enumeration = (XSDEnumerationFacet) e.next();
                    for (Iterator v = enumeration.getValue().iterator(); v.hasNext(); ) {
                        values.add(v.next());
                    }
                }
                for (int i = 0; i < list.length; i++) {
                    if (!values.contains(list[i])) {
                    //validation exception
                    }
                }
            }
            //now we must parse the items up
            final XSDSimpleTypeDefinition itemType = type.getItemTypeDefinition();
            List parsed = new ArrayList();
            //create a pseudo declaration
            final XSDElementDeclaration element = XSDFactory.eINSTANCE.createXSDElementDeclaration();
            element.setTypeDefinition(itemType);
            if (instance.getName() != null) {
                element.setName(instance.getName());
            }
            if (instance.getNamespace() != null) {
                element.setTargetNamespace(instance.getNamespace());
            }
            //create a new instance of the specified type
            InstanceComponentImpl theInstance = new InstanceComponentImpl() {

                public XSDTypeDefinition getTypeDefinition() {
                    return itemType;
                }

                public XSDNamedComponent getDeclaration() {
                    return element;
                }

                ;
            };
            for (int i = 0; i < list.length; i++) {
                theInstance.setText(list[i]);
                //perform the parse
                ParseExecutor executor = new ParseExecutor(theInstance, null, context, parser);
                parser.getBindingWalker().walk(element, executor, context);
                parsed.add(executor.getValue());
            }
            return parsed;
        } else if (type.getVariety() == XSDVariety.UNION_LITERAL) {
            // datatypes
            return text;
        } else {
            //walk through the facets and preparse as necessary 
            for (Iterator f = type.getFacets().iterator(); f.hasNext(); ) {
                XSDFacet facet = (XSDFacet) f.next();
                //white space
                if (facet instanceof XSDWhiteSpaceFacet) {
                    XSDWhiteSpaceFacet whitespace = (XSDWhiteSpaceFacet) facet;
                    if (whitespace.getValue() == XSDWhiteSpace.REPLACE_LITERAL) {
                        text = Whitespace.REPLACE.preparse(text);
                    }
                    if (whitespace.getValue() == XSDWhiteSpace.COLLAPSE_LITERAL) {
                        text = Whitespace.COLLAPSE.preparse(text);
                    }
                    if (whitespace.getValue() == XSDWhiteSpace.PRESERVE_LITERAL) {
                    //do nothing
                    }
                }
            }
            return text;
        }
    } else {
        // for mixed
        if (instance.getTypeDefinition() instanceof XSDComplexTypeDefinition && ((XSDComplexTypeDefinition) instance.getTypeDefinition()).isMixed()) {
            //collape the text
            text = Whitespace.COLLAPSE.preparse(text);
        }
    }
    return text;
}
Example 13
Project: geotools-2.7.x-master  File: ParseExecutor.java View source code
/**
     * Pre-parses the instance compontent checking the following:
     * <p>
     *
     * </p>
     * @param instance
     */
protected Object preParse(InstanceComponent instance) {
    // we only preparse text, so simple types
    XSDSimpleTypeDefinition type = null;
    if (instance.getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
        type = (XSDSimpleTypeDefinition) instance.getTypeDefinition();
    } else {
        XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) instance.getTypeDefinition();
        if (complexType.getContentType() instanceof XSDSimpleTypeDefinition) {
            type = (XSDSimpleTypeDefinition) complexType.getContentType();
        }
    }
    String text = instance.getText();
    if (type != null) {
        //first base on variety
        if (type.getVariety() == XSDVariety.LIST_LITERAL) {
            //list, whiteSpace is fixed to "COLLAPSE 
            text = Whitespace.COLLAPSE.preparse(text);
            //lists are seperated by spaces
            String[] list = text.split(" +");
            // 4. enumeration
            if (type.getLengthFacet() != null) {
                XSDLengthFacet length = type.getLengthFacet();
                if (list.length != length.getValue()) {
                //validation exception
                }
            }
            if (type.getMaxLengthFacet() != null) {
                XSDMaxLengthFacet length = type.getMaxLengthFacet();
                if (list.length > length.getValue()) {
                //validation exception
                }
            }
            if (type.getMinLengthFacet() != null) {
                XSDMinLengthFacet length = type.getMinLengthFacet();
                if (list.length < length.getValue()) {
                //validation exception
                }
            }
            if (!type.getEnumerationFacets().isEmpty()) {
                //gather up all teh possible values
                Set values = new HashSet();
                for (Iterator e = type.getEnumerationFacets().iterator(); e.hasNext(); ) {
                    XSDEnumerationFacet enumeration = (XSDEnumerationFacet) e.next();
                    for (Iterator v = enumeration.getValue().iterator(); v.hasNext(); ) {
                        values.add(v.next());
                    }
                }
                for (int i = 0; i < list.length; i++) {
                    if (!values.contains(list[i])) {
                    //validation exception
                    }
                }
            }
            //now we must parse the items up
            final XSDSimpleTypeDefinition itemType = type.getItemTypeDefinition();
            List parsed = new ArrayList();
            //create a pseudo declaration
            final XSDElementDeclaration element = XSDFactory.eINSTANCE.createXSDElementDeclaration();
            element.setTypeDefinition(itemType);
            if (instance.getName() != null) {
                element.setName(instance.getName());
            }
            if (instance.getNamespace() != null) {
                element.setTargetNamespace(instance.getNamespace());
            }
            //create a new instance of the specified type
            InstanceComponentImpl theInstance = new InstanceComponentImpl() {

                public XSDTypeDefinition getTypeDefinition() {
                    return itemType;
                }

                public XSDNamedComponent getDeclaration() {
                    return element;
                }

                ;
            };
            for (int i = 0; i < list.length; i++) {
                theInstance.setText(list[i]);
                //perform the parse
                ParseExecutor executor = new ParseExecutor(theInstance, null, context, parser);
                parser.getBindingWalker().walk(element, executor, context);
                parsed.add(executor.getValue());
            }
            return parsed;
        } else if (type.getVariety() == XSDVariety.UNION_LITERAL) {
            // datatypes
            return text;
        } else {
            //walk through the facets and preparse as necessary 
            for (Iterator f = type.getFacets().iterator(); f.hasNext(); ) {
                XSDFacet facet = (XSDFacet) f.next();
                //white space
                if (facet instanceof XSDWhiteSpaceFacet) {
                    XSDWhiteSpaceFacet whitespace = (XSDWhiteSpaceFacet) facet;
                    if (whitespace.getValue() == XSDWhiteSpace.REPLACE_LITERAL) {
                        text = Whitespace.REPLACE.preparse(text);
                    }
                    if (whitespace.getValue() == XSDWhiteSpace.COLLAPSE_LITERAL) {
                        text = Whitespace.COLLAPSE.preparse(text);
                    }
                    if (whitespace.getValue() == XSDWhiteSpace.PRESERVE_LITERAL) {
                    //do nothing
                    }
                }
            }
            return text;
        }
    } else {
        // for mixed
        if (instance.getTypeDefinition() instanceof XSDComplexTypeDefinition && ((XSDComplexTypeDefinition) instance.getTypeDefinition()).isMixed()) {
            //collape the text
            text = Whitespace.COLLAPSE.preparse(text);
        }
    }
    return text;
}
Example 14
Project: geotools-old-master  File: ParseExecutor.java View source code
/**
     * Pre-parses the instance compontent checking the following:
     * <p>
     *
     * </p>
     * @param instance
     */
protected Object preParse(InstanceComponent instance) {
    // we only preparse text, so simple types
    XSDSimpleTypeDefinition type = null;
    if (instance.getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
        type = (XSDSimpleTypeDefinition) instance.getTypeDefinition();
    } else {
        XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) instance.getTypeDefinition();
        if (complexType.getContentType() instanceof XSDSimpleTypeDefinition) {
            type = (XSDSimpleTypeDefinition) complexType.getContentType();
        }
    }
    String text = instance.getText();
    if (type != null) {
        //first base on variety
        if (type.getVariety() == XSDVariety.LIST_LITERAL) {
            //list, whiteSpace is fixed to "COLLAPSE 
            text = Whitespace.COLLAPSE.preparse(text);
            //lists are seperated by spaces
            String[] list = text.split(" +");
            // 4. enumeration
            if (type.getLengthFacet() != null) {
                XSDLengthFacet length = type.getLengthFacet();
                if (list.length != length.getValue()) {
                //validation exception
                }
            }
            if (type.getMaxLengthFacet() != null) {
                XSDMaxLengthFacet length = type.getMaxLengthFacet();
                if (list.length > length.getValue()) {
                //validation exception
                }
            }
            if (type.getMinLengthFacet() != null) {
                XSDMinLengthFacet length = type.getMinLengthFacet();
                if (list.length < length.getValue()) {
                //validation exception
                }
            }
            if (!type.getEnumerationFacets().isEmpty()) {
                //gather up all teh possible values
                Set values = new HashSet();
                for (Iterator e = type.getEnumerationFacets().iterator(); e.hasNext(); ) {
                    XSDEnumerationFacet enumeration = (XSDEnumerationFacet) e.next();
                    for (Iterator v = enumeration.getValue().iterator(); v.hasNext(); ) {
                        values.add(v.next());
                    }
                }
                for (int i = 0; i < list.length; i++) {
                    if (!values.contains(list[i])) {
                    //validation exception
                    }
                }
            }
            //now we must parse the items up
            final XSDSimpleTypeDefinition itemType = type.getItemTypeDefinition();
            List parsed = new ArrayList();
            //create a pseudo declaration
            final XSDElementDeclaration element = XSDFactory.eINSTANCE.createXSDElementDeclaration();
            element.setTypeDefinition(itemType);
            if (instance.getName() != null) {
                element.setName(instance.getName());
            }
            if (instance.getNamespace() != null) {
                element.setTargetNamespace(instance.getNamespace());
            }
            //create a new instance of the specified type
            InstanceComponentImpl theInstance = new InstanceComponentImpl() {

                public XSDTypeDefinition getTypeDefinition() {
                    return itemType;
                }

                public XSDNamedComponent getDeclaration() {
                    return element;
                }

                ;
            };
            for (int i = 0; i < list.length; i++) {
                theInstance.setText(list[i]);
                //perform the parse
                ParseExecutor executor = new ParseExecutor(theInstance, null, context, parser);
                parser.getBindingWalker().walk(element, executor, context);
                parsed.add(executor.getValue());
            }
            return parsed;
        } else if (type.getVariety() == XSDVariety.UNION_LITERAL) {
            // datatypes
            return text;
        } else {
            //walk through the facets and preparse as necessary 
            for (Iterator f = type.getFacets().iterator(); f.hasNext(); ) {
                XSDFacet facet = (XSDFacet) f.next();
                //white space
                if (facet instanceof XSDWhiteSpaceFacet) {
                    XSDWhiteSpaceFacet whitespace = (XSDWhiteSpaceFacet) facet;
                    if (whitespace.getValue() == XSDWhiteSpace.REPLACE_LITERAL) {
                        text = Whitespace.REPLACE.preparse(text);
                    }
                    if (whitespace.getValue() == XSDWhiteSpace.COLLAPSE_LITERAL) {
                        text = Whitespace.COLLAPSE.preparse(text);
                    }
                    if (whitespace.getValue() == XSDWhiteSpace.PRESERVE_LITERAL) {
                    //do nothing
                    }
                }
            }
            return text;
        }
    } else {
        // for mixed
        if (instance.getTypeDefinition() instanceof XSDComplexTypeDefinition && ((XSDComplexTypeDefinition) instance.getTypeDefinition()).isMixed()) {
            //collape the text
            text = Whitespace.COLLAPSE.preparse(text);
        }
    }
    return text;
}
Example 15
Project: bpel-master  File: XSD2XMLGenerator.java View source code
/**
		 * This was stolen directly from XSDImpl. It builds a list of the enumeration
		 * values for the given XSD type definition.
		 * 
		 * @param type - an XSD type definition (presumably determined from a CMNode)
		 * @param result - List to which we will add our results
		 */
public void getEnumeratedValuesForSimpleType(XSDTypeDefinition type, List result) {
    List enumerationFacets = ((XSDSimpleTypeDefinition) type).getEnumerationFacets();
    for (Iterator i = enumerationFacets.iterator(); i.hasNext(); ) {
        XSDEnumerationFacet enumFacet = (XSDEnumerationFacet) i.next();
        List values = enumFacet.getValue();
        for (Iterator j = values.iterator(); j.hasNext(); ) {
            Object o = j.next();
            if (o != null) {
                if (!result.contains(o)) {
                    result.add(o.toString());
                }
            }
        }
    }
}