Java Doc for DatatypeConverter.java in  » 6.0-JDK-Core » xml » javax » xml » bind » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » xml » javax.xml.bind 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   javax.xml.bind.DatatypeConverter

DatatypeConverter
final public class DatatypeConverter (Code)

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 ( XML Schema Part2: Datatypes specification ) and hence may be difficult to write.

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:

 // 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;
 }
 

There is a static parse and print method corresponding to each parse and print method respectively in the DatatypeConverterInterface DatatypeConverterInterface .

The static methods defined in the class can also be used to specify a parse or a print method in a javaType binding declaration.

JAXB Providers are required to call the DatatypeConverter.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.

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.


author:
  
  • Sekhar Vajjhala, Sun Microsystems, Inc.
  • Joe Fialli, Sun Microsystems Inc.
  • Kohsuke Kawaguchi, Sun Microsystems, Inc.
  • Ryan Shoemaker,Sun Microsystems Inc.

version:
   $Revision: 1.2 $
See Also:   DatatypeConverterInterface
See Also:   ParseConversionEvent
See Also:   PrintConversionEvent
since:
   JAXB1.0




Method Summary
public static  StringparseAnySimpleType(String lexicalXSDAnySimpleType)
    

Return a string containing the lexical representation of the simple type.

public static  byte[]parseBase64Binary(String lexicalXSDBase64Binary)
    

Converts the string argument into an array of bytes.

public static  booleanparseBoolean(String lexicalXSDBoolean)
    

Converts the string argument into a boolean value.

public static  byteparseByte(String lexicalXSDByte)
    

Converts the string argument into a byte value.

public static  java.util.CalendarparseDate(String lexicalXSDDate)
    

Converts the string argument into a Calendar value.

public static  java.util.CalendarparseDateTime(String lexicalXSDDateTime)
    

Converts the string argument into a Calendar value.

public static  java.math.BigDecimalparseDecimal(String lexicalXSDDecimal)
    

Converts the string argument into a BigDecimal value.

public static  doubleparseDouble(String lexicalXSDDouble)
    

Converts the string argument into a double value.

public static  floatparseFloat(String lexicalXSDFloat)
    

Converts the string argument into a float value.

public static  byte[]parseHexBinary(String lexicalXSDHexBinary)
    

Converts the string argument into an array of bytes.

public static  intparseInt(String lexicalXSDInt)
    

Convert the string argument into an int value.

public static  java.math.BigIntegerparseInteger(String lexicalXSDInteger)
    

Convert the string argument into a BigInteger value.

public static  longparseLong(String lexicalXSDLong)
    

Converts the string argument into a long value.

public static  javax.xml.namespace.QNameparseQName(String lexicalXSDQName, NamespaceContext nsc)
    

Converts the string argument into a byte value.

public static  shortparseShort(String lexicalXSDShort)
    

Converts the string argument into a short value.

public static  StringparseString(String lexicalXSDString)
    

Convert the lexical XSD string argument into a String value.

public static  java.util.CalendarparseTime(String lexicalXSDTime)
    

Converts the string argument into a Calendar value.

public static  longparseUnsignedInt(String lexicalXSDUnsignedInt)
    

Converts the string argument into a long value.

public static  intparseUnsignedShort(String lexicalXSDUnsignedShort)
    

Converts the string argument into an int value.

public static  StringprintAnySimpleType(String val)
    

Converts a string value into a string.

public static  StringprintBase64Binary(byte[] val)
    

Converts an array of bytes into a string.

public static  StringprintBoolean(boolean val)
    

Converts a boolean value into a string.

public static  StringprintByte(byte val)
    

Converts a byte value into a string.

public static  StringprintDate(java.util.Calendar val)
    

Converts a Calendar value into a string.

public static  StringprintDateTime(java.util.Calendar val)
    

Converts a Calendar value into a string.

public static  StringprintDecimal(java.math.BigDecimal val)
    

Converts a BigDecimal value into a string.

public static  StringprintDouble(double val)
    

Converts a double value into a string.

public static  StringprintFloat(float val)
    

Converts a float value into a string.

public static  StringprintHexBinary(byte[] val)
    

Converts an array of bytes into a string.

public static  StringprintInt(int val)
    

Converts an int value into a string.

public static  StringprintInteger(java.math.BigInteger val)
    

Converts a BigInteger value into a string.

public static  StringprintLong(long val)
    

Converts A long value into a string.

public static  StringprintQName(javax.xml.namespace.QName val, NamespaceContext nsc)
    

Converts a QName instance into a string.

public static  StringprintShort(short val)
    

Converts a short value into a string.

public static  StringprintString(String val)
    

Converts the string argument into a string.

public static  StringprintTime(java.util.Calendar val)
    

Converts a Calendar value into a string.

public static  StringprintUnsignedInt(long val)
    

Converts a long value into a string.

public static  StringprintUnsignedShort(int val)
    

Converts an int value into a string.

public static  voidsetDatatypeConverter(DatatypeConverterInterface converter)
     This method is for JAXB provider use only.

JAXB Providers are required to call this method at some point before allowing any of the JAXB client marshal or unmarshal operations to occur.




Method Detail
parseAnySimpleType
public static String parseAnySimpleType(String lexicalXSDAnySimpleType)(Code)

Return a string containing the lexical representation of the simple type.
Parameters:
  lexicalXSDAnySimpleType - A string containing lexicalrepresentation of the simple type.A string containing the lexical representation of the simple type.




parseBase64Binary
public static byte[] parseBase64Binary(String lexicalXSDBase64Binary)(Code)

Converts the string argument into an array of bytes.
Parameters:
  lexicalXSDBase64Binary - A string containing lexical representationof xsd:base64Binary.An array of bytes represented by the string argument.
throws:
  IllegalArgumentException - if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:base64Binary




parseBoolean
public static boolean parseBoolean(String lexicalXSDBoolean)(Code)

Converts the string argument into a boolean value.
Parameters:
  lexicalXSDBoolean - A string containing lexical representation ofxsd:boolean.A boolean value represented by the string argument.
throws:
  IllegalArgumentException - if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:boolean.




parseByte
public static byte parseByte(String lexicalXSDByte)(Code)

Converts the string argument into a byte value.
Parameters:
  lexicalXSDByte - A string containing lexical representation ofxsd:byte.A byte value represented by the string argument.
throws:
  IllegalArgumentException - if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:byte.




parseDate
public static java.util.Calendar parseDate(String lexicalXSDDate)(Code)

Converts the string argument into a Calendar value.
Parameters:
  lexicalXSDDate - A string containing lexical representation ofxsd:Date.A Calendar value represented by the string argument.
throws:
  IllegalArgumentException - if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:Date.




parseDateTime
public static java.util.Calendar parseDateTime(String lexicalXSDDateTime)(Code)

Converts the string argument into a Calendar value.
Parameters:
  lexicalXSDDateTime - A string containing lexical representation ofxsd:datetime.A Calendar object represented by the string argument.
throws:
  IllegalArgumentException - if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:dateTime.




parseDecimal
public static java.math.BigDecimal parseDecimal(String lexicalXSDDecimal)(Code)

Converts the string argument into a BigDecimal value.
Parameters:
  lexicalXSDDecimal - A string containing lexical representation ofxsd:decimal.A BigDecimal value represented by the string argument.
throws:
  NumberFormatException - lexicalXSDDecimal is not a valid string representation of java.math.BigDecimal.




parseDouble
public static double parseDouble(String lexicalXSDDouble)(Code)

Converts the string argument into a double value.
Parameters:
  lexicalXSDDouble - A string containing lexical representation ofxsd:double.A double value represented by the string argument.
throws:
  NumberFormatException - lexicalXSDDouble is not a valid string representation of a double value.




parseFloat
public static float parseFloat(String lexicalXSDFloat)(Code)

Converts the string argument into a float value.
Parameters:
  lexicalXSDFloat - A string containing lexical representation ofxsd:float.A float value represented by the string argument.
throws:
  NumberFormatException - lexicalXSDFloat is not a valid string representation of a float value.




parseHexBinary
public static byte[] parseHexBinary(String lexicalXSDHexBinary)(Code)

Converts the string argument into an array of bytes.
Parameters:
  lexicalXSDHexBinary - A string containing lexical representation ofxsd:hexBinary.An array of bytes represented by the string argument.
throws:
  IllegalArgumentException - if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:hexBinary.




parseInt
public static int parseInt(String lexicalXSDInt)(Code)

Convert the string argument into an int value.
Parameters:
  lexicalXSDInt - A string containing a lexical representation ofxsd:int.A int value represented by the string argument.
throws:
  NumberFormatException - lexicalXSDInt is not a valid string representation of an int value.




parseInteger
public static java.math.BigInteger parseInteger(String lexicalXSDInteger)(Code)

Convert the string argument into a BigInteger value.
Parameters:
  lexicalXSDInteger - A string containing a lexical representation ofxsd:integer.A BigInteger value represented by the string argument.
throws:
  NumberFormatException - lexicalXSDInteger is not a valid string representation of a java.math.BigInteger value.




parseLong
public static long parseLong(String lexicalXSDLong)(Code)

Converts the string argument into a long value.
Parameters:
  lexicalXSDLong - A string containing lexical representation ofxsd:long.A long value represented by the string argument.
throws:
  NumberFormatException - lexicalXSDLong is not a valid string representation of a long value.




parseQName
public static javax.xml.namespace.QName parseQName(String lexicalXSDQName, NamespaceContext nsc)(Code)

Converts the string argument into a byte value.

String parameter lexicalXSDQname must conform to lexical value space specifed at XML Schema Part 2:Datatypes specification:QNames
Parameters:
  lexicalXSDQName - A string containing lexical representation of xsd:QName.
Parameters:
  nsc - A namespace context for interpreting a prefix within a QName.A QName value represented by the string argument.
throws:
  IllegalArgumentException - if string parameter does not conform to XML Schema Part 2 specification or if namespace prefix of lexicalXSDQname is not bound to a URI in NamespaceContext nsc.




parseShort
public static short parseShort(String lexicalXSDShort)(Code)

Converts the string argument into a short value.
Parameters:
  lexicalXSDShort - A string containing lexical representation ofxsd:short.A short value represented by the string argument.
throws:
  NumberFormatException - lexicalXSDShort is not a valid string representation of a short value.




parseString
public static String parseString(String lexicalXSDString)(Code)

Convert the lexical XSD string argument into a String value.
Parameters:
  lexicalXSDString - A string containing a lexical representation ofxsd:string.A String value represented by the string argument.




parseTime
public static java.util.Calendar parseTime(String lexicalXSDTime)(Code)

Converts the string argument into a Calendar value.
Parameters:
  lexicalXSDTime - A string containing lexical representation ofxsd:time.A Calendar value represented by the string argument.
throws:
  IllegalArgumentException - if string parameter does not conform to lexical value space defined in XML Schema Part 2: Datatypes for xsd:Time.




parseUnsignedInt
public static long parseUnsignedInt(String lexicalXSDUnsignedInt)(Code)

Converts the string argument into a long value.
Parameters:
  lexicalXSDUnsignedInt - A string containing lexical representationof xsd:unsignedInt.A long value represented by the string argument.
throws:
  NumberFormatException - if string parameter can not be parsed into a long value.




parseUnsignedShort
public static int parseUnsignedShort(String lexicalXSDUnsignedShort)(Code)

Converts the string argument into an int value.
Parameters:
  lexicalXSDUnsignedShort - A string containing lexicalrepresentation of xsd:unsignedShort.An int value represented by the string argument.
throws:
  NumberFormatException - if string parameter can not be parsed into an int value.




printAnySimpleType
public static String printAnySimpleType(String val)(Code)

Converts a string value into a string.
Parameters:
  val - A string valueA string containing a lexical representation of xsd:AnySimpleType




printBase64Binary
public static String printBase64Binary(byte[] val)(Code)

Converts an array of bytes into a string.
Parameters:
  val - An array of bytesA string containing a lexical representation of xsd:base64Binary
throws:
  IllegalArgumentException - if val is null.




printBoolean
public static String printBoolean(boolean val)(Code)

Converts a boolean value into a string.
Parameters:
  val - A boolean valueA string containing a lexical representation of xsd:boolean




printByte
public static String printByte(byte val)(Code)

Converts a byte value into a string.
Parameters:
  val - A byte valueA string containing a lexical representation of xsd:byte




printDate
public static String printDate(java.util.Calendar val)(Code)

Converts a Calendar value into a string.
Parameters:
  val - A Calendar valueA string containing a lexical representation of xsd:date
throws:
  IllegalArgumentException - if val is null.




printDateTime
public static String printDateTime(java.util.Calendar val)(Code)

Converts a Calendar value into a string.
Parameters:
  val - A Calendar valueA string containing a lexical representation of xsd:dateTime
throws:
  IllegalArgumentException - if val is null.




printDecimal
public static String printDecimal(java.math.BigDecimal val)(Code)

Converts a BigDecimal value into a string.
Parameters:
  val - A BigDecimal valueA string containing a lexical representation of xsd:decimal
throws:
  IllegalArgumentException - val is null.




printDouble
public static String printDouble(double val)(Code)

Converts a double value into a string.
Parameters:
  val - A double valueA string containing a lexical representation of xsd:double




printFloat
public static String printFloat(float val)(Code)

Converts a float value into a string.
Parameters:
  val - A float valueA string containing a lexical representation of xsd:float




printHexBinary
public static String printHexBinary(byte[] val)(Code)

Converts an array of bytes into a string.
Parameters:
  val - An array of bytesA string containing a lexical representation of xsd:hexBinary
throws:
  IllegalArgumentException - if val is null.




printInt
public static String printInt(int val)(Code)

Converts an int value into a string.
Parameters:
  val - An int valueA string containing a lexical representation of xsd:int




printInteger
public static String printInteger(java.math.BigInteger val)(Code)

Converts a BigInteger value into a string.
Parameters:
  val - A BigInteger valueA string containing a lexical representation of xsd:integer
throws:
  IllegalArgumentException - val is null.




printLong
public static String printLong(long val)(Code)

Converts A long value into a string.
Parameters:
  val - A long valueA string containing a lexical representation of xsd:long




printQName
public static String printQName(javax.xml.namespace.QName val, NamespaceContext nsc)(Code)

Converts a QName instance into a string.
Parameters:
  val - A QName value
Parameters:
  nsc - A namespace context for interpreting a prefix within a QName.A string containing a lexical representation of QName
throws:
  IllegalArgumentException - if val is null or if nsc is non-null or nsc.getPrefix(nsprefixFromVal) is null.




printShort
public static String printShort(short val)(Code)

Converts a short value into a string.
Parameters:
  val - A short valueA string containing a lexical representation of xsd:short




printString
public static String printString(String val)(Code)

Converts the string argument into a string.
Parameters:
  val - A string value.A string containing a lexical representation of xsd:string.




printTime
public static String printTime(java.util.Calendar val)(Code)

Converts a Calendar value into a string.
Parameters:
  val - A Calendar valueA string containing a lexical representation of xsd:time
throws:
  IllegalArgumentException - if val is null.




printUnsignedInt
public static String printUnsignedInt(long val)(Code)

Converts a long value into a string.
Parameters:
  val - A long valueA string containing a lexical representation of xsd:unsignedInt




printUnsignedShort
public static String printUnsignedShort(int val)(Code)

Converts an int value into a string.
Parameters:
  val - An int valueA string containing a lexical representation of xsd:unsignedShort




setDatatypeConverter
public static void setDatatypeConverter(DatatypeConverterInterface converter)(Code)
This method is for JAXB provider use only.

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.

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.
Parameters:
  converter - an instance of a class that implements the DatatypeConverterInterface class - this parameter must not be null.
throws:
  IllegalArgumentException - if the parameter is null




Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.