Search in sources :

Example 6 with ParticleInfo

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

the class SchemaJavascriptBuilder method domDeserializerFunction.

/**
 * Generate a JavaScript function that takes an element for a complex type and walks through its children
 * using them to fill in the values for a JavaScript object.
 *
 * @param type schema type for the process
 * @return the string contents of the JavaScript.
 */
public void domDeserializerFunction(QName name, XmlSchemaComplexType type) {
    utils = new JavascriptUtils(code);
    List<XmlSchemaObject> contentElements = JavascriptUtils.getContentElements(type, xmlSchemaCollection);
    String typeObjectName = nameManager.getJavascriptName(name);
    code.append("function " + typeObjectName + "_deserialize (cxfjsutils, element) {\n");
    // create the object we are deserializing into.
    utils.appendLine("var newobject = new " + typeObjectName + "();");
    utils.appendLine("cxfjsutils.trace('element: ' + cxfjsutils.traceElementName(element));");
    utils.appendLine("var curElement = cxfjsutils.getFirstElementChild(element);");
    utils.appendLine("var item;");
    int nContentElements = contentElements.size();
    for (int i = 0; i < contentElements.size(); i++) {
        XmlSchemaObject contentElement = contentElements.get(i);
        utils.appendLine("cxfjsutils.trace('curElement: ' + cxfjsutils.traceElementName(curElement));");
        ParticleInfo itemInfo = ParticleInfo.forLocalItem(contentElement, xmlSchema, xmlSchemaCollection, prefixAccumulator, type.getQName());
        if (itemInfo.isAny()) {
            ParticleInfo nextItem = null;
            if (i != nContentElements - 1) {
                XmlSchemaObject nextThing = contentElements.get(i + 1);
                nextItem = ParticleInfo.forLocalItem(nextThing, xmlSchema, xmlSchemaCollection, prefixAccumulator, type.getQName());
                // namespaces.
                if (nextItem.isAny()) {
                    unsupportedConstruct("MULTIPLE_ANY", type.getQName());
                }
            }
            deserializeAny(type, itemInfo, nextItem);
        } else {
            deserializeElement(type, itemInfo);
        }
    }
    utils.appendLine("return newobject;");
    code.append("}\n\n");
}
Also used : XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) JavascriptUtils(org.apache.cxf.javascript.JavascriptUtils) ParticleInfo(org.apache.cxf.javascript.ParticleInfo)

Example 7 with ParticleInfo

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

the class SchemaJavascriptBuilder method complexTypeConstructorAndAccessors.

// In general, I (bimargulies) hate fields that are temporary communications
// between members of a class. However, given the style restrictions on the
// number
// of parameters, it's the least of the evils.
public void complexTypeConstructorAndAccessors(QName name, XmlSchemaComplexType type) {
    accessors = new StringBuilder();
    utils = new JavascriptUtils(code);
    List<XmlSchemaObject> items = JavascriptUtils.getContentElements(type, xmlSchemaCollection);
    List<XmlSchemaAnnotated> attrs = XmlSchemaUtils.getContentAttributes(type, xmlSchemaCollection);
    final String elementPrefix = "this._";
    String typeObjectName = nameManager.getJavascriptName(name);
    code.append("//\n");
    code.append("// Constructor for XML Schema item " + name.toString() + "\n");
    code.append("//\n");
    code.append("function " + typeObjectName + " () {\n");
    // to assist in debugging we put a type property into every object.
    utils.appendLine("this.typeMarker = '" + typeObjectName + "';");
    for (XmlSchemaObject thing : items) {
        ParticleInfo itemInfo = ParticleInfo.forLocalItem(thing, xmlSchema, xmlSchemaCollection, prefixAccumulator, type.getQName());
        constructItem(type, elementPrefix, typeObjectName, itemInfo);
    }
    for (XmlSchemaAnnotated thing : attrs) {
        AttributeInfo itemInfo = AttributeInfo.forLocalItem(thing, xmlSchema, xmlSchemaCollection, prefixAccumulator, type.getQName());
        constructOneItem(type, elementPrefix, typeObjectName, itemInfo);
    }
    code.append("}\n\n");
    code.append(accessors.toString());
}
Also used : AttributeInfo(org.apache.cxf.javascript.AttributeInfo) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) JavascriptUtils(org.apache.cxf.javascript.JavascriptUtils) ParticleInfo(org.apache.cxf.javascript.ParticleInfo) XmlSchemaAnnotated(org.apache.ws.commons.schema.XmlSchemaAnnotated)

Aggregations

ParticleInfo (org.apache.cxf.javascript.ParticleInfo)7 XmlSchemaType (org.apache.ws.commons.schema.XmlSchemaType)4 QName (javax.xml.namespace.QName)3 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)3 JavascriptUtils (org.apache.cxf.javascript.JavascriptUtils)2 MessageInfo (org.apache.cxf.service.model.MessageInfo)2 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)2 XmlSchema (org.apache.ws.commons.schema.XmlSchema)2 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)2 XmlSchemaObject (org.apache.ws.commons.schema.XmlSchemaObject)2 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)2 ArrayList (java.util.ArrayList)1 SoapVersion (org.apache.cxf.binding.soap.SoapVersion)1 AttributeInfo (org.apache.cxf.javascript.AttributeInfo)1 XmlSchemaAnnotated (org.apache.ws.commons.schema.XmlSchemaAnnotated)1 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)1 XmlSchemaSequenceMember (org.apache.ws.commons.schema.XmlSchemaSequenceMember)1