Skip to content

Commit 60b2f2d

Browse files
committed
Fixes #50, #135.
1 parent 6c7494b commit 60b2f2d

File tree

2 files changed

+90
-78
lines changed

2 files changed

+90
-78
lines changed

dist/Jsonix-all.js

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,6 +2108,7 @@ Jsonix.Binding.Unmarshaller.Simplified = Jsonix.Class(Jsonix.Binding.Unmarshalle
21082108
CLASS_NAME : 'Jsonix.Binding.Unmarshaller.Simplified'
21092109
});
21102110
Jsonix.Model.TypeInfo = Jsonix.Class({
2111+
module: null,
21112112
name : null,
21122113
baseTypeInfo : null,
21132114
initialize : function() {
@@ -2199,17 +2200,17 @@ Jsonix.Model.ClassInfo = Jsonix
21992200
// Obsolete
22002201
destroy : function() {
22012202
},
2202-
build : function(context, module) {
2203+
build : function(context) {
22032204
if (!this.built) {
2204-
this.baseTypeInfo = context.resolveTypeInfo(this.baseTypeInfo, module);
2205+
this.baseTypeInfo = context.resolveTypeInfo(this.baseTypeInfo, this.module);
22052206
if (Jsonix.Util.Type.exists(this.baseTypeInfo)) {
2206-
this.baseTypeInfo.build(context, module);
2207+
this.baseTypeInfo.build(context);
22072208
}
22082209

22092210
// Build properties in this context
22102211
for ( var index = 0; index < this.properties.length; index++) {
22112212
var propertyInfo = this.properties[index];
2212-
propertyInfo.build(context, module);
2213+
propertyInfo.build(context, this.module);
22132214
}
22142215

22152216
// Build the structure
@@ -2553,10 +2554,10 @@ Jsonix.Model.EnumLeafInfo = Jsonix.Class(Jsonix.Model.TypeInfo, {
25532554
this.entries = vs;
25542555
}
25552556
},
2556-
build : function(context, module) {
2557+
build : function(context) {
25572558
if (!this.built) {
2558-
this.baseTypeInfo = context.resolveTypeInfo(this.baseTypeInfo, module);
2559-
this.baseTypeInfo.build(context, module);
2559+
this.baseTypeInfo = context.resolveTypeInfo(this.baseTypeInfo, this.module);
2560+
this.baseTypeInfo.build(context);
25602561
var items = this.entries;
25612562
var entries = {};
25622563
var keys = [];
@@ -2687,6 +2688,7 @@ Jsonix.Model.EnumLeafInfo = Jsonix.Class(Jsonix.Model.TypeInfo, {
26872688
CLASS_NAME : 'Jsonix.Model.EnumLeafInfo'
26882689
});
26892690
Jsonix.Model.ElementInfo = Jsonix.Class({
2691+
module: null,
26902692
elementName : null,
26912693
typeInfo : null,
26922694
substitutionHead : null,
@@ -2715,11 +2717,11 @@ Jsonix.Model.ElementInfo = Jsonix.Class({
27152717
var sc = mapping.scope||mapping.sc||null;
27162718
this.scope = sc;
27172719
},
2718-
build : function(context, module) {
2720+
build : function(context) {
27192721
// If element info is not yet built
27202722
if (!this.built) {
2721-
this.typeInfo = context.resolveTypeInfo(this.typeInfo, module);
2722-
this.scope = context.resolveTypeInfo(this.scope, module);
2723+
this.typeInfo = context.resolveTypeInfo(this.typeInfo, this.module);
2724+
this.scope = context.resolveTypeInfo(this.scope, this.module);
27232725
this.built = true;
27242726
}
27252727
},
@@ -3874,6 +3876,7 @@ Jsonix.Model.Module = Jsonix.Class(Jsonix.Mapping.Styled, {
38743876
var classInfo = new this.mappingStyle.classInfo(mapping, {
38753877
mappingStyle : this.mappingStyle
38763878
});
3879+
classInfo.module = this;
38773880
return classInfo;
38783881
},
38793882
createEnumLeafInfo : function(mapping) {
@@ -3883,6 +3886,7 @@ Jsonix.Model.Module = Jsonix.Class(Jsonix.Mapping.Styled, {
38833886
var enumLeafInfo = new this.mappingStyle.enumLeafInfo(mapping, {
38843887
mappingStyle : this.mappingStyle
38853888
});
3889+
enumLeafInfo.module = this;
38863890
return enumLeafInfo;
38873891
},
38883892
createList : function(mapping) {
@@ -3899,7 +3903,9 @@ Jsonix.Model.Module = Jsonix.Class(Jsonix.Mapping.Styled, {
38993903
}
39003904
var s = mapping.separator || mapping.sep || ' ';
39013905
Jsonix.Util.Ensure.ensureExists(ti);
3902-
return new Jsonix.Schema.XSD.List(ti, tn, s);
3906+
var listTypeInfo = new Jsonix.Schema.XSD.List(ti, tn, s);
3907+
listTypeInfo.module = this;
3908+
return listTypeInfo;
39033909
},
39043910
createElementInfo : function(mapping) {
39053911
Jsonix.Util.Ensure.ensureObject(mapping);
@@ -3935,6 +3941,7 @@ Jsonix.Model.Module = Jsonix.Class(Jsonix.Mapping.Styled, {
39353941
var elementInfo = new this.mappingStyle.elementInfo(mapping, {
39363942
mappingStyle : this.mappingStyle
39373943
});
3944+
elementInfo.module = this;
39383945
return elementInfo;
39393946
},
39403947
registerTypeInfos : function(context) {
@@ -4138,9 +4145,9 @@ Jsonix.Schema.XSD.List = Jsonix
41384145
this.trimmedSeparator = trimmedSeparator;
41394146
}
41404147
},
4141-
build : function(context, module) {
4148+
build : function(context) {
41424149
if (!this.built) {
4143-
this.typeInfo = context.resolveTypeInfo(this.typeInfo, module);
4150+
this.typeInfo = context.resolveTypeInfo(this.typeInfo, this.module);
41444151
this.built = true;
41454152
}
41464153
},
@@ -5268,25 +5275,25 @@ Jsonix.Schema.XSD.Duration = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, {
52685275
result += '-';
52695276
}
52705277
result += 'P';
5271-
if (value.years) {
5278+
if (Jsonix.Util.Type.exists(value.years)) {
52725279
result += (value.years + 'Y');
52735280
}
5274-
if (value.months) {
5281+
if (Jsonix.Util.Type.exists(value.months)) {
52755282
result += (value.months + 'M');
52765283
}
5277-
if (value.days) {
5284+
if (Jsonix.Util.Type.exists(value.days)) {
52785285
result += (value.days + 'D');
52795286
}
5280-
if (value.hours || value.minutes || value.seconds)
5287+
if (Jsonix.Util.Type.exists(value.hours) || Jsonix.Util.Type.exists(value.minutes) || Jsonix.Util.Type.exists(value.seconds))
52815288
{
52825289
result += 'T';
5283-
if (value.hours) {
5290+
if (Jsonix.Util.Type.exists(value.hours)) {
52845291
result += (value.hours + 'H');
52855292
}
5286-
if (value.minutes) {
5293+
if (Jsonix.Util.Type.exists(value.minutes)) {
52875294
result += (value.minutes + 'M');
52885295
}
5289-
if (value.seconds) {
5296+
if (Jsonix.Util.Type.exists(value.seconds)) {
52905297
result += (value.seconds + 'S');
52915298
}
52925299
}

dist/Jsonix-min.js

Lines changed: 63 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ this.unmarshalElement(this.context,f,j,h);
850850
return g
851851
},CLASS_NAME:"Jsonix.Binding.Unmarshaller"});
852852
Jsonix.Binding.Unmarshaller.Simplified=Jsonix.Class(Jsonix.Binding.Unmarshaller,Jsonix.Binding.Unmarshalls.Element.AsSimplifiedElementRef,{CLASS_NAME:"Jsonix.Binding.Unmarshaller.Simplified"});
853-
Jsonix.Model.TypeInfo=Jsonix.Class({name:null,baseTypeInfo:null,initialize:function(){},isBasedOn:function(c){var d=this;
853+
Jsonix.Model.TypeInfo=Jsonix.Class({module:null,name:null,baseTypeInfo:null,initialize:function(){},isBasedOn:function(c){var d=this;
854854
while(d){if(c===d){return true
855855
}d=d.baseTypeInfo
856856
}return false
@@ -886,15 +886,15 @@ for(var s=0;
886886
s<x.length;
887887
s++){this.p(x[s])
888888
}},getPropertyInfoByName:function(b){return this.propertiesMap[b]
889-
},destroy:function(){},build:function(i,j){if(!this.built){this.baseTypeInfo=i.resolveTypeInfo(this.baseTypeInfo,j);
890-
if(Jsonix.Util.Type.exists(this.baseTypeInfo)){this.baseTypeInfo.build(i,j)
891-
}for(var f=0;
892-
f<this.properties.length;
893-
f++){var h=this.properties[f];
894-
h.build(i,j)
895-
}var g={elements:null,attributes:{},anyAttribute:null,value:null,any:null};
896-
this.buildStructure(i,g);
897-
this.structure=g
889+
},destroy:function(){},build:function(h){if(!this.built){this.baseTypeInfo=h.resolveTypeInfo(this.baseTypeInfo,this.module);
890+
if(Jsonix.Util.Type.exists(this.baseTypeInfo)){this.baseTypeInfo.build(h)
891+
}for(var e=0;
892+
e<this.properties.length;
893+
e++){var g=this.properties[e];
894+
g.build(h,this.module)
895+
}var f={elements:null,attributes:{},anyAttribute:null,value:null,any:null};
896+
this.buildStructure(h,f);
897+
this.structure=f
898898
}},buildStructure:function(h,f){if(Jsonix.Util.Type.exists(this.baseTypeInfo)){this.baseTypeInfo.buildStructure(h,f)
899899
}for(var e=0;
900900
e<this.properties.length;
@@ -995,39 +995,39 @@ var h=f.values||f.vs||undefined;
995995
Jsonix.Util.Ensure.ensureExists(h);
996996
if(!(Jsonix.Util.Type.isObject(h)||Jsonix.Util.Type.isArray(h))){throw new Error("Enum values must be either an array or an object.")
997997
}else{this.entries=h
998-
}},build:function(r,q){if(!this.built){this.baseTypeInfo=r.resolveTypeInfo(this.baseTypeInfo,q);
999-
this.baseTypeInfo.build(r,q);
1000-
var n=this.entries;
1001-
var p={};
1002-
var j=[];
1003-
var k=[];
998+
}},build:function(m){if(!this.built){this.baseTypeInfo=m.resolveTypeInfo(this.baseTypeInfo,this.module);
999+
this.baseTypeInfo.build(m);
1000+
var p=this.entries;
1001+
var j={};
1002+
var l=[];
1003+
var i=[];
10041004
var o=0;
1005-
var l;
1006-
var m;
1007-
if(Jsonix.Util.Type.isArray(n)){for(o=0;
1008-
o<n.length;
1009-
o++){m=n[o];
1010-
if(Jsonix.Util.Type.isString(m)){l=m;
1005+
var n;
1006+
var k;
1007+
if(Jsonix.Util.Type.isArray(p)){for(o=0;
1008+
o<p.length;
1009+
o++){k=p[o];
1010+
if(Jsonix.Util.Type.isString(k)){n=k;
10111011
if(!(Jsonix.Util.Type.isFunction(this.baseTypeInfo.parse))){throw new Error("Enum value is provided as string but the base type ["+this.baseTypeInfo.name+"] of the enum info ["+this.name+"] does not implement the parse method.")
1012-
}m=this.baseTypeInfo.parse(m,r,null,this)
1013-
}else{if(this.baseTypeInfo.isInstance(m,r,this)){if(!(Jsonix.Util.Type.isFunction(this.baseTypeInfo.print))){throw new Error("The base type ["+this.baseTypeInfo.name+"] of the enum info ["+this.name+"] does not implement the print method, unable to produce the enum key as string.")
1014-
}l=this.baseTypeInfo.print(m,r,null,this)
1015-
}else{throw new Error("Enum value ["+m+"] is not an instance of the enum base type ["+this.baseTypeInfo.name+"].")
1016-
}}p[l]=m;
1017-
j[o]=l;
1018-
k[o]=m
1019-
}}else{if(Jsonix.Util.Type.isObject(n)){for(l in n){if(n.hasOwnProperty(l)){m=n[l];
1020-
if(Jsonix.Util.Type.isString(m)){if(!(Jsonix.Util.Type.isFunction(this.baseTypeInfo.parse))){throw new Error("Enum value is provided as string but the base type ["+this.baseTypeInfo.name+"] of the enum info ["+this.name+"] does not implement the parse method.")
1021-
}m=this.baseTypeInfo.parse(m,r,null,this)
1022-
}else{if(!this.baseTypeInfo.isInstance(m,r,this)){throw new Error("Enum value ["+m+"] is not an instance of the enum base type ["+this.baseTypeInfo.name+"].")
1023-
}}p[l]=m;
1024-
j[o]=l;
1025-
k[o]=m;
1012+
}k=this.baseTypeInfo.parse(k,m,null,this)
1013+
}else{if(this.baseTypeInfo.isInstance(k,m,this)){if(!(Jsonix.Util.Type.isFunction(this.baseTypeInfo.print))){throw new Error("The base type ["+this.baseTypeInfo.name+"] of the enum info ["+this.name+"] does not implement the print method, unable to produce the enum key as string.")
1014+
}n=this.baseTypeInfo.print(k,m,null,this)
1015+
}else{throw new Error("Enum value ["+k+"] is not an instance of the enum base type ["+this.baseTypeInfo.name+"].")
1016+
}}j[n]=k;
1017+
l[o]=n;
1018+
i[o]=k
1019+
}}else{if(Jsonix.Util.Type.isObject(p)){for(n in p){if(p.hasOwnProperty(n)){k=p[n];
1020+
if(Jsonix.Util.Type.isString(k)){if(!(Jsonix.Util.Type.isFunction(this.baseTypeInfo.parse))){throw new Error("Enum value is provided as string but the base type ["+this.baseTypeInfo.name+"] of the enum info ["+this.name+"] does not implement the parse method.")
1021+
}k=this.baseTypeInfo.parse(k,m,null,this)
1022+
}else{if(!this.baseTypeInfo.isInstance(k,m,this)){throw new Error("Enum value ["+k+"] is not an instance of the enum base type ["+this.baseTypeInfo.name+"].")
1023+
}}j[n]=k;
1024+
l[o]=n;
1025+
i[o]=k;
10261026
o++
10271027
}}}else{throw new Error("Enum values must be either an array or an object.")
1028-
}}this.entries=p;
1029-
this.keys=j;
1030-
this.values=k;
1028+
}}this.entries=j;
1029+
this.keys=l;
1030+
this.values=i;
10311031
this.built=true
10321032
}},unmarshal:function(e,f,h){var g=f.getElementText();
10331033
return this.parse(g,e,f,h)
@@ -1046,7 +1046,7 @@ f<this.values.length;
10461046
f++){if(this.values[f]===g){return true
10471047
}}return false
10481048
},CLASS_NAME:"Jsonix.Model.EnumLeafInfo"});
1049-
Jsonix.Model.ElementInfo=Jsonix.Class({elementName:null,typeInfo:null,substitutionHead:null,scope:null,built:false,initialize:function(g){Jsonix.Util.Ensure.ensureObject(g);
1049+
Jsonix.Model.ElementInfo=Jsonix.Class({module:null,elementName:null,typeInfo:null,substitutionHead:null,scope:null,built:false,initialize:function(g){Jsonix.Util.Ensure.ensureObject(g);
10501050
var j=g.defaultElementNamespaceURI||g.dens||"";
10511051
this.defaultElementNamespaceURI=j;
10521052
var h=g.elementName||g.en||undefined;
@@ -1059,8 +1059,8 @@ var l=g.substitutionHead||g.sh||null;
10591059
this.substitutionHead=l;
10601060
var i=g.scope||g.sc||null;
10611061
this.scope=i
1062-
},build:function(c,d){if(!this.built){this.typeInfo=c.resolveTypeInfo(this.typeInfo,d);
1063-
this.scope=c.resolveTypeInfo(this.scope,d);
1062+
},build:function(b){if(!this.built){this.typeInfo=b.resolveTypeInfo(this.typeInfo,this.module);
1063+
this.scope=b.resolveTypeInfo(this.scope,this.module);
10641064
this.built=true
10651065
}},CLASS_NAME:"Jsonix.Model.ElementInfo"});
10661066
Jsonix.Model.PropertyInfo=Jsonix.Class({name:null,collection:false,targetNamespace:"",defaultElementNamespaceURI:"",defaultAttributeNamespaceURI:"",built:false,initialize:function(r){Jsonix.Util.Ensure.ensureObject(r);
@@ -1507,19 +1507,23 @@ var h=f.defaultAttributeNamespaceURI||f.dans||this.defaultAttributeNamespaceURI;
15071507
f.defaultAttributeNamespaceURI=h;
15081508
this.initializeNames(f);
15091509
var i=new this.mappingStyle.classInfo(f,{mappingStyle:this.mappingStyle});
1510+
i.module=this;
15101511
return i
15111512
},createEnumLeafInfo:function(d){Jsonix.Util.Ensure.ensureObject(d);
15121513
this.initializeNames(d);
15131514
var c=new this.mappingStyle.enumLeafInfo(d,{mappingStyle:this.mappingStyle});
1515+
c.module=this;
15141516
return c
1515-
},createList:function(e){Jsonix.Util.Ensure.ensureObject(e);
1516-
var g=e.baseTypeInfo||e.typeInfo||e.bti||e.ti||"String";
1517-
var f=e.typeName||e.tn||null;
1518-
if(Jsonix.Util.Type.exists(f)){if(Jsonix.Util.Type.isString(f)){f=new Jsonix.XML.QName(this.targetNamespace,f)
1519-
}else{f=Jsonix.XML.QName.fromObject(f)
1520-
}}var h=e.separator||e.sep||" ";
1521-
Jsonix.Util.Ensure.ensureExists(g);
1522-
return new Jsonix.Schema.XSD.List(g,f,h)
1517+
},createList:function(f){Jsonix.Util.Ensure.ensureObject(f);
1518+
var h=f.baseTypeInfo||f.typeInfo||f.bti||f.ti||"String";
1519+
var g=f.typeName||f.tn||null;
1520+
if(Jsonix.Util.Type.exists(g)){if(Jsonix.Util.Type.isString(g)){g=new Jsonix.XML.QName(this.targetNamespace,g)
1521+
}else{g=Jsonix.XML.QName.fromObject(g)
1522+
}}var i=f.separator||f.sep||" ";
1523+
Jsonix.Util.Ensure.ensureExists(h);
1524+
var j=new Jsonix.Schema.XSD.List(h,g,i);
1525+
j.module=this;
1526+
return j
15231527
},createElementInfo:function(g){Jsonix.Util.Ensure.ensureObject(g);
15241528
g=Jsonix.Util.Type.cloneObject(g);
15251529
var i=g.defaultElementNamespaceURI||g.dens||this.defaultElementNamespaceURI;
@@ -1537,6 +1541,7 @@ if(Jsonix.Util.Type.exists(l)){if(Jsonix.Util.Type.isObject(l)){g.substitutionHe
15371541
}else{Jsonix.Util.Ensure.ensureString(l);
15381542
g.substitutionHead=new Jsonix.XML.QName(this.defaultElementNamespaceURI,l)
15391543
}}var k=new this.mappingStyle.elementInfo(g,{mappingStyle:this.mappingStyle});
1544+
k.module=this;
15401545
return k
15411546
},registerTypeInfos:function(d){for(var e=0;
15421547
e<this.typeInfos.length;
@@ -1594,7 +1599,7 @@ if(!Jsonix.Util.Type.exists(this.name)){this.name=e.name+"*"
15941599
}var g=Jsonix.Util.StringUtils.trim(this.separator);
15951600
if(g.length===0){this.trimmedSeparator=Jsonix.Util.StringUtils.whitespaceCharacters
15961601
}else{this.trimmedSeparator=g
1597-
}},build:function(c,d){if(!this.built){this.typeInfo=c.resolveTypeInfo(this.typeInfo,d);
1602+
}},build:function(b){if(!this.built){this.typeInfo=b.resolveTypeInfo(this.typeInfo,this.module);
15981603
this.built=true
15991604
}},print:function(i,k,g,j){if(!Jsonix.Util.Type.exists(i)){return null
16001605
}Jsonix.Util.Ensure.ensureArray(i);
@@ -2136,13 +2141,13 @@ if(e){throw new Error("At least one of the components (years, months, days, hour
21362141
var g="";
21372142
if(h.sign===-1){g+="-"
21382143
}g+="P";
2139-
if(h.years){g+=(h.years+"Y")
2140-
}if(h.months){g+=(h.months+"M")
2141-
}if(h.days){g+=(h.days+"D")
2142-
}if(h.hours||h.minutes||h.seconds){g+="T";
2143-
if(h.hours){g+=(h.hours+"H")
2144-
}if(h.minutes){g+=(h.minutes+"M")
2145-
}if(h.seconds){g+=(h.seconds+"S")
2144+
if(Jsonix.Util.Type.exists(h.years)){g+=(h.years+"Y")
2145+
}if(Jsonix.Util.Type.exists(h.months)){g+=(h.months+"M")
2146+
}if(Jsonix.Util.Type.exists(h.days)){g+=(h.days+"D")
2147+
}if(Jsonix.Util.Type.exists(h.hours)||Jsonix.Util.Type.exists(h.minutes)||Jsonix.Util.Type.exists(h.seconds)){g+="T";
2148+
if(Jsonix.Util.Type.exists(h.hours)){g+=(h.hours+"H")
2149+
}if(Jsonix.Util.Type.exists(h.minutes)){g+=(h.minutes+"M")
2150+
}if(Jsonix.Util.Type.exists(h.seconds)){g+=(h.seconds+"S")
21462151
}}return g
21472152
},parse:function(m,p,j,o){var k=new RegExp("^"+Jsonix.Schema.XSD.Duration.PATTERN+"$");
21482153
var i=m.match(k);

0 commit comments

Comments
 (0)