Search in sources :

Example 1 with UnsupportedConstruct

use of org.apache.cxf.javascript.UnsupportedConstruct in project cxf by apache.

the class SchemaJavascriptBuilder method generateCodeForSchema.

public String generateCodeForSchema(XmlSchema schema) {
    xmlSchema = schema;
    code = new StringBuilder();
    code.append("//\n");
    code.append("// Definitions for schema: ").append(schema.getTargetNamespace());
    if (schema.getSourceURI() != null) {
        code.append("\n//  ").append(schema.getSourceURI());
    }
    code.append("\n//\n");
    Map<QName, XmlSchemaType> schemaTypes = schema.getSchemaTypes();
    for (Map.Entry<QName, XmlSchemaType> e : schemaTypes.entrySet()) {
        XmlSchemaType type = e.getValue();
        if (type instanceof XmlSchemaComplexType) {
            try {
                XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
                if (!JavascriptUtils.notVeryComplexType(complexType) && complexType.getName() != null) {
                    complexTypeConstructorAndAccessors(complexType.getQName(), complexType);
                    complexTypeSerializerFunction(complexType.getQName(), complexType);
                    domDeserializerFunction(complexType.getQName(), complexType);
                }
            } catch (UnsupportedConstruct usc) {
                LOG.warning(usc.toString());
                // it could be empty, but the style checker
                continue;
            // would complain.
            }
        } else if (type instanceof XmlSchemaSimpleType) {
            XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) type;
            if (XmlSchemaUtils.isEumeration(simpleType)) {
                List<String> values = XmlSchemaUtils.enumeratorValues(simpleType);
                code.append("//\n");
                code.append("// Simple type (enumeration) ").append(simpleType.getQName()).append('\n');
                code.append("//\n");
                for (String value : values) {
                    code.append("// - ").append(value).append('\n');
                }
            }
        }
    }
    for (Map.Entry<QName, XmlSchemaElement> e : schema.getElements().entrySet()) {
        XmlSchemaElement element = e.getValue();
        try {
            if (element.getSchemaTypeName() == null && element.getSchemaType() == null) {
                Message message = new Message("ELEMENT_MISSING_TYPE", LOG, element.getQName(), element.getSchemaTypeName(), schema.getTargetNamespace());
                LOG.warning(message.toString());
                continue;
            }
            XmlSchemaType type;
            if (element.getSchemaType() != null) {
                type = element.getSchemaType();
            } else {
                type = schema.getTypeByName(element.getSchemaTypeName());
            }
            if (!(type instanceof XmlSchemaComplexType)) {
                // we never make classes for simple type.
                continue;
            }
            XmlSchemaComplexType complexType = (XmlSchemaComplexType) type;
            // element.
            if (!JavascriptUtils.notVeryComplexType(complexType) && complexType.getName() == null) {
                complexTypeConstructorAndAccessors(element.getQName(), complexType);
                complexTypeSerializerFunction(element.getQName(), complexType);
                domDeserializerFunction(element.getQName(), complexType);
            }
        } catch (UnsupportedConstruct usc) {
            LOG.warning(usc.getMessage());
            // it could be empty, but the style checker
            continue;
        // would complain.
        }
    }
    String returnValue = code.toString();
    LOG.finer(returnValue);
    return returnValue;
}
Also used : Message(org.apache.cxf.common.i18n.Message) QName(javax.xml.namespace.QName) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) UnsupportedConstruct(org.apache.cxf.javascript.UnsupportedConstruct) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) XmlSchemaComplexType(org.apache.ws.commons.schema.XmlSchemaComplexType) List(java.util.List) Map(java.util.Map)

Example 2 with UnsupportedConstruct

use of org.apache.cxf.javascript.UnsupportedConstruct in project cxf by apache.

the class ServiceJavascriptBuilder method getElementType.

/**
 * Follow a chain of references from element to element until we can obtain
 * a type.
 *
 * @param element
 */
public static XmlSchemaType getElementType(SchemaCollection xmlSchemaCollection, String referencingURI, XmlSchemaElement element, XmlSchemaType containingType) {
    assert element != null;
    if (element.getSchemaTypeName() != null) {
        XmlSchemaType type = xmlSchemaCollection.getTypeByQName(element.getSchemaTypeName());
        if (type == null) {
            Message message = new Message("ELEMENT_TYPE_MISSING", LOG, element.getQName(), element.getSchemaTypeName().toString());
            throw new UnsupportedConstruct(message);
        }
        return type;
    }
    // The referencing URI only helps if there is a schema that points to
    // it.
    // It might be the URI for the wsdl TNS, which might have no schema.
    // if (xmlSchemaCollection.getSchemaByTargetNamespace(referencingURI) == null) {
    // referencingURI = null;
    // }
    // 
    // if (referencingURI == null && containingType != null) {
    // referencingURI = containingType.getQName().getNamespaceURI();
    // }
    XmlSchemaElement originalElement = element;
    while (element.getSchemaType() == null && element.isRef()) {
        /*
             * This code assumes that all schemas are in the collection.
             */
        XmlSchemaElement nextElement = element.getRef().getTarget();
        assert nextElement != null;
        element = nextElement;
    }
    if (element.getSchemaType() == null) {
        unsupportedConstruct("ELEMENT_HAS_NO_TYPE", originalElement.getName(), containingType.getQName(), containingType);
    }
    return element.getSchemaType();
}
Also used : Message(org.apache.cxf.common.i18n.Message) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) UnsupportedConstruct(org.apache.cxf.javascript.UnsupportedConstruct) XmlSchemaType(org.apache.ws.commons.schema.XmlSchemaType)

Example 3 with UnsupportedConstruct

use of org.apache.cxf.javascript.UnsupportedConstruct in project cxf by apache.

the class ServiceJavascriptBuilder method unsupportedConstruct.

public static void unsupportedConstruct(String messageKey, String what, QName subjectName, XmlSchemaObject subject) {
    Message message = new Message(messageKey, LOG, what, subjectName == null ? "anonymous" : subjectName, cleanedUpSchemaSource(subject));
    LOG.severe(message.toString());
    throw new UnsupportedConstruct(message);
}
Also used : Message(org.apache.cxf.common.i18n.Message) UnsupportedConstruct(org.apache.cxf.javascript.UnsupportedConstruct)

Example 4 with UnsupportedConstruct

use of org.apache.cxf.javascript.UnsupportedConstruct in project cxf by apache.

the class ServiceJavascriptBuilder method unsupportedConstruct.

public static void unsupportedConstruct(String messageKey, XmlSchemaType subject) {
    Message message = new Message(messageKey, LOG, subject.getQName(), cleanedUpSchemaSource(subject));
    LOG.severe(message.toString());
    throw new UnsupportedConstruct(message);
}
Also used : Message(org.apache.cxf.common.i18n.Message) UnsupportedConstruct(org.apache.cxf.javascript.UnsupportedConstruct)

Aggregations

Message (org.apache.cxf.common.i18n.Message)4 UnsupportedConstruct (org.apache.cxf.javascript.UnsupportedConstruct)4 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)2 XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)2 List (java.util.List)1 Map (java.util.Map)1 QName (javax.xml.namespace.QName)1 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)1 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)1