background image

Syntax for the javaType customization

<< javaType Binding Declarations | Typesafe Enumeration Binding Declarations >>
<< javaType Binding Declarations | Typesafe Enumeration Binding Declarations >>
46
U
SING
JAXB
If you prefer to define your own datatype conversions, JAXB defines a static
class,
DatatypeConverter
, to assist in the parsing and printing of valid lexical
representations of the XML Schema built-in datatypes.
The syntax for the
<javaType>
customization is:
<javaType name= "javaType"
[ xmlType= "xmlType" ]
[ hasNsContext = "true" | "false" ]
[ parseMethod= "parseMethod" ]
[ printMethod= "printMethod" ]>
·
name
is the Java datatype to which
xmlType
is to be bound.
·
xmlType
is the name of the XML Schema datatype to which
javaType
is
to bound; this attribute is required when the parent of the
<javaType>
dec-
laration is
<globalBindings>
.
·
parseMethod
is the name of the parse method to be called during unmar-
shalling.
·
printMethod
is the name of the print method to be called during marshal-
ling.
·
hasNsContext
allows a namespace context to be specified as a second
parameter to a print or a parse method; can be either
true
,
false
,
1
, or
0
.
By default, this attribute is
false
, and in most cases you will not need to
change it.
The
<javaType>
declaration can be used in:
· A
<globalBindings>
declaration
· An annotation element for simple type definitions,
GlobalBindings
, and
<basetype>
declarations.
· A
<property>
declaration.
See MyDatatypeConverter Class (page 54) for an example of how
<javaType>
declarations and the
DatatypeConverterInterface
interface are implemented
in a custom datatype converter class.