- Direct Known Subclasses:
DynamicJAXBContext
Purpose:Provide a EclipseLink implementation of the JAXBContext interface.
Responsibilities:
- Create Marshaller instances
- Create Unmarshaller instances
- Create Binder instances
- Create Introspector instances
- Create Validator instances
- Generate Schema Files
This is the EclipseLink JAXB 2.0 implementation of jakarta.xml.bind.JAXBContext. This class is created by the JAXBContextFactory and is used to create Marshallers, Unmarshallers, Validators, Binders and Introspectors. A JAXBContext can also be used to create Schema Files.
Bootstrapping: When bootstrapping the JAXBContext from a EclipseLink externalized metadata file(s) a number of input options are available. The externalized metadata file (one per package) is passed in through a property when creating the JAXBContext. The key used in the properties map is "eclipselink-oxm-xml". The externalized metadata file can be set in the properties map in one of three ways:
i) For a single externalized metadata file, one of the following can be set in the properties map:
- java.io.File
- java.io.InputStream
- java.io.Reader
- java.net.URL
- javax.xml.stream.XMLEventReader
- javax.xml.stream.XMLStreamReader
- javax.xml.transform.Source
- org.w3c.dom.Node
- org.xml.sax.InputSource
ii) For multiple externalized metadata files where the package name is specified within each externalized metadata file, a List can be used. The entries in the List are to be one of the types listed in i) above.
iii) For multiple externalized metadata files where the package name is not specified in each externalized metadata file, a Map can be used. The key must be a String (package name) and each value in the Map (externalized metadata file) is to be one of the types listed in i) above.
Note that in each of the above cases the package name can be set via package-name attribute on the xml-bindings element in the externalized metadata file. If set, any java-type names in the given metadata file that do not contain the package name will have that package name prepended to it. Also note that a List or Map can be used for a single externalized metadata file.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
The JAXBContextInput is used to create a JAXBContextState which is responsible for accessing the underlying XMLContextprotected static class
-
Field Summary
Modifier and TypeFieldDescriptionprotected JAXBContext.JAXBContextInput
protected JAXBContext.JAXBContextState
protected static final ValidationEventHandler
For JAXB 2 there is no explicitly defined default validation handler and the default event handling only terminates the operation after encountering a fatal error.Fields inherited from class jakarta.xml.bind.JAXBContext
JAXB_CONTEXT_FACTORY
-
Constructor Summary
ModifierConstructorDescriptionprotected
protected
JAXBContext
(JAXBContext.JAXBContextInput contextInput) JAXBContext
(XMLContext context) Create a JAXBContext for a given XMLContext.JAXBContext
(XMLContext context, Generator generator, Type[] boundTypes) Create a JAXBContext.JAXBContext
(XMLContext context, Generator generator, TypeMappingInfo[] boundTypes) Create a JAXBContext. -
Method Summary
Modifier and TypeMethodDescriptionvoid
applyORMMetadata
(AbstractSession ormSession) ADVANCED: Adjust the OXM metadata to take into account ORM mapping metadataCreate a JAXBBinder.<T> JAXBBinder
createBinder
(Class<T> nodeClass) Create a JAXBBinder.createByQualifiedName
(String namespace, String typeName, boolean isGlobalType) Create a new object instance for a given XML namespace and name.<T> T
createByXPath
(Object parentObject, String xPath, NamespaceResolver namespaceResolver, Class<T> returnType) Create a new object instance for a given XPath, relative to the parentObject.protected JAXBElement
createJAXBElement
(QName qname, Class<?> theClass, Object value) protected JAXBElement
createJAXBElementFromXMLRoot
(Root xmlRoot, Class<?> declaredType) Creates a JAXBIntrospector object.Create a JAXBMarshaller.createObjectGraph
(Class<?> type) createObjectGraph
(String typeName) Create a JAXBUnmarshaller.Create a JAXBValidator.void
generateJsonSchema
(SchemaOutputResolver outputResolver, Class<?> rootClass) void
generateSchema
(SchemaOutputResolver outputResolver) Generate a Schema for this JAXBContextvoid
generateSchema
(SchemaOutputResolver outputResolver, Map<QName, Type> additonalGlobalElements) Generate a Schema for this JAXBContextINTERNAL: Get the map for which array class (by name) corresponds to which generated classReturns BeanValidationHelper.INTERNAL: Get the map containing which Class (by name) corresponds to which generated class.INTERNAL: Get the map for which collection class (by Type) corresponds to which generated classINTERNAL: Get the map of which QName corresponds to which declared class.INTERNAL: Get the map of which TypeMappingInfo corresponds to which QName.INTERNAL: Get the map of which Type corresponds to which QName.<T> T
getValueByXPath
(Object object, String xPath, NamespaceResolver namespaceResolver, Class<T> returnType) Get a value from an object based on an XPath statement.Return the XMLContext associated with this JAXBContext.boolean
Returns true if any Object in this context contains a property annotated with an XmlAttachmentRef annotation.void
INTERNAL: Populate the map of which Type corresponds to which QName.void
ADVANCED:void
setClassToGeneratedClasses
(HashMap<String, Class<?>> classToClass) INTERNAL: Set the map containing which Class (by name) corresponds to which generated class.void
setQNamesToDeclaredClasses
(HashMap<QName, Class<?>> nameToDeclaredClasses) INTERNAL: Set the map of which QName corresponds to which declared class.void
setQNameToGeneratedClasses
(HashMap<QName, Class<?>> qNameToClass) INTERNAL: Set the map containing which QName corresponds to which generated class.void
setValueByXPath
(Object object, String xPath, NamespaceResolver namespaceResolver, Object value) Set a value on an object based on an XPath statement.void
setXMLContext
(XMLContext xmlContext) Methods inherited from class jakarta.xml.bind.JAXBContext
newInstance, newInstance, newInstance, newInstance, newInstance
-
Field Details
-
DEFAULT_VALIDATION_EVENT_HANDLER
For JAXB 2 there is no explicitly defined default validation handler and the default event handling only terminates the operation after encountering a fatal error. -
contextInput
-
contextState
-
-
Constructor Details
-
JAXBContext
protected JAXBContext() -
JAXBContext
- Throws:
JAXBException
-
JAXBContext
Create a JAXBContext for a given XMLContext. The XMLContext contains the metadata about the Object to XML mappings. -
JAXBContext
Create a JAXBContext. The XMLContext contains the metadata about the Object to XML mappings. -
JAXBContext
Create a JAXBContext. The XMLContext contains the metadata about the Object to XML mappings.
-
-
Method Details
-
getBeanValidationHelper
Returns BeanValidationHelper. Can return null if bean validation jar is not on class path. -
getXMLInputFactory
-
refreshMetadata
ADVANCED:Refresh the underlying metadata based on the inputs that were used to create the JAXBContext. This is particularly useful when using the virtual property mappings. The refreshMetadata call could be made in the following way:
org.eclipse.persistence.jaxb.JAXBHelper.getJAXBContext(aJAXBContext).refreshMetadata();
Note:- As instances of Binder maintain a cache, calling refreshMetadata will not affect instances of Binder. To get the new metadata you must create a new instance of Binder after the refresh metadata call has been made.
- Throws:
JAXBException
-
getXMLContext
Return the XMLContext associated with this JAXBContext. -
setXMLContext
-
generateSchema
Generate a Schema for this JAXBContext- Overrides:
generateSchema
in classJAXBContext
- Parameters:
outputResolver
- Class that decides where the schema file (of the given namespace URI) will be written
-
generateJsonSchema
-
generateSchema
public void generateSchema(SchemaOutputResolver outputResolver, Map<QName, Type> additonalGlobalElements) Generate a Schema for this JAXBContext- Parameters:
outputResolver
- Class that decides where the schema file (of the given namespace URI) will be writtenadditonalGlobalElements
- Map of additional global elements to be added to the generated XSD. Note that if any QName in this map conflicts with another global element (for example from a TypeMappingInfo object) then the element generated from this map will be the one that is present in the XSD.
-
createMarshaller
Create a JAXBMarshaller. The JAXBMarshaller is used to convert Java objects to XML.- Specified by:
createMarshaller
in classJAXBContext
- Throws:
JAXBException
-
createUnmarshaller
Create a JAXBUnmarshaller. The JAXBUnmarshaller is used to convert XML into Java objects.- Specified by:
createUnmarshaller
in classJAXBContext
- Throws:
JAXBException
-
createValidator
Create a JAXBValidator. The JAXBValidator is used to validate Java objects against an XSD. -
createBinder
Create a JAXBBinder. The JAXBBinder is used to preserve unmapped XML Data.- Overrides:
createBinder
in classJAXBContext
-
createBinder
Create a JAXBBinder. The JAXBBinder is used to preserve unmapped XML Data.- Overrides:
createBinder
in classJAXBContext
- Parameters:
nodeClass
- The DOM Node class to use
-
createJAXBIntrospector
Creates a JAXBIntrospector object. The JAXBIntrospector allows the user to access certain pieces of metadata about an instance of a JAXB bound class.- Overrides:
createJAXBIntrospector
in classJAXBContext
-
setQNameToGeneratedClasses
INTERNAL: Set the map containing which QName corresponds to which generated class. -
getClassToGeneratedClasses
INTERNAL: Get the map containing which Class (by name) corresponds to which generated class. -
setClassToGeneratedClasses
INTERNAL: Set the map containing which Class (by name) corresponds to which generated class. -
applyORMMetadata
ADVANCED: Adjust the OXM metadata to take into account ORM mapping metadata -
getQNamesToDeclaredClasses
INTERNAL: Get the map of which QName corresponds to which declared class. -
setQNamesToDeclaredClasses
INTERNAL: Set the map of which QName corresponds to which declared class. -
getArrayClassesToGeneratedClasses
INTERNAL: Get the map for which array class (by name) corresponds to which generated class -
getCollectionClassesToGeneratedClasses
INTERNAL: Get the map for which collection class (by Type) corresponds to which generated class -
initTypeToSchemaType
public void initTypeToSchemaType()INTERNAL: Populate the map of which Type corresponds to which QName. The keys should be all the boundTypes used to create the JAXBContext. If the JAXBContext was not created with the constructor that takes a Type[] then this Map will be empty. -
getTypeMappingInfoToSchemaType
INTERNAL: Get the map of which TypeMappingInfo corresponds to which QName. The keys should be all the boundTypes used to create the JAXBContext. If the JAXBContext was not created with the constructor that takes a TypeMappingInfo[] this Map will be empty. -
getTypeToSchemaType
INTERNAL: Get the map of which Type corresponds to which QName. The keys should be all the boundTypes used to create the JAXBContext. If the JAXBContext was not created with the constructor that takes a Type[] then this Map will be empty. -
getValueByXPath
public <T> T getValueByXPath(Object object, String xPath, NamespaceResolver namespaceResolver, Class<T> returnType) Get a value from an object based on an XPath statement.- Type Parameters:
T
- The return type of this method corresponds to the returnType parameter.- Parameters:
object
- The XPath will be executed relative to this object.xPath
- The XPath statement.namespaceResolver
- ANamespaceResolver
containing the prefix/URI pairings from the XPath statement.returnType
- The return type.- Returns:
- The object corresponding to the XPath or null if no result was found.
-
setValueByXPath
public void setValueByXPath(Object object, String xPath, NamespaceResolver namespaceResolver, Object value) Set a value on an object based on an XPath statement.- Parameters:
object
- The XPath will be executed relative to this object.xPath
- The XPath statement.namespaceResolver
- ANamespaceResolver
containing the prefix/URI pairings from the XPath statement.value
- The value to be set.
-
createByQualifiedName
Create a new object instance for a given XML namespace and name.- Parameters:
namespace
- The namespace of the complex type to create a new Java instance of.typeName
- The XML type name to create a new Java instance of.isGlobalType
- True if the object to be created represents a global type, false if it represents a global element.- Returns:
- An instance of the Java class mapped to the indicated XML type, or null if no result was found.
-
createByXPath
public <T> T createByXPath(Object parentObject, String xPath, NamespaceResolver namespaceResolver, Class<T> returnType) Create a new object instance for a given XPath, relative to the parentObject.- Type Parameters:
T
- The return type of this method corresponds to the returnType parameter.- Parameters:
parentObject
- The XPath will be executed relative to this object.xPath
- The XPath statement.namespaceResolver
- A NamespaceResolver containing the prefix/URI pairings from the XPath statement.returnType
- The return type.- Returns:
- An instance of the Java class mapped to the supplied XML type, or null if no result was found.
-
createObjectGraph
-
createObjectGraph
-
createJAXBElementFromXMLRoot
-
createJAXBElement
-
hasSwaRef
public boolean hasSwaRef()Returns true if any Object in this context contains a property annotated with an XmlAttachmentRef annotation.
-