Java Code Examples for org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction#getFacets()

The following examples show how to use org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction#getFacets() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WSDLToCorbaHelper.java    From cxf with Apache License 2.0 6 votes vote down vote up
private Enum createCorbaEnum(XmlSchemaSimpleTypeRestriction restrictionType, QName name,
                             QName schematypeName) {
    Enum corbaEnum = new Enum();
    corbaEnum.setType(schematypeName);
    corbaEnum.setName(name.getLocalPart());
    corbaEnum.setQName(name);

    corbaEnum.setRepositoryID(REPO_STRING + name.getLocalPart().replace('.', '/') + IDL_VERSION);

    for (XmlSchemaFacet f : restrictionType.getFacets()) {
        XmlSchemaEnumerationFacet val = (XmlSchemaEnumerationFacet)f;
        Enumerator enumerator = new Enumerator();
        enumerator.setValue(val.getValue().toString());
        corbaEnum.getEnumerator().add(enumerator);
    }
    return corbaEnum;
}
 
Example 2
Source File: EnumType.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public void writeSchema(XmlSchema root) {

    XmlSchemaSimpleType simple = new XmlSchemaSimpleType(root, true);
    simple.setName(getSchemaType().getLocalPart());
    XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
    restriction.setBaseTypeName(Constants.XSD_STRING);
    simple.setContent(restriction);

    Object[] constants = getTypeClass().getEnumConstants();

    List<XmlSchemaFacet> facets = restriction.getFacets();
    for (Object constant : constants) {
        XmlSchemaEnumerationFacet f = new XmlSchemaEnumerationFacet();
        f.setValue(getValue(constant));
        facets.add(f);
    }
}
 
Example 3
Source File: XmlSchemaUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * Return true if a simple type is a straightforward XML Schema representation of an enumeration.
 * If we discover schemas that are 'enum-like' with more complex structures, we might
 * make this deal with them.
 * @param type Simple type, possible an enumeration.
 * @return true for an enumeration.
 */
public static boolean isEumeration(XmlSchemaSimpleType type) {
    XmlSchemaSimpleTypeContent content = type.getContent();
    if (!(content instanceof XmlSchemaSimpleTypeRestriction)) {
        return false;
    }
    XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction) content;
    List<XmlSchemaFacet> facets = restriction.getFacets();
    for (XmlSchemaFacet facet : facets) {
        if (!(facet instanceof XmlSchemaEnumerationFacet)) {
            return false;
        }
    }
    return true;
}
 
Example 4
Source File: XmlSchemaUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve the string values for an enumeration.
 * @param type
 */
public static List<String> enumeratorValues(XmlSchemaSimpleType type) {
    XmlSchemaSimpleTypeContent content = type.getContent();
    XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction) content;
    List<XmlSchemaFacet> facets = restriction.getFacets();
    List<String> values = new ArrayList<>();
    for (XmlSchemaFacet facet : facets) {
        XmlSchemaEnumerationFacet enumFacet = (XmlSchemaEnumerationFacet) facet;
        values.add(enumFacet.getValue().toString());
    }
    return values;
}
 
Example 5
Source File: WSDLToCorbaHelper.java    From cxf with Apache License 2.0 5 votes vote down vote up
private boolean isEnumeration(XmlSchemaSimpleTypeRestriction restriction) {

        if ((restriction == null) || (restriction.getFacets().isEmpty())
            || (restriction.getBaseTypeName() == null)) {
            return false;
        }


        for (XmlSchemaFacet facet : restriction.getFacets()) {
            if (facet instanceof XmlSchemaEnumerationFacet) {
                return true;
            }
        }
        return false;
    }
 
Example 6
Source File: Xsd2CobolTypesModelBuilder.java    From legstar-core2 with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Retrieve the properties of a primitive type.
 * 
 * @param xsdSimpleType the XML schema primitive type
 * @param cobolAnnotations the associated COBOL annotations
 * @return a set of properties
 */
private Map < String, Object > getProps(XmlSchemaSimpleType xsdSimpleType,
        final CobolAnnotations cobolAnnotations) {
    XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction) xsdSimpleType
            .getContent();
    if (restriction != null && restriction.getBaseTypeName() != null) {
        QName xsdTypeName = restriction.getBaseTypeName();
        List < XmlSchemaFacet > facets = restriction.getFacets();
        if (xsdTypeName.equals(Constants.XSD_STRING)) {
            return getCobolAlphanumType(facets);
        } else if (xsdTypeName.equals(Constants.XSD_HEXBIN)) {
            return getCobolOctetStreamType(facets);
        } else if (xsdTypeName.equals(Constants.XSD_INT)) {
            return getCobolDecimalType(cobolAnnotations, Integer.class);
        } else if (xsdTypeName.equals(Constants.XSD_LONG)) {
            return getCobolDecimalType(cobolAnnotations, Long.class);
        } else if (xsdTypeName.equals(Constants.XSD_SHORT)) {
            return getCobolDecimalType(cobolAnnotations, Short.class);
        } else if (xsdTypeName.equals(Constants.XSD_DECIMAL)) {
            return getCobolDecimalType(cobolAnnotations, BigDecimal.class);
        } else if (xsdTypeName.equals(Constants.XSD_FLOAT)) {
            return getCobolDecimalType(cobolAnnotations, Float.class);
        } else if (xsdTypeName.equals(Constants.XSD_DOUBLE)) {
            return getCobolDecimalType(cobolAnnotations, Double.class);
        } else if (xsdTypeName.equals(Constants.XSD_UNSIGNEDINT)) {
            return getCobolDecimalType(cobolAnnotations, Long.class);
        } else if (xsdTypeName.equals(Constants.XSD_UNSIGNEDSHORT)) {
            return getCobolDecimalType(cobolAnnotations, Integer.class);
        } else if (xsdTypeName.equals(Constants.XSD_UNSIGNEDLONG)) {
            return getCobolDecimalType(cobolAnnotations, BigInteger.class);
        } else if (xsdTypeName.equals(Constants.XSD_INTEGER)) {
            return getCobolDecimalType(cobolAnnotations, BigInteger.class);
        } else {
            throw new Xsd2ConverterException("Unsupported xsd type "
                    + xsdTypeName);
        }

    } else {
        throw new Xsd2ConverterException("Simple type without restriction "
                + xsdSimpleType.getQName());
    }

}
 
Example 7
Source File: WSDLToCorbaHelper.java    From cxf with Apache License 2.0 4 votes vote down vote up
private CorbaType processSimpleRestrictionType(XmlSchemaSimpleType stype,
                                                   QName name, QName schematypeName,
                                                   boolean anonymous)
    throws Exception {
    CorbaType corbaTypeImpl = null;

    // checks if enumeration
    XmlSchemaSimpleTypeRestriction restrictionType = (XmlSchemaSimpleTypeRestriction)stype
        .getContent();

    QName baseName = checkPrefix(restrictionType.getBaseTypeName());

    String maxLength = null;
    String length = null;

    for (XmlSchemaFacet val : restrictionType.getFacets()) {
        if (val instanceof XmlSchemaMaxLengthFacet) {
            maxLength = val.getValue().toString();
        }
        if (val instanceof XmlSchemaLengthFacet) {
            length = val.getValue().toString();
        }
    }

    if (isEnumeration(restrictionType)) {
        corbaTypeImpl = createCorbaEnum(restrictionType, name, schematypeName);
    } else {
        if (restrictionType.getBaseType() != null) {
            corbaTypeImpl = convertSchemaToCorbaType(restrictionType.getBaseType(), schematypeName,
                                                     stype, null, false);
        } else {
            corbaTypeImpl = processPrimitiveType(baseName);
            if (corbaTypeImpl == null) {
                XmlSchemaType schematype = findSchemaType(baseName);
                corbaTypeImpl = convertSchemaToCorbaType(schematype, schematypeName,
                                                         schematype, null, false);
            }
        }

        if (corbaTypeImpl != null) {
            if (corbaTypeImpl.getType().equals(W3CConstants.NT_SCHEMA_STRING)
                || (baseName.equals(W3CConstants.NT_SCHEMA_STRING))) {
                corbaTypeImpl =
                    WSDLTypes.processStringType(corbaTypeImpl, name, maxLength, length);
            } else if (corbaTypeImpl.getType().equals(W3CConstants.NT_SCHEMA_DECIMAL)
                || (baseName.equals(W3CConstants.NT_SCHEMA_DECIMAL))) {
                corbaTypeImpl = WSDLTypes.processDecimalType(restrictionType, name,
                                                         corbaTypeImpl, anonymous);
            } else if ((corbaTypeImpl.getType().equals(W3CConstants.NT_SCHEMA_BASE64))
                || (baseName.equals(W3CConstants.NT_SCHEMA_BASE64))
                || (corbaTypeImpl.getType().equals(W3CConstants.NT_SCHEMA_HBIN))) {
                corbaTypeImpl = WSDLTypes.processBase64Type(corbaTypeImpl,
                                                            name, maxLength, length);
            }
        }
    }

    return corbaTypeImpl;
}