1:
37:
38: package ;
39:
40: import ;
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51:
52:
59: public abstract class DatatypeFactory
60: {
61:
62:
65: public static final String DATATYPEFACTORY_PROPERTY = "javax.xml.datatype.DatatypeFactory";
66:
67:
70: public static final String DATATYPEFACTORY_IMPLEMENTATION_CLASS = "gnu.xml.datatype.JAXPDatatypeFactory";
71:
72: protected DatatypeFactory()
73: {
74: }
75:
76:
79: public static DatatypeFactory newInstance()
80: throws DatatypeConfigurationException
81: {
82: try
83: {
84:
85: String className = System.getProperty(DATATYPEFACTORY_PROPERTY);
86: if (className != null)
87: return (DatatypeFactory) Class.forName(className).newInstance();
88:
89: File javaHome = new File(System.getProperty("java.home"));
90: File javaHomeLib = new File(javaHome, "lib");
91: File jaxpProperties = new File(javaHomeLib, "jaxp.properties");
92: if (jaxpProperties.exists())
93: {
94: FileInputStream in = new FileInputStream(jaxpProperties);
95: Properties p = new Properties();
96: p.load(in);
97: in.close();
98: className = p.getProperty(DATATYPEFACTORY_PROPERTY);
99: if (className != null)
100: return (DatatypeFactory) Class.forName(className).newInstance();
101: }
102:
103: Iterator i = ServiceFactory.lookupProviders(DatatypeFactory.class);
104: if (i.hasNext())
105: return (DatatypeFactory) i.next();
106:
107: Class t = Class.forName(DATATYPEFACTORY_IMPLEMENTATION_CLASS);
108: return (DatatypeFactory) t.newInstance();
109: }
110: catch (Exception e)
111: {
112: throw new DatatypeConfigurationException(e);
113: }
114: }
115:
116:
121: public abstract Duration newDuration(String lexicalRepresentation);
122:
123:
127: public abstract Duration newDuration(long durationInMilliSeconds);
128:
129:
139: public abstract Duration newDuration(boolean isPositive,
140: BigInteger years,
141: BigInteger months,
142: BigInteger days,
143: BigInteger hours,
144: BigInteger minutes,
145: BigDecimal seconds);
146:
147:
157: public Duration newDuration(boolean isPositive,
158: int years,
159: int months,
160: int days,
161: int hours,
162: int minutes,
163: int seconds)
164: {
165: return newDuration(isPositive,
166: BigInteger.valueOf((long) years),
167: BigInteger.valueOf((long) months),
168: BigInteger.valueOf((long) days),
169: BigInteger.valueOf((long) hours),
170: BigInteger.valueOf((long) minutes),
171: BigDecimal.valueOf((long) seconds));
172: }
173:
174:
179: public Duration newDurationDayTime(String lexicalRepresentation)
180: {
181: return newDuration(lexicalRepresentation);
182: }
183:
184:
188: public Duration newDurationDayTime(long durationInMilliseconds)
189: {
190:
191: return newDuration(durationInMilliseconds);
192: }
193:
194:
202: public Duration newDurationDayTime(boolean isPositive,
203: BigInteger days,
204: BigInteger hours,
205: BigInteger minutes,
206: BigInteger seconds)
207: {
208: return newDuration(isPositive,
209: null,
210: null,
211: days,
212: hours,
213: minutes,
214: new BigDecimal(seconds));
215: }
216:
217:
225: public Duration newDurationDayTime(boolean isPositive,
226: int days,
227: int hours,
228: int minutes,
229: int seconds)
230: {
231: return newDuration(isPositive,
232: null,
233: null,
234: BigInteger.valueOf((long) days),
235: BigInteger.valueOf((long) hours),
236: BigInteger.valueOf((long) minutes),
237: BigDecimal.valueOf((long) seconds));
238: }
239:
240:
245: public Duration newDurationYearMonth(String lexicalRepresentation)
246: {
247: return newDuration(lexicalRepresentation);
248: }
249:
250:
254: public Duration newDurationYearMonth(long durationInMilliseconds)
255: {
256:
257: return newDuration(durationInMilliseconds);
258: }
259:
260:
266: public Duration newDurationYearMonth(boolean isPositive,
267: BigInteger years,
268: BigInteger months)
269: {
270: return newDuration(isPositive,
271: years,
272: months,
273: null,
274: null,
275: null,
276: null);
277: }
278:
279:
285: public Duration newDurationYearMonth(boolean isPositive,
286: int years,
287: int months)
288: {
289: return newDuration(isPositive,
290: BigInteger.valueOf((long) years),
291: BigInteger.valueOf((long) months),
292: null,
293: null,
294: null,
295: null);
296: }
297:
298:
301: public abstract XMLGregorianCalendar newXMLGregorianCalendar();
302:
303:
308: public abstract XMLGregorianCalendar newXMLGregorianCalendar(String lexicalRepresentation);
309:
310:
314: public abstract XMLGregorianCalendar newXMLGregorianCalendar(GregorianCalendar cal);
315:
316:
319: public abstract XMLGregorianCalendar newXMLGregorianCalendar(BigInteger year,
320: int month,
321: int day,
322: int hour,
323: int minute,
324: int second,
325: BigDecimal fractionalSecond,
326: int timezone);
327:
328:
331: public XMLGregorianCalendar newXMLGregorianCalendar(int year,
332: int month,
333: int day,
334: int hour,
335: int minute,
336: int second,
337: int millisecond,
338: int timezone)
339: {
340: return newXMLGregorianCalendar(BigInteger.valueOf((long) year),
341: month,
342: day,
343: hour,
344: minute,
345: second,
346: new BigDecimal(((double) millisecond) / 1000.0),
347: timezone);
348: }
349:
350:
353: public XMLGregorianCalendar newXMLGregorianCalendarDate(int year,
354: int month,
355: int day,
356: int timezone)
357: {
358: return newXMLGregorianCalendar(BigInteger.valueOf((long) year),
359: month,
360: day,
361: DatatypeConstants.FIELD_UNDEFINED,
362: DatatypeConstants.FIELD_UNDEFINED,
363: DatatypeConstants.FIELD_UNDEFINED,
364: null,
365: timezone);
366: }
367:
368:
371: public XMLGregorianCalendar newXMLGregorianCalendarTime(int hours,
372: int minutes,
373: int seconds,
374: int timezone)
375: {
376: return newXMLGregorianCalendar(null,
377: DatatypeConstants.FIELD_UNDEFINED,
378: DatatypeConstants.FIELD_UNDEFINED,
379: hours,
380: minutes,
381: seconds,
382: null,
383: timezone);
384: }
385:
386:
389: public XMLGregorianCalendar newXMLGregorianCalendarTime(int hours,
390: int minutes,
391: int seconds,
392: BigDecimal fractionalSecond,
393: int timezone)
394: {
395: return newXMLGregorianCalendar(null,
396: DatatypeConstants.FIELD_UNDEFINED,
397: DatatypeConstants.FIELD_UNDEFINED,
398: hours,
399: minutes,
400: seconds,
401: fractionalSecond,
402: timezone);
403: }
404:
405:
408: public XMLGregorianCalendar newXMLGregorianCalendarTime(int hours,
409: int minutes,
410: int seconds,
411: int milliseconds,
412: int timezone)
413: {
414: return newXMLGregorianCalendar(null,
415: DatatypeConstants.FIELD_UNDEFINED,
416: DatatypeConstants.FIELD_UNDEFINED,
417: hours,
418: minutes,
419: seconds,
420: new BigDecimal(((double) milliseconds) / 1000.0),
421: timezone);
422: }
423:
424: }