Skip to content

Commit c901e02

Browse files
committed
Issue #73.
1 parent 945a214 commit c901e02

File tree

9 files changed

+415
-315
lines changed

9 files changed

+415
-315
lines changed

nodejs/scripts/jsonix.js

Lines changed: 194 additions & 155 deletions
Large diffs are not rendered by default.

nodejs/scripts/tests/xsd.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,33 @@ module.exports =
195195
test.equal(-733, dt1.timezone);
196196
test.equal('-1234-05-06T07:08:09.1011-12:13', Jsonix.Schema.XSD.Calendar.INSTANCE.print(dt1));
197197

198+
var gym = Jsonix.Schema.XSD.Calendar.INSTANCE.parse('-1234-05-12:13');
199+
test.equal(-1234, gym.year);
200+
test.equal(5, gym.month);
201+
test.equal(-733, gym.timezone);
202+
test.equal('-1234-05-12:13', Jsonix.Schema.XSD.Calendar.INSTANCE.print(gym));
203+
204+
var gy = Jsonix.Schema.XSD.Calendar.INSTANCE.parse('-1234-12:13');
205+
test.equal(-1234, gy.year);
206+
test.equal(-733, gy.timezone);
207+
test.equal('-1234-12:13', Jsonix.Schema.XSD.Calendar.INSTANCE.print(gy));
208+
209+
var gm = Jsonix.Schema.XSD.Calendar.INSTANCE.parse('--05-12:13');
210+
test.equal(5, gm.month);
211+
test.equal(-733, gm.timezone);
212+
test.equal('--05-12:13', Jsonix.Schema.XSD.Calendar.INSTANCE.print(gm));
213+
214+
var gmd = Jsonix.Schema.XSD.Calendar.INSTANCE.parse('--05-06-12:13');
215+
test.equal(5, gmd.month);
216+
test.equal(6, gmd.day);
217+
test.equal(-733, gmd.timezone);
218+
test.equal('--05-06-12:13', Jsonix.Schema.XSD.Calendar.INSTANCE.print(gmd));
219+
220+
var gd = Jsonix.Schema.XSD.Calendar.INSTANCE.parse('---06-12:13');
221+
test.equal(6, gd.day);
222+
test.equal(-733, gd.timezone);
223+
test.equal('---06-12:13', Jsonix.Schema.XSD.Calendar.INSTANCE.print(gd));
224+
198225
test.done();
199226
},
200227

pom.xml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,9 @@
5656
</modules>
5757
</profile>
5858
</profiles>
59-
<mailingLists>
60-
<mailingList>
61-
<name>User List</name>
62-
<subscribe>[email protected]</subscribe>
63-
<unsubscribe>[email protected]</unsubscribe>
64-
<post>[email protected]</post>
65-
<archive>http://sourceforge.net/mailarchive/forum.php?forum_name=jsonix-users</archive>
66-
</mailingList>
67-
</mailingLists>
6859
<properties>
6960
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
70-
<jsonix-schema-compiler.version>2.3.4</jsonix-schema-compiler.version>
61+
<jsonix-schema-compiler.version>2.3.6</jsonix-schema-compiler.version>
7162
<jaxb.version>2.2.11</jaxb.version>
7263
</properties>
7364
<dependencies>

scripts/src/main/javascript/org/hisrc/jsonix/Jsonix/Schema/XSD/Calendar.js

Lines changed: 178 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,88 @@ Jsonix.Schema.XSD.Calendar = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, {
44
parse : function(text, context, input, scope) {
55
Jsonix.Util.Ensure.ensureString(text);
66
if (text.match(new RegExp("^" + Jsonix.Schema.XSD.Calendar.DATETIME_PATTERN + "$"))) {
7-
return this.parseDateTime(text);
7+
return this.parseDateTime(text, context, input, scope);
88
} else if (text.match(new RegExp("^" + Jsonix.Schema.XSD.Calendar.DATE_PATTERN + "$"))) {
9-
return this.parseDate(text);
9+
return this.parseDate(text, context, input, scope);
1010
} else if (text.match(new RegExp("^" + Jsonix.Schema.XSD.Calendar.TIME_PATTERN + "$"))) {
11-
return this.parseTime(text);
11+
return this.parseTime(text, context, input, scope);
12+
} else if (text.match(new RegExp("^" + Jsonix.Schema.XSD.Calendar.GYEAR_MONTH_PATTERN + "$"))) {
13+
return this.parseGYearMonth(text, context, input, scope);
14+
} else if (text.match(new RegExp("^" + Jsonix.Schema.XSD.Calendar.GYEAR_PATTERN + "$"))) {
15+
return this.parseGYear(text, context, input, scope);
16+
} else if (text.match(new RegExp("^" + Jsonix.Schema.XSD.Calendar.GMONTH_DAY_PATTERN + "$"))) {
17+
return this.parseGMonthDay(text, context, input, scope);
18+
} else if (text.match(new RegExp("^" + Jsonix.Schema.XSD.Calendar.GMONTH_PATTERN + "$"))) {
19+
return this.parseGMonth(text, context, input, scope);
20+
} else if (text.match(new RegExp("^" + Jsonix.Schema.XSD.Calendar.GDAY_PATTERN + "$"))) {
21+
return this.parseGDay(text, context, input, scope);
1222
} else {
13-
throw new Error('Value [' + text + '] does not match xs:dateTime, xs:date or xs:time patterns.');
23+
throw new Error('Value [' + text + '] does not match xs:dateTime, xs:date, xs:time, xs:gYearMonth, xs:gYear, xs:gMonthDay, xs:gMonth or xs:gDay patterns.');
1424
}
1525
},
16-
parseDateTime : function(text) {
26+
parseGYearMonth : function(value, context, input, scope) {
27+
var gYearMonthExpression = new RegExp("^" + Jsonix.Schema.XSD.Calendar.GYEAR_MONTH_PATTERN + "$");
28+
var results = value.match(gYearMonthExpression);
29+
if (results !== null) {
30+
var data = {
31+
year : parseInt(results[1], 10),
32+
month : parseInt(results[5], 10),
33+
timezone : this.parseTimezoneString(results[7])
34+
};
35+
return new Jsonix.XML.Calendar(data);
36+
}
37+
throw new Error('Value [' + value + '] does not match the xs:gYearMonth pattern.');
38+
},
39+
parseGYear : function(value, context, input, scope) {
40+
var gYearExpression = new RegExp("^" + Jsonix.Schema.XSD.Calendar.GYEAR_PATTERN + "$");
41+
var results = value.match(gYearExpression);
42+
if (results !== null) {
43+
var data = {
44+
year : parseInt(results[1], 10),
45+
timezone : this.parseTimezoneString(results[5])
46+
};
47+
return new Jsonix.XML.Calendar(data);
48+
}
49+
throw new Error('Value [' + value + '] does not match the xs:gYear pattern.');
50+
},
51+
parseGMonthDay : function(value, context, input, scope) {
52+
var gMonthDayExpression = new RegExp("^" + Jsonix.Schema.XSD.Calendar.GMONTH_DAY_PATTERN + "$");
53+
var results = value.match(gMonthDayExpression);
54+
if (results !== null) {
55+
var data = {
56+
month : parseInt(results[2], 10),
57+
day : parseInt(results[3], 10),
58+
timezone : this.parseTimezoneString(results[5])
59+
};
60+
return new Jsonix.XML.Calendar(data);
61+
}
62+
throw new Error('Value [' + value + '] does not match the xs:gMonthDay pattern.');
63+
},
64+
parseGMonth : function(value, context, input, scope) {
65+
var gMonthExpression = new RegExp("^" + Jsonix.Schema.XSD.Calendar.GMONTH_PATTERN + "$");
66+
var results = value.match(gMonthExpression);
67+
if (results !== null) {
68+
var data = {
69+
month : parseInt(results[2], 10),
70+
timezone : this.parseTimezoneString(results[3])
71+
};
72+
return new Jsonix.XML.Calendar(data);
73+
}
74+
throw new Error('Value [' + value + '] does not match the xs:gMonth pattern.');
75+
},
76+
parseGDay : function(value, context, input, scope) {
77+
var gDayExpression = new RegExp("^" + Jsonix.Schema.XSD.Calendar.GDAY_PATTERN + "$");
78+
var results = value.match(gDayExpression);
79+
if (results !== null) {
80+
var data = {
81+
day : parseInt(results[2], 10),
82+
timezone : this.parseTimezoneString(results[3])
83+
};
84+
return new Jsonix.XML.Calendar(data);
85+
}
86+
throw new Error('Value [' + value + '] does not match the xs:gDay pattern.');
87+
},
88+
parseDateTime : function(text, context, input, scope) {
1789
Jsonix.Util.Ensure.ensureString(text);
1890
var expression = new RegExp("^" + Jsonix.Schema.XSD.Calendar.DATETIME_PATTERN + "$");
1991
var results = text.match(expression);
@@ -32,7 +104,7 @@ Jsonix.Schema.XSD.Calendar = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, {
32104
}
33105
throw new Error('Value [' + value + '] does not match the xs:date pattern.');
34106
},
35-
parseDate : function(text) {
107+
parseDate : function(text, context, input, scope) {
36108
Jsonix.Util.Ensure.ensureString(text);
37109
var expression = new RegExp("^" + Jsonix.Schema.XSD.Calendar.DATE_PATTERN + "$");
38110
var results = text.match(expression);
@@ -47,7 +119,7 @@ Jsonix.Schema.XSD.Calendar = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, {
47119
}
48120
throw new Error('Value [' + value + '] does not match the xs:date pattern.');
49121
},
50-
parseTime : function(text) {
122+
parseTime : function(text, context, input, scope) {
51123
Jsonix.Util.Ensure.ensureString(text);
52124
var expression = new RegExp("^" + Jsonix.Schema.XSD.Calendar.TIME_PATTERN + "$");
53125
var results = text.match(expression);
@@ -71,7 +143,7 @@ Jsonix.Schema.XSD.Calendar = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, {
71143
return NaN;
72144
} else if (text === 'Z') {
73145
return 0;
74-
}else if (text === '+14:00') {
146+
} else if (text === '+14:00') {
75147
return 14 * 60;
76148
} else if (text === '-14:00') {
77149
return -14 * 60;
@@ -95,6 +167,16 @@ Jsonix.Schema.XSD.Calendar = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, {
95167
return this.printDate(value);
96168
} else if (Jsonix.Util.NumberUtils.isInteger(value.hour) && Jsonix.Util.NumberUtils.isInteger(value.minute) && Jsonix.Util.NumberUtils.isInteger(value.second)) {
97169
return this.printTime(value);
170+
} else if (Jsonix.Util.NumberUtils.isInteger(value.year) && Jsonix.Util.NumberUtils.isInteger(value.month)) {
171+
return this.printGYearMonth(value);
172+
} else if (Jsonix.Util.NumberUtils.isInteger(value.month) && Jsonix.Util.NumberUtils.isInteger(value.day)) {
173+
return this.printGMonthDay(value);
174+
} else if (Jsonix.Util.NumberUtils.isInteger(value.year)) {
175+
return this.printGYear(value);
176+
} else if (Jsonix.Util.NumberUtils.isInteger(value.month)) {
177+
return this.printGMonth(value);
178+
} else if (Jsonix.Util.NumberUtils.isInteger(value.day)) {
179+
return this.printGDay(value);
98180
} else {
99181
throw new Error('Value [' + value + '] is not recognized as dateTime, date or time.');
100182
}
@@ -205,6 +287,94 @@ Jsonix.Schema.XSD.Calendar = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, {
205287
}
206288
}
207289
},
290+
printGDay : function(value, context, output, scope) {
291+
Jsonix.Util.Ensure.ensureObject(value);
292+
var day = undefined;
293+
var timezone = undefined;
294+
295+
if (value instanceof Date) {
296+
day = value.getDate();
297+
} else {
298+
Jsonix.Util.Ensure.ensureInteger(value.day);
299+
day = value.day;
300+
timezone = value.timezone;
301+
}
302+
Jsonix.XML.Calendar.validateDay(day);
303+
Jsonix.XML.Calendar.validateTimezone(timezone);
304+
return "---" + this.printDay(day) + this.printTimezoneString(timezone);
305+
},
306+
printGMonth : function(value, context, output, scope) {
307+
Jsonix.Util.Ensure.ensureObject(value);
308+
var month = undefined;
309+
var timezone = undefined;
310+
311+
if (value instanceof Date) {
312+
month = value.getMonth() + 1;
313+
} else {
314+
Jsonix.Util.Ensure.ensureInteger(value.month);
315+
month = value.month;
316+
timezone = value.timezone;
317+
}
318+
Jsonix.XML.Calendar.validateMonth(month);
319+
Jsonix.XML.Calendar.validateTimezone(timezone);
320+
return "--" + this.printMonth(month) + this.printTimezoneString(timezone);
321+
},
322+
printGMonthDay : function(value, context, output, scope) {
323+
Jsonix.Util.Ensure.ensureObject(value);
324+
var month = undefined;
325+
var day = undefined;
326+
var timezone = undefined;
327+
328+
if (value instanceof Date) {
329+
month = value.getMonth() + 1;
330+
day = value.getDate();
331+
} else {
332+
Jsonix.Util.Ensure.ensureInteger(value.month);
333+
Jsonix.Util.Ensure.ensureInteger(value.day);
334+
month = value.month;
335+
day = value.day;
336+
timezone = value.timezone;
337+
}
338+
Jsonix.XML.Calendar.validateMonthDay(month, day);
339+
Jsonix.XML.Calendar.validateTimezone(timezone);
340+
return "--" + this.printMonth(month) + "-" + this.printDay(day) + this.printTimezoneString(timezone);
341+
},
342+
printGYear : function(value, context, output, scope) {
343+
Jsonix.Util.Ensure.ensureObject(value);
344+
var year = undefined;
345+
var timezone = undefined;
346+
347+
if (value instanceof Date) {
348+
year = value.getFullYear();
349+
} else {
350+
Jsonix.Util.Ensure.ensureInteger(value.year);
351+
year = value.year;
352+
timezone = value.timezone;
353+
}
354+
Jsonix.XML.Calendar.validateYear(year);
355+
Jsonix.XML.Calendar.validateTimezone(timezone);
356+
return this.printSignedYear(year) + this.printTimezoneString(timezone);
357+
},
358+
printGYearMonth : function(value, context, output, scope) {
359+
Jsonix.Util.Ensure.ensureObject(value);
360+
var year = undefined;
361+
var month = undefined;
362+
var timezone = undefined;
363+
364+
if (value instanceof Date) {
365+
year = value.getFullYear();
366+
month = value.getMonth() + 1;
367+
} else {
368+
Jsonix.Util.Ensure.ensureInteger(value.year);
369+
year = value.year;
370+
month = value.month;
371+
timezone = value.timezone;
372+
}
373+
Jsonix.XML.Calendar.validateYear(year);
374+
Jsonix.XML.Calendar.validateMonth(month);
375+
Jsonix.XML.Calendar.validateTimezone(timezone);
376+
return this.printSignedYear(year) + "-" + this.printMonth(month) + this.printTimezoneString(timezone);
377+
},
208378
printSignedYear : function(value) {
209379
return value < 0 ? ("-" + this.printYear(value * -1)) : (this.printYear(value));
210380
},
@@ -251,10 +421,6 @@ Jsonix.Schema.XSD.Calendar = Jsonix.Class(Jsonix.Schema.XSD.AnySimpleType, {
251421
if (value < 0) {
252422
throw new Error('Value [' + value + '] must not be negative.');
253423
}
254-
// if (value >= Math.pow(10, length)) {
255-
// throw new Error('Value [' + value + '] must be less than [' +
256-
// Math.pow(10, length) + '].');
257-
// }
258424
var result = String(value);
259425
for (var i = result.length; i < length; i++) {
260426
result = '0' + result;

scripts/src/main/javascript/org/hisrc/jsonix/Jsonix/Schema/XSD/GDay.js

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,11 @@ Jsonix.Schema.XSD.GDay = Jsonix.Class(Jsonix.Schema.XSD.Calendar, {
44
CLASS_NAME : 'Jsonix.Schema.XSD.GDay',
55

66
parse : function(value, context, input, scope) {
7-
var gDayExpression = new RegExp("^" + Jsonix.Schema.XSD.Calendar.GDAY_PATTERN + "$");
8-
var results = value.match(gDayExpression);
9-
if (results !== null) {
10-
var data = {
11-
day : parseInt(results[2], 10),
12-
timezone : this.parseTimezoneString(results[3])
13-
};
14-
return new Jsonix.XML.Calendar(data);
15-
}
16-
throw new Error('Value [' + value + '] does not match the xs:gDay pattern.');
7+
return this.parseGDay(value, context, input, scope);
178
},
189

19-
print : function(value, context, input, scope) {
20-
Jsonix.Util.Ensure.ensureObject(value);
21-
var day = undefined;
22-
var timezone = undefined;
23-
24-
if (value instanceof Date) {
25-
day = value.getDate();
26-
} else {
27-
Jsonix.Util.Ensure.ensureInteger(value.day);
28-
day = value.day;
29-
timezone = value.timezone;
30-
}
31-
Jsonix.XML.Calendar.validateDay(day);
32-
Jsonix.XML.Calendar.validateTimezone(timezone);
33-
return "---" + this.printDay(day) + this.printTimezoneString(timezone);
10+
print : function(value, context, output, scope) {
11+
return this.printGDay(value, context, output, scope);
3412
}
3513

3614
});

scripts/src/main/javascript/org/hisrc/jsonix/Jsonix/Schema/XSD/GMonth.js

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,11 @@ Jsonix.Schema.XSD.GMonth = Jsonix.Class(Jsonix.Schema.XSD.Calendar, {
22
name : 'GMonth',
33
typeName : Jsonix.Schema.XSD.qname('gMonth'),
44
CLASS_NAME : 'Jsonix.Schema.XSD.GMonth',
5-
65
parse : function(value, context, input, scope) {
7-
var gMonthExpression = new RegExp("^" + Jsonix.Schema.XSD.Calendar.GMONTH_PATTERN + "$");
8-
var results = value.match(gMonthExpression);
9-
if (results !== null) {
10-
var data = {
11-
month : parseInt(results[2], 10),
12-
timezone : this.parseTimezoneString(results[3])
13-
};
14-
return new Jsonix.XML.Calendar(data);
15-
}
16-
throw new Error('Value [' + value + '] does not match the xs:gMonth pattern.');
6+
return this.parseGMonth(value, context, input, scope);
177
},
18-
19-
print : function(value, context, input, scope) {
20-
Jsonix.Util.Ensure.ensureObject(value);
21-
var month = undefined;
22-
var timezone = undefined;
23-
24-
if (value instanceof Date) {
25-
month = value.getMonth() + 1;
26-
} else {
27-
Jsonix.Util.Ensure.ensureInteger(value.month);
28-
month = value.month;
29-
timezone = value.timezone;
30-
}
31-
Jsonix.XML.Calendar.validateMonth(month);
32-
Jsonix.XML.Calendar.validateTimezone(timezone);
33-
return "--" + this.printMonth(month) + this.printTimezoneString(timezone);
8+
print : function(value, context, output, scope) {
9+
return this.printGMonth(value, context, output, scope);
3410
}
3511
});
3612
Jsonix.Schema.XSD.GMonth.INSTANCE = new Jsonix.Schema.XSD.GMonth();

0 commit comments

Comments
 (0)