Skip to content

Commit b37f7f8

Browse files
committed
Issue #61.
1 parent f8085ab commit b37f7f8

File tree

8 files changed

+142
-28
lines changed

8 files changed

+142
-28
lines changed

dist/Jsonix-all.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1914,6 +1914,8 @@ Jsonix.Model.TypeInfo = Jsonix.Class({
19141914
Jsonix.Model.ClassInfo = Jsonix
19151915
.Class(Jsonix.Model.TypeInfo, Jsonix.Mapping.Styled, {
19161916
name : null,
1917+
localName : null,
1918+
typeName : null,
19171919
baseTypeInfo : null,
19181920
instanceFactory : null,
19191921
properties : null,
@@ -1929,6 +1931,9 @@ Jsonix.Model.ClassInfo = Jsonix
19291931
Jsonix.Util.Ensure.ensureString(n);
19301932
this.name = n;
19311933

1934+
var ln = mapping.localName||mapping.ln||null;
1935+
this.localName = ln;
1936+
19321937
var dens = mapping.defaultElementNamespaceURI||mapping.dens||'';
19331938
this.defaultElementNamespaceURI = dens;
19341939

@@ -1946,12 +1951,23 @@ Jsonix.Model.ClassInfo = Jsonix
19461951
this.instanceFactory = inF;
19471952
}
19481953

1954+
var tn = mapping.typeName||mapping.tn||undefined;
1955+
1956+
if (Jsonix.Util.Type.exists(tn))
1957+
{
1958+
this.typeName = Jsonix.XML.QName.fromObject(tn);
1959+
}
1960+
else if (Jsonix.Util.Type.exists(ln))
1961+
{
1962+
this.typeName = new Jsonix.XML.QName(dens, ln);
1963+
}
1964+
19491965
this.properties = [];
19501966
var ps = mapping.propertyInfos||mapping.ps||[];
19511967
Jsonix.Util.Ensure.ensureArray(ps);
19521968
for ( var index = 0; index < ps.length; index++) {
19531969
this.p(ps[index]);
1954-
}
1970+
}
19551971
},
19561972
// Obsolete
19571973
destroy : function() {
@@ -5400,6 +5416,7 @@ Jsonix.Context = Jsonix
54005416
.Class(Jsonix.Mapping.Styled, {
54015417
modules : [],
54025418
typeInfos : null,
5419+
typeNameKeyToTypeInfo : null,
54035420
elementInfos : null,
54045421
options : null,
54055422
substitutionMembersMap : null,
@@ -5409,6 +5426,7 @@ Jsonix.Context = Jsonix
54095426
this.modules = [];
54105427
this.elementInfos = [];
54115428
this.typeInfos = {};
5429+
this.typeNameKeyToTypeInfo = {};
54125430
this.registerBuiltinTypeInfos();
54135431
this.namespacePrefixes = {};
54145432
this.prefixNamespaces = {};
@@ -5489,6 +5507,10 @@ Jsonix.Context = Jsonix
54895507
var n = typeInfo.name||typeInfo.n||null;
54905508
Jsonix.Util.Ensure.ensureString(n);
54915509
this.typeInfos[n] = typeInfo;
5510+
if (typeInfo.typeName && typeInfo.typeName.key)
5511+
{
5512+
this.typeNameKeyToTypeInfo[typeInfo.typeName.key] = typeInfo;
5513+
}
54925514
},
54935515
resolveTypeInfo : function(mapping, module) {
54945516
if (!Jsonix.Util.Type.exists(mapping)) {
@@ -5553,6 +5575,9 @@ Jsonix.Context = Jsonix
55535575
scopedElementInfos[elementInfo.elementName.key] = elementInfo;
55545576

55555577
},
5578+
getTypeInfoByTypeNameKey : function(typeNameKey) {
5579+
return this.typeNameKeyToTypeInfo[typeNameKey];
5580+
},
55565581
getElementInfo : function(name, scope) {
55575582
if (Jsonix.Util.Type.exists(scope)) {
55585583
var scopeKey = scope.name;

dist/Jsonix-min.js

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -753,27 +753,32 @@ if(Jsonix.Util.Type.exists(h)){return h.typeInfo
753753
}},CLASS_NAME:"Jsonix.Binding.Unmarshaller"});
754754
Jsonix.Binding.Unmarshaller.Simplified=Jsonix.Class(Jsonix.Binding.Unmarshaller,Jsonix.Binding.ElementUnmarshaller.Simplified,{CLASS_NAME:"Jsonix.Binding.Unmarshaller.Simplified"});
755755
Jsonix.Model.TypeInfo=Jsonix.Class({name:null,initialize:function(){},CLASS_NAME:"Jsonix.Model.TypeInfo"});
756-
Jsonix.Model.ClassInfo=Jsonix.Class(Jsonix.Model.TypeInfo,Jsonix.Mapping.Styled,{name:null,baseTypeInfo:null,instanceFactory:null,properties:null,structure:null,defaultElementNamespaceURI:"",defaultAttributeNamespaceURI:"",built:false,initialize:function(q,j){Jsonix.Model.TypeInfo.prototype.initialize.apply(this,[]);
757-
Jsonix.Mapping.Styled.prototype.initialize.apply(this,[j]);
758-
Jsonix.Util.Ensure.ensureObject(q);
759-
var p=q.name||q.n||undefined;
760-
Jsonix.Util.Ensure.ensureString(p);
761-
this.name=p;
762-
var l=q.defaultElementNamespaceURI||q.dens||"";
763-
this.defaultElementNamespaceURI=l;
764-
var k=q.defaultAttributeNamespaceURI||q.dans||"";
765-
this.defaultAttributeNamespaceURI=k;
766-
var o=q.baseTypeInfo||q.bti||null;
767-
this.baseTypeInfo=o;
768-
var n=q.instanceFactory||q.inF||undefined;
769-
if(Jsonix.Util.Type.exists(n)){Jsonix.Util.Ensure.ensureFunction(n);
770-
this.instanceFactory=n
771-
}this.properties=[];
772-
var r=q.propertyInfos||q.ps||[];
773-
Jsonix.Util.Ensure.ensureArray(r);
774-
for(var m=0;
775-
m<r.length;
776-
m++){this.p(r[m])
756+
Jsonix.Model.ClassInfo=Jsonix.Class(Jsonix.Model.TypeInfo,Jsonix.Mapping.Styled,{name:null,localName:null,typeName:null,baseTypeInfo:null,instanceFactory:null,properties:null,structure:null,defaultElementNamespaceURI:"",defaultAttributeNamespaceURI:"",built:false,initialize:function(u,l){Jsonix.Model.TypeInfo.prototype.initialize.apply(this,[]);
757+
Jsonix.Mapping.Styled.prototype.initialize.apply(this,[l]);
758+
Jsonix.Util.Ensure.ensureObject(u);
759+
var t=u.name||u.n||undefined;
760+
Jsonix.Util.Ensure.ensureString(t);
761+
this.name=t;
762+
var o=u.localName||u.ln||null;
763+
this.localName=o;
764+
var p=u.defaultElementNamespaceURI||u.dens||"";
765+
this.defaultElementNamespaceURI=p;
766+
var n=u.defaultAttributeNamespaceURI||u.dans||"";
767+
this.defaultAttributeNamespaceURI=n;
768+
var s=u.baseTypeInfo||u.bti||null;
769+
this.baseTypeInfo=s;
770+
var r=u.instanceFactory||u.inF||undefined;
771+
if(Jsonix.Util.Type.exists(r)){Jsonix.Util.Ensure.ensureFunction(r);
772+
this.instanceFactory=r
773+
}var m=u.typeName||u.tn||undefined;
774+
if(Jsonix.Util.Type.exists(m)){this.typeName=Jsonix.XML.QName.fromObject(m)
775+
}else{if(Jsonix.Util.Type.exists(o)){this.typeName=new Jsonix.XML.QName(p,o)
776+
}}this.properties=[];
777+
var v=u.propertyInfos||u.ps||[];
778+
Jsonix.Util.Ensure.ensureArray(v);
779+
for(var q=0;
780+
q<v.length;
781+
q++){this.p(v[q])
777782
}},destroy:function(){},build:function(i,j){if(!this.built){this.baseTypeInfo=i.resolveTypeInfo(this.baseTypeInfo,j);
778783
if(Jsonix.Util.Type.exists(this.baseTypeInfo)){this.baseTypeInfo.build(i,j)
779784
}for(var f=0;
@@ -2123,10 +2128,11 @@ Jsonix.Schema.XSD.IDREF.INSTANCE.LIST=new Jsonix.Schema.XSD.List(Jsonix.Schema.X
21232128
Jsonix.Schema.XSD.IDREFS=Jsonix.Class(Jsonix.Schema.XSD.List,{name:"IDREFS",initialize:function(){Jsonix.Schema.XSD.List.prototype.initialize.apply(this,[Jsonix.Schema.XSD.IDREF.INSTANCE,Jsonix.Schema.XSD.qname("IDREFS")," "])
21242129
},CLASS_NAME:"Jsonix.Schema.XSD.IDREFS"});
21252130
Jsonix.Schema.XSD.IDREFS.INSTANCE=new Jsonix.Schema.XSD.IDREFS();
2126-
Jsonix.Context=Jsonix.Class(Jsonix.Mapping.Styled,{modules:[],typeInfos:null,elementInfos:null,options:null,substitutionMembersMap:null,scopedElementInfosMap:null,initialize:function(i,l){Jsonix.Mapping.Styled.prototype.initialize.apply(this,[l]);
2131+
Jsonix.Context=Jsonix.Class(Jsonix.Mapping.Styled,{modules:[],typeInfos:null,typeNameKeyToTypeInfo:null,elementInfos:null,options:null,substitutionMembersMap:null,scopedElementInfosMap:null,initialize:function(i,l){Jsonix.Mapping.Styled.prototype.initialize.apply(this,[l]);
21272132
this.modules=[];
21282133
this.elementInfos=[];
21292134
this.typeInfos={};
2135+
this.typeNameKeyToTypeInfo={};
21302136
this.registerBuiltinTypeInfos();
21312137
this.namespacePrefixes={};
21322138
this.prefixNamespaces={};
@@ -2171,8 +2177,9 @@ c.buildElementInfos(this)
21712177
}},registerTypeInfo:function(d){Jsonix.Util.Ensure.ensureObject(d);
21722178
var c=d.name||d.n||null;
21732179
Jsonix.Util.Ensure.ensureString(c);
2174-
this.typeInfos[c]=d
2175-
},resolveTypeInfo:function(f,j){if(!Jsonix.Util.Type.exists(f)){return null
2180+
this.typeInfos[c]=d;
2181+
if(d.typeName&&d.typeName.key){this.typeNameKeyToTypeInfo[d.typeName.key]=d
2182+
}},resolveTypeInfo:function(f,j){if(!Jsonix.Util.Type.exists(f)){return null
21762183
}else{if(f instanceof Jsonix.Model.TypeInfo){return f
21772184
}else{if(Jsonix.Util.Type.isString(f)){var g;
21782185
if(f.length>0&&f.charAt(0)==="."){var h=j.name||j.n||undefined;
@@ -2201,6 +2208,7 @@ if(Jsonix.Util.Type.exists(k.scope)){i=this.resolveTypeInfo(k.scope,m).name
22012208
if(!Jsonix.Util.Type.isObject(j)){j={};
22022209
this.scopedElementInfosMap[i]=j
22032210
}j[k.elementName.key]=k
2211+
},getTypeInfoByTypeNameKey:function(b){return this.typeNameKeyToTypeInfo[b]
22042212
},getElementInfo:function(o,m){if(Jsonix.Util.Type.exists(m)){var j=m.name;
22052213
var k=this.scopedElementInfosMap[j];
22062214
if(Jsonix.Util.Type.exists(k)){var n=k[o.key];

nodejs/scripts/jsonix.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1914,6 +1914,8 @@ Jsonix.Model.TypeInfo = Jsonix.Class({
19141914
Jsonix.Model.ClassInfo = Jsonix
19151915
.Class(Jsonix.Model.TypeInfo, Jsonix.Mapping.Styled, {
19161916
name : null,
1917+
localName : null,
1918+
typeName : null,
19171919
baseTypeInfo : null,
19181920
instanceFactory : null,
19191921
properties : null,
@@ -1929,6 +1931,9 @@ Jsonix.Model.ClassInfo = Jsonix
19291931
Jsonix.Util.Ensure.ensureString(n);
19301932
this.name = n;
19311933

1934+
var ln = mapping.localName||mapping.ln||null;
1935+
this.localName = ln;
1936+
19321937
var dens = mapping.defaultElementNamespaceURI||mapping.dens||'';
19331938
this.defaultElementNamespaceURI = dens;
19341939

@@ -1946,12 +1951,23 @@ Jsonix.Model.ClassInfo = Jsonix
19461951
this.instanceFactory = inF;
19471952
}
19481953

1954+
var tn = mapping.typeName||mapping.tn||undefined;
1955+
1956+
if (Jsonix.Util.Type.exists(tn))
1957+
{
1958+
this.typeName = Jsonix.XML.QName.fromObject(tn);
1959+
}
1960+
else if (Jsonix.Util.Type.exists(ln))
1961+
{
1962+
this.typeName = new Jsonix.XML.QName(dens, ln);
1963+
}
1964+
19491965
this.properties = [];
19501966
var ps = mapping.propertyInfos||mapping.ps||[];
19511967
Jsonix.Util.Ensure.ensureArray(ps);
19521968
for ( var index = 0; index < ps.length; index++) {
19531969
this.p(ps[index]);
1954-
}
1970+
}
19551971
},
19561972
// Obsolete
19571973
destroy : function() {
@@ -5400,6 +5416,7 @@ Jsonix.Context = Jsonix
54005416
.Class(Jsonix.Mapping.Styled, {
54015417
modules : [],
54025418
typeInfos : null,
5419+
typeNameKeyToTypeInfo : null,
54035420
elementInfos : null,
54045421
options : null,
54055422
substitutionMembersMap : null,
@@ -5409,6 +5426,7 @@ Jsonix.Context = Jsonix
54095426
this.modules = [];
54105427
this.elementInfos = [];
54115428
this.typeInfos = {};
5429+
this.typeNameKeyToTypeInfo = {};
54125430
this.registerBuiltinTypeInfos();
54135431
this.namespacePrefixes = {};
54145432
this.prefixNamespaces = {};
@@ -5489,6 +5507,10 @@ Jsonix.Context = Jsonix
54895507
var n = typeInfo.name||typeInfo.n||null;
54905508
Jsonix.Util.Ensure.ensureString(n);
54915509
this.typeInfos[n] = typeInfo;
5510+
if (typeInfo.typeName && typeInfo.typeName.key)
5511+
{
5512+
this.typeNameKeyToTypeInfo[typeInfo.typeName.key] = typeInfo;
5513+
}
54925514
},
54935515
resolveTypeInfo : function(mapping, module) {
54945516
if (!Jsonix.Util.Type.exists(mapping)) {
@@ -5553,6 +5575,9 @@ Jsonix.Context = Jsonix
55535575
scopedElementInfos[elementInfo.elementName.key] = elementInfo;
55545576

55555577
},
5578+
getTypeInfoByTypeNameKey : function(typeNameKey) {
5579+
return this.typeNameKeyToTypeInfo[typeNameKey];
5580+
},
55565581
getElementInfo : function(name, scope) {
55575582
if (Jsonix.Util.Type.exists(scope)) {
55585583
var scopeKey = scope.name;

nodejs/scripts/tests/GH61/GH61.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var Jsonix = require("../../jsonix").Jsonix;
2+
var Zero = require("./Mappings.js").Zero;
3+
4+
module.exports = {
5+
"GetTypeInfoByTypeNameKey" : function(test) {
6+
var context = new Jsonix.Context([Zero]);
7+
test.equal("String", context.getTypeInfoByTypeNameKey("{http://www.w3.org/2001/XMLSchema}string").name);
8+
test.equal("Zero.AType", context.getTypeInfoByTypeNameKey("{urn:zero}AType").name);
9+
test.equal("Zero.BType", context.getTypeInfoByTypeNameKey("{urn:b}B").name);
10+
test.equal("Zero.CType", context.getTypeInfoByTypeNameKey("{urn:c}C").name);
11+
test.done();
12+
}
13+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var Zero = {
2+
name: "Zero",
3+
dens: "urn:zero",
4+
typeInfos: [{
5+
type: "classInfo",
6+
localName: "AType"
7+
}, {
8+
type: "classInfo",
9+
localName: "BType",
10+
typeName: { ns: "urn:b", lp : "B" }
11+
}, {
12+
type: "classInfo",
13+
localName: "CType",
14+
typeName: { ns: "urn:c", lp : "C" }
15+
}]
16+
};
17+
module.exports.Zero = Zero;

nodejs/scripts/tests/issues.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = {
22
"Issues" : {
3-
"GH56" : require('./GH56/GH56')
3+
"GH56" : require('./GH56/GH56'),
4+
"GH61" : require('./GH61/GH61')
45
}
56
};

scripts/src/main/javascript/org/hisrc/jsonix/Jsonix/Context.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Jsonix.Context = Jsonix
22
.Class(Jsonix.Mapping.Styled, {
33
modules : [],
44
typeInfos : null,
5+
typeNameKeyToTypeInfo : null,
56
elementInfos : null,
67
options : null,
78
substitutionMembersMap : null,
@@ -11,6 +12,7 @@ Jsonix.Context = Jsonix
1112
this.modules = [];
1213
this.elementInfos = [];
1314
this.typeInfos = {};
15+
this.typeNameKeyToTypeInfo = {};
1416
this.registerBuiltinTypeInfos();
1517
this.namespacePrefixes = {};
1618
this.prefixNamespaces = {};
@@ -91,6 +93,10 @@ Jsonix.Context = Jsonix
9193
var n = typeInfo.name||typeInfo.n||null;
9294
Jsonix.Util.Ensure.ensureString(n);
9395
this.typeInfos[n] = typeInfo;
96+
if (typeInfo.typeName && typeInfo.typeName.key)
97+
{
98+
this.typeNameKeyToTypeInfo[typeInfo.typeName.key] = typeInfo;
99+
}
94100
},
95101
resolveTypeInfo : function(mapping, module) {
96102
if (!Jsonix.Util.Type.exists(mapping)) {
@@ -155,6 +161,9 @@ Jsonix.Context = Jsonix
155161
scopedElementInfos[elementInfo.elementName.key] = elementInfo;
156162

157163
},
164+
getTypeInfoByTypeNameKey : function(typeNameKey) {
165+
return this.typeNameKeyToTypeInfo[typeNameKey];
166+
},
158167
getElementInfo : function(name, scope) {
159168
if (Jsonix.Util.Type.exists(scope)) {
160169
var scopeKey = scope.name;

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Jsonix.Model.ClassInfo = Jsonix
22
.Class(Jsonix.Model.TypeInfo, Jsonix.Mapping.Styled, {
33
name : null,
4+
localName : null,
5+
typeName : null,
46
baseTypeInfo : null,
57
instanceFactory : null,
68
properties : null,
@@ -16,6 +18,9 @@ Jsonix.Model.ClassInfo = Jsonix
1618
Jsonix.Util.Ensure.ensureString(n);
1719
this.name = n;
1820

21+
var ln = mapping.localName||mapping.ln||null;
22+
this.localName = ln;
23+
1924
var dens = mapping.defaultElementNamespaceURI||mapping.dens||'';
2025
this.defaultElementNamespaceURI = dens;
2126

@@ -33,12 +38,23 @@ Jsonix.Model.ClassInfo = Jsonix
3338
this.instanceFactory = inF;
3439
}
3540

41+
var tn = mapping.typeName||mapping.tn||undefined;
42+
43+
if (Jsonix.Util.Type.exists(tn))
44+
{
45+
this.typeName = Jsonix.XML.QName.fromObject(tn);
46+
}
47+
else if (Jsonix.Util.Type.exists(ln))
48+
{
49+
this.typeName = new Jsonix.XML.QName(dens, ln);
50+
}
51+
3652
this.properties = [];
3753
var ps = mapping.propertyInfos||mapping.ps||[];
3854
Jsonix.Util.Ensure.ensureArray(ps);
3955
for ( var index = 0; index < ps.length; index++) {
4056
this.p(ps[index]);
41-
}
57+
}
4258
},
4359
// Obsolete
4460
destroy : function() {

0 commit comments

Comments
 (0)