Merge from the pain train
[official-gcc.git] / libjava / javax / xml / datatype / DatatypeFactory.java
blobb3c8cf4314217e3546311ec7ee845959ad66820c
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)
9 any later version.
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
19 02111-1307 USA.
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
24 combination.
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;
44 /**
45 * Factory class to create new datatype objects mapping XML to and from Java
46 * objects.
48 * @author (a href='mailto:dog@gnu.org'>Chris Burdess</a)
49 * @since 1.3
51 public abstract class DatatypeFactory
54 /**
55 * JAXP 1.3 default property name.
57 public static final String DATATYPEFACTORY_PROPERTY = "javax.xml.datatype.DatatypeFactory";
59 /**
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()
68 /**
69 * Returns a new factory instance.
71 public static DatatypeFactory newInstance()
72 throws DatatypeConfigurationException
74 try
76 Class t = Class.forName(DATATYPEFACTORY_IMPLEMENTATION_CLASS);
77 return (DatatypeFactory) t.newInstance();
79 catch (Exception e)
81 throw new DatatypeConfigurationException (e);
85 /**
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);
92 /**
93 * Returns a new duration.
94 * @param durationInMilliseconds the duration in milliseconds
96 public abstract Duration newDuration(long durationInMilliSeconds);
98 /**
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,
109 BigInteger years,
110 BigInteger months,
111 BigInteger days,
112 BigInteger hours,
113 BigInteger minutes,
114 BigDecimal seconds);
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,
127 int years,
128 int months,
129 int days,
130 int hours,
131 int minutes,
132 int seconds)
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,
172 BigInteger days,
173 BigInteger hours,
174 BigInteger minutes,
175 BigDecimal seconds)
177 return newDuration(isPositive,
178 null,
179 null,
180 days,
181 hours,
182 minutes,
183 seconds);
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,
195 int days,
196 int hours,
197 int minutes,
198 int seconds)
200 return newDuration(isPositive,
201 null,
202 null,
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,
240 BigInteger years,
241 BigInteger months)
243 return newDuration(isPositive,
244 years,
245 months,
246 null,
247 null,
248 null,
249 null);
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,
263 int years,
264 int months)
266 return newDuration(isPositive,
267 BigInteger.valueOf((long) years),
268 BigInteger.valueOf((long) months),
269 null,
270 null,
271 null,
272 null);
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
289 * calendar.
291 public abstract XMLGregorianCalendar newXMLGregorianCalendar(GregorianCalendar cal);
294 * Returns a new XMLGregorianCalendar with the specified components.
296 public abstract XMLGregorianCalendar newXMLGregorianCalendar(BigInteger year,
297 int month,
298 int day,
299 int hour,
300 int minute,
301 int second,
302 BigDecimal fractionalSecond,
303 int timezone);
306 * Returns a new XMLGregorianCalendar with the specified components.
308 public XMLGregorianCalendar newXMLGregorianCalendar(int year,
309 int month,
310 int day,
311 int hour,
312 int minute,
313 int second,
314 int millisecond,
315 int timezone)
317 return newXMLGregorianCalendar(BigInteger.valueOf((long) year),
318 month,
319 day,
320 hour,
321 minute,
322 second,
323 new BigDecimal(((double) millisecond) / 1000.0),
324 timezone);
328 * Returns a new XMLGregorianCalendar with the specified components.
330 public XMLGregorianCalendar newXMLGregorianCalendarDate(int year,
331 int month,
332 int day,
333 int timezone)
335 return newXMLGregorianCalendar(BigInteger.valueOf((long) year),
336 month,
337 day,
338 DatatypeConstants.FIELD_UNDEFINED,
339 DatatypeConstants.FIELD_UNDEFINED,
340 DatatypeConstants.FIELD_UNDEFINED,
341 null,
342 timezone);
346 * Returns a new XMLGregorianCalendar with the specified components.
348 public XMLGregorianCalendar newXMLGregorianCalendarTime(int hours,
349 int minutes,
350 int seconds,
351 int timezone)
353 return newXMLGregorianCalendar(null,
354 DatatypeConstants.FIELD_UNDEFINED,
355 DatatypeConstants.FIELD_UNDEFINED,
356 hours,
357 minutes,
358 seconds,
359 null,
360 timezone);
364 * Returns a new XMLGregorianCalendar with the specified components.
366 public XMLGregorianCalendar newXMLGregorianCalendarTime(int hours,
367 int minutes,
368 int seconds,
369 BigDecimal fractionalSecond,
370 int timezone)
372 return newXMLGregorianCalendar(null,
373 DatatypeConstants.FIELD_UNDEFINED,
374 DatatypeConstants.FIELD_UNDEFINED,
375 hours,
376 minutes,
377 seconds,
378 fractionalSecond,
379 timezone);
383 * Returns a new XMLGregorianCalendar with the specified components.
385 public XMLGregorianCalendar newXMLGregorianCalendarTime(int hours,
386 int minutes,
387 int seconds,
388 int milliseconds,
389 int timezone)
391 return newXMLGregorianCalendar(null,
392 DatatypeConstants.FIELD_UNDEFINED,
393 DatatypeConstants.FIELD_UNDEFINED,
394 hours,
395 minutes,
396 seconds,
397 new BigDecimal(((double) milliseconds) / 1000.0),
398 timezone);