|
Préférences
Moteurs de recherche
|
|||||||||||||||||||||||||||||||||||||||
JavaTM Platform, Enterprise Edition, v 5.0
javax.xml.bind
|
Field Summary | |
---|---|
static String |
JAXB_CONTEXT_FACTORY
The name of the property that contains the name of the class capable of creating new JAXBContext objects. |
Constructor Summary | |
---|---|
protected |
JAXBContext()
|
Method Summary | ||
---|---|---|
Binder<Node> |
createBinder()
Creates a Binder for W3C DOM. |
|
|
createBinder(Class<T> domType)
Creates a Binder object that can be used for associative/in-place unmarshalling/marshalling. |
|
JAXBIntrospector |
createJAXBIntrospector()
Creates a JAXBIntrospector object that can be used to introspect JAXB objects. |
|
abstract Marshaller |
createMarshaller()
Create a Marshaller object that can be used to convert a java content tree into XML data. |
|
abstract Unmarshaller |
createUnmarshaller()
Create an Unmarshaller object that can be used to convert XML data into a java content tree. |
|
abstract Validator |
createValidator()
Deprecated. since JAXB2.0 |
|
void |
generateSchema(SchemaOutputResolver outputResolver)
Generates the schema documents for this context. |
|
static JAXBContext |
newInstance(Class... classesToBeBound)
Obtain a new instance of a JAXBContext class. |
|
static JAXBContext |
newInstance(Class[] classesToBeBound,
Map<String,?> properties)
Obtain a new instance of a JAXBContext class. |
|
static JAXBContext |
newInstance(String contextPath)
Obtain a new instance of a JAXBContext class. |
|
static JAXBContext |
newInstance(String contextPath,
ClassLoader classLoader)
Obtain a new instance of a JAXBContext class. |
|
static JAXBContext |
newInstance(String contextPath,
ClassLoader classLoader,
Map<String,?> properties)
Obtain a new instance of a JAXBContext class. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String JAXB_CONTEXT_FACTORY
Constructor Detail |
---|
protected JAXBContext()
Method Detail |
---|
public static JAXBContext newInstance(String contextPath) throws JAXBException
Obtain a new instance of a JAXBContext class.
This is a convenience method for the
newInstance
method. It uses
the context class loader of the current thread. To specify the use of
a different class loader, either set it via the
Thread.setContextClassLoader() api or use the
newInstance
method.
JAXBException
- if an error was encountered while creating the
JAXBContext such as
public static JAXBContext newInstance(String contextPath, ClassLoader classLoader) throws JAXBException
Obtain a new instance of a JAXBContext class.
The client application must supply a context path which is a list of colon (':', \u003A) separated java package names that contain schema-derived classes and/or fully qualified JAXB-annotated classes. Schema-derived code is registered with the JAXBContext by the ObjectFactory.class generated per package. Alternatively than being listed in the context path, programmer annotated JAXB mapped classes can be listed in a jaxb.index resource file, format described below. Note that a java package can contain both schema-derived classes and user annotated JAXB classes. Additionally, the java package may contain JAXB package annotations that must be processed. (see JLS 3rd Edition, Section 7.4.1. "Package Annotations").
Every package listed on the contextPath must meet one or both of the following conditions otherwise a JAXBException will be thrown:
Format for jaxb.index
The file contains a newline-separated list of class names.
Space and tab characters, as well as blank
lines, are ignored. The comment character
is '#' (0x23); on each line all characters following the first comment
character are ignored. The file must be encoded in UTF-8. Classes that
are reachable, as defined in newInstance(Class...)
, from the
listed classes are also registered with JAXBContext.
Constraints on class name occuring in a jaxb.index file are:
To maintain compatibility with JAXB 1.0 schema to java
interface/implementation binding, enabled by schema customization
If there are any global XML element name collisions across the various packages listed on the contextPath, a JAXBException will be thrown.
Mixing generated interface/impl bindings from multiple JAXB Providers in the same context path may result in a JAXBException being thrown.
contextPath
- list of java package names that contain schema
derived class and/or java to schema (JAXB-annotated)
mapped classesclassLoader
- This class loader will be used to locate the implementation
classes.
JAXBException
- if an error was encountered while creating the
JAXBContext such as
public static JAXBContext newInstance(String contextPath, ClassLoader classLoader, Map<String,?> properties) throws JAXBException
Obtain a new instance of a JAXBContext class.
This is mostly the same as newInstance(String, ClassLoader)
,
but this version allows you to pass in provider-specific properties to configure
the instanciation of JAXBContext
.
The interpretation of properties is up to implementations.
contextPath
- list of java package names that contain schema derived classesclassLoader
- This class loader will be used to locate the implementation classes.properties
- provider-specific properties
JAXBException
- if an error was encountered while creating the
JAXBContext such as
public static JAXBContext newInstance(Class... classesToBeBound) throws JAXBException
Obtain a new instance of a JAXBContext class.
The client application must supply a list of classes that the new
context object needs to recognize.
Not only the new context will recognize all the classes specified,
but it will also recognize any classes that are directly/indirectly
referenced statically from the specified classes. Subclasses of
referenced classes nor @XmlTransient referenced classes
are not registered with JAXBContext.
For example, in the following Java code, if you do
newInstance(Foo.class), the newly created JAXBContext
will recognize both Foo and Bar, but not Zot or FooBar:
class Foo { @XmlTransient FooBar c; Bar b; } class Bar { int x; } class Zot extends Bar { int y; } class FooBar { }Therefore, a typical client application only needs to specify the top-level classes, but it needs to be careful.
Note that for each java package registered with JAXBContext, when the optional package annotations exist, they must be processed. (see JLS 3rd Edition, Section 7.4.1. "Package Annotations").
classesToBeBound
- list of java classes to be recognized by the new JAXBContext
.
Can be empty, in which case a JAXBContext
that only knows about
spec-defined classes will be returned.
JAXBException
- if an error was encountered while creating the
JAXBContext, such as (but not limited to):
IllegalArgumentException
- if the parameter contains null
(i.e., newInstance(null);
)public static JAXBContext newInstance(Class[] classesToBeBound, Map<String,?> properties) throws JAXBException
Obtain a new instance of a JAXBContext class.
An overloading of newInstance(Class...)
to configure 'properties' for this instantiation of JAXBContext
.
The interpretation of properties is implementation specific.
classesToBeBound
- list of java classes to be recognized by the new JAXBContext
.
Can be empty, in which case a JAXBContext
that only knows about
spec-defined classes will be returned.
JAXBException
- if an error was encountered while creating the
JAXBContext, such as (but not limited to):
IllegalArgumentException
- if the parameter contains null
(i.e., newInstance(null);
)public abstract Unmarshaller createUnmarshaller() throws JAXBException
JAXBException
- if an error was encountered while creating the
Unmarshaller objectpublic abstract Marshaller createMarshaller() throws JAXBException
JAXBException
- if an error was encountered while creating the
Marshaller objectpublic abstract Validator createValidator() throws JAXBException
Validator
has been made optional and deprecated in JAXB 2.0. Please
refer to the javadoc for Validator
for more detail.
Create a Validator object that can be used to validate a java content tree against its source schema.
JAXBException
- if an error was encountered while creating the
Validator objectpublic <T> Binder<T> createBinder(Class<T> domType)
domType
- select the DOM API to use by passing in its DOM Node class.
UnsupportedOperationException
- if DOM API corresponding to domType is not supported by
the implementation.public Binder<Node> createBinder()
public JAXBIntrospector createJAXBIntrospector()
UnsupportedOperationException
- Calling this method on JAXB 1.0 implementations will throw
an UnsupportedOperationException.public void generateSchema(SchemaOutputResolver outputResolver) throws IOException
outputResolver
- this object controls the output to which schemas
will be sent.
IOException
- if SchemaOutputResolver
throws an IOException
.
UnsupportedOperationException
- Calling this method on JAXB 1.0 implementations will throw
an UnsupportedOperationException.