Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle TopLink
11g Release 1 (11.1.1)

E28847-01


org.eclipse.persistence.jaxb
Class JAXBContext

java.lang.Object
  extended by javax.xml.bind.JAXBContext
      extended by org.eclipse.persistence.jaxb.JAXBContext

Direct Known Subclasses:
DynamicJAXBContext

public class JAXBContext
extends javax.xml.bind.JAXBContext

Purpose:Provide a EclipseLink implementation of the JAXBContext interface.

Responsibilities:

This is the EclipseLink JAXB 2.0 implementation of javax.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:

When using one of the above options, the package name must be set via package-name attribute on the xml-bindings element in the externalized metadata file.

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.

Author:
mmacivor
See Also:
JAXBContext, JAXBMarshaller, JAXBUnmarshaller, JAXBBinder, JAXBIntrospector

Nested Class Summary
(package private) static class JAXBContext.ContextPathInput
           
(package private) static class JAXBContext.JAXBContextInput
           
private static class JAXBContext.JAXBContextState
           
(package private) static class JAXBContext.RootLevelXmlAdapter
           
(package private) static class JAXBContext.TypeMappingInfoInput
           

 

Field Summary
private  JAXBContext.JAXBContextInput contextInput
           
private  JAXBContext.JAXBContextState contextState
           
private static java.util.Map<java.lang.String,java.lang.Boolean> PARSER_FEATURES
           

 

Fields inherited from class javax.xml.bind.JAXBContext
JAXB_CONTEXT_FACTORY

 

Constructor Summary
protected JAXBContext()
           
protected JAXBContext(JAXBContext.JAXBContextInput contextInput)
           
  JAXBContext(XMLContext context)
          Create a JAXBContext for a given XMLContext.
  JAXBContext(XMLContext context, Generator generator, java.lang.reflect.Type[] boundTypes)
          Create a JAXBContext.
  JAXBContext(XMLContext context, Generator generator, TypeMappingInfo[] boundTypes)
          Create a JAXBContext.

 

Method Summary
 void applyORMMetadata(org.eclipse.persistence.internal.sessions.AbstractSession ormSession)
          ADVANCED: Adjust the OXM metadata to take into account ORM mapping metadata
 JAXBBinder createBinder()
          Create a JAXBBinder.
<T> JAXBBinder
createBinder(java.lang.Class<T> nodeClass)
          Create a JAXBBinder.
 java.lang.Object createByQualifiedName(java.lang.String namespace, java.lang.String typeName, boolean isGlobalType)
          Create a new object instance for a given XML namespace and name.
<T> T
createByXPath(java.lang.Object parentObject, java.lang.String xPath, NamespaceResolver namespaceResolver, java.lang.Class<T> returnType)
          Create a new object instance for a given XPath, relative to the parentObject.
 JAXBIntrospector createJAXBIntrospector()
          Creates a JAXBIntrospector object.
 JAXBMarshaller createMarshaller()
          Create a JAXBMarshaller.
 JAXBUnmarshaller createUnmarshaller()
          Create a JAXBUnmarshaller.
 JAXBValidator createValidator()
          Create a JAXBValidator.
 void generateSchema(javax.xml.bind.SchemaOutputResolver outputResolver)
          Generate a Schema for this JAXBContext
 void generateSchema(javax.xml.bind.SchemaOutputResolver outputResolver, java.util.Map<javax.xml.namespace.QName,java.lang.reflect.Type> additonalGlobalElements)
          Generate a Schema for this JAXBContext
 java.util.Map<java.lang.String,java.lang.Class> getArrayClassesToGeneratedClasses()
          INTERNAL: Get the map for which array class (by name) corresponds to which generated class
 java.util.HashMap<java.lang.String,java.lang.Class> getClassToGeneratedClasses()
          INTERNAL: Get the map containing which Class (by name) corresponds to which generated class.
 java.util.Map<java.lang.reflect.Type,java.lang.Class> getCollectionClassesToGeneratedClasses()
          INTERNAL: Get the map for which collection class (by Type) corresponds to which generated class
 java.util.HashMap<javax.xml.namespace.QName,java.lang.Class> getQNamesToDeclaredClasses()
          INTERNAL: Get the map of which QName corresponds to which declared class.
(package private)  java.util.Map<javax.xml.namespace.QName,java.lang.Class> getQNameToGeneratedClasses()
          INTERNAL: Get the map of which QName corresponds to which generated class.
(package private)  java.util.Map<TypeMappingInfo,java.lang.Class> getTypeMappingInfoToGeneratedType()
           
(package private)  java.util.Map<TypeMappingInfo,JAXBContext.RootLevelXmlAdapter> getTypeMappingInfoToJavaTypeAdapters()
           
 java.util.Map<TypeMappingInfo,javax.xml.namespace.QName> getTypeMappingInfoToSchemaType()
          INTERNAL: Get the map of which TypeMappingInfo corresponds to which QName.
 java.util.HashMap<java.lang.reflect.Type,javax.xml.namespace.QName> getTypeToSchemaType()
          INTERNAL: Get the map of which Type corresponds to which QName.
(package private)  java.util.Map<java.lang.reflect.Type,TypeMappingInfo> getTypeToTypeMappingInfo()
           
<T> T
getValueByXPath(java.lang.Object object, java.lang.String xPath, NamespaceResolver namespaceResolver, java.lang.Class<T> returnType)
          Get a value from an object based on an XPath statement.
 XMLContext getXMLContext()
          Return the XMLContext associated with this JAXBContext.
 boolean hasSwaRef()
          Returns true if any Object in this context contains a property annotated with an XmlAttachmentRef annotation.
 void initTypeToSchemaType()
          INTERNAL: Populate the map of which Type corresponds to which QName.
 void refreshMetadata()
          ADVANCED: Refresh the underlying metadata based on the inputs that were used to create the JAXBContext.
 void setClassToGeneratedClasses(java.util.HashMap<java.lang.String,java.lang.Class> classToClass)
          INTERNAL: Set the map containing which Class (by name) corresponds to which generated class.
 void setQNamesToDeclaredClasses(java.util.HashMap<javax.xml.namespace.QName,java.lang.Class> nameToDeclaredClasses)
          INTERNAL: Set the map of which QName corresponds to which declared class.
 void setQNameToGeneratedClasses(java.util.HashMap<javax.xml.namespace.QName,java.lang.Class> qNameToClass)
          INTERNAL: Set the map containing which QName corresponds to which generated class.
(package private)  void setTypeMappingInfoToJavaTypeAdapaters(java.util.Map<TypeMappingInfo,JAXBContext.RootLevelXmlAdapter> typeMappingInfoToAdapters)
           
(package private)  void setTypeToTypeMappingInfo(java.util.Map<java.lang.reflect.Type,TypeMappingInfo> typeToMappingInfo)
           
 void setValueByXPath(java.lang.Object object, java.lang.String xPath, NamespaceResolver namespaceResolver, java.lang.Object value)
          Set a value on an object based on an XPath statement.
 void setXMLContext(XMLContext xmlContext)
           

 

Methods inherited from class javax.xml.bind.JAXBContext
newInstance, newInstance, newInstance, newInstance, newInstance

 

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

 

Field Detail

PARSER_FEATURES

private static final java.util.Map<java.lang.String,java.lang.Boolean> PARSER_FEATURES

contextInput

private JAXBContext.JAXBContextInput contextInput

contextState

private volatile JAXBContext.JAXBContextState contextState

Constructor Detail

JAXBContext

protected JAXBContext()

JAXBContext

protected JAXBContext(JAXBContext.JAXBContextInput contextInput)
               throws javax.xml.bind.JAXBException
Throws:
javax.xml.bind.JAXBException

JAXBContext

public JAXBContext(XMLContext context)
Create a JAXBContext for a given XMLContext. The XMLContext contains the metadata about the Object to XML mappings.

JAXBContext

public JAXBContext(XMLContext context,
                   Generator generator,
                   java.lang.reflect.Type[] boundTypes)
Create a JAXBContext. The XMLContext contains the metadata about the Object to XML mappings.

JAXBContext

public JAXBContext(XMLContext context,
                   Generator generator,
                   TypeMappingInfo[] boundTypes)
Create a JAXBContext. The XMLContext contains the metadata about the Object to XML mappings.

Method Detail

refreshMetadata

public void refreshMetadata()
                     throws javax.xml.bind.JAXBException
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:
Throws:
javax.xml.bind.JAXBException

getXMLContext

public XMLContext getXMLContext()
Return the XMLContext associated with this JAXBContext.

setXMLContext

public void setXMLContext(XMLContext xmlContext)

generateSchema

public void generateSchema(javax.xml.bind.SchemaOutputResolver outputResolver)
Generate a Schema for this JAXBContext
Overrides:
generateSchema in class javax.xml.bind.JAXBContext
Parameters:
outputResolver - Class that decides where the schema file (of the given namespace URI) will be written

generateSchema

public void generateSchema(javax.xml.bind.SchemaOutputResolver outputResolver,
                           java.util.Map<javax.xml.namespace.QName,java.lang.reflect.Type> additonalGlobalElements)
Generate a Schema for this JAXBContext
Parameters:
outputResolver - Class that decides where the schema file (of the given namespace URI) will be written
additonalGlobalElements - 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

public JAXBMarshaller createMarshaller()
Create a JAXBMarshaller. The JAXBMarshaller is used to convert Java objects to XML.
Specified by:
createMarshaller in class javax.xml.bind.JAXBContext

createUnmarshaller

public JAXBUnmarshaller createUnmarshaller()
Create a JAXBUnmarshaller. The JAXBUnmarshaller is used to convert XML into Java objects.
Specified by:
createUnmarshaller in class javax.xml.bind.JAXBContext

createValidator

public JAXBValidator createValidator()
Create a JAXBValidator. The JAXBValidator is used to validate Java objects against an XSD.
Specified by:
createValidator in class javax.xml.bind.JAXBContext

createBinder

public JAXBBinder createBinder()
Create a JAXBBinder. The JAXBBinder is used to preserve unmapped XML Data.
Overrides:
createBinder in class javax.xml.bind.JAXBContext

createBinder

public <T> JAXBBinder createBinder(java.lang.Class<T> nodeClass)
Create a JAXBBinder. The JAXBBinder is used to preserve unmapped XML Data.
Overrides:
createBinder in class javax.xml.bind.JAXBContext
Parameters:
nodeClass - The DOM Node class to use

createJAXBIntrospector

public JAXBIntrospector 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 class javax.xml.bind.JAXBContext

setQNameToGeneratedClasses

public void setQNameToGeneratedClasses(java.util.HashMap<javax.xml.namespace.QName,java.lang.Class> qNameToClass)
INTERNAL: Set the map containing which QName corresponds to which generated class.

getClassToGeneratedClasses

public java.util.HashMap<java.lang.String,java.lang.Class> getClassToGeneratedClasses()
INTERNAL: Get the map containing which Class (by name) corresponds to which generated class.

setClassToGeneratedClasses

public void setClassToGeneratedClasses(java.util.HashMap<java.lang.String,java.lang.Class> classToClass)
INTERNAL: Set the map containing which Class (by name) corresponds to which generated class.

applyORMMetadata

public void applyORMMetadata(org.eclipse.persistence.internal.sessions.AbstractSession ormSession)
ADVANCED: Adjust the OXM metadata to take into account ORM mapping metadata

getQNamesToDeclaredClasses

public java.util.HashMap<javax.xml.namespace.QName,java.lang.Class> getQNamesToDeclaredClasses()
INTERNAL: Get the map of which QName corresponds to which declared class.

getQNameToGeneratedClasses

java.util.Map<javax.xml.namespace.QName,java.lang.Class> getQNameToGeneratedClasses()
INTERNAL: Get the map of which QName corresponds to which generated class.

setQNamesToDeclaredClasses

public void setQNamesToDeclaredClasses(java.util.HashMap<javax.xml.namespace.QName,java.lang.Class> nameToDeclaredClasses)
INTERNAL: Set the map of which QName corresponds to which declared class.

getArrayClassesToGeneratedClasses

public java.util.Map<java.lang.String,java.lang.Class> getArrayClassesToGeneratedClasses()
INTERNAL: Get the map for which array class (by name) corresponds to which generated class

getCollectionClassesToGeneratedClasses

public java.util.Map<java.lang.reflect.Type,java.lang.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

public java.util.Map<TypeMappingInfo,javax.xml.namespace.QName> 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

public java.util.HashMap<java.lang.reflect.Type,javax.xml.namespace.QName> 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.

getTypeMappingInfoToGeneratedType

java.util.Map<TypeMappingInfo,java.lang.Class> getTypeMappingInfoToGeneratedType()

getTypeToTypeMappingInfo

java.util.Map<java.lang.reflect.Type,TypeMappingInfo> getTypeToTypeMappingInfo()

setTypeToTypeMappingInfo

void setTypeToTypeMappingInfo(java.util.Map<java.lang.reflect.Type,TypeMappingInfo> typeToMappingInfo)

setTypeMappingInfoToJavaTypeAdapaters

void setTypeMappingInfoToJavaTypeAdapaters(java.util.Map<TypeMappingInfo,JAXBContext.RootLevelXmlAdapter> typeMappingInfoToAdapters)

getTypeMappingInfoToJavaTypeAdapters

java.util.Map<TypeMappingInfo,JAXBContext.RootLevelXmlAdapter> getTypeMappingInfoToJavaTypeAdapters()

getValueByXPath

public <T> T getValueByXPath(java.lang.Object object,
                             java.lang.String xPath,
                             NamespaceResolver namespaceResolver,
                             java.lang.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 - A NamespaceResolver 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(java.lang.Object object,
                            java.lang.String xPath,
                            NamespaceResolver namespaceResolver,
                            java.lang.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 - A NamespaceResolver containing the prefix/URI pairings from the XPath statement.
value - The value to be set.

createByQualifiedName

public java.lang.Object createByQualifiedName(java.lang.String namespace,
                                              java.lang.String typeName,
                                              boolean isGlobalType)
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(java.lang.Object parentObject,
                           java.lang.String xPath,
                           NamespaceResolver namespaceResolver,
                           java.lang.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.

hasSwaRef

public boolean hasSwaRef()
Returns true if any Object in this context contains a property annotated with an XmlAttachmentRef annotation.
Returns:

Skip navigation links

Copyright © 1998, 2012, Oracle. All Rights Reserved.