Skip to content

Commit adec82d

Browse files
committed
Fixes #101.
1 parent da245a2 commit adec82d

File tree

10 files changed

+155
-28
lines changed

10 files changed

+155
-28
lines changed

dist/Jsonix-all.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,6 +2124,7 @@ Jsonix.Model.ClassInfo = Jsonix
21242124
typeName : null,
21252125
instanceFactory : null,
21262126
properties : null,
2127+
propertiesMap : null,
21272128
structure : null,
21282129
targetNamespace : '',
21292130
defaultElementNamespaceURI : '',
@@ -2178,12 +2179,16 @@ Jsonix.Model.ClassInfo = Jsonix
21782179
}
21792180

21802181
this.properties = [];
2182+
this.propertiesMap = {};
21812183
var ps = mapping.propertyInfos||mapping.ps||[];
21822184
Jsonix.Util.Ensure.ensureArray(ps);
21832185
for ( var index = 0; index < ps.length; index++) {
21842186
this.p(ps[index]);
21852187
}
21862188
},
2189+
getPropertyInfoByName : function(name) {
2190+
return this.propertiesMap[name];
2191+
},
21872192
// Obsolete
21882193
destroy : function() {
21892194
},
@@ -2488,6 +2493,7 @@ Jsonix.Model.ClassInfo = Jsonix
24882493
},
24892494
addProperty : function(property) {
24902495
this.properties.push(property);
2496+
this.propertiesMap[property.name] = property;
24912497
return this;
24922498
},
24932499
CLASS_NAME : 'Jsonix.Model.ClassInfo'
@@ -2732,6 +2738,32 @@ Jsonix.Model.PropertyInfo = Jsonix.Class({
27322738
this.defaultAttributeNamespaceURI = dans;
27332739
var col = mapping.collection || mapping.col || false;
27342740
this.collection = col;
2741+
var rq = mapping.required || mapping.rq || false;
2742+
this.required = rq;
2743+
if (this.collection) {
2744+
var mno;
2745+
if (Jsonix.Util.Type.isNumber(mapping.minOccurs)) {
2746+
mno = mapping.minOccurs;
2747+
}
2748+
else if (Jsonix.Util.Type.isNumber(mapping.mno)) {
2749+
mno = mapping.mno;
2750+
}
2751+
else {
2752+
mno = 1;
2753+
}
2754+
this.minOccurs = mno;
2755+
var mxo;
2756+
if (Jsonix.Util.Type.isNumber(mapping.maxOccurs)) {
2757+
mxo = mapping.maxOccurs;
2758+
}
2759+
else if (Jsonix.Util.Type.isNumber(mapping.mxo)) {
2760+
mxo = mapping.mxo;
2761+
}
2762+
else {
2763+
mxo = null;
2764+
}
2765+
this.maxOccurs = mxo;
2766+
}
27352767
},
27362768
build : function(context, module) {
27372769
if (!this.built) {

dist/Jsonix-min.js

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ while(d){if(c===d){return true
854854
}d=d.baseTypeInfo
855855
}return false
856856
},CLASS_NAME:"Jsonix.Model.TypeInfo"});
857-
Jsonix.Model.ClassInfo=Jsonix.Class(Jsonix.Model.TypeInfo,Jsonix.Mapping.Styled,{name:null,localName:null,typeName:null,instanceFactory:null,properties:null,structure:null,targetNamespace:"",defaultElementNamespaceURI:"",defaultAttributeNamespaceURI:"",built:false,initialize:function(w,m){Jsonix.Model.TypeInfo.prototype.initialize.apply(this,[]);
857+
Jsonix.Model.ClassInfo=Jsonix.Class(Jsonix.Model.TypeInfo,Jsonix.Mapping.Styled,{name:null,localName:null,typeName:null,instanceFactory:null,properties:null,propertiesMap:null,structure:null,targetNamespace:"",defaultElementNamespaceURI:"",defaultAttributeNamespaceURI:"",built:false,initialize:function(w,m){Jsonix.Model.TypeInfo.prototype.initialize.apply(this,[]);
858858
Jsonix.Mapping.Styled.prototype.initialize.apply(this,[m]);
859859
Jsonix.Util.Ensure.ensureObject(w);
860860
var v=w.name||w.n||undefined;
@@ -878,12 +878,14 @@ if(Jsonix.Util.Type.exists(o)){if(Jsonix.Util.Type.isString(o)){this.typeName=ne
878878
}else{this.typeName=Jsonix.XML.QName.fromObject(o)
879879
}}else{if(Jsonix.Util.Type.exists(q)){this.typeName=new Jsonix.XML.QName(n,q)
880880
}}this.properties=[];
881+
this.propertiesMap={};
881882
var x=w.propertyInfos||w.ps||[];
882883
Jsonix.Util.Ensure.ensureArray(x);
883884
for(var s=0;
884885
s<x.length;
885886
s++){this.p(x[s])
886-
}},destroy:function(){},build:function(i,j){if(!this.built){this.baseTypeInfo=i.resolveTypeInfo(this.baseTypeInfo,j);
887+
}},getPropertyInfoByName:function(b){return this.propertiesMap[b]
888+
},destroy:function(){},build:function(i,j){if(!this.built){this.baseTypeInfo=i.resolveTypeInfo(this.baseTypeInfo,j);
887889
if(Jsonix.Util.Type.exists(this.baseTypeInfo)){this.baseTypeInfo.build(i,j)
888890
}for(var f=0;
889891
f<this.properties.length;
@@ -977,6 +979,7 @@ return this.addProperty(new this.mappingStyle.valuePropertyInfo(b,{mappingStyle:
977979
},addDefaultNamespaces:function(b){if(Jsonix.Util.Type.isObject(b)){if(!Jsonix.Util.Type.isString(b.defaultElementNamespaceURI)){b.defaultElementNamespaceURI=this.defaultElementNamespaceURI
978980
}if(!Jsonix.Util.Type.isString(b.defaultAttributeNamespaceURI)){b.defaultAttributeNamespaceURI=this.defaultAttributeNamespaceURI
979981
}}},addProperty:function(b){this.properties.push(b);
982+
this.propertiesMap[b.name]=b;
980983
return this
981984
},CLASS_NAME:"Jsonix.Model.ClassInfo"});
982985
Jsonix.Model.ClassInfo.prototype.propertyInfoCreators={aa:Jsonix.Model.ClassInfo.prototype.aa,anyAttribute:Jsonix.Model.ClassInfo.prototype.aa,ae:Jsonix.Model.ClassInfo.prototype.ae,anyElement:Jsonix.Model.ClassInfo.prototype.ae,a:Jsonix.Model.ClassInfo.prototype.a,attribute:Jsonix.Model.ClassInfo.prototype.a,em:Jsonix.Model.ClassInfo.prototype.em,elementMap:Jsonix.Model.ClassInfo.prototype.em,e:Jsonix.Model.ClassInfo.prototype.e,element:Jsonix.Model.ClassInfo.prototype.e,es:Jsonix.Model.ClassInfo.prototype.es,elements:Jsonix.Model.ClassInfo.prototype.es,er:Jsonix.Model.ClassInfo.prototype.er,elementRef:Jsonix.Model.ClassInfo.prototype.er,ers:Jsonix.Model.ClassInfo.prototype.ers,elementRefs:Jsonix.Model.ClassInfo.prototype.ers,v:Jsonix.Model.ClassInfo.prototype.v,value:Jsonix.Model.ClassInfo.prototype.v};
@@ -1059,19 +1062,31 @@ this.scope=i
10591062
this.scope=c.resolveTypeInfo(this.scope,d);
10601063
this.built=true
10611064
}},CLASS_NAME:"Jsonix.Model.ElementInfo"});
1062-
Jsonix.Model.PropertyInfo=Jsonix.Class({name:null,collection:false,targetNamespace:"",defaultElementNamespaceURI:"",defaultAttributeNamespaceURI:"",built:false,initialize:function(l){Jsonix.Util.Ensure.ensureObject(l);
1063-
var i=l.name||l.n||undefined;
1064-
Jsonix.Util.Ensure.ensureString(i);
1065-
this.name=i;
1066-
var k=l.defaultElementNamespaceURI||l.dens||l.targetNamespace||l.tns||"";
1067-
this.defaultElementNamespaceURI=k;
1068-
var g=l.targetNamespace||l.tns||l.defaultElementNamespaceURI||l.dens||this.defaultElementNamespaceURI;
1069-
this.targetNamespace=g;
1070-
var j=l.defaultAttributeNamespaceURI||l.dans||"";
1071-
this.defaultAttributeNamespaceURI=j;
1072-
var h=l.collection||l.col||false;
1073-
this.collection=h
1074-
},build:function(c,d){if(!this.built){this.doBuild(c,d);
1065+
Jsonix.Model.PropertyInfo=Jsonix.Class({name:null,collection:false,targetNamespace:"",defaultElementNamespaceURI:"",defaultAttributeNamespaceURI:"",built:false,initialize:function(r){Jsonix.Util.Ensure.ensureObject(r);
1066+
var p=r.name||r.n||undefined;
1067+
Jsonix.Util.Ensure.ensureString(p);
1068+
this.name=p;
1069+
var m=r.defaultElementNamespaceURI||r.dens||r.targetNamespace||r.tns||"";
1070+
this.defaultElementNamespaceURI=m;
1071+
var j=r.targetNamespace||r.tns||r.defaultElementNamespaceURI||r.dens||this.defaultElementNamespaceURI;
1072+
this.targetNamespace=j;
1073+
var k=r.defaultAttributeNamespaceURI||r.dans||"";
1074+
this.defaultAttributeNamespaceURI=k;
1075+
var o=r.collection||r.col||false;
1076+
this.collection=o;
1077+
var n=r.required||r.rq||false;
1078+
this.required=n;
1079+
if(this.collection){var l;
1080+
if(Jsonix.Util.Type.isNumber(r.minOccurs)){l=r.minOccurs
1081+
}else{if(Jsonix.Util.Type.isNumber(r.mno)){l=r.mno
1082+
}else{l=1
1083+
}}this.minOccurs=l;
1084+
var q;
1085+
if(Jsonix.Util.Type.isNumber(r.maxOccurs)){q=r.maxOccurs
1086+
}else{if(Jsonix.Util.Type.isNumber(r.mxo)){q=r.mxo
1087+
}else{q=null
1088+
}}this.maxOccurs=q
1089+
}},build:function(c,d){if(!this.built){this.doBuild(c,d);
10751090
this.built=true
10761091
}},doBuild:function(c,d){throw new Error("Abstract method [doBuild].")
10771092
},buildStructure:function(c,d){throw new Error("Abstract method [buildStructure].")

nodejs/scripts/jsonix.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,6 +2124,7 @@ Jsonix.Model.ClassInfo = Jsonix
21242124
typeName : null,
21252125
instanceFactory : null,
21262126
properties : null,
2127+
propertiesMap : null,
21272128
structure : null,
21282129
targetNamespace : '',
21292130
defaultElementNamespaceURI : '',
@@ -2178,12 +2179,16 @@ Jsonix.Model.ClassInfo = Jsonix
21782179
}
21792180

21802181
this.properties = [];
2182+
this.propertiesMap = {};
21812183
var ps = mapping.propertyInfos||mapping.ps||[];
21822184
Jsonix.Util.Ensure.ensureArray(ps);
21832185
for ( var index = 0; index < ps.length; index++) {
21842186
this.p(ps[index]);
21852187
}
21862188
},
2189+
getPropertyInfoByName : function(name) {
2190+
return this.propertiesMap[name];
2191+
},
21872192
// Obsolete
21882193
destroy : function() {
21892194
},
@@ -2488,6 +2493,7 @@ Jsonix.Model.ClassInfo = Jsonix
24882493
},
24892494
addProperty : function(property) {
24902495
this.properties.push(property);
2496+
this.propertiesMap[property.name] = property;
24912497
return this;
24922498
},
24932499
CLASS_NAME : 'Jsonix.Model.ClassInfo'
@@ -2732,6 +2738,32 @@ Jsonix.Model.PropertyInfo = Jsonix.Class({
27322738
this.defaultAttributeNamespaceURI = dans;
27332739
var col = mapping.collection || mapping.col || false;
27342740
this.collection = col;
2741+
var rq = mapping.required || mapping.rq || false;
2742+
this.required = rq;
2743+
if (this.collection) {
2744+
var mno;
2745+
if (Jsonix.Util.Type.isNumber(mapping.minOccurs)) {
2746+
mno = mapping.minOccurs;
2747+
}
2748+
else if (Jsonix.Util.Type.isNumber(mapping.mno)) {
2749+
mno = mapping.mno;
2750+
}
2751+
else {
2752+
mno = 1;
2753+
}
2754+
this.minOccurs = mno;
2755+
var mxo;
2756+
if (Jsonix.Util.Type.isNumber(mapping.maxOccurs)) {
2757+
mxo = mapping.maxOccurs;
2758+
}
2759+
else if (Jsonix.Util.Type.isNumber(mapping.mxo)) {
2760+
mxo = mapping.mxo;
2761+
}
2762+
else {
2763+
mxo = null;
2764+
}
2765+
this.maxOccurs = mxo;
2766+
}
27352767
},
27362768
build : function(context, module) {
27372769
if (!this.built) {

nodejs/tests/ar/AR.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,30 @@ var AR_Module_Factory = function () {
33
name: 'AR',
44
defaultElementNamespaceURI: 'urn:test',
55
typeInfos: [{
6-
localName: 'AccumulateResponse',
7-
propertyInfos: [{
8-
name: 'testCase',
9-
collection: true,
10-
elementName: 'TestCase',
11-
typeInfo: '.AccumulateResponse.TestCase'
12-
}]
13-
}, {
146
localName: 'AccumulateResponse.TestCase',
157
typeName: null,
168
propertyInfos: [{
179
name: 'transactionId',
10+
required: true,
1811
elementName: 'TransactionId'
1912
}, {
2013
name: 'transactionType',
14+
required: true,
2115
elementName: 'TransactionType'
2216
}, {
2317
name: 'status',
18+
required: true,
2419
elementName: 'Status'
2520
}]
21+
}, {
22+
localName: 'AccumulateResponse',
23+
propertyInfos: [{
24+
name: 'testCase',
25+
minOccurs: 0,
26+
collection: true,
27+
elementName: 'TestCase',
28+
typeInfo: '.AccumulateResponse.TestCase'
29+
}]
2630
}],
2731
elementInfos: [{
2832
elementName: 'AccumulateResponse',

nodejs/tests/po/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
],
77
"main": "jsonix-tests-po.js",
88
"dependencies": {
9-
"jsonix": ">=2.3.0",
10-
"jsonix-schema-compiler": ">=2.3.6",
9+
"jsonix": ">=2.3.1",
10+
"jsonix-schema-compiler": ">=2.3.7",
1111
"ajv": ">=1.2.1"
1212
},
1313
"devDependencies" : {
1414
"nodeunit" : "~0.x.x"
1515
},
1616
"scripts": {
17-
"prepublish" : "java -jar node_modules/jsonix-schema-compiler/lib/jsonix-schema-compiler-full.jar -generateJsonSchema -compact -logLevel TRACE -d mappings purchaseorder.xsd -b bindings.xjb",
17+
"prepublish" : "java -jar node_modules/jsonix-schema-compiler/lib/jsonix-schema-compiler-full.jar -generateJsonSchema -logLevel TRACE -d mappings purchaseorder.xsd -b bindings.xjb",
1818
"test": "nodeunit tests/tests.js"
1919
}
2020
}

nodejs/tests/po/purchaseorder.xsd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
<xsd:complexType name="Items">
3737
<xsd:sequence>
38-
<xsd:element name="item" minOccurs="0" maxOccurs="unbounded">
38+
<xsd:element name="item" minOccurs="0" maxOccurs="100">
3939
<xsd:complexType>
4040
<xsd:sequence>
4141
<xsd:element name="productName" type="xsd:string"/>

nodejs/tests/po/tests/po-tests.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ var Jsonix = require('jsonix').Jsonix;
44
var PO = require('../mappings/PO').PO;
55

66
module.exports = {
7+
"MinMaxOccurs": function(test) {
8+
9+
// Create Jsonix context
10+
var context = new Jsonix.Context([ PO ]);
11+
12+
var itemsClassInfo = context.getTypeInfoByName("PO.Items");
13+
var itemPropertyInfo = itemsClassInfo.getPropertyInfoByName("item");
14+
test.equal(false, itemPropertyInfo.required);
15+
test.equal(0, itemPropertyInfo.minOccurs);
16+
test.equal(100, itemPropertyInfo.maxOccurs);
17+
test.done();
18+
},
719
"UnmarshalFile": function(test) {
820

921
// Create Jsonix context

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
</profiles>
5959
<properties>
6060
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
61-
<jsonix-schema-compiler.version>2.3.6</jsonix-schema-compiler.version>
61+
<jsonix-schema-compiler.version>2.3.7</jsonix-schema-compiler.version>
6262
<jaxb.version>2.2.11</jaxb.version>
6363
</properties>
6464
<dependencies>

scripts/src/main/javascript/org/hisrc/jsonix/Jsonix/Model/ClassInfo.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Jsonix.Model.ClassInfo = Jsonix
55
typeName : null,
66
instanceFactory : null,
77
properties : null,
8+
propertiesMap : null,
89
structure : null,
910
targetNamespace : '',
1011
defaultElementNamespaceURI : '',
@@ -59,12 +60,16 @@ Jsonix.Model.ClassInfo = Jsonix
5960
}
6061

6162
this.properties = [];
63+
this.propertiesMap = {};
6264
var ps = mapping.propertyInfos||mapping.ps||[];
6365
Jsonix.Util.Ensure.ensureArray(ps);
6466
for ( var index = 0; index < ps.length; index++) {
6567
this.p(ps[index]);
6668
}
6769
},
70+
getPropertyInfoByName : function(name) {
71+
return this.propertiesMap[name];
72+
},
6873
// Obsolete
6974
destroy : function() {
7075
},
@@ -369,6 +374,7 @@ Jsonix.Model.ClassInfo = Jsonix
369374
},
370375
addProperty : function(property) {
371376
this.properties.push(property);
377+
this.propertiesMap[property.name] = property;
372378
return this;
373379
},
374380
CLASS_NAME : 'Jsonix.Model.ClassInfo'

scripts/src/main/javascript/org/hisrc/jsonix/Jsonix/Model/PropertyInfo.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,32 @@ Jsonix.Model.PropertyInfo = Jsonix.Class({
1818
this.defaultAttributeNamespaceURI = dans;
1919
var col = mapping.collection || mapping.col || false;
2020
this.collection = col;
21+
var rq = mapping.required || mapping.rq || false;
22+
this.required = rq;
23+
if (this.collection) {
24+
var mno;
25+
if (Jsonix.Util.Type.isNumber(mapping.minOccurs)) {
26+
mno = mapping.minOccurs;
27+
}
28+
else if (Jsonix.Util.Type.isNumber(mapping.mno)) {
29+
mno = mapping.mno;
30+
}
31+
else {
32+
mno = 1;
33+
}
34+
this.minOccurs = mno;
35+
var mxo;
36+
if (Jsonix.Util.Type.isNumber(mapping.maxOccurs)) {
37+
mxo = mapping.maxOccurs;
38+
}
39+
else if (Jsonix.Util.Type.isNumber(mapping.mxo)) {
40+
mxo = mapping.mxo;
41+
}
42+
else {
43+
mxo = null;
44+
}
45+
this.maxOccurs = mxo;
46+
}
2147
},
2248
build : function(context, module) {
2349
if (!this.built) {

0 commit comments

Comments
 (0)