12005
|
1 |
/*
|
|
2 |
* reserved comment block
|
|
3 |
* DO NOT REMOVE OR ALTER!
|
|
4 |
*/
|
|
5 |
/*
|
|
6 |
* Copyright 2005 The Apache Software Foundation.
|
|
7 |
*
|
|
8 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9 |
* you may not use this file except in compliance with the License.
|
|
10 |
* You may obtain a copy of the License at
|
|
11 |
*
|
|
12 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13 |
*
|
|
14 |
* Unless required by applicable law or agreed to in writing, software
|
|
15 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17 |
* See the License for the specific language governing permissions and
|
|
18 |
* limitations under the License.
|
|
19 |
*/
|
|
20 |
|
|
21 |
package com.sun.org.apache.xerces.internal.jaxp.datatype;
|
|
22 |
|
|
23 |
import java.math.BigInteger;
|
|
24 |
import java.math.BigDecimal;
|
|
25 |
import java.util.GregorianCalendar;
|
|
26 |
|
|
27 |
import javax.xml.datatype.DatatypeConstants;
|
|
28 |
import javax.xml.datatype.DatatypeFactory;
|
|
29 |
import javax.xml.datatype.Duration;
|
|
30 |
import javax.xml.datatype.XMLGregorianCalendar;
|
|
31 |
|
|
32 |
/**
|
|
33 |
* <p>Factory that creates new <code>javax.xml.datatype</code> <code>Object</code>s that map XML to/from Java <code>Object</code>s.</p>
|
|
34 |
*
|
|
35 |
* <p id="DatatypeFactory.newInstance">{@link #newInstance()} is used to create a new <code>DatatypeFactory</code>.
|
|
36 |
* The following implementation resolution mechanisms are used in the following order:</p>
|
|
37 |
* <ol>
|
|
38 |
* <li>
|
|
39 |
* If the system property specified by {@link #DATATYPEFACTORY_PROPERTY}, "<code>javax.xml.datatype.DatatypeFactory</code>",
|
|
40 |
* exists, a class with the name of the property's value is instantiated.
|
|
41 |
* Any Exception thrown during the instantiation process is wrapped as a {@link DatatypeConfigurationException}.
|
|
42 |
* </li>
|
|
43 |
* <li>
|
27574
|
44 |
* If the file ${JAVA_HOME}/conf/jaxp.properties exists, it is loaded in a {@link java.util.Properties} <code>Object</code>.
|
12005
|
45 |
* The <code>Properties</code> <code>Object </code> is then queried for the property as documented in the prior step
|
|
46 |
* and processed as documented in the prior step.
|
|
47 |
* </li>
|
|
48 |
* <li>
|
|
49 |
* The services resolution mechanism is used, e.g. <code>META-INF/services/java.xml.datatype.DatatypeFactory</code>.
|
|
50 |
* Any Exception thrown during the instantiation process is wrapped as a {@link DatatypeConfigurationException}.
|
|
51 |
* </li>
|
|
52 |
* <li>
|
|
53 |
* The final mechanism is to attempt to instantiate the <code>Class</code> specified by
|
|
54 |
* {@link #DATATYPEFACTORY_IMPLEMENTATION_CLASS}, "<code>javax.xml.datatype.DatatypeFactoryImpl</code>".
|
|
55 |
* Any Exception thrown during the instantiation process is wrapped as a {@link DatatypeConfigurationException}.
|
|
56 |
* </li>
|
|
57 |
* </ol>
|
|
58 |
*
|
|
59 |
* @author <a href="mailto:Joseph.Fialli@Sun.COM">Joseph Fialli</a>
|
|
60 |
* @author <a href="mailto:Jeff.Suttor@Sun.com">Jeff Suttor</a>
|
|
61 |
*/
|
|
62 |
public class DatatypeFactoryImpl
|
|
63 |
extends DatatypeFactory {
|
|
64 |
|
|
65 |
/**
|
|
66 |
* <p>Public constructor is empty..</p>
|
|
67 |
*
|
|
68 |
* <p>Use {@link DatatypeFactory#newInstance()} to create a <code>DatatypeFactory</code>.</p>
|
|
69 |
*/
|
|
70 |
public DatatypeFactoryImpl() {
|
|
71 |
}
|
|
72 |
|
|
73 |
/**
|
|
74 |
* <p>Obtain a new instance of a <code>Duration</code>
|
|
75 |
* specifying the <code>Duration</code> as its string representation, "PnYnMnDTnHnMnS",
|
|
76 |
* as defined in XML Schema 1.0 section 3.2.6.1.</p>
|
|
77 |
*
|
|
78 |
* <p>XML Schema Part 2: Datatypes, 3.2.6 duration, defines <code>duration</code> as:</p>
|
|
79 |
* <blockquote>
|
|
80 |
* duration represents a duration of time.
|
|
81 |
* The value space of duration is a six-dimensional space where the coordinates designate the
|
|
82 |
* Gregorian year, month, day, hour, minute, and second components defined in Section 5.5.3.2 of [ISO 8601], respectively.
|
|
83 |
* These components are ordered in their significance by their order of appearance i.e. as
|
|
84 |
* year, month, day, hour, minute, and second.
|
|
85 |
* </blockquote>
|
|
86 |
* <p>All six values are set and availabe from the created {@link Duration}</p>
|
|
87 |
*
|
|
88 |
* <p>The XML Schema specification states that values can be of an arbitrary size.
|
|
89 |
* Implementations may chose not to or be incapable of supporting arbitrarily large and/or small values.
|
|
90 |
* An {@link UnsupportedOperationException} will be thrown with a message indicating implementation limits
|
|
91 |
* if implementation capacities are exceeded.</p>
|
|
92 |
*
|
|
93 |
* @param lexicalRepresentation <code>String</code> representation of a <code>Duration</code>.
|
|
94 |
*
|
|
95 |
* @return New <code>Duration</code> created from parsing the <code>lexicalRepresentation</code>.
|
|
96 |
*
|
|
97 |
* @throws IllegalArgumentException If <code>lexicalRepresentation</code> is not a valid representation of a <code>Duration</code>.
|
|
98 |
* @throws UnsupportedOperationException If implementation cannot support requested values.
|
|
99 |
* @throws NullPointerException if <code>lexicalRepresentation</code> is <code>null</code>.
|
|
100 |
*/
|
|
101 |
public Duration newDuration(final String lexicalRepresentation) {
|
|
102 |
|
|
103 |
return new DurationImpl(lexicalRepresentation);
|
|
104 |
}
|
|
105 |
|
|
106 |
/**
|
|
107 |
* <p>Obtain a new instance of a <code>Duration</code>
|
|
108 |
* specifying the <code>Duration</code> as milliseconds.</p>
|
|
109 |
*
|
|
110 |
* <p>XML Schema Part 2: Datatypes, 3.2.6 duration, defines <code>duration</code> as:</p>
|
|
111 |
* <blockquote>
|
|
112 |
* duration represents a duration of time.
|
|
113 |
* The value space of duration is a six-dimensional space where the coordinates designate the
|
|
114 |
* Gregorian year, month, day, hour, minute, and second components defined in Section 5.5.3.2 of [ISO 8601], respectively.
|
|
115 |
* These components are ordered in their significance by their order of appearance i.e. as
|
|
116 |
* year, month, day, hour, minute, and second.
|
|
117 |
* </blockquote>
|
|
118 |
* <p>All six values are set by computing their values from the specified milliseconds
|
|
119 |
* and are availabe using the <code>get</code> methods of the created {@link Duration}.
|
|
120 |
* The values conform to and are defined by:</p>
|
|
121 |
* <ul>
|
|
122 |
* <li>ISO 8601:2000(E) Section 5.5.3.2 Alternative format</li>
|
|
123 |
* <li><a href="http://www.w3.org/TR/xmlschema-2/#isoformats">
|
|
124 |
* W3C XML Schema 1.0 Part 2, Appendix D, ISO 8601 Date and Time Formats</a>
|
|
125 |
* </li>
|
|
126 |
* <li>{@link XMLGregorianCalendar} Date/Time Datatype Field Mapping Between XML Schema 1.0 and Java Representation</li>
|
|
127 |
* </ul>
|
|
128 |
*
|
|
129 |
* <p>The default start instance is defined by {@link GregorianCalendar}'s use of the start of the epoch: i.e.,
|
|
130 |
* {@link java.util.Calendar#YEAR} = 1970,
|
|
131 |
* {@link java.util.Calendar#MONTH} = {@link java.util.Calendar#JANUARY},
|
|
132 |
* {@link java.util.Calendar#DATE} = 1, etc.
|
|
133 |
* This is important as there are variations in the Gregorian Calendar,
|
|
134 |
* e.g. leap years have different days in the month = {@link java.util.Calendar#FEBRUARY}
|
|
135 |
* so the result of {@link Duration#getMonths()} and {@link Duration#getDays()} can be influenced.</p>
|
|
136 |
*
|
|
137 |
* @param durationInMilliseconds Duration in milliseconds to create.
|
|
138 |
*
|
|
139 |
* @return New <code>Duration</code> representing <code>durationInMilliseconds</code>.
|
|
140 |
*/
|
|
141 |
public Duration newDuration(final long durationInMilliseconds) {
|
|
142 |
|
|
143 |
return new DurationImpl(durationInMilliseconds);
|
|
144 |
}
|
|
145 |
|
|
146 |
/**
|
|
147 |
* <p>Obtain a new instance of a <code>Duration</code>
|
|
148 |
* specifying the <code>Duration</code> as isPositive, years, months, days, hours, minutes, seconds.</p>
|
|
149 |
*
|
|
150 |
* <p>The XML Schema specification states that values can be of an arbitrary size.
|
|
151 |
* Implementations may chose not to or be incapable of supporting arbitrarily large and/or small values.
|
|
152 |
* An {@link UnsupportedOperationException} will be thrown with a message indicating implementation limits
|
|
153 |
* if implementation capacities are exceeded.</p>
|
|
154 |
*
|
|
155 |
* @param isPositive Set to <code>false</code> to create a negative duration. When the length
|
|
156 |
* of the duration is zero, this parameter will be ignored.
|
|
157 |
* @param years of this <code>Duration</code>
|
|
158 |
* @param months of this <code>Duration</code>
|
|
159 |
* @param days of this <code>Duration</code>
|
|
160 |
* @param hours of this <code>Duration</code>
|
|
161 |
* @param minutes of this <code>Duration</code>
|
|
162 |
* @param seconds of this <code>Duration</code>
|
|
163 |
*
|
|
164 |
* @return New <code>Duration</code> created from the specified values.
|
|
165 |
*
|
|
166 |
* @throws IllegalArgumentException If values are not a valid representation of a <code>Duration</code>.
|
|
167 |
* @throws UnsupportedOperationException If implementation cannot support requested values.
|
|
168 |
* @throws NullPointerException If any values are <code>null</code>.
|
|
169 |
*
|
|
170 |
* @see #newDuration(boolean isPositive, BigInteger years, BigInteger months, BigInteger days,
|
|
171 |
* BigInteger hours, BigInteger minutes, BigDecimal seconds)
|
|
172 |
*/
|
|
173 |
public Duration newDuration(
|
|
174 |
final boolean isPositive,
|
|
175 |
final BigInteger years,
|
|
176 |
final BigInteger months,
|
|
177 |
final BigInteger days,
|
|
178 |
final BigInteger hours,
|
|
179 |
final BigInteger minutes,
|
|
180 |
final BigDecimal seconds) {
|
|
181 |
|
|
182 |
return new DurationImpl(
|
|
183 |
isPositive,
|
|
184 |
years,
|
|
185 |
months,
|
|
186 |
days,
|
|
187 |
hours,
|
|
188 |
minutes,
|
|
189 |
seconds
|
|
190 |
);
|
|
191 |
}
|
|
192 |
/**
|
|
193 |
* <p>Create a <code>Duration</code> of type <code>xdt:yearMonthDuration</code> using the specified
|
|
194 |
* <code>year</code> and <code>month</code> as defined in
|
|
195 |
* <a href="http://www.w3.org/TR/xpath-datamodel#yearMonthDuration">
|
|
196 |
* XQuery 1.0 and XPath 2.0 Data Model, xdt:yearMonthDuration</a>.</p>
|
|
197 |
*
|
|
198 |
* <p>The XML Schema specification states that values can be of an arbitrary size.
|
|
199 |
* Implementations may chose not to or be incapable of supporting arbitrarily large and/or small values.
|
|
200 |
* An {@link UnsupportedOperationException} will be thrown with a message indicating implementation limits
|
|
201 |
* if implementation capacities are exceeded.</p>
|
|
202 |
*
|
|
203 |
* <p>A <code>null</code> value indicates that field is not set.</p>
|
|
204 |
*
|
|
205 |
* @param isPositive Set to <code>false</code> to create a negative duration. When the length
|
|
206 |
* of the duration is zero, this parameter will be ignored.
|
|
207 |
* @param year Year of <code>Duration</code>.
|
|
208 |
* @param month Month of <code>Duration</code>.
|
|
209 |
*
|
|
210 |
* @return New <code>Duration</code> created using the specified <code>year</code> and <code>month</code>.
|
|
211 |
*
|
|
212 |
* @throws IllegalArgumentException If the values are not a valid representation of a
|
|
213 |
* <code>Duration</code>: if all of the fields (year, month) are null or
|
|
214 |
* if any of the fields is negative.
|
|
215 |
* @throws UnsupportedOperationException If implementation cannot support requested values.
|
|
216 |
*/
|
|
217 |
public Duration newDurationYearMonth(
|
|
218 |
final boolean isPositive,
|
|
219 |
final BigInteger year,
|
|
220 |
final BigInteger month) {
|
|
221 |
|
|
222 |
return new DurationYearMonthImpl(
|
|
223 |
isPositive,
|
|
224 |
year,
|
|
225 |
month
|
|
226 |
);
|
|
227 |
|
|
228 |
}
|
|
229 |
/**
|
|
230 |
* <p>Create a <code>Duration</code> of type <code>xdt:yearMonthDuration</code> using the specified
|
|
231 |
* <code>year</code> and <code>month</code> as defined in
|
|
232 |
* <a href="http://www.w3.org/TR/xpath-datamodel#yearMonthDuration">
|
|
233 |
* XQuery 1.0 and XPath 2.0 Data Model, xdt:yearMonthDuration</a>.</p>
|
|
234 |
*
|
|
235 |
* <p>A {@link DatatypeConstants#FIELD_UNDEFINED} value indicates that field is not set.</p>
|
|
236 |
*
|
|
237 |
* @param isPositive Set to <code>false</code> to create a negative duration. When the length
|
|
238 |
* of the duration is zero, this parameter will be ignored.
|
|
239 |
* @param year Year of <code>Duration</code>.
|
|
240 |
* @param month Month of <code>Duration</code>.
|
|
241 |
*
|
|
242 |
* @return New <code>Duration</code> created using the specified <code>year</code> and <code>month</code>.
|
|
243 |
*
|
|
244 |
* @throws IllegalArgumentException If the values are not a valid representation of a
|
|
245 |
* <code>Duration</code>: if any of the fields (year, month) is negative.
|
|
246 |
*/
|
|
247 |
@Override
|
|
248 |
public Duration newDurationYearMonth(
|
|
249 |
final boolean isPositive,
|
|
250 |
final int year,
|
|
251 |
final int month) {
|
|
252 |
|
|
253 |
return new DurationYearMonthImpl(
|
|
254 |
isPositive,
|
|
255 |
year,
|
|
256 |
month);
|
|
257 |
}
|
|
258 |
|
|
259 |
/**
|
|
260 |
* <p>Create a <code>Duration</code> of type <code>xdt:yearMonthDuration</code> by parsing its <code>String</code> representation,
|
|
261 |
* "<em>PnYnM</em>", <a href="http://www.w3.org/TR/xpath-datamodel#yearMonthDuration">
|
|
262 |
* XQuery 1.0 and XPath 2.0 Data Model, xdt:yearMonthDuration</a>.</p>
|
|
263 |
*
|
|
264 |
* <p>The datatype <code>xdt:yearMonthDuration</code> is a subtype of <code>xs:duration</code>
|
|
265 |
* whose lexical representation contains only year and month components.
|
|
266 |
* This datatype resides in the namespace {@link javax.xml.XMLConstants#W3C_XPATH_DATATYPE_NS_URI}.</p>
|
|
267 |
*
|
|
268 |
* <p>Both values are set and availabe from the created {@link Duration}</p>
|
|
269 |
*
|
|
270 |
* <p>The XML Schema specification states that values can be of an arbitrary size.
|
|
271 |
* Implementations may chose not to or be incapable of supporting arbitrarily large and/or small values.
|
|
272 |
* An {@link UnsupportedOperationException} will be thrown with a message indicating implementation limits
|
|
273 |
* if implementation capacities are exceeded.</p>
|
|
274 |
*
|
|
275 |
* @param lexicalRepresentation Lexical representation of a duration.
|
|
276 |
*
|
|
277 |
* @return New <code>Duration</code> created using the specified <code>lexicalRepresentation</code>.
|
|
278 |
*
|
|
279 |
* @throws IllegalArgumentException If <code>lexicalRepresentation</code> is not a valid representation of a <code>Duration</code> expressed only in terms of years and months.
|
|
280 |
* @throws UnsupportedOperationException If implementation cannot support requested values.
|
|
281 |
* @throws NullPointerException If <code>lexicalRepresentation</code> is <code>null</code>.
|
|
282 |
*/
|
|
283 |
public Duration newDurationYearMonth(
|
|
284 |
final String lexicalRepresentation) {
|
|
285 |
|
|
286 |
return new DurationYearMonthImpl(lexicalRepresentation);
|
|
287 |
|
|
288 |
}
|
|
289 |
/**
|
|
290 |
* <p>Create a <code>Duration</code> of type <code>xdt:yearMonthDuration</code> using the specified milliseconds as defined in
|
|
291 |
* <a href="http://www.w3.org/TR/xpath-datamodel#yearMonthDuration">
|
|
292 |
* XQuery 1.0 and XPath 2.0 Data Model, xdt:yearMonthDuration</a>.</p>
|
|
293 |
*
|
|
294 |
* <p>The datatype <code>xdt:yearMonthDuration</code> is a subtype of <code>xs:duration</code>
|
|
295 |
* whose lexical representation contains only year and month components.
|
|
296 |
* This datatype resides in the namespace {@link javax.xml.XMLConstants#W3C_XPATH_DATATYPE_NS_URI}.</p>
|
|
297 |
*
|
|
298 |
* <p>Both values are set by computing their values from the specified milliseconds
|
|
299 |
* and are availabe using the <code>get</code> methods of the created {@link Duration}.
|
|
300 |
* The values conform to and are defined by:</p>
|
|
301 |
* <ul>
|
|
302 |
* <li>ISO 8601:2000(E) Section 5.5.3.2 Alternative format</li>
|
|
303 |
* <li><a href="http://www.w3.org/TR/xmlschema-2/#isoformats">
|
|
304 |
* W3C XML Schema 1.0 Part 2, Appendix D, ISO 8601 Date and Time Formats</a>
|
|
305 |
* </li>
|
|
306 |
* <li>{@link XMLGregorianCalendar} Date/Time Datatype Field Mapping Between XML Schema 1.0 and Java Representation</li>
|
|
307 |
* </ul>
|
|
308 |
*
|
|
309 |
* <p>The default start instance is defined by {@link GregorianCalendar}'s use of the start of the epoch: i.e.,
|
|
310 |
* {@link java.util.Calendar#YEAR} = 1970,
|
|
311 |
* {@link java.util.Calendar#MONTH} = {@link java.util.Calendar#JANUARY},
|
|
312 |
* {@link java.util.Calendar#DATE} = 1, etc.
|
|
313 |
* This is important as there are variations in the Gregorian Calendar,
|
|
314 |
* e.g. leap years have different days in the month = {@link java.util.Calendar#FEBRUARY}
|
|
315 |
* so the result of {@link Duration#getMonths()} can be influenced.</p>
|
|
316 |
*
|
|
317 |
* <p>Any remaining milliseconds after determining the year and month are discarded.</p>
|
|
318 |
*
|
|
319 |
* @param durationInMilliseconds Milliseconds of <code>Duration</code> to create.
|
|
320 |
*
|
|
321 |
* @return New <code>Duration</code> created using the specified <code>durationInMilliseconds</code>.
|
|
322 |
*/
|
|
323 |
public Duration newDurationYearMonth(
|
|
324 |
final long durationInMilliseconds) {
|
|
325 |
|
|
326 |
return new DurationYearMonthImpl(durationInMilliseconds);
|
|
327 |
}
|
|
328 |
|
|
329 |
/**
|
|
330 |
* <p>Create a <code>Duration</code> of type <code>xdt:dayTimeDuration</code> by parsing its <code>String</code> representation,
|
|
331 |
* "<em>PnDTnHnMnS</em>", <a href="http://www.w3.org/TR/xpath-datamodel#dayTimeDuration">
|
|
332 |
* XQuery 1.0 and XPath 2.0 Data Model, xdt:dayTimeDuration</a>.</p>
|
|
333 |
*
|
|
334 |
* <p>The datatype <code>xdt:dayTimeDuration</code> is a subtype of <code>xs:duration</code>
|
|
335 |
* whose lexical representation contains only day, hour, minute, and second components.
|
|
336 |
* This datatype resides in the namespace <code>http://www.w3.org/2003/11/xpath-datatypes</code>.</p>
|
|
337 |
*
|
|
338 |
* <p>All four values are set and availabe from the created {@link Duration}</p>
|
|
339 |
*
|
|
340 |
* <p>The XML Schema specification states that values can be of an arbitrary size.
|
|
341 |
* Implementations may chose not to or be incapable of supporting arbitrarily large and/or small values.
|
|
342 |
* An {@link UnsupportedOperationException} will be thrown with a message indicating implementation limits
|
|
343 |
* if implementation capacities are exceeded.</p>
|
|
344 |
*
|
|
345 |
* @param lexicalRepresentation Lexical representation of a duration.
|
|
346 |
*
|
|
347 |
* @return New <code>Duration</code> created using the specified <code>lexicalRepresentation</code>.
|
|
348 |
*
|
|
349 |
* @throws IllegalArgumentException If <code>lexicalRepresentation</code> is not a valid representation of a <code>Duration</code> expressed only in terms of days and time.
|
|
350 |
* @throws UnsupportedOperationException If implementation cannot support requested values.
|
|
351 |
* @throws NullPointerException If <code>lexicalRepresentation</code> is <code>null</code>.
|
|
352 |
*/
|
|
353 |
public Duration newDurationDayTime(final String lexicalRepresentation) {
|
|
354 |
// lexicalRepresentation must be non-null
|
|
355 |
if (lexicalRepresentation == null) {
|
|
356 |
throw new NullPointerException(
|
|
357 |
"Trying to create an xdt:dayTimeDuration with an invalid"
|
|
358 |
+ " lexical representation of \"null\"");
|
|
359 |
}
|
|
360 |
|
|
361 |
return new DurationDayTimeImpl(lexicalRepresentation);
|
|
362 |
}
|
|
363 |
|
|
364 |
/**
|
|
365 |
* <p>Create a <code>Duration</code> of type <code>xdt:dayTimeDuration</code> using the specified milliseconds as defined in
|
|
366 |
* <a href="http://www.w3.org/TR/xpath-datamodel#dayTimeDuration">
|
|
367 |
* XQuery 1.0 and XPath 2.0 Data Model, xdt:dayTimeDuration</a>.</p>
|
|
368 |
*
|
|
369 |
* <p>The datatype <code>xdt:dayTimeDuration</code> is a subtype of <code>xs:duration</code>
|
|
370 |
* whose lexical representation contains only day, hour, minute, and second components.
|
|
371 |
* This datatype resides in the namespace <code>http://www.w3.org/2003/11/xpath-datatypes</code>.</p>
|
|
372 |
*
|
|
373 |
* <p>All four values are set by computing their values from the specified milliseconds
|
|
374 |
* and are availabe using the <code>get</code> methods of the created {@link Duration}.
|
|
375 |
* The values conform to and are defined by:</p>
|
|
376 |
* <ul>
|
|
377 |
* <li>ISO 8601:2000(E) Section 5.5.3.2 Alternative format</li>
|
|
378 |
* <li><a href="http://www.w3.org/TR/xmlschema-2/#isoformats">
|
|
379 |
* W3C XML Schema 1.0 Part 2, Appendix D, ISO 8601 Date and Time Formats</a>
|
|
380 |
* </li>
|
|
381 |
* <li>{@link XMLGregorianCalendar} Date/Time Datatype Field Mapping Between XML Schema 1.0 and Java Representation</li>
|
|
382 |
* </ul>
|
|
383 |
*
|
|
384 |
* <p>The default start instance is defined by {@link GregorianCalendar}'s use of the start of the epoch: i.e.,
|
|
385 |
* {@link java.util.Calendar#YEAR} = 1970,
|
|
386 |
* {@link java.util.Calendar#MONTH} = {@link java.util.Calendar#JANUARY},
|
|
387 |
* {@link java.util.Calendar#DATE} = 1, etc.
|
|
388 |
* This is important as there are variations in the Gregorian Calendar,
|
|
389 |
* e.g. leap years have different days in the month = {@link java.util.Calendar#FEBRUARY}
|
|
390 |
* so the result of {@link Duration#getDays()} can be influenced.</p>
|
|
391 |
*
|
|
392 |
* <p>Any remaining milliseconds after determining the day, hour, minute and second are discarded.</p>
|
|
393 |
*
|
|
394 |
* @param durationInMilliseconds Milliseconds of <code>Duration</code> to create.
|
|
395 |
*
|
|
396 |
* @return New <code>Duration</code> created with the specified <code>durationInMilliseconds</code>.
|
|
397 |
*
|
|
398 |
* @see <a href="http://www.w3.org/TR/xpath-datamodel#dayTimeDuration">
|
|
399 |
* XQuery 1.0 and XPath 2.0 Data Model, xdt:dayTimeDuration</a>
|
|
400 |
*/
|
|
401 |
public Duration newDurationDayTime(final long durationInMilliseconds) {
|
|
402 |
|
|
403 |
return new DurationDayTimeImpl(durationInMilliseconds);
|
|
404 |
}
|
|
405 |
|
|
406 |
/**
|
|
407 |
* <p>Create a <code>Duration</code> of type <code>xdt:dayTimeDuration</code> using the specified
|
|
408 |
* <code>day</code>, <code>hour</code>, <code>minute</code> and <code>second</code> as defined in
|
|
409 |
* <a href="http://www.w3.org/TR/xpath-datamodel#dayTimeDuration">
|
|
410 |
* XQuery 1.0 and XPath 2.0 Data Model, xdt:dayTimeDuration</a>.</p>
|
|
411 |
*
|
|
412 |
* <p>The datatype <code>xdt:dayTimeDuration</code> is a subtype of <code>xs:duration</code>
|
|
413 |
* whose lexical representation contains only day, hour, minute, and second components.
|
|
414 |
* This datatype resides in the namespace <code>http://www.w3.org/2003/11/xpath-datatypes</code>.</p>
|
|
415 |
*
|
|
416 |
* <p>The XML Schema specification states that values can be of an arbitrary size.
|
|
417 |
* Implementations may chose not to or be incapable of supporting arbitrarily large and/or small values.
|
|
418 |
* An {@link UnsupportedOperationException} will be thrown with a message indicating implementation limits
|
|
419 |
* if implementation capacities are exceeded.</p>
|
|
420 |
*
|
|
421 |
* <p>A <code>null</code> value indicates that field is not set.</p>
|
|
422 |
*
|
|
423 |
* @param isPositive Set to <code>false</code> to create a negative duration. When the length
|
|
424 |
* of the duration is zero, this parameter will be ignored.
|
|
425 |
* @param day Day of <code>Duration</code>.
|
|
426 |
* @param hour Hour of <code>Duration</code>.
|
|
427 |
* @param minute Minute of <code>Duration</code>.
|
|
428 |
* @param second Second of <code>Duration</code>.
|
|
429 |
*
|
|
430 |
* @return New <code>Duration</code> created with the specified <code>day</code>, <code>hour</code>, <code>minute</code>
|
|
431 |
* and <code>second</code>.
|
|
432 |
*
|
|
433 |
* @throws IllegalArgumentException If the values are not a valid representation of a
|
|
434 |
* <code>Duration</code>: if all the fields (day, hour, ...) are null or
|
|
435 |
* if any of the fields is negative.
|
|
436 |
* @throws UnsupportedOperationException If implementation cannot support requested values.
|
|
437 |
*/
|
|
438 |
public Duration newDurationDayTime(
|
|
439 |
final boolean isPositive,
|
|
440 |
final BigInteger day,
|
|
441 |
final BigInteger hour,
|
|
442 |
final BigInteger minute,
|
|
443 |
final BigInteger second) {
|
|
444 |
|
|
445 |
return new DurationDayTimeImpl(
|
|
446 |
isPositive,
|
|
447 |
day,
|
|
448 |
hour,
|
|
449 |
minute,
|
|
450 |
(second != null)? new BigDecimal(second):null
|
|
451 |
);
|
|
452 |
}
|
|
453 |
|
|
454 |
/**
|
|
455 |
* <p>Create a <code>Duration</code> of type <code>xdt:dayTimeDuration</code> using the specified
|
|
456 |
* <code>day</code>, <code>hour</code>, <code>minute</code> and <code>second</code> as defined in
|
|
457 |
* <a href="http://www.w3.org/TR/xpath-datamodel#dayTimeDuration">
|
|
458 |
* XQuery 1.0 and XPath 2.0 Data Model, xdt:dayTimeDuration</a>.</p>
|
|
459 |
*
|
|
460 |
* <p>The datatype <code>xdt:dayTimeDuration</code> is a subtype of <code>xs:duration</code>
|
|
461 |
* whose lexical representation contains only day, hour, minute, and second components.
|
|
462 |
* This datatype resides in the namespace <code>http://www.w3.org/2003/11/xpath-datatypes</code>.</p>
|
|
463 |
*
|
|
464 |
* <p>A {@link DatatypeConstants#FIELD_UNDEFINED} value indicates that field is not set.</p>
|
|
465 |
*
|
|
466 |
* @param isPositive Set to <code>false</code> to create a negative duration. When the length
|
|
467 |
* of the duration is zero, this parameter will be ignored.
|
|
468 |
* @param day Day of <code>Duration</code>.
|
|
469 |
* @param hour Hour of <code>Duration</code>.
|
|
470 |
* @param minute Minute of <code>Duration</code>.
|
|
471 |
* @param second Second of <code>Duration</code>.
|
|
472 |
*
|
|
473 |
* @return New <code>Duration</code> created with the specified <code>day</code>, <code>hour</code>, <code>minute</code>
|
|
474 |
* and <code>second</code>.
|
|
475 |
*
|
|
476 |
* @throws IllegalArgumentException If the values are not a valid representation of a
|
|
477 |
* <code>Duration</code>: if any of the fields (day, hour, ...) is negative.
|
|
478 |
*/
|
|
479 |
public Duration newDurationDayTime(
|
|
480 |
final boolean isPositive,
|
|
481 |
final int day,
|
|
482 |
final int hour,
|
|
483 |
final int minute,
|
|
484 |
final int second) {
|
|
485 |
|
|
486 |
return new DurationDayTimeImpl(
|
|
487 |
isPositive,
|
|
488 |
day,
|
|
489 |
hour,
|
|
490 |
minute,
|
|
491 |
second
|
|
492 |
);
|
|
493 |
}
|
|
494 |
|
|
495 |
/**
|
|
496 |
* <p>Create a new instance of an <code>XMLGregorianCalendar</code>.</p>
|
|
497 |
*
|
|
498 |
* <p>All date/time datatype fields set to {@link DatatypeConstants#FIELD_UNDEFINED} or null.</p>
|
|
499 |
*
|
|
500 |
* @return New <code>XMLGregorianCalendar</code> with all date/time datatype fields set to
|
|
501 |
* {@link DatatypeConstants#FIELD_UNDEFINED} or null.
|
|
502 |
*/
|
|
503 |
public XMLGregorianCalendar newXMLGregorianCalendar() {
|
|
504 |
|
|
505 |
return new XMLGregorianCalendarImpl();
|
|
506 |
}
|
|
507 |
|
|
508 |
/**
|
|
509 |
* <p>Create a new XMLGregorianCalendar by parsing the String as a lexical representation.</p>
|
|
510 |
*
|
|
511 |
* <p>Parsing the lexical string representation is defined in
|
|
512 |
* <a href="http://www.w3.org/TR/xmlschema-2/#dateTime-order">XML Schema 1.0 Part 2, Section 3.2.[7-14].1,
|
|
513 |
* <em>Lexical Representation</em>.</a></p>
|
|
514 |
*
|
|
515 |
* <p>The string representation may not have any leading and trailing whitespaces.</p>
|
|
516 |
*
|
|
517 |
* <p>The parsing is done field by field so that
|
|
518 |
* the following holds for any lexically correct String x:</p>
|
|
519 |
* <pre>
|
|
520 |
* newXMLGregorianCalendar(x).toXMLFormat().equals(x)
|
|
521 |
* </pre>
|
|
522 |
* <p>Except for the noted lexical/canonical representation mismatches
|
|
523 |
* listed in <a href="http://www.w3.org/2001/05/xmlschema-errata#e2-45">
|
|
524 |
* XML Schema 1.0 errata, Section 3.2.7.2</a>.</p>
|
|
525 |
*
|
|
526 |
* @param lexicalRepresentation Lexical representation of one the eight XML Schema date/time datatypes.
|
|
527 |
*
|
|
528 |
* @return <code>XMLGregorianCalendar</code> created from the <code>lexicalRepresentation</code>.
|
|
529 |
*
|
|
530 |
* @throws IllegalArgumentException If the <code>lexicalRepresentation</code> is not a valid <code>XMLGregorianCalendar</code>.
|
|
531 |
* @throws NullPointerException If <code>lexicalRepresentation</code> is <code>null</code>.
|
|
532 |
*/
|
|
533 |
public XMLGregorianCalendar newXMLGregorianCalendar(final String lexicalRepresentation) {
|
|
534 |
|
|
535 |
return new XMLGregorianCalendarImpl(lexicalRepresentation);
|
|
536 |
}
|
|
537 |
|
|
538 |
/**
|
|
539 |
* <p>Create an <code>XMLGregorianCalendar</code> from a {@link GregorianCalendar}.</p>
|
|
540 |
*
|
|
541 |
* <table border="2" rules="all" cellpadding="2">
|
|
542 |
* <thead>
|
|
543 |
* <tr>
|
|
544 |
* <th align="center" colspan="2">
|
|
545 |
* Field by Field Conversion from
|
|
546 |
* {@link GregorianCalendar} to an {@link XMLGregorianCalendar}
|
|
547 |
* </th>
|
|
548 |
* </tr>
|
|
549 |
* <tr>
|
|
550 |
* <th><code>java.util.GregorianCalendar</code> field</th>
|
|
551 |
* <th><code>javax.xml.datatype.XMLGregorianCalendar</code> field</th>
|
|
552 |
* </tr>
|
|
553 |
* </thead>
|
|
554 |
* <tbody>
|
|
555 |
* <tr>
|
|
556 |
* <td><code>ERA == GregorianCalendar.BC ? -YEAR : YEAR</code></td>
|
|
557 |
* <td>{@link XMLGregorianCalendar#setYear(int year)}</td>
|
|
558 |
* </tr>
|
|
559 |
* <tr>
|
|
560 |
* <td><code>MONTH + 1</code></td>
|
|
561 |
* <td>{@link XMLGregorianCalendar#setMonth(int month)}</td>
|
|
562 |
* </tr>
|
|
563 |
* <tr>
|
|
564 |
* <td><code>DAY_OF_MONTH</code></td>
|
|
565 |
* <td>{@link XMLGregorianCalendar#setDay(int day)}</td>
|
|
566 |
* </tr>
|
|
567 |
* <tr>
|
|
568 |
* <td><code>HOUR_OF_DAY, MINUTE, SECOND, MILLISECOND</code></td>
|
|
569 |
* <td>{@link XMLGregorianCalendar#setTime(int hour, int minute, int second, BigDecimal fractional)}</td>
|
|
570 |
* </tr>
|
|
571 |
* <tr>
|
|
572 |
* <td>
|
|
573 |
* <code>(ZONE_OFFSET + DST_OFFSET) / (60*1000)</code><br/>
|
|
574 |
* <em>(in minutes)</em>
|
|
575 |
* </td>
|
|
576 |
* <td>{@link XMLGregorianCalendar#setTimezone(int offset)}<sup><em>*</em></sup>
|
|
577 |
* </td>
|
|
578 |
* </tr>
|
|
579 |
* </tbody>
|
|
580 |
* </table>
|
|
581 |
* <p><em>*</em>conversion loss of information. It is not possible to represent
|
|
582 |
* a <code>java.util.GregorianCalendar</code> daylight savings timezone id in the
|
|
583 |
* XML Schema 1.0 date/time datatype representation.</p>
|
|
584 |
*
|
|
585 |
* <p>To compute the return value's <code>TimeZone</code> field,
|
|
586 |
* <ul>
|
|
587 |
* <li>when <code>this.getTimezone() != FIELD_UNDEFINED</code>,
|
|
588 |
* create a <code>java.util.TimeZone</code> with a custom timezone id
|
|
589 |
* using the <code>this.getTimezone()</code>.</li>
|
|
590 |
* <li>else use the <code>GregorianCalendar</code> default timezone value
|
|
591 |
* for the host is defined as specified by
|
|
592 |
* <code>java.util.TimeZone.getDefault()</code>.</li></p>
|
|
593 |
*
|
|
594 |
* @param cal <code>java.util.GregorianCalendar</code> used to create <code>XMLGregorianCalendar</code>
|
|
595 |
*
|
|
596 |
* @return <code>XMLGregorianCalendar</code> created from <code>java.util.GregorianCalendar</code>
|
|
597 |
*
|
|
598 |
* @throws NullPointerException If <code>cal</code> is <code>null</code>.
|
|
599 |
*/
|
|
600 |
public XMLGregorianCalendar newXMLGregorianCalendar(final GregorianCalendar cal) {
|
|
601 |
|
|
602 |
return new XMLGregorianCalendarImpl(cal);
|
|
603 |
}
|
|
604 |
|
|
605 |
/**
|
|
606 |
* <p>Constructor allowing for complete value spaces allowed by
|
|
607 |
* W3C XML Schema 1.0 recommendation for xsd:dateTime and related
|
|
608 |
* builtin datatypes. Note that <code>year</code> parameter supports
|
|
609 |
* arbitrarily large numbers and fractionalSecond has infinite
|
|
610 |
* precision.</p>
|
|
611 |
*
|
|
612 |
* @param year of <code>XMLGregorianCalendar</code> to be created.
|
|
613 |
* @param month of <code>XMLGregorianCalendar</code> to be created.
|
|
614 |
* @param day of <code>XMLGregorianCalendar</code> to be created.
|
|
615 |
* @param hour of <code>XMLGregorianCalendar</code> to be created.
|
|
616 |
* @param minute of <code>XMLGregorianCalendar</code> to be created.
|
|
617 |
* @param second of <code>XMLGregorianCalendar</code> to be created.
|
|
618 |
* @param fractionalSecond of <code>XMLGregorianCalendar</code> to be created.
|
|
619 |
* @param timezone of <code>XMLGregorianCalendar</code> to be created.
|
|
620 |
*
|
|
621 |
* @return <code>XMLGregorianCalendar</code> created from specified values.
|
|
622 |
*
|
|
623 |
* @throws IllegalArgumentException If any individual parameter's value is outside the maximum value constraint for the field
|
|
624 |
* as determined by the Date/Time Data Mapping table in {@link XMLGregorianCalendar}
|
|
625 |
* or if the composite values constitute an invalid <code>XMLGregorianCalendar</code> instance
|
|
626 |
* as determined by {@link XMLGregorianCalendar#isValid()}.
|
|
627 |
* @throws NullPointerException If any parameters are <code>null</code>.
|
|
628 |
*
|
|
629 |
*/
|
|
630 |
public XMLGregorianCalendar newXMLGregorianCalendar(
|
|
631 |
final BigInteger year,
|
|
632 |
final int month,
|
|
633 |
final int day,
|
|
634 |
final int hour,
|
|
635 |
final int minute,
|
|
636 |
final int second,
|
|
637 |
final BigDecimal fractionalSecond,
|
|
638 |
final int timezone) {
|
|
639 |
|
|
640 |
return new XMLGregorianCalendarImpl(
|
|
641 |
year,
|
|
642 |
month,
|
|
643 |
day,
|
|
644 |
hour,
|
|
645 |
minute,
|
|
646 |
second,
|
|
647 |
fractionalSecond,
|
|
648 |
timezone
|
|
649 |
);
|
|
650 |
}
|
|
651 |
}
|