Save This Page
Home » Open-JDK-6.b17-src » com.sun.org.apache.xerces.internal » jaxp » datatype » [javadoc | source]
    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>
   44    *      If the file ${JAVA_HOME}/lib/jaxp.properties exists, it is loaded in a {@link java.util.Properties} <code>Object</code>.
   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           /**
  194            * <p>Create a new instance of an <code>XMLGregorianCalendar</code>.</p>
  195            *
  196        * <p>All date/time datatype fields set to {@link DatatypeConstants#FIELD_UNDEFINED} or null.</p>
  197        *
  198        * @return New <code>XMLGregorianCalendar</code> with all date/time datatype fields set to
  199        *   {@link DatatypeConstants#FIELD_UNDEFINED} or null.
  200            */
  201           public XMLGregorianCalendar newXMLGregorianCalendar() {
  202   
  203                   return new XMLGregorianCalendarImpl();
  204           }
  205   
  206           /**
  207            * <p>Create a new XMLGregorianCalendar by parsing the String as a lexical representation.</p>
  208            *
  209        * <p>Parsing the lexical string representation is defined in
  210        * <a href="http://www.w3.org/TR/xmlschema-2/#dateTime-order">XML Schema 1.0 Part 2, Section 3.2.[7-14].1,
  211        * <em>Lexical Representation</em>.</a></p>
  212        *
  213        * <p>The string representation may not have any leading and trailing whitespaces.</p>
  214        *
  215        * <p>The parsing is done field by field so that
  216        * the following holds for any lexically correct String x:</p>
  217        * <pre>
  218        * newXMLGregorianCalendar(x).toXMLFormat().equals(x)
  219        * </pre>
  220        * <p>Except for the noted lexical/canonical representation mismatches
  221        * listed in <a href="http://www.w3.org/2001/05/xmlschema-errata#e2-45">
  222        * XML Schema 1.0 errata, Section 3.2.7.2</a>.</p>
  223            *
  224            * @param lexicalRepresentation Lexical representation of one the eight XML Schema date/time datatypes.
  225            *
  226            * @return <code>XMLGregorianCalendar</code> created from the <code>lexicalRepresentation</code>.
  227            *
  228            * @throws IllegalArgumentException If the <code>lexicalRepresentation</code> is not a valid <code>XMLGregorianCalendar</code>.
  229            * @throws NullPointerException If <code>lexicalRepresentation</code> is <code>null</code>.
  230            */
  231           public XMLGregorianCalendar newXMLGregorianCalendar(final String lexicalRepresentation) {
  232   
  233                   return new XMLGregorianCalendarImpl(lexicalRepresentation);
  234           }
  235   
  236           /**
  237            * <p>Create an <code>XMLGregorianCalendar</code> from a {@link GregorianCalendar}.</p>
  238            *
  239            * <table border="2" rules="all" cellpadding="2">
  240            *   <thead>
  241            *     <tr>
  242            *       <th align="center" colspan="2">
  243            *          Field by Field Conversion from
  244            *          {@link GregorianCalendar} to an {@link XMLGregorianCalendar}
  245            *       </th>
  246            *     </tr>
  247            *     <tr>
  248            *        <th><code>java.util.GregorianCalendar</code> field</th>
  249            *        <th><code>javax.xml.datatype.XMLGregorianCalendar</code> field</th>
  250            *     </tr>
  251            *   </thead>
  252            *   <tbody>
  253            *     <tr>
  254            *       <td><code>ERA == GregorianCalendar.BC ? -YEAR : YEAR</code></td>
  255            *       <td>{@link XMLGregorianCalendar#setYear(int year)}</td>
  256            *     </tr>
  257            *     <tr>
  258            *       <td><code>MONTH + 1</code></td>
  259            *       <td>{@link XMLGregorianCalendar#setMonth(int month)}</td>
  260            *     </tr>
  261            *     <tr>
  262            *       <td><code>DAY_OF_MONTH</code></td>
  263            *       <td>{@link XMLGregorianCalendar#setDay(int day)}</td>
  264            *     </tr>
  265            *     <tr>
  266            *       <td><code>HOUR_OF_DAY, MINUTE, SECOND, MILLISECOND</code></td>
  267            *       <td>{@link XMLGregorianCalendar#setTime(int hour, int minute, int second, BigDecimal fractional)}</td>
  268            *     </tr>
  269            *     <tr>
  270            *       <td>
  271            *         <code>(ZONE_OFFSET + DST_OFFSET) / (60*1000)</code><br/>
  272            *         <em>(in minutes)</em>
  273            *       </td>
  274            *       <td>{@link XMLGregorianCalendar#setTimezone(int offset)}<sup><em>*</em></sup>
  275            *       </td>
  276            *     </tr>
  277            *   </tbody>
  278            * </table>
  279            * <p><em>*</em>conversion loss of information. It is not possible to represent
  280            * a <code>java.util.GregorianCalendar</code> daylight savings timezone id in the
  281            * XML Schema 1.0 date/time datatype representation.</p>
  282            *
  283            * <p>To compute the return value's <code>TimeZone</code> field,
  284            * <ul>
  285            * <li>when <code>this.getTimezone() != FIELD_UNDEFINED</code>,
  286            * create a <code>java.util.TimeZone</code> with a custom timezone id
  287            * using the <code>this.getTimezone()</code>.</li>
  288            * <li>else use the <code>GregorianCalendar</code> default timezone value
  289            * for the host is defined as specified by
  290            * <code>java.util.TimeZone.getDefault()</code>.</li></p>
  291            *
  292            * @param cal <code>java.util.GregorianCalendar</code> used to create <code>XMLGregorianCalendar</code>
  293            *
  294            * @return <code>XMLGregorianCalendar</code> created from <code>java.util.GregorianCalendar</code>
  295            *
  296            * @throws NullPointerException If <code>cal</code> is <code>null</code>.
  297            */
  298           public XMLGregorianCalendar newXMLGregorianCalendar(final GregorianCalendar cal) {
  299   
  300                   return new XMLGregorianCalendarImpl(cal);
  301           }
  302   
  303           /**
  304            * <p>Constructor allowing for complete value spaces allowed by
  305            * W3C XML Schema 1.0 recommendation for xsd:dateTime and related
  306            * builtin datatypes. Note that <code>year</code> parameter supports
  307            * arbitrarily large numbers and fractionalSecond has infinite
  308            * precision.</p>
  309            *
  310            * @param year of <code>XMLGregorianCalendar</code> to be created.
  311            * @param month of <code>XMLGregorianCalendar</code> to be created.
  312            * @param day of <code>XMLGregorianCalendar</code> to be created.
  313            * @param hour of <code>XMLGregorianCalendar</code> to be created.
  314            * @param minute of <code>XMLGregorianCalendar</code> to be created.
  315            * @param second of <code>XMLGregorianCalendar</code> to be created.
  316            * @param fractionalSecond of <code>XMLGregorianCalendar</code> to be created.
  317            * @param timezone of <code>XMLGregorianCalendar</code> to be created.
  318            *
  319            * @return <code>XMLGregorianCalendar</code> created from specified values.
  320            *
  321            * @throws IllegalArgumentException If any individual parameter's value is outside the maximum value constraint for the field
  322            *   as determined by the Date/Time Data Mapping table in {@link XMLGregorianCalendar}
  323            *   or if the composite values constitute an invalid <code>XMLGregorianCalendar</code> instance
  324            *   as determined by {@link XMLGregorianCalendar#isValid()}.
  325            * @throws NullPointerException If any parameters are <code>null</code>.
  326            *
  327            */
  328           public XMLGregorianCalendar newXMLGregorianCalendar(
  329                   final BigInteger year,
  330                   final int month,
  331                   final int day,
  332                   final int hour,
  333                   final int minute,
  334                   final int second,
  335                   final BigDecimal fractionalSecond,
  336                   final int timezone) {
  337   
  338                   return new XMLGregorianCalendarImpl(
  339                           year,
  340                           month,
  341                           day,
  342                           hour,
  343                           minute,
  344                           second,
  345                           fractionalSecond,
  346                           timezone
  347                   );
  348           }
  349   }

Save This Page
Home » Open-JDK-6.b17-src » com.sun.org.apache.xerces.internal » jaxp » datatype » [javadoc | source]