From 1b97ec47e5d86e6bc917f269848f2701553d1704 Mon Sep 17 00:00:00 2001 From: highsource Date: Sat, 11 Apr 2015 22:15:39 +0200 Subject: [PATCH] Version 2.2.1 --- dist/Jsonix-all.js | 286 ++++++++++++++++---------------- dist/Jsonix-min.js | 107 ++++++------ dist/pom.xml | 2 +- nodejs/pom.xml | 2 +- nodejs/scripts/package.json | 2 +- nodejs/scripts/pom.xml | 2 +- nodejs/tests/ar/AR.js | 1 + nodejs/tests/ar/pom.xml | 2 +- nodejs/tests/basic/pom.xml | 2 +- nodejs/tests/browserify/pom.xml | 2 +- nodejs/tests/po/pom.xml | 2 +- nodejs/tests/pom.xml | 2 +- nodejs/tests/wps/pom.xml | 2 +- pom.xml | 2 +- scripts/pom.xml | 2 +- 15 files changed, 203 insertions(+), 215 deletions(-) diff --git a/dist/Jsonix-all.js b/dist/Jsonix-all.js index 0e012662..6f5662e7 100644 --- a/dist/Jsonix-all.js +++ b/dist/Jsonix-all.js @@ -297,7 +297,6 @@ Jsonix.Request = Jsonix transport.onreadystatechange = function() { that.handleTransport(transport, onSuccess, onFailure); }; - console.log('Sending.'); transport.send(data); } } @@ -1777,19 +1776,20 @@ Jsonix.Mapping.Styled = Jsonix.Class({ CLASS_NAME : 'Jsonix.Mapping.Styled' }); Jsonix.Binding = {}; -Jsonix.Binding.ElementMarshaller = Jsonix.Class({ +Jsonix.Binding.Marshalls = { +}; + +Jsonix.Binding.Marshalls.Element = Jsonix.Class({ marshalElement : function(value, context, output, scope) { - var elementValue = this.getOutputElementValue(value, context, output, scope); + var elementValue = this.convertToTypedNamedValue(value, context, output, scope); var declaredTypeInfo = elementValue.typeInfo; var typeInfo = declaredTypeInfo; - if (Jsonix.Util.Type.exists(declaredTypeInfo)) - { + if (Jsonix.Util.Type.exists(declaredTypeInfo)) { output.writeStartElement(elementValue.name); if (Jsonix.Util.Type.exists(elementValue.value)) { if (context.supportXsiType) { var actualTypeInfo = context.getTypeInfoByValue(elementValue.value); - if (actualTypeInfo && actualTypeInfo.typeName && declaredTypeInfo !== actualTypeInfo) - { + if (actualTypeInfo && actualTypeInfo.typeName && declaredTypeInfo !== actualTypeInfo) { typeInfo = actualTypeInfo; var xsiTypeName = actualTypeInfo.typeName; var xsiType = Jsonix.Schema.XSD.QName.INSTANCE.print(xsiTypeName, context, output, scope); @@ -1799,22 +1799,30 @@ Jsonix.Binding.ElementMarshaller = Jsonix.Class({ typeInfo.marshal(elementValue.value, context, output, scope); } output.writeEndElement(); - } - else - { + } else { throw new Error("Element [" + elementValue.name.key + "] is not known in this context."); } }, - getOutputElementValue : function (value, context, output, scope) { + getTypeInfoByElementName : function(name, context, scope) { + var elementInfo = context.getElementInfo(name, scope); + if (Jsonix.Util.Type.exists(elementInfo)) { + return elementInfo.typeInfo; + } else { + return undefined; + } + } +}); +Jsonix.Binding.Marshalls.Element.AsElementRef = Jsonix.Class({ + convertToTypedNamedValue : function(value, context, output, scope) { Jsonix.Util.Ensure.ensureObject(value); - var elementValue = this.convertFromElementValue(value, context, output, scope); + var elementValue = this.convertToNamedValue(value, context, output, scope); return { name : elementValue.name, value : elementValue.value, typeInfo : this.getTypeInfoByElementName(elementValue.name, context, scope) }; }, - convertFromElementValue : function(elementValue, context, output, scope) { + convertToNamedValue : function(elementValue, context, output, scope) { var name; var value; if (Jsonix.Util.Type.exists(elementValue.name) && !Jsonix.Util.Type.isUndefined(elementValue.value)) { @@ -1837,19 +1845,13 @@ Jsonix.Binding.ElementMarshaller = Jsonix.Class({ } } throw new Error("Invalid element value [" + elementValue + "]. Element values must either have {name:'myElementName', value: elementValue} or {myElementName:elementValue} structure."); - }, - getTypeInfoByElementName : function(name, context, scope) { - var elementInfo = context.getElementInfo(name, scope); - if (Jsonix.Util.Type.exists(elementInfo)) { - return elementInfo.typeInfo; - } else { - return undefined; - } } }); -Jsonix.Binding.ElementUnmarshaller = Jsonix.Class({ - allowTypedObject : true, - allowDom : false, + +Jsonix.Binding.Unmarshalls = { +}; + +Jsonix.Binding.Unmarshalls.WrapperElement = Jsonix.Class({ mixed : false, unmarshalWrapperElement : function(context, input, scope, callback) { var et = input.next(); @@ -1867,20 +1869,27 @@ Jsonix.Binding.ElementUnmarshaller = Jsonix.Class({ } et = input.next(); } - }, + } +}); + +Jsonix.Binding.Unmarshalls.Element = Jsonix.Class({ + allowTypedObject : true, + allowDom : false, unmarshalElement : function(context, input, scope, callback) { if (input.eventType != 1) { throw new Error("Parser must be on START_ELEMENT to read next element."); } - var typeInfo = this.getInputTypeInfo(context, input, scope); + var typeInfo = this.getTypeInfoByInputElement(context, input, scope); var name = input.getName(); var elementValue; if (this.allowTypedObject && Jsonix.Util.Type.exists(typeInfo)) { var value = typeInfo.unmarshal(context, input, scope); - elementValue = this.convertToElementValue({ + var typedNamedValue = { name : name, - value : value - }, context, input, scope); + value : value, + typeInfo : typeInfo + }; + elementValue = this.convertFromTypedNamedValue(typedNamedValue, context, input, scope); } else if (this.allowDom) { elementValue = input.getElement(); } else { @@ -1889,14 +1898,11 @@ Jsonix.Binding.ElementUnmarshaller = Jsonix.Class({ } callback(elementValue); }, - getInputTypeInfo : function (context, input, scope) - { - // Issue #70 work in progress here + getTypeInfoByInputElement : function(context, input, scope) { var xsiTypeInfo = null; if (context.supportXsiType) { var xsiType = input.getAttributeValueNS(Jsonix.Schema.XSI.NAMESPACE_URI, Jsonix.Schema.XSI.TYPE); - if (Jsonix.Util.StringUtils.isNotBlank(xsiType)) - { + if (Jsonix.Util.StringUtils.isNotBlank(xsiType)) { var xsiTypeName = Jsonix.Schema.XSD.QName.INSTANCE.parse(xsiType, context, input, scope); xsiTypeInfo = context.getTypeInfoByTypeNameKey(xsiTypeName.key); } @@ -1904,18 +1910,35 @@ Jsonix.Binding.ElementUnmarshaller = Jsonix.Class({ var name = input.getName(); var typeInfo = xsiTypeInfo ? xsiTypeInfo : this.getTypeInfoByElementName(name, context, scope); return typeInfo; + }, + getTypeInfoByElementName : function(name, context, scope) { + var elementInfo = context.getElementInfo(name, scope); + if (Jsonix.Util.Type.exists(elementInfo)) { + return elementInfo.typeInfo; + } else { + return undefined; + } } }); -Jsonix.Binding.ElementUnmarshaller.Simplified = Jsonix.Class(Jsonix.Binding.ElementUnmarshaller, { - convertToElementValue : function(elementValue, context, input, scope) { - var propertyName = elementValue.name.toCanonicalString(context); +Jsonix.Binding.Unmarshalls.Element.AsElementRef = Jsonix.Class({ + convertFromTypedNamedValue : function(typedNamedValue, context, input, scope) { + return { + name : typedNamedValue.name, + value : typedNamedValue.value + }; + } +}); + +Jsonix.Binding.Unmarshalls.Element.AsSimplifiedElementRef = Jsonix.Class({ + convertFromTypedNamedValue : function(typedNamedValue, context, input, scope) { + var propertyName = typedNamedValue.name.toCanonicalString(context); var value = {}; - value[propertyName] = elementValue.value; + value[propertyName] = typedNamedValue.value; return value; } }); -Jsonix.Binding.Marshaller = Jsonix.Class(Jsonix.Binding.ElementMarshaller, { +Jsonix.Binding.Marshaller = Jsonix.Class(Jsonix.Binding.Marshalls.Element, Jsonix.Binding.Marshalls.Element.AsElementRef, { context : null, initialize : function(context) { Jsonix.Util.Ensure.ensureObject(context); @@ -1941,7 +1964,7 @@ Jsonix.Binding.Marshaller = Jsonix.Class(Jsonix.Binding.ElementMarshaller, { Jsonix.Binding.Marshaller.Simplified = Jsonix.Class(Jsonix.Binding.Marshaller, { CLASS_NAME : 'Jsonix.Binding.Marshaller.Simplified' }); -Jsonix.Binding.Unmarshaller = Jsonix.Class(Jsonix.Binding.ElementUnmarshaller, { +Jsonix.Binding.Unmarshaller = Jsonix.Class(Jsonix.Binding.Unmarshalls.Element, Jsonix.Binding.Unmarshalls.Element.AsElementRef, { context : null, allowTypedObject : true, allowDom : false, @@ -1997,20 +2020,9 @@ Jsonix.Binding.Unmarshaller = Jsonix.Class(Jsonix.Binding.ElementUnmarshaller, { return result; }, - convertToElementValue : function(elementValue, context, input, scope) { - return elementValue; - }, - getTypeInfoByElementName : function(name, context, scope) { - var elementInfo = context.getElementInfo(name, scope); - if (Jsonix.Util.Type.exists(elementInfo)) { - return elementInfo.typeInfo; - } else { - return undefined; - } - }, CLASS_NAME : 'Jsonix.Binding.Unmarshaller' }); -Jsonix.Binding.Unmarshaller.Simplified = Jsonix.Class(Jsonix.Binding.Unmarshaller, Jsonix.Binding.ElementUnmarshaller.Simplified, { +Jsonix.Binding.Unmarshaller.Simplified = Jsonix.Class(Jsonix.Binding.Unmarshaller, Jsonix.Binding.Unmarshalls.Element.AsSimplifiedElementRef, { CLASS_NAME : 'Jsonix.Binding.Unmarshaller.Simplified' }); Jsonix.Model.TypeInfo = Jsonix.Class({ @@ -2848,7 +2860,7 @@ Jsonix.Model.ValuePropertyInfo = Jsonix.Class(Jsonix.Model.SingleTypePropertyInf CLASS_NAME : 'Jsonix.Model.ValuePropertyInfo' }); -Jsonix.Model.AbstractElementsPropertyInfo = Jsonix.Class(Jsonix.Binding.ElementUnmarshaller, Jsonix.Model.PropertyInfo, { +Jsonix.Model.AbstractElementsPropertyInfo = Jsonix.Class(Jsonix.Binding.Unmarshalls.Element, Jsonix.Binding.Unmarshalls.WrapperElement, Jsonix.Model.PropertyInfo, { wrapperElementName : null, allowDom : false, allowTypedObject : true, @@ -2919,7 +2931,7 @@ Jsonix.Model.AbstractElementsPropertyInfo = Jsonix.Class(Jsonix.Binding.ElementU output.writeEndElement(); } }, - convertToElementValue : function(elementValue, context, input, scope) { + convertFromTypedNamedValue : function(elementValue, context, input, scope) { return elementValue.value; }, buildStructure : function(context, structure) { @@ -2943,46 +2955,48 @@ Jsonix.Model.AbstractElementsPropertyInfo = Jsonix.Class(Jsonix.Binding.ElementU CLASS_NAME : 'Jsonix.Model.AbstractElementsPropertyInfo' }); -Jsonix.Model.ElementPropertyInfo = Jsonix.Class( - Jsonix.Model.AbstractElementsPropertyInfo, Jsonix.Binding.ElementMarshaller, { - typeInfo : 'String', - elementName : null, - initialize : function(mapping) { - Jsonix.Util.Ensure.ensureObject(mapping); - Jsonix.Model.AbstractElementsPropertyInfo.prototype.initialize - .apply(this, [ mapping ]); - var ti = mapping.typeInfo||mapping.ti||'String'; - if (Jsonix.Util.Type.isObject(ti)) { - this.typeInfo = ti; - } else { - Jsonix.Util.Ensure.ensureString(ti); - this.typeInfo = ti; - } - var en = mapping.elementName||mapping.en||undefined; - if (Jsonix.Util.Type.isObject(en)) { - this.elementName = Jsonix.XML.QName.fromObject(en); - } else if (Jsonix.Util.Type.isString(en)) { - this.elementName = new Jsonix.XML.QName(this.defaultElementNamespaceURI, en); - } else { - this.elementName = new Jsonix.XML.QName(this.defaultElementNamespaceURI, this.name); - } - }, - getTypeInfoByElementName : function(elementName, context, scope) { - return this.typeInfo; - }, - getOutputElementValue : function (value, context, output, scope) { - return { name : this.elementName, value : value, typeInfo : this.typeInfo}; - }, - doBuild : function(context, module) { - this.typeInfo = context.resolveTypeInfo(this.typeInfo, module); - }, - buildStructureElements : function(context, structure) { - structure.elements[this.elementName.key] = this; - }, - CLASS_NAME : 'Jsonix.Model.ElementPropertyInfo' - }); +Jsonix.Model.ElementPropertyInfo = Jsonix.Class(Jsonix.Model.AbstractElementsPropertyInfo, Jsonix.Binding.Marshalls.Element, { + typeInfo : 'String', + elementName : null, + initialize : function(mapping) { + Jsonix.Util.Ensure.ensureObject(mapping); + Jsonix.Model.AbstractElementsPropertyInfo.prototype.initialize.apply(this, [ mapping ]); + var ti = mapping.typeInfo || mapping.ti || 'String'; + if (Jsonix.Util.Type.isObject(ti)) { + this.typeInfo = ti; + } else { + Jsonix.Util.Ensure.ensureString(ti); + this.typeInfo = ti; + } + var en = mapping.elementName || mapping.en || undefined; + if (Jsonix.Util.Type.isObject(en)) { + this.elementName = Jsonix.XML.QName.fromObject(en); + } else if (Jsonix.Util.Type.isString(en)) { + this.elementName = new Jsonix.XML.QName(this.defaultElementNamespaceURI, en); + } else { + this.elementName = new Jsonix.XML.QName(this.defaultElementNamespaceURI, this.name); + } + }, + getTypeInfoByElementName : function(elementName, context, scope) { + return this.typeInfo; + }, + convertToTypedNamedValue : function(value, context, output, scope) { + return { + name : this.elementName, + value : value, + typeInfo : this.typeInfo + }; + }, + doBuild : function(context, module) { + this.typeInfo = context.resolveTypeInfo(this.typeInfo, module); + }, + buildStructureElements : function(context, structure) { + structure.elements[this.elementName.key] = this; + }, + CLASS_NAME : 'Jsonix.Model.ElementPropertyInfo' +}); -Jsonix.Model.ElementsPropertyInfo = Jsonix.Class(Jsonix.Model.AbstractElementsPropertyInfo, Jsonix.Binding.ElementMarshaller, { +Jsonix.Model.ElementsPropertyInfo = Jsonix.Class(Jsonix.Model.AbstractElementsPropertyInfo, Jsonix.Binding.Marshalls.Element, { elementTypeInfos : null, elementTypeInfosMap : null, initialize : function(mapping) { @@ -2991,16 +3005,14 @@ Jsonix.Model.ElementsPropertyInfo = Jsonix.Class(Jsonix.Model.AbstractElementsPr var etis = mapping.elementTypeInfos || mapping.etis || []; Jsonix.Util.Ensure.ensureArray(etis); this.elementTypeInfos = []; - for (var index = 0; index < etis.length; index++) - { - this.elementTypeInfos[index] = Jsonix.Util.Type.cloneObject(etis[index]); + for (var index = 0; index < etis.length; index++) { + this.elementTypeInfos[index] = Jsonix.Util.Type.cloneObject(etis[index]); } }, getTypeInfoByElementName : function(elementName, context, scope) { - var elementNameKey = elementName.key; - return this.elementTypeInfosMap[elementNameKey]; + return this.elementTypeInfosMap[elementName.key]; }, - getOutputElementValue : function(value, context, output, scope) { + convertToTypedNamedValue : function(value, context, output, scope) { for (var index = 0; index < this.elementTypeInfos.length; index++) { var elementTypeInfo = this.elementTypeInfos[index]; var typeInfo = elementTypeInfo.typeInfo; @@ -3017,20 +3029,15 @@ Jsonix.Model.ElementsPropertyInfo = Jsonix.Class(Jsonix.Model.AbstractElementsPr if (context.supportXsiType) { // Find the actual type var actualTypeInfo = context.getTypeInfoByValue(value); - if (actualTypeInfo && actualTypeInfo.typeName) - { - console.log("Actual type info:"); - console.log(actualTypeInfo); + if (actualTypeInfo && actualTypeInfo.typeName) { for (var jndex = 0; jndex < this.elementTypeInfos.length; jndex++) { var eti = this.elementTypeInfos[jndex]; - console.log("Checking element type info:"); - console.log(eti); var ti = eti.typeInfo; // TODO Can be optimized - // Find an element type info which has a type info that is a supertype of the actual type info - if (actualTypeInfo.isBasedOn(ti)) - { - var en = eti.elementName; + // Find an element type info which has a type info that is a + // supertype of the actual type info + if (actualTypeInfo.isBasedOn(ti)) { + var en = eti.elementName; return { name : en, value : value, @@ -3075,12 +3082,12 @@ Jsonix.Model.ElementMapPropertyInfo = Jsonix.Class(Jsonix.Model.AbstractElements Jsonix.Util.Ensure.ensureObject(mapping); Jsonix.Model.AbstractElementsPropertyInfo.prototype.initialize.apply(this, [ mapping ]); // TODO Ensure correct argument - var k = mapping.key||mapping.k||undefined; + var k = mapping.key || mapping.k || undefined; Jsonix.Util.Ensure.ensureObject(k); - var v = mapping.value||mapping.v||undefined; + var v = mapping.value || mapping.v || undefined; Jsonix.Util.Ensure.ensureObject(v); // TODO Ensure correct argument - var en = mapping.elementName||mapping.en||undefined; + var en = mapping.elementName || mapping.en || undefined; if (Jsonix.Util.Type.isObject(en)) { this.elementName = Jsonix.XML.QName.fromObject(en); } else if (Jsonix.Util.Type.isString(en)) { @@ -3089,7 +3096,7 @@ Jsonix.Model.ElementMapPropertyInfo = Jsonix.Class(Jsonix.Model.AbstractElements this.elementName = new Jsonix.XML.QName(this.defaultElementNamespaceURI, this.name); } this.entryTypeInfo = new Jsonix.Model.ClassInfo({ - name: 'Map<' + k.name + ',' + v.name + '>', + name : 'Map<' + k.name + ',' + v.name + '>', propertyInfos : [ k, v ] }); @@ -3132,10 +3139,10 @@ Jsonix.Model.ElementMapPropertyInfo = Jsonix.Class(Jsonix.Model.AbstractElements } return result; }, - getInputTypeInfo : function (context, input, scope) { + getTypeInfoByInputElement : function(context, input, scope) { return this.entryTypeInfo; }, - convertToElementValue : function(elementValue, context, input, scope) { + convertFromTypedNamedValue : function(elementValue, context, input, scope) { var entry = elementValue.value; var result = {}; if (Jsonix.Util.Type.isString(entry[this.key.name])) { @@ -3174,7 +3181,7 @@ Jsonix.Model.ElementMapPropertyInfo = Jsonix.Class(Jsonix.Model.AbstractElements output.writeEndElement(); } else { - for ( var index = 0; index < attributeValue.length; index++) { + for (var index = 0; index < attributeValue.length; index++) { var collectionEntry = {}; collectionEntry[this.key.name] = attributeName; collectionEntry[this.value.name] = attributeValue[index]; @@ -3187,10 +3194,10 @@ Jsonix.Model.ElementMapPropertyInfo = Jsonix.Class(Jsonix.Model.AbstractElements } } }, - doBuild: function(context, module) { + doBuild : function(context, module) { this.entryTypeInfo.build(context, module); // TODO get property by name - this.key = this.entryTypeInfo.properties[0]; + this.key = this.entryTypeInfo.properties[0]; this.value = this.entryTypeInfo.properties[1]; }, buildStructureElements : function(context, structure) { @@ -3211,7 +3218,7 @@ Jsonix.Model.ElementMapPropertyInfo = Jsonix.Class(Jsonix.Model.AbstractElements map[attributeName] = []; } - for ( var index = 0; index < attributeValue.length; index++) { + for (var index = 0; index < attributeValue.length; index++) { map[attributeName].push(attributeValue[index]); } } else { @@ -3224,7 +3231,7 @@ Jsonix.Model.ElementMapPropertyInfo = Jsonix.Class(Jsonix.Model.AbstractElements CLASS_NAME : 'Jsonix.Model.ElementMapPropertyInfo' }); -Jsonix.Model.AbstractElementRefsPropertyInfo = Jsonix.Class(Jsonix.Binding.ElementMarshaller, Jsonix.Binding.ElementUnmarshaller, Jsonix.Model.PropertyInfo, { +Jsonix.Model.AbstractElementRefsPropertyInfo = Jsonix.Class(Jsonix.Binding.Marshalls.Element, Jsonix.Binding.Marshalls.Element.AsElementRef, Jsonix.Binding.Unmarshalls.Element, Jsonix.Binding.Unmarshalls.WrapperElement, Jsonix.Binding.Unmarshalls.Element.AsElementRef, Jsonix.Model.PropertyInfo, { wrapperElementName : null, allowDom : true, allowTypedObject : true, @@ -3330,9 +3337,6 @@ Jsonix.Model.AbstractElementRefsPropertyInfo = Jsonix.Class(Jsonix.Binding.Eleme } }, - convertToElementValue : function(elementValue, context, input, scope) { - return elementValue; - }, getTypeInfoByElementName : function(elementName, context, scope) { var propertyElementTypeInfo = this.getPropertyElementTypeInfo(elementName, context); if (Jsonix.Util.Type.exists(propertyElementTypeInfo)) { @@ -3374,7 +3378,7 @@ Jsonix.Model.AbstractElementRefsPropertyInfo = Jsonix.Class(Jsonix.Binding.Eleme // { // structure.elements[key] = this; // } - + if ((this.allowDom || this.allowTypedObject)) { structure.any = this; } @@ -3445,7 +3449,7 @@ Jsonix.Model.ElementRefPropertyInfo = Jsonix.Class(Jsonix.Model.AbstractElementR }, CLASS_NAME : 'Jsonix.Model.ElementRefPropertyInfo' }); -Jsonix.Model.ElementRefPropertyInfo.Simplified = Jsonix.Class(Jsonix.Model.ElementRefPropertyInfo, Jsonix.Binding.ElementUnmarshaller.Simplified, { +Jsonix.Model.ElementRefPropertyInfo.Simplified = Jsonix.Class(Jsonix.Model.ElementRefPropertyInfo, Jsonix.Binding.Unmarshalls.Element.AsSimplifiedElementRef, { CLASS_NAME : 'Jsonix.Model.ElementRefPropertyInfo.Simplified' }); Jsonix.Model.ElementRefsPropertyInfo = Jsonix.Class(Jsonix.Model.AbstractElementRefsPropertyInfo, { @@ -3460,7 +3464,7 @@ Jsonix.Model.ElementRefsPropertyInfo = Jsonix.Class(Jsonix.Model.AbstractElement this.elementTypeInfos = []; for (var index = 0; index < etis.length; index++) { - this.elementTypeInfos[index] = Jsonix.Util.Type.cloneObject(etis[index]); + this.elementTypeInfos[index] = Jsonix.Util.Type.cloneObject(etis[index]); } }, getPropertyElementTypeInfo : function(elementName, context) { @@ -3497,11 +3501,11 @@ Jsonix.Model.ElementRefsPropertyInfo = Jsonix.Class(Jsonix.Model.AbstractElement }, CLASS_NAME : 'Jsonix.Model.ElementRefsPropertyInfo' }); -Jsonix.Model.ElementRefsPropertyInfo.Simplified = Jsonix.Class(Jsonix.Model.ElementRefsPropertyInfo, Jsonix.Binding.ElementUnmarshaller.Simplified, { +Jsonix.Model.ElementRefsPropertyInfo.Simplified = Jsonix.Class(Jsonix.Model.ElementRefsPropertyInfo, Jsonix.Binding.Unmarshalls.Element.AsSimplifiedElementRef, { CLASS_NAME : 'Jsonix.Model.ElementRefsPropertyInfo.Simplified' }); -Jsonix.Model.AnyElementPropertyInfo = Jsonix.Class(Jsonix.Binding.ElementMarshaller, Jsonix.Binding.ElementUnmarshaller, Jsonix.Model.PropertyInfo, { +Jsonix.Model.AnyElementPropertyInfo = Jsonix.Class(Jsonix.Binding.Marshalls.Element, Jsonix.Binding.Marshalls.Element.AsElementRef, Jsonix.Binding.Unmarshalls.Element, Jsonix.Binding.Unmarshalls.Element.AsElementRef, Jsonix.Model.PropertyInfo, { allowDom : true, allowTypedObject : true, mixed : true, @@ -3534,7 +3538,7 @@ Jsonix.Model.AnyElementPropertyInfo = Jsonix.Class(Jsonix.Binding.ElementMarshal } } }; - + var et = input.eventType; if (et === Jsonix.XML.Input.START_ELEMENT) { this.unmarshalElement(context, input, scope, callback); @@ -3544,12 +3548,12 @@ Jsonix.Model.AnyElementPropertyInfo = Jsonix.Class(Jsonix.Binding.ElementMarshal // Whitespace // return null; } else if (et === Jsonix.XML.Input.COMMENT || et === Jsonix.XML.Input.PROCESSING_INSTRUCTION) { - //return null; + // return null; } else { // TODO better exception throw new Error("Illegal state: unexpected event type [" + et + "]."); } - + return result; }, marshal : function(value, context, output, scope) { @@ -3560,7 +3564,7 @@ Jsonix.Model.AnyElementPropertyInfo = Jsonix.Class(Jsonix.Binding.ElementMarshal this.marshalItem(value, context, output, scope); } else { Jsonix.Util.Ensure.ensureArray(value); - for ( var index = 0; index < value.length; index++) { + for (var index = 0; index < value.length; index++) { this.marshalItem(value[index], context, output, scope); } } @@ -3574,24 +3578,12 @@ Jsonix.Model.AnyElementPropertyInfo = Jsonix.Class(Jsonix.Binding.ElementMarshal output.writeNode(value); } else { - if (this.allowTypedObject) - { + if (this.allowTypedObject) { this.marshalElement(value, context, output, scope); } } }, - convertToElementValue : function(elementValue, context, input, scope) { - return elementValue; - }, - getTypeInfoByElementName : function(name, context, scope) { - var elementInfo = context.getElementInfo(name, scope); - if (Jsonix.Util.Type.exists(elementInfo)) { - return elementInfo.typeInfo; - } else { - return undefined; - } - }, - doBuild : function(context, module) { + doBuild : function(context, module) { // Nothing to do }, buildStructure : function(context, structure) { @@ -3626,7 +3618,7 @@ Jsonix.Model.AnyElementPropertyInfo = Jsonix.Class(Jsonix.Binding.ElementMarshal }, CLASS_NAME : 'Jsonix.Model.AnyElementPropertyInfo' }); -Jsonix.Model.AnyElementPropertyInfo.Simplified = Jsonix.Class(Jsonix.Model.AnyElementPropertyInfo, Jsonix.Binding.ElementUnmarshaller.Simplified, { +Jsonix.Model.AnyElementPropertyInfo.Simplified = Jsonix.Class(Jsonix.Model.AnyElementPropertyInfo, Jsonix.Binding.Unmarshalls.Element.AsSimplifiedElementRef, { CLASS_NAME : 'Jsonix.Model.AnyElementPropertyInfo.Simplified' }); Jsonix.Model.Module = Jsonix.Class(Jsonix.Mapping.Styled, { diff --git a/dist/Jsonix-min.js b/dist/Jsonix-min.js index 4a4a2e84..b78370ee 100644 --- a/dist/Jsonix-min.js +++ b/dist/Jsonix-min.js @@ -107,7 +107,6 @@ window.setTimeout(function(){w.send(t) },0) }else{w.onreadystatechange=function(){r.handleTransport(w,q,x) }; -console.log("Sending."); w.send(t) }}return w },handleTransport:function(f,d,e){if(f.readyState==4){if(!f.status||(f.status>=200&&f.status<300)){d(f) @@ -693,7 +692,8 @@ if(!c){throw new Error("Mapping style ["+d.mappingStyle+"] is not known.") }}}if(!this.mappingStyle){this.mappingStyle=Jsonix.Mapping.Style.STYLES.standard }},CLASS_NAME:"Jsonix.Mapping.Styled"}); Jsonix.Binding={}; -Jsonix.Binding.ElementMarshaller=Jsonix.Class({marshalElement:function(n,s,r,k){var p=this.getOutputElementValue(n,s,r,k); +Jsonix.Binding.Marshalls={}; +Jsonix.Binding.Marshalls.Element=Jsonix.Class({marshalElement:function(n,s,r,k){var p=this.convertToTypedNamedValue(n,s,r,k); var o=p.typeInfo; var l=o; if(Jsonix.Util.Type.exists(o)){r.writeStartElement(p.name); @@ -705,10 +705,14 @@ r.writeAttribute(Jsonix.Schema.XSI.TYPE_QNAME,q) }}l.marshal(p.value,s,r,k) }r.writeEndElement() }else{throw new Error("Element ["+p.name.key+"] is not known in this context.") -}},getOutputElementValue:function(i,f,g,j){Jsonix.Util.Ensure.ensureObject(i); -var h=this.convertFromElementValue(i,f,g,j); +}},getTypeInfoByElementName:function(f,e,g){var h=e.getElementInfo(f,g); +if(Jsonix.Util.Type.exists(h)){return h.typeInfo +}else{return undefined +}}}); +Jsonix.Binding.Marshalls.Element.AsElementRef=Jsonix.Class({convertToTypedNamedValue:function(i,f,g,j){Jsonix.Util.Ensure.ensureObject(i); +var h=this.convertToNamedValue(i,f,g,j); return{name:h.name,value:h.value,typeInfo:this.getTypeInfoByElementName(h.name,f,j)} -},convertFromElementValue:function(j,m,h,l){var n; +},convertToNamedValue:function(j,m,h,l){var n; var k; if(Jsonix.Util.Type.exists(j.name)&&!Jsonix.Util.Type.isUndefined(j.value)){n=Jsonix.XML.QName.fromObjectOrString(j.name,m); k=Jsonix.Util.Type.exists(j.value)?j.value:null; @@ -717,38 +721,43 @@ return{name:n,value:k} k=j[i]; return{name:n,value:k} }}}throw new Error("Invalid element value ["+j+"]. Element values must either have {name:'myElementName', value: elementValue} or {myElementName:elementValue} structure.") -},getTypeInfoByElementName:function(f,e,g){var h=e.getElementInfo(f,g); -if(Jsonix.Util.Type.exists(h)){return h.typeInfo -}else{return undefined -}}}); -Jsonix.Binding.ElementUnmarshaller=Jsonix.Class({allowTypedObject:true,allowDom:false,mixed:false,unmarshalWrapperElement:function(f,g,j,h){var i=g.next(); +}}); +Jsonix.Binding.Unmarshalls={}; +Jsonix.Binding.Unmarshalls.WrapperElement=Jsonix.Class({mixed:false,unmarshalWrapperElement:function(f,g,j,h){var i=g.next(); while(i!==Jsonix.XML.Input.END_ELEMENT){if(i===Jsonix.XML.Input.START_ELEMENT){this.unmarshalElement(f,g,j,h) }else{if(this.mixed&&(i===Jsonix.XML.Input.CHARACTERS||i===Jsonix.XML.Input.CDATA||i===Jsonix.XML.Input.ENTITY_REFERENCE)){h(g.getText()) }else{if(i===Jsonix.XML.Input.SPACE||i===Jsonix.XML.Input.COMMENT||i===Jsonix.XML.Input.PROCESSING_INSTRUCTION){}else{throw new Error("Illegal state: unexpected event type ["+i+"].") }}}i=g.next() -}},unmarshalElement:function(p,j,o,k){if(j.eventType!=1){throw new Error("Parser must be on START_ELEMENT to read next element.") -}var m=this.getInputTypeInfo(p,j,o); -var i=j.getName(); -var l; -if(this.allowTypedObject&&Jsonix.Util.Type.exists(m)){var n=m.unmarshal(p,j,o); -l=this.convertToElementValue({name:i,value:n},p,j,o) -}else{if(this.allowDom){l=j.getElement() -}else{throw new Error("Element ["+i.toString()+"] is not known in this context and property does not allow DOM.") -}}k(l) -},getInputTypeInfo:function(n,p,m){var i=null; +}}}); +Jsonix.Binding.Unmarshalls.Element=Jsonix.Class({allowTypedObject:true,allowDom:false,unmarshalElement:function(q,o,j,l){if(o.eventType!=1){throw new Error("Parser must be on START_ELEMENT to read next element.") +}var k=this.getTypeInfoByInputElement(q,o,j); +var r=o.getName(); +var p; +if(this.allowTypedObject&&Jsonix.Util.Type.exists(k)){var n=k.unmarshal(q,o,j); +var m={name:r,value:n,typeInfo:k}; +p=this.convertFromTypedNamedValue(m,q,o,j) +}else{if(this.allowDom){p=o.getElement() +}else{throw new Error("Element ["+r.toString()+"] is not known in this context and property does not allow DOM.") +}}l(p) +},getTypeInfoByInputElement:function(n,p,m){var i=null; if(n.supportXsiType){var j=p.getAttributeValueNS(Jsonix.Schema.XSI.NAMESPACE_URI,Jsonix.Schema.XSI.TYPE); if(Jsonix.Util.StringUtils.isNotBlank(j)){var k=Jsonix.Schema.XSD.QName.INSTANCE.parse(j,n,p,m); i=n.getTypeInfoByTypeNameKey(k.key) }}var o=p.getName(); var l=i?i:this.getTypeInfoByElementName(o,n,m); return l +},getTypeInfoByElementName:function(f,e,g){var h=e.getElementInfo(f,g); +if(Jsonix.Util.Type.exists(h)){return h.typeInfo +}else{return undefined +}}}); +Jsonix.Binding.Unmarshalls.Element.AsElementRef=Jsonix.Class({convertFromTypedNamedValue:function(g,e,f,h){return{name:g.name,value:g.value} }}); -Jsonix.Binding.ElementUnmarshaller.Simplified=Jsonix.Class(Jsonix.Binding.ElementUnmarshaller,{convertToElementValue:function(i,l,g,k){var h=i.name.toCanonicalString(l); +Jsonix.Binding.Unmarshalls.Element.AsSimplifiedElementRef=Jsonix.Class({convertFromTypedNamedValue:function(i,l,g,k){var h=i.name.toCanonicalString(l); var j={}; j[h]=i.value; return j }}); -Jsonix.Binding.Marshaller=Jsonix.Class(Jsonix.Binding.ElementMarshaller,{context:null,initialize:function(b){Jsonix.Util.Ensure.ensureObject(b); +Jsonix.Binding.Marshaller=Jsonix.Class(Jsonix.Binding.Marshalls.Element,Jsonix.Binding.Marshalls.Element.AsElementRef,{context:null,initialize:function(b){Jsonix.Util.Ensure.ensureObject(b); this.context=b },marshalString:function(e){var d=this.marshalDocument(e); var f=Jsonix.DOM.serialize(d); @@ -760,7 +769,7 @@ e.writeEndDocument(); return f },CLASS_NAME:"Jsonix.Binding.Marshaller"}); Jsonix.Binding.Marshaller.Simplified=Jsonix.Class(Jsonix.Binding.Marshaller,{CLASS_NAME:"Jsonix.Binding.Marshaller.Simplified"}); -Jsonix.Binding.Unmarshaller=Jsonix.Class(Jsonix.Binding.ElementUnmarshaller,{context:null,allowTypedObject:true,allowDom:false,initialize:function(b){Jsonix.Util.Ensure.ensureObject(b); +Jsonix.Binding.Unmarshaller=Jsonix.Class(Jsonix.Binding.Unmarshalls.Element,Jsonix.Binding.Unmarshalls.Element.AsElementRef,{context:null,allowTypedObject:true,allowDom:false,initialize:function(b){Jsonix.Util.Ensure.ensureObject(b); this.context=b },unmarshalString:function(c){Jsonix.Util.Ensure.ensureString(c); var d=Jsonix.DOM.parse(c); @@ -789,12 +798,8 @@ var h=function(a){g=a f.nextTag(); this.unmarshalElement(this.context,f,j,h); return g -},convertToElementValue:function(g,e,f,h){return g -},getTypeInfoByElementName:function(f,e,g){var h=e.getElementInfo(f,g); -if(Jsonix.Util.Type.exists(h)){return h.typeInfo -}else{return undefined -}},CLASS_NAME:"Jsonix.Binding.Unmarshaller"}); -Jsonix.Binding.Unmarshaller.Simplified=Jsonix.Class(Jsonix.Binding.Unmarshaller,Jsonix.Binding.ElementUnmarshaller.Simplified,{CLASS_NAME:"Jsonix.Binding.Unmarshaller.Simplified"}); +},CLASS_NAME:"Jsonix.Binding.Unmarshaller"}); +Jsonix.Binding.Unmarshaller.Simplified=Jsonix.Class(Jsonix.Binding.Unmarshaller,Jsonix.Binding.Unmarshalls.Element.AsSimplifiedElementRef,{CLASS_NAME:"Jsonix.Binding.Unmarshaller.Simplified"}); Jsonix.Model.TypeInfo=Jsonix.Class({name:null,baseTypeInfo:null,initialize:function(){},isBasedOn:function(c){var d=this; while(d){if(c===d){return true }d=d.baseTypeInfo @@ -1089,7 +1094,7 @@ return this.unmarshalValue(g,e,f,h) if(Jsonix.Util.Type.exists(d.elements)){throw new Error("The structure already defines element mappings, it cannot define a value property.") }else{d.value=this }},CLASS_NAME:"Jsonix.Model.ValuePropertyInfo"}); -Jsonix.Model.AbstractElementsPropertyInfo=Jsonix.Class(Jsonix.Binding.ElementUnmarshaller,Jsonix.Model.PropertyInfo,{wrapperElementName:null,allowDom:false,allowTypedObject:true,mixed:false,initialize:function(c){Jsonix.Util.Ensure.ensureObject(c); +Jsonix.Model.AbstractElementsPropertyInfo=Jsonix.Class(Jsonix.Binding.Unmarshalls.Element,Jsonix.Binding.Unmarshalls.WrapperElement,Jsonix.Model.PropertyInfo,{wrapperElementName:null,allowDom:false,allowTypedObject:true,mixed:false,initialize:function(c){Jsonix.Util.Ensure.ensureObject(c); Jsonix.Model.PropertyInfo.prototype.initialize.apply(this,[c]); var d=c.wrapperElementName||c.wen||undefined; if(Jsonix.Util.Type.isObject(d)){this.wrapperElementName=Jsonix.XML.QName.fromObject(d) @@ -1114,7 +1119,7 @@ g org.hisrc.jsonix jsonix-project - 2.2.1-SNAPSHOT + 2.2.1 diff --git a/nodejs/pom.xml b/nodejs/pom.xml index 38e6e115..c1c4334c 100644 --- a/nodejs/pom.xml +++ b/nodejs/pom.xml @@ -6,7 +6,7 @@ org.hisrc.jsonix jsonix-project - 2.2.1-SNAPSHOT + 2.2.1 scripts diff --git a/nodejs/scripts/package.json b/nodejs/scripts/package.json index 1405c361..1ca563a6 100644 --- a/nodejs/scripts/package.json +++ b/nodejs/scripts/package.json @@ -1,6 +1,6 @@ { "name" : "jsonix", - "version" : "2.2.1-SNAPSHOT", + "version" : "2.2.1", "description" : "Jsonix (JSON interfaces for XML) is a JavaScript library which allows converting between XML and JSON structures.", "keywords" : [ "json", "xml", "unmarshal", "unmarshalling", "marshal", "marshalling", "parse", "parsing", "serialize", "serializing", diff --git a/nodejs/scripts/pom.xml b/nodejs/scripts/pom.xml index 8fbdee5f..6f4360e9 100644 --- a/nodejs/scripts/pom.xml +++ b/nodejs/scripts/pom.xml @@ -6,7 +6,7 @@ org.hisrc.jsonix jsonix-nodejs - 2.2.1-SNAPSHOT + 2.2.1 diff --git a/nodejs/tests/ar/AR.js b/nodejs/tests/ar/AR.js index 384e5464..09428c0f 100644 --- a/nodejs/tests/ar/AR.js +++ b/nodejs/tests/ar/AR.js @@ -4,6 +4,7 @@ var AR_Module_Factory = function () { defaultElementNamespaceURI: 'urn:test', typeInfos: [{ localName: 'AccumulateResponse.TestCase', + typeName: null, propertyInfos: [{ name: 'transactionId', elementName: 'TransactionId' diff --git a/nodejs/tests/ar/pom.xml b/nodejs/tests/ar/pom.xml index 63b3c668..ce01b9fa 100644 --- a/nodejs/tests/ar/pom.xml +++ b/nodejs/tests/ar/pom.xml @@ -6,7 +6,7 @@ org.hisrc.jsonix jsonix-nodejs-tests - 2.2.1-SNAPSHOT + 2.2.1 diff --git a/nodejs/tests/basic/pom.xml b/nodejs/tests/basic/pom.xml index b332518f..0b039a29 100644 --- a/nodejs/tests/basic/pom.xml +++ b/nodejs/tests/basic/pom.xml @@ -6,7 +6,7 @@ org.hisrc.jsonix jsonix-nodejs-tests - 2.2.1-SNAPSHOT + 2.2.1 diff --git a/nodejs/tests/browserify/pom.xml b/nodejs/tests/browserify/pom.xml index 1bce59ea..2db042c1 100644 --- a/nodejs/tests/browserify/pom.xml +++ b/nodejs/tests/browserify/pom.xml @@ -6,7 +6,7 @@ org.hisrc.jsonix jsonix-nodejs-tests - 2.2.1-SNAPSHOT + 2.2.1 diff --git a/nodejs/tests/po/pom.xml b/nodejs/tests/po/pom.xml index f75f9d72..9583e69c 100644 --- a/nodejs/tests/po/pom.xml +++ b/nodejs/tests/po/pom.xml @@ -6,7 +6,7 @@ org.hisrc.jsonix jsonix-nodejs-tests - 2.2.1-SNAPSHOT + 2.2.1 diff --git a/nodejs/tests/pom.xml b/nodejs/tests/pom.xml index f0fa0399..ae5fdac6 100644 --- a/nodejs/tests/pom.xml +++ b/nodejs/tests/pom.xml @@ -6,7 +6,7 @@ org.hisrc.jsonix jsonix-nodejs - 2.2.1-SNAPSHOT + 2.2.1 basic diff --git a/nodejs/tests/wps/pom.xml b/nodejs/tests/wps/pom.xml index de20ca00..d8744d7f 100644 --- a/nodejs/tests/wps/pom.xml +++ b/nodejs/tests/wps/pom.xml @@ -6,7 +6,7 @@ org.hisrc.jsonix jsonix-nodejs-tests - 2.2.1-SNAPSHOT + 2.2.1 diff --git a/pom.xml b/pom.xml index ba7dcfce..363146b6 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.hisrc.jsonix jsonix-project pom - 2.2.1-SNAPSHOT + 2.2.1 Jsonix Jsonix is a JavaScript library which allows you to convert between XML and JSON structures based on mappings. https://github.com/highsource/jsonix diff --git a/scripts/pom.xml b/scripts/pom.xml index 93ab8d77..b1b4f1d1 100644 --- a/scripts/pom.xml +++ b/scripts/pom.xml @@ -6,7 +6,7 @@ org.hisrc.jsonix jsonix-project - 2.2.1-SNAPSHOT + 2.2.1