org.apache.ws.commons.schema.XmlSchemaEnumerationFacet Java Examples

The following examples show how to use org.apache.ws.commons.schema.XmlSchemaEnumerationFacet. 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: XsdEmitter.java    From legstar-core2 with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Create an XML schema enumeration facet.
 * 
 * @param conditionValue the value to set
 * @return an XML schema enumeration facet
 */
protected XmlSchemaEnumerationFacet createEnumerationFacet(
        final String conditionValue) {
    XmlSchemaEnumerationFacet xmlSchemaEnumerationFacet = new XmlSchemaEnumerationFacet();
    xmlSchemaEnumerationFacet.setValue(conditionValue);
    return xmlSchemaEnumerationFacet;
}
 
Example #6
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 #7
Source File: Xsd2UmlConvert.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
private static final EnumLiteral enumLiteralFromFacet(final XmlSchemaEnumerationFacet enumFacet,
        final Xsd2UmlConfig context) {
    final List<TaggedValue> annotation = annotations(enumFacet, context);
    // We're assuming here that the whiteSpace facet for this enumeration
    // type is "collapse".
    // In general, this will not be true and we will have to compute it.
    final String name = XmlTools.collapseWhitespace(enumFacet.getValue().toString());
    return new EnumLiteral(name, annotation);
}
 
Example #8
Source File: EnumVisitor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void visit(AST enumNode) {
    // <enum_type> ::= "enum" <identifier> "{" <enumerator> {"," <enumerator>}* "}"
    // <enumerator> ::= <identifier>


    AST enumNameNode = enumNode.getFirstChild();
    Scope enumNameScope = new Scope(getScope(), enumNameNode);

    // xmlschema:enum
    XmlSchemaSimpleType enumSchemaSimpleType = new XmlSchemaSimpleType(schema, true);
    enumSchemaSimpleType.setName(mapper.mapToQName(enumNameScope));

    XmlSchemaSimpleTypeRestriction enumSchemaSimpleTypeRestriction = new XmlSchemaSimpleTypeRestriction();
    enumSchemaSimpleTypeRestriction.setBaseTypeName(Constants.XSD_STRING);

    //XmlSchemaSimpleTypeContent xmlSchemaSimpleTypeContent = enumSchemaSimpleTypeRestriction;
    enumSchemaSimpleType.setContent(enumSchemaSimpleTypeRestriction);


    // corba:enum
    Enum corbaEnum = new Enum();
    corbaEnum.setQName(new QName(typeMap.getTargetNamespace(), enumNameScope.toString()));
    corbaEnum.setRepositoryID(enumNameScope.toIDLRepositoryID());
    corbaEnum.setType(enumSchemaSimpleType.getQName());


    AST node = enumNameNode.getNextSibling();
    while (node != null) {
        // xmlschema:enumeration
        XmlSchemaEnumerationFacet enumeration = new XmlSchemaEnumerationFacet();
        enumeration.setValue(node.toString());
        enumSchemaSimpleTypeRestriction.getFacets().add(enumeration);

        // corba:enumerator
        Enumerator enumerator = new Enumerator();
        enumerator.setValue(node.toString());
        corbaEnum.getEnumerator().add(enumerator);

        node = node.getNextSibling();
    }

    // add corbaType
    typeMap.getStructOrExceptionOrUnion().add(corbaEnum);

    // REVISIT: are there assignments needed?
    setSchemaType(enumSchemaSimpleType);
    setCorbaType(corbaEnum);
}
 
Example #9
Source File: CommonsSchemaInfoBuilder.java    From tomee with Apache License 2.0 4 votes vote down vote up
public static XmlTypeInfo createXmlTypeInfo(QName qname, XmlSchemaType type) {
    if (qname == null) throw new NullPointerException("qname is null");
    if (type == null) throw new NullPointerException("type is null");

    XmlTypeInfo typeInfo = new XmlTypeInfo();
    typeInfo.qname = qname;
    typeInfo.anonymous = qname.getLocalPart().indexOf('>') >= 0;

    if (type instanceof XmlSchemaSimpleType) {
        XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) type;
        XmlSchemaSimpleTypeContent content = simpleType.getContent();
        if (content instanceof XmlSchemaSimpleTypeList) {
            XmlSchemaSimpleTypeList list = (XmlSchemaSimpleTypeList) content;
            typeInfo.simpleBaseType = list.getItemType().getQName();

            // this is a list
            typeInfo.listType = true;
        } else if (content instanceof XmlSchemaSimpleTypeRestriction) {
            XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction) content;
            typeInfo.simpleBaseType = restriction.getBaseTypeName();

            // is this an enumeration?
            for (Iterator iterator = restriction.getFacets().getIterator(); iterator.hasNext(); ) {
                if (iterator.next() instanceof XmlSchemaEnumerationFacet) {
                    typeInfo.enumType = true;
                    break;
                }

            }
        }
    } else if (type instanceof XmlSchemaComplexType) {
        XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;

        // SOAP array component type
        typeInfo.arrayComponentType = extractSoapArrayComponentType(complexType);

        // process attributes (skip soap arrays which have non-mappable attributes)
        if (!isSoapArray(complexType)) {
            XmlSchemaObjectCollection attributes = complexType.getAttributes();
            for (Iterator iterator = attributes.getIterator(); iterator.hasNext(); ) {
                Object item = iterator.next();
                if (item instanceof XmlSchemaAttribute) {
                    XmlSchemaAttribute attribute = (XmlSchemaAttribute) item;
                    Object old = typeInfo.attributes.put(attribute.getQName().getLocalPart(), attribute.getSchemaTypeName());
                    if (old != null) {
                        throw new IllegalArgumentException("Complain to your expert group member, spec does not support attributes with the same local name and differing namespaces: original: " + old + ", duplicate local name: " + attribute);
                    }
                }
            }
        }
    } else {
        LOG.warn("Unknown schema type class " + typeInfo.getClass().getName());
    }

    return typeInfo;
}