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");
}
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());
}
Aggregations