/*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
package javax.xml.bind;
import javax.xml.namespace.NamespaceContext;
/**
* <p>
* The javaType binding declaration can be used to customize the binding of
* an XML schema datatype to a Java datatype. Customizations can involve
* writing a parse and print method for parsing and printing lexical
* representations of a XML schema datatype respectively. However, writing
* parse and print methods requires knowledge of the lexical representations (
* <a href="http://www.w3.org/TR/xmlschema-2/"> XML Schema Part2: Datatypes
* specification </a>) and hence may be difficult to write.
* </p>
* <p>
* This class makes it easier to write parse and print methods. It defines
* static parse and print methods that provide access to a JAXB provider's
* implementation of parse and print methods. These methods are invoked by
* custom parse and print methods. For example, the binding of xsd:dateTime
* to a long can be customized using parse and print methods as follows:
* <blockquote>
* <pre>
* // Customized parse method
* public long myParseCal( String dateTimeString ) {
* java.util.Calendar cal = DatatypeConverter.parseDateTime(dateTimeString);
* long longval = convert_calendar_to_long(cal); //application specific
* return longval;
* }
*
* // Customized print method
* public String myPrintCal( Long longval ) {
* java.util.Calendar cal = convert_long_to_calendar(longval) ; //application specific
* String dateTimeString = DatatypeConverter.printDateTime(cal);
* return dateTimeString;
* }
* </pre>
* </blockquote>
* <p>
* There is a static parse and print method corresponding to each parse and
* print method respectively in the {@link DatatypeConverterInterface
* DatatypeConverterInterface}.
* <p>
* The static methods defined in the class can also be used to specify
* a parse or a print method in a javaType binding declaration.
* </p>
* <p>
* JAXB Providers are required to call the
* {@link #setDatatypeConverter(DatatypeConverterInterface)
* setDatatypeConverter} api at some point before the first marshal or unmarshal
* operation (perhaps during the call to JAXBContext.newInstance). This step is
* necessary to configure the converter that should be used to perform the
* print and parse functionality.
* </p>
*
* <p>
* A print method for a XML schema datatype can output any lexical
* representation that is valid with respect to the XML schema datatype.
* If an error is encountered during conversion, then an IllegalArgumentException,
* or a subclass of IllegalArgumentException must be thrown by the method.
* </p>
*
* @author <ul><li>Sekhar Vajjhala, Sun Microsystems, Inc.</li><li>Joe Fialli, Sun Microsystems Inc.</li><li>Kohsuke
Kawaguchi, Sun Microsystems, Inc.</li><li>Ryan Shoemaker,Sun Microsystems Inc.</li></ul>
* @version $Revision: 1.2 $
* @see DatatypeConverterInterface
* @see ParseConversionEvent
* @see PrintConversionEvent
* @since JAXB1.0
*/
final public class DatatypeConverter {
// delegate to this instance of DatatypeConverter
private static DatatypeConverterInterface theConverter = null;
private DatatypeConverter() {
// private constructor
}
/**
* This method is for JAXB provider use only.
* <p>
* JAXB Providers are required to call this method at some point before
* allowing any of the JAXB client marshal or unmarshal operations to
* occur. This is necessary to configure the datatype converter that
* should be used to perform the print and parse conversions.
*
* <p>
* Calling this api repeatedly will have no effect - the
* DatatypeConverterInterface instance passed into the first invocation is
* the one that will be used from then on.
*
* @param converter an instance of a class that implements the
* DatatypeConverterInterface class - this parameter must not be null.
* @throws IllegalArgumentException if the parameter is null
*/
=1= |