1 /* DatatypeFactory.java --
2 Copyright (C) 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package javax
.xml
.datatype
;
40 import java
.math
.BigDecimal
;
41 import java
.math
.BigInteger
;
42 import java
.util
.GregorianCalendar
;
45 * Factory class to create new datatype objects mapping XML to and from Java
48 * @author (a href='mailto:dog@gnu.org'>Chris Burdess</a)
51 public abstract class DatatypeFactory
55 * JAXP 1.3 default property name.
57 public static final String DATATYPEFACTORY_PROPERTY
= "javax.xml.datatype.DatatypeFactory";
60 * JAXP 1.3 default implementation class name.
62 public static final java
.lang
.String DATATYPEFACTORY_IMPLEMENTATION_CLASS
= "gnu.xml.datatype.JAXPDatatypeFactory";
64 protected DatatypeFactory()
69 * Returns a new factory instance.
71 public static DatatypeFactory
newInstance()
72 throws DatatypeConfigurationException
76 Class t
= Class
.forName(DATATYPEFACTORY_IMPLEMENTATION_CLASS
);
77 return (DatatypeFactory
) t
.newInstance();
81 throw new DatatypeConfigurationException (e
);
86 * Returns a new duration from its string representation.
87 * @param lexicalRepresentation the lexical representation of the
88 * duration, as specified in XML Schema 1.0 section 3.2.6.1.
90 public abstract Duration
newDuration(String lexicalRepresentation
);
93 * Returns a new duration.
94 * @param durationInMilliseconds the duration in milliseconds
96 public abstract Duration
newDuration(long durationInMilliSeconds
);
99 * Returns a new duration by specifying the individual components.
100 * @param isPositive whether the duration is positive
101 * @param years the number of years
102 * @param months the number of months
103 * @param days the number of days
104 * @param hours the number of hours
105 * @param minutes th number of minutes
106 * @param seconds the number of seconds
108 public abstract Duration
newDuration(boolean isPositive
,
117 * Returns a new duration by specifying the individual components.
118 * @param isPositive whether the duration is positive
119 * @param years the number of years
120 * @param months the number of months
121 * @param days the number of days
122 * @param hours the number of hours
123 * @param minutes th number of minutes
124 * @param seconds the number of seconds
126 public Duration
newDuration(boolean isPositive
,
134 return newDuration(isPositive
,
135 BigInteger
.valueOf((long) years
),
136 BigInteger
.valueOf((long) months
),
137 BigInteger
.valueOf((long) days
),
138 BigInteger
.valueOf((long) hours
),
139 BigInteger
.valueOf((long) minutes
),
140 BigDecimal
.valueOf((long) seconds
));
144 * Returns a new dayTimeDuration from its string representation.
145 * @param lexicalRepresentation the lexical representation of the
146 * duration, as specified in XML Schema 1.0 section 3.2.6.1.
148 public Duration
newDurationDayTime(String lexicalRepresentation
)
150 return newDuration(lexicalRepresentation
);
154 * Returns a new dayTimeDuration.
155 * @param durationInMilliseconds the duration in milliseconds
157 public Duration
newDurationDayTime(long durationInMilliseconds
)
159 // TODO xmlSchemaType
160 return newDuration(durationInMilliseconds
);
164 * Returns a new dayTimeDuration by specifying the individual components.
165 * @param isPositive whether the duration is positive
166 * @param days the number of days
167 * @param hours the number of hours
168 * @param minutes th number of minutes
169 * @param seconds the number of seconds
171 public Duration
newDurationDayTime(boolean isPositive
,
177 return newDuration(isPositive
,
187 * Returns a new dayTimeDuration by specifying the individual components.
188 * @param isPositive whether the duration is positive
189 * @param days the number of days
190 * @param hours the number of hours
191 * @param minutes th number of minutes
192 * @param seconds the number of seconds
194 public Duration
newDurationDayTime(boolean isPositive
,
200 return newDuration(isPositive
,
203 BigInteger
.valueOf((long) days
),
204 BigInteger
.valueOf((long) hours
),
205 BigInteger
.valueOf((long) minutes
),
206 BigDecimal
.valueOf((long) seconds
));
210 * Returns a new yearMonthDuration from its string representation.
211 * @param lexicalRepresentation the lexical representation of the
212 * duration, as specified in XML Schema 1.0 section 3.2.6.1.
214 public Duration
newDurationYearMonth(String lexicalRepresentation
)
216 return newDuration(lexicalRepresentation
);
220 * Returns a new yearMonthDuration.
221 * @param durationInMilliseconds the duration in milliseconds
223 public Duration
newDurationYearMonth(long durationInMilliseconds
)
225 // TODO xmlSchemaType
226 return newDuration(durationInMilliseconds
);
230 * Returns a new yearMonthDuration by specifying the individual components.
231 * @param isPositive whether the duration is positive
232 * @param years the number of years
233 * @param months the number of months
234 * @param days the number of days
235 * @param hours the number of hours
236 * @param minutes th number of minutes
237 * @param seconds the number of seconds
239 public Duration
newDurationYearMonth(boolean isPositive
,
243 return newDuration(isPositive
,
253 * Returns a new yearMonthDuration by specifying the individual components.
254 * @param isPositive whether the duration is positive
255 * @param years the number of years
256 * @param months the number of months
257 * @param days the number of days
258 * @param hours the number of hours
259 * @param minutes th number of minutes
260 * @param seconds the number of seconds
262 public Duration
newDurationYearMonth(boolean isPositive
,
266 return newDuration(isPositive
,
267 BigInteger
.valueOf((long) years
),
268 BigInteger
.valueOf((long) months
),
276 * Returns a new XMLGregorianCalendar with no fields initialized.
278 public abstract XMLGregorianCalendar
newXMLGregorianCalendar();
281 * Returns a new XMLGregorianCalendar from a string representation.
282 * @param lexicalRepresentation the lexical representation as specified in
283 * XML Schema 1.0 Part 2, section 3.2.[7-14].1.
285 public abstract XMLGregorianCalendar
newXMLGregorianCalendar(String lexicalRepresentation
);
288 * Returns a new XMLGregorianCalendar based on the specified Gregorian
291 public abstract XMLGregorianCalendar
newXMLGregorianCalendar(GregorianCalendar cal
);
294 * Returns a new XMLGregorianCalendar with the specified components.
296 public abstract XMLGregorianCalendar
newXMLGregorianCalendar(BigInteger year
,
302 BigDecimal fractionalSecond
,
306 * Returns a new XMLGregorianCalendar with the specified components.
308 public XMLGregorianCalendar
newXMLGregorianCalendar(int year
,
317 return newXMLGregorianCalendar(BigInteger
.valueOf((long) year
),
323 new BigDecimal(((double) millisecond
) / 1000.0),
328 * Returns a new XMLGregorianCalendar with the specified components.
330 public XMLGregorianCalendar
newXMLGregorianCalendarDate(int year
,
335 return newXMLGregorianCalendar(BigInteger
.valueOf((long) year
),
338 DatatypeConstants
.FIELD_UNDEFINED
,
339 DatatypeConstants
.FIELD_UNDEFINED
,
340 DatatypeConstants
.FIELD_UNDEFINED
,
346 * Returns a new XMLGregorianCalendar with the specified components.
348 public XMLGregorianCalendar
newXMLGregorianCalendarTime(int hours
,
353 return newXMLGregorianCalendar(null,
354 DatatypeConstants
.FIELD_UNDEFINED
,
355 DatatypeConstants
.FIELD_UNDEFINED
,
364 * Returns a new XMLGregorianCalendar with the specified components.
366 public XMLGregorianCalendar
newXMLGregorianCalendarTime(int hours
,
369 BigDecimal fractionalSecond
,
372 return newXMLGregorianCalendar(null,
373 DatatypeConstants
.FIELD_UNDEFINED
,
374 DatatypeConstants
.FIELD_UNDEFINED
,
383 * Returns a new XMLGregorianCalendar with the specified components.
385 public XMLGregorianCalendar
newXMLGregorianCalendarTime(int hours
,
391 return newXMLGregorianCalendar(null,
392 DatatypeConstants
.FIELD_UNDEFINED
,
393 DatatypeConstants
.FIELD_UNDEFINED
,
397 new BigDecimal(((double) milliseconds
) / 1000.0),