Skip to content

Commit

Permalink
Fixes #101.
Browse files Browse the repository at this point in the history
  • Loading branch information
highsource committed Sep 12, 2015
1 parent da245a2 commit adec82d
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 28 deletions.
32 changes: 32 additions & 0 deletions dist/Jsonix-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -2124,6 +2124,7 @@ Jsonix.Model.ClassInfo = Jsonix
typeName : null,
instanceFactory : null,
properties : null,
propertiesMap : null,
structure : null,
targetNamespace : '',
defaultElementNamespaceURI : '',
Expand Down Expand Up @@ -2178,12 +2179,16 @@ Jsonix.Model.ClassInfo = Jsonix
}

this.properties = [];
this.propertiesMap = {};
var ps = mapping.propertyInfos||mapping.ps||[];
Jsonix.Util.Ensure.ensureArray(ps);
for ( var index = 0; index < ps.length; index++) {
this.p(ps[index]);
}
},
getPropertyInfoByName : function(name) {
return this.propertiesMap[name];
},
// Obsolete
destroy : function() {
},
Expand Down Expand Up @@ -2488,6 +2493,7 @@ Jsonix.Model.ClassInfo = Jsonix
},
addProperty : function(property) {
this.properties.push(property);
this.propertiesMap[property.name] = property;
return this;
},
CLASS_NAME : 'Jsonix.Model.ClassInfo'
Expand Down Expand Up @@ -2732,6 +2738,32 @@ Jsonix.Model.PropertyInfo = Jsonix.Class({
this.defaultAttributeNamespaceURI = dans;
var col = mapping.collection || mapping.col || false;
this.collection = col;
var rq = mapping.required || mapping.rq || false;
this.required = rq;
if (this.collection) {
var mno;
if (Jsonix.Util.Type.isNumber(mapping.minOccurs)) {
mno = mapping.minOccurs;
}
else if (Jsonix.Util.Type.isNumber(mapping.mno)) {
mno = mapping.mno;
}
else {
mno = 1;
}
this.minOccurs = mno;
var mxo;
if (Jsonix.Util.Type.isNumber(mapping.maxOccurs)) {
mxo = mapping.maxOccurs;
}
else if (Jsonix.Util.Type.isNumber(mapping.mxo)) {
mxo = mapping.mxo;
}
else {
mxo = null;
}
this.maxOccurs = mxo;
}
},
build : function(context, module) {
if (!this.built) {
Expand Down
45 changes: 30 additions & 15 deletions dist/Jsonix-min.js
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ while(d){if(c===d){return true
}d=d.baseTypeInfo
}return false
},CLASS_NAME:"Jsonix.Model.TypeInfo"});
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,[]);
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,[]);
Jsonix.Mapping.Styled.prototype.initialize.apply(this,[m]);
Jsonix.Util.Ensure.ensureObject(w);
var v=w.name||w.n||undefined;
Expand All @@ -878,12 +878,14 @@ if(Jsonix.Util.Type.exists(o)){if(Jsonix.Util.Type.isString(o)){this.typeName=ne
}else{this.typeName=Jsonix.XML.QName.fromObject(o)
}}else{if(Jsonix.Util.Type.exists(q)){this.typeName=new Jsonix.XML.QName(n,q)
}}this.properties=[];
this.propertiesMap={};
var x=w.propertyInfos||w.ps||[];
Jsonix.Util.Ensure.ensureArray(x);
for(var s=0;
s<x.length;
s++){this.p(x[s])
}},destroy:function(){},build:function(i,j){if(!this.built){this.baseTypeInfo=i.resolveTypeInfo(this.baseTypeInfo,j);
}},getPropertyInfoByName:function(b){return this.propertiesMap[b]
},destroy:function(){},build:function(i,j){if(!this.built){this.baseTypeInfo=i.resolveTypeInfo(this.baseTypeInfo,j);
if(Jsonix.Util.Type.exists(this.baseTypeInfo)){this.baseTypeInfo.build(i,j)
}for(var f=0;
f<this.properties.length;
Expand Down Expand Up @@ -977,6 +979,7 @@ return this.addProperty(new this.mappingStyle.valuePropertyInfo(b,{mappingStyle:
},addDefaultNamespaces:function(b){if(Jsonix.Util.Type.isObject(b)){if(!Jsonix.Util.Type.isString(b.defaultElementNamespaceURI)){b.defaultElementNamespaceURI=this.defaultElementNamespaceURI
}if(!Jsonix.Util.Type.isString(b.defaultAttributeNamespaceURI)){b.defaultAttributeNamespaceURI=this.defaultAttributeNamespaceURI
}}},addProperty:function(b){this.properties.push(b);
this.propertiesMap[b.name]=b;
return this
},CLASS_NAME:"Jsonix.Model.ClassInfo"});
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};
Expand Down Expand Up @@ -1059,19 +1062,31 @@ this.scope=i
this.scope=c.resolveTypeInfo(this.scope,d);
this.built=true
}},CLASS_NAME:"Jsonix.Model.ElementInfo"});
Jsonix.Model.PropertyInfo=Jsonix.Class({name:null,collection:false,targetNamespace:"",defaultElementNamespaceURI:"",defaultAttributeNamespaceURI:"",built:false,initialize:function(l){Jsonix.Util.Ensure.ensureObject(l);
var i=l.name||l.n||undefined;
Jsonix.Util.Ensure.ensureString(i);
this.name=i;
var k=l.defaultElementNamespaceURI||l.dens||l.targetNamespace||l.tns||"";
this.defaultElementNamespaceURI=k;
var g=l.targetNamespace||l.tns||l.defaultElementNamespaceURI||l.dens||this.defaultElementNamespaceURI;
this.targetNamespace=g;
var j=l.defaultAttributeNamespaceURI||l.dans||"";
this.defaultAttributeNamespaceURI=j;
var h=l.collection||l.col||false;
this.collection=h
},build:function(c,d){if(!this.built){this.doBuild(c,d);
Jsonix.Model.PropertyInfo=Jsonix.Class({name:null,collection:false,targetNamespace:"",defaultElementNamespaceURI:"",defaultAttributeNamespaceURI:"",built:false,initialize:function(r){Jsonix.Util.Ensure.ensureObject(r);
var p=r.name||r.n||undefined;
Jsonix.Util.Ensure.ensureString(p);
this.name=p;
var m=r.defaultElementNamespaceURI||r.dens||r.targetNamespace||r.tns||"";
this.defaultElementNamespaceURI=m;
var j=r.targetNamespace||r.tns||r.defaultElementNamespaceURI||r.dens||this.defaultElementNamespaceURI;
this.targetNamespace=j;
var k=r.defaultAttributeNamespaceURI||r.dans||"";
this.defaultAttributeNamespaceURI=k;
var o=r.collection||r.col||false;
this.collection=o;
var n=r.required||r.rq||false;
this.required=n;
if(this.collection){var l;
if(Jsonix.Util.Type.isNumber(r.minOccurs)){l=r.minOccurs
}else{if(Jsonix.Util.Type.isNumber(r.mno)){l=r.mno
}else{l=1
}}this.minOccurs=l;
var q;
if(Jsonix.Util.Type.isNumber(r.maxOccurs)){q=r.maxOccurs
}else{if(Jsonix.Util.Type.isNumber(r.mxo)){q=r.mxo
}else{q=null
}}this.maxOccurs=q
}},build:function(c,d){if(!this.built){this.doBuild(c,d);
this.built=true
}},doBuild:function(c,d){throw new Error("Abstract method [doBuild].")
},buildStructure:function(c,d){throw new Error("Abstract method [buildStructure].")
Expand Down
32 changes: 32 additions & 0 deletions nodejs/scripts/jsonix.js
Original file line number Diff line number Diff line change
Expand Up @@ -2124,6 +2124,7 @@ Jsonix.Model.ClassInfo = Jsonix
typeName : null,
instanceFactory : null,
properties : null,
propertiesMap : null,
structure : null,
targetNamespace : '',
defaultElementNamespaceURI : '',
Expand Down Expand Up @@ -2178,12 +2179,16 @@ Jsonix.Model.ClassInfo = Jsonix
}

this.properties = [];
this.propertiesMap = {};
var ps = mapping.propertyInfos||mapping.ps||[];
Jsonix.Util.Ensure.ensureArray(ps);
for ( var index = 0; index < ps.length; index++) {
this.p(ps[index]);
}
},
getPropertyInfoByName : function(name) {
return this.propertiesMap[name];
},
// Obsolete
destroy : function() {
},
Expand Down Expand Up @@ -2488,6 +2493,7 @@ Jsonix.Model.ClassInfo = Jsonix
},
addProperty : function(property) {
this.properties.push(property);
this.propertiesMap[property.name] = property;
return this;
},
CLASS_NAME : 'Jsonix.Model.ClassInfo'
Expand Down Expand Up @@ -2732,6 +2738,32 @@ Jsonix.Model.PropertyInfo = Jsonix.Class({
this.defaultAttributeNamespaceURI = dans;
var col = mapping.collection || mapping.col || false;
this.collection = col;
var rq = mapping.required || mapping.rq || false;
this.required = rq;
if (this.collection) {
var mno;
if (Jsonix.Util.Type.isNumber(mapping.minOccurs)) {
mno = mapping.minOccurs;
}
else if (Jsonix.Util.Type.isNumber(mapping.mno)) {
mno = mapping.mno;
}
else {
mno = 1;
}
this.minOccurs = mno;
var mxo;
if (Jsonix.Util.Type.isNumber(mapping.maxOccurs)) {
mxo = mapping.maxOccurs;
}
else if (Jsonix.Util.Type.isNumber(mapping.mxo)) {
mxo = mapping.mxo;
}
else {
mxo = null;
}
this.maxOccurs = mxo;
}
},
build : function(context, module) {
if (!this.built) {
Expand Down
20 changes: 12 additions & 8 deletions nodejs/tests/ar/AR.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,30 @@ var AR_Module_Factory = function () {
name: 'AR',
defaultElementNamespaceURI: 'urn:test',
typeInfos: [{
localName: 'AccumulateResponse',
propertyInfos: [{
name: 'testCase',
collection: true,
elementName: 'TestCase',
typeInfo: '.AccumulateResponse.TestCase'
}]
}, {
localName: 'AccumulateResponse.TestCase',
typeName: null,
propertyInfos: [{
name: 'transactionId',
required: true,
elementName: 'TransactionId'
}, {
name: 'transactionType',
required: true,
elementName: 'TransactionType'
}, {
name: 'status',
required: true,
elementName: 'Status'
}]
}, {
localName: 'AccumulateResponse',
propertyInfos: [{
name: 'testCase',
minOccurs: 0,
collection: true,
elementName: 'TestCase',
typeInfo: '.AccumulateResponse.TestCase'
}]
}],
elementInfos: [{
elementName: 'AccumulateResponse',
Expand Down
6 changes: 3 additions & 3 deletions nodejs/tests/po/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
],
"main": "jsonix-tests-po.js",
"dependencies": {
"jsonix": ">=2.3.0",
"jsonix-schema-compiler": ">=2.3.6",
"jsonix": ">=2.3.1",
"jsonix-schema-compiler": ">=2.3.7",
"ajv": ">=1.2.1"
},
"devDependencies" : {
"nodeunit" : "~0.x.x"
},
"scripts": {
"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",
"prepublish" : "java -jar node_modules/jsonix-schema-compiler/lib/jsonix-schema-compiler-full.jar -generateJsonSchema -logLevel TRACE -d mappings purchaseorder.xsd -b bindings.xjb",
"test": "nodeunit tests/tests.js"
}
}
2 changes: 1 addition & 1 deletion nodejs/tests/po/purchaseorder.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<xsd:complexType name="Items">
<xsd:sequence>
<xsd:element name="item" minOccurs="0" maxOccurs="unbounded">
<xsd:element name="item" minOccurs="0" maxOccurs="100">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="productName" type="xsd:string"/>
Expand Down
12 changes: 12 additions & 0 deletions nodejs/tests/po/tests/po-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ var Jsonix = require('jsonix').Jsonix;
var PO = require('../mappings/PO').PO;

module.exports = {
"MinMaxOccurs": function(test) {

// Create Jsonix context
var context = new Jsonix.Context([ PO ]);

var itemsClassInfo = context.getTypeInfoByName("PO.Items");
var itemPropertyInfo = itemsClassInfo.getPropertyInfoByName("item");
test.equal(false, itemPropertyInfo.required);
test.equal(0, itemPropertyInfo.minOccurs);
test.equal(100, itemPropertyInfo.maxOccurs);
test.done();
},
"UnmarshalFile": function(test) {

// Create Jsonix context
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</profiles>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jsonix-schema-compiler.version>2.3.6</jsonix-schema-compiler.version>
<jsonix-schema-compiler.version>2.3.7</jsonix-schema-compiler.version>
<jaxb.version>2.2.11</jaxb.version>
</properties>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Jsonix.Model.ClassInfo = Jsonix
typeName : null,
instanceFactory : null,
properties : null,
propertiesMap : null,
structure : null,
targetNamespace : '',
defaultElementNamespaceURI : '',
Expand Down Expand Up @@ -59,12 +60,16 @@ Jsonix.Model.ClassInfo = Jsonix
}

this.properties = [];
this.propertiesMap = {};
var ps = mapping.propertyInfos||mapping.ps||[];
Jsonix.Util.Ensure.ensureArray(ps);
for ( var index = 0; index < ps.length; index++) {
this.p(ps[index]);
}
},
getPropertyInfoByName : function(name) {
return this.propertiesMap[name];
},
// Obsolete
destroy : function() {
},
Expand Down Expand Up @@ -369,6 +374,7 @@ Jsonix.Model.ClassInfo = Jsonix
},
addProperty : function(property) {
this.properties.push(property);
this.propertiesMap[property.name] = property;
return this;
},
CLASS_NAME : 'Jsonix.Model.ClassInfo'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,32 @@ Jsonix.Model.PropertyInfo = Jsonix.Class({
this.defaultAttributeNamespaceURI = dans;
var col = mapping.collection || mapping.col || false;
this.collection = col;
var rq = mapping.required || mapping.rq || false;
this.required = rq;
if (this.collection) {
var mno;
if (Jsonix.Util.Type.isNumber(mapping.minOccurs)) {
mno = mapping.minOccurs;
}
else if (Jsonix.Util.Type.isNumber(mapping.mno)) {
mno = mapping.mno;
}
else {
mno = 1;
}
this.minOccurs = mno;
var mxo;
if (Jsonix.Util.Type.isNumber(mapping.maxOccurs)) {
mxo = mapping.maxOccurs;
}
else if (Jsonix.Util.Type.isNumber(mapping.mxo)) {
mxo = mapping.mxo;
}
else {
mxo = null;
}
this.maxOccurs = mxo;
}
},
build : function(context, module) {
if (!this.built) {
Expand Down

0 comments on commit adec82d

Please sign in to comment.