Top Description Fields Constructors Methods
org.glassfish.jaxb.runtime.api

public abstract Class JAXBRIContext

extends JAXBContext
Class Inheritance
Known Direct Subclasses
org.glassfish.jaxb.runtime.v2.runtime.JAXBContextImpl
Imports
com.sun.istack.NotNull, .Nullable, org.glassfish.jaxb.core.api.impl.NameConverter, org.glassfish.jaxb.runtime.v2.ContextFactory, org.glassfish.jaxb.runtime.v2.model.annotation.RuntimeAnnotationReader, org.glassfish.jaxb.runtime.v2.model.runtime.RuntimeTypeInfoSet, jakarta.xml.bind.JAXBContext, .JAXBException, .Marshaller, .SchemaOutputResolver, jakarta.xml.bind.annotation.XmlAttachmentRef, javax.xml.namespace.QName, javax.xml.transform.Result, java.io.IOException, java.lang.reflect.Type, java.util.*

JAXBContext enhanced with JAXB RI specific functionalities.

Subject to change without notice.

Author
Kohsuke Kawaguchi ([email protected])
Since
2.0 EA1

Field Summary

Modifier and TypeField and Description
public static final String
ANNOTATION_READER

The property that you can specify to JAXBContext#newInstance to use alternative RuntimeAnnotationReader implementation.

public static final String
BACKUP_WITH_PARENT_NAMESPACE

If true and element namespace is not specified, namespace of parent element will be used.

public static final String
CANONICALIZATION_SUPPORT

The property that you can specify to JAXBContext#newInstance and Marshaller#setProperty(String, Object) to enable the c14n marshalling support in the JAXBContext.

public static final String
DEFAULT_NAMESPACE_REMAP

The property that you can specify to JAXBContext#newInstance to reassign the default namespace URI to something else at the runtime.

public static final String
DISABLE_XML_SECURITY

If true XML security features when parsing XML documents will be disabled.

public static final String
ENABLE_XOP

Marshaller/Unmarshaller property to enable XOP processing.

public static final String
IMPROVED_XSI_TYPE_HANDLING

Improves handling of xsi:type used on leaf properties.

public static final String
MAX_ERRORS

The maximum number of errors to report.

public static final String
RETAIN_REFERENCE_TO_INFO

Retains references to PropertyInfos.

public static final String
SUBCLASS_REPLACEMENTS

The property that you can specify to JAXBContext#newInstance to specify specific classes that replace the reference to generic classes.

public static final String
SUPRESS_ACCESSOR_WARNINGS

Supress security warnings when trying to access fields through reflection.

public static final String
TREAT_EVERYTHING_NILLABLE

The property that you can specify to JAXBContext#newInstance to allow unmarshaller to honor xsi:nil anywhere, even if they are not specifically allowed by the schema.

public static final String
TYPE_REFERENCES

The property that you can specify to JAXBContext#newInstance to put additional JAXB type references into the JAXBContext.

public static final String
XMLACCESSORFACTORY_SUPPORT

The property that you can specify to JAXBContext#newInstance enable support of XmlAccessorFactory annotation in the JAXBContext.

Inherited from jakarta.xml.bind.JAXBContext:
JAXB_CONTEXT_FACTORY

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public abstract Bridge<T>

Returns:

null if the specified reference is not given to JAXBRIContext#newInstance.
createBridge
(TypeReference ref)

Creates a mini-marshaller/unmarshaller that can process a TypeReference.

public abstract void
generateEpisode(Result
This receives the generated episode file.
output
)

Generates the episode file that represents the binding known to this JAXBContext, so that XJC can later do separate compilation.

public abstract void
generateSchema(SchemaOutputResolver
this object controls the output to which schemas will be sent.
outputResolver
)

Overrides jakarta.xml.bind.JAXBContext.generateSchema.

Generates the schema documents from the model.

public static Type

Returns:

The use of baseType in type. or null if the type is not assignable to the base type.
getBaseType
(Type
The type that derives from baseType
type
,
Class<T>
The class whose parameterization we are interested in.
baseType
)

Gets the parameterization of the given base type.

public abstract String

Returns:

may be null, if the runtime is loaded by a class loader that doesn't support the access to the manifest informatino.
getBuildId
()

Gets the build information of the JAXB runtime.

public abstract QName

Returns:

null if the object is not bound to an element.
getElementName
(Object o)

If the given object is bound to an element in XML by JAXB, returns the element name.

public abstract QName
getElementName(Class<T> o)

Allows to retrieve the element name based on Class.

public abstract <
type of the wrapper bean
B
,
type of the property of the bean
V
>
RawAccessor<B, V>

Returns:

always return non-null valid accessor object.
getElementPropertyAccessor
(Class<B> wrapperBean, String nsUri, String localName)

Gets a RawAccessor for the specified element property of the specified wrapper bean class.

public abstract List<String>

Returns:

always non-null.
getKnownNamespaceURIs
()

Gets the namespace URIs statically known to this JAXBContext.

public abstract RuntimeTypeInfoSet
getRuntimeTypeInfoSet()

Allows you to access the runtime model information of the JAXB XML/Java binding.

public abstract QName

Returns:

null if the referenced type is an anonymous and therefore doesn't have a name.
getTypeName
(TypeReference
must not be null. This must be one of the TypeReferences specified in the JAXBRIContext#newInstance method.
tr
)

Returns the name of the XML Type bound to the specified Java type.

public abstract boolean
hasSwaRef()

Returns true if this context includes a class that has XmlAttachmentRef.

public static String

Returns:

Typically, this method returns "NameLikeThis".
mangleNameToClassName
(String localName)

Computes a Java class name from a local name.

public static String

Returns:

Typically, this method returns "NameLikeThis".
mangleNameToPropertyName
(String localName)

Computes a Java class name from a local name.

public static String

Returns:

Typically, this method returns "nameLikeThis".
mangleNameToVariableName
(String localName)

Computes a Java identifier from a local name.

public static JAXBRIContext
newInstance(Class<T>[]
Classes to be bound. See JAXBContext#newInstance(Class[]) for the meaning.
classes
,
Collection<TypeReference>
See TYPE_REFERENCES for the meaning of this parameter. Can be null.
typeRefs
,
Map<Class<T>, Class<T>>
See SUBCLASS_REPLACEMENTS for the meaning of this parameter. Can be null.
subclassReplacements
,
String
See DEFAULT_NAMESPACE_REMAP for the meaning of this parameter. Can be null (and should be null for ordinary use of JAXB.)
defaultNamespaceRemap
,
boolean
See CANONICALIZATION_SUPPORT for the meaning of this parameter.
c14nSupport
,
RuntimeAnnotationReader
See ANNOTATION_READER for the meaning of this parameter. Can be null.
ar
)

Creates a new .

public static JAXBRIContext
newInstance(Class<T>[]
Classes to be bound. See JAXBContext#newInstance(Class[]) for the meaning.
classes
,
Collection<TypeReference>
See TYPE_REFERENCES for the meaning of this parameter. Can be null.
typeRefs
,
Map<Class<T>, Class<T>>
See SUBCLASS_REPLACEMENTS for the meaning of this parameter. Can be null.
subclassReplacements
,
String
See DEFAULT_NAMESPACE_REMAP for the meaning of this parameter. Can be null (and should be null for ordinary use of JAXB.)
defaultNamespaceRemap
,
boolean
See CANONICALIZATION_SUPPORT for the meaning of this parameter.
c14nSupport
,
RuntimeAnnotationReader
See ANNOTATION_READER for the meaning of this parameter. Can be null.
ar
,
boolean
See XMLACCESSORFACTORY_SUPPORT for the meaning of this parameter.
xmlAccessorFactorySupport
,
boolean
See TREAT_EVERYTHING_NILLABLE for the meaning of this parameter.
allNillable
,
boolean
See RETAIN_REFERENCE_TO_INFO for the meaning of this parameter.
retainPropertyInfo
,
boolean
See SUPRESS_ACCESSOR_WARNINGS for the meaning of this parameter.
supressAccessorWarnings
)

Creates a new .

Inherited from jakarta.xml.bind.JAXBContext:
createBindercreateBindercreateJAXBIntrospectorcreateMarshallercreateUnmarshallernewInstancenewInstancenewInstancenewInstancenewInstance

Field Detail

ANNOTATION_READERback to summary
public static final String ANNOTATION_READER

The property that you can specify to JAXBContext#newInstance to use alternative RuntimeAnnotationReader implementation.

Since
2.1 EA2
BACKUP_WITH_PARENT_NAMESPACEback to summary
public static final String BACKUP_WITH_PARENT_NAMESPACE

If true and element namespace is not specified, namespace of parent element will be used. The default value is false. Boolean

Since
2.3.0
CANONICALIZATION_SUPPORTback to summary
public static final String CANONICALIZATION_SUPPORT

The property that you can specify to JAXBContext#newInstance and Marshaller#setProperty(String, Object) to enable the c14n marshalling support in the JAXBContext. Boolean

Since
2.0 EA2
DEFAULT_NAMESPACE_REMAPback to summary
public static final String DEFAULT_NAMESPACE_REMAP

The property that you can specify to JAXBContext#newInstance to reassign the default namespace URI to something else at the runtime.

The value of the property is String, and it is used as the namespace URI that succeeds the default namespace URI.

Since
2.0 EA1
DISABLE_XML_SECURITYback to summary
public static final String DISABLE_XML_SECURITY

If true XML security features when parsing XML documents will be disabled. The default value is false. Boolean

Since
2.2.6
ENABLE_XOPback to summary
public static final String ENABLE_XOP

Marshaller/Unmarshaller property to enable XOP processing.

Since
2.0 EA2
IMPROVED_XSI_TYPE_HANDLINGback to summary
public static final String IMPROVED_XSI_TYPE_HANDLING

Improves handling of xsi:type used on leaf properties. Boolean

Since
2.2.3
MAX_ERRORSback to summary
public static final String MAX_ERRORS

The maximum number of errors to report. Use negative value to report all errors. The default value is 10. Boolean

Since
2.3.3
RETAIN_REFERENCE_TO_INFOback to summary
public static final String RETAIN_REFERENCE_TO_INFO

Retains references to PropertyInfos. Boolean

Since
2.1.10
SUBCLASS_REPLACEMENTSback to summary
public static final String SUBCLASS_REPLACEMENTS

The property that you can specify to JAXBContext#newInstance to specify specific classes that replace the reference to generic classes.

See the release notes for more details about this feature.

Since
2.1 EA2
SUPRESS_ACCESSOR_WARNINGSback to summary
public static final String SUPRESS_ACCESSOR_WARNINGS

Supress security warnings when trying to access fields through reflection. Boolean

Since
2.1.14, 2.2.2
TREAT_EVERYTHING_NILLABLEback to summary
public static final String TREAT_EVERYTHING_NILLABLE

The property that you can specify to JAXBContext#newInstance to allow unmarshaller to honor xsi:nil anywhere, even if they are not specifically allowed by the schema. Boolean

Since
2.1.3
TYPE_REFERENCESback to summary
public static final String TYPE_REFERENCES

The property that you can specify to JAXBContext#newInstance to put additional JAXB type references into the JAXBContext.

The value of the property is Collection<TypeReference>. Those TypeReferences can then be used to create Bridges.

This mechanism allows additional element declarations that were not a part of the schema into the created JAXBContext.

Since
2.0 EA1
XMLACCESSORFACTORY_SUPPORTback to summary
public static final String XMLACCESSORFACTORY_SUPPORT

The property that you can specify to JAXBContext#newInstance enable support of XmlAccessorFactory annotation in the JAXBContext.

Since
2.1 EA2

Constructor Detail

JAXBRIContextback to summary
protected JAXBRIContext()

Method Detail

createBridgeback to summary
public abstract Bridge<T> createBridge(TypeReference ref)

Creates a mini-marshaller/unmarshaller that can process a TypeReference.

Returns:Bridge<T>

null if the specified reference is not given to JAXBRIContext#newInstance.

Since
2.0 EA1
generateEpisodeback to summary
public abstract void generateEpisode(Result output)

Generates the episode file that represents the binding known to this JAXBContext, so that XJC can later do separate compilation.

Episode file is really just a JAXB customization file, except that currently we use the RI-specific SCD to refer to schema components.

Parameters
output:Result

This receives the generated episode file.

Since
2.1
generateSchemaback to summary
public abstract void generateSchema(SchemaOutputResolver outputResolver) throws IOException

Overrides jakarta.xml.bind.JAXBContext.generateSchema.

Generates the schema documents from the model.

The caller can use the additionalElementDecls parameter to add element declarations to the generate schema. For example, if the JAX-RPC passes in the following entry: {foo}bar -> DeclaredType for java.lang.String then JAXB generates the following element declaration (in the schema document for the namespace "foo")" <xs:element name="bar" type="xs:string" /> This can be used for generating schema components necessary for WSDL.

Parameters
outputResolver:SchemaOutputResolver

this object controls the output to which schemas will be sent.

Annotations
@Override
Exceptions
IOException:
if SchemaOutputResolver throws an IOException.
getBaseTypeback to summary
public static Type getBaseType(Type type, Class<T> baseType)

Gets the parameterization of the given base type.

For example, given the following

interface Foo<T> extends List<List<T>> {}
interface Bar extends Foo<String> {}
This method works like this:
getBaseClass( Bar, List ) = List<List<String>
getBaseClass( Bar, Foo  ) = Foo<String>
getBaseClass( Foo<? extends Number>, Collection ) = Collection<List<? extends Number>>
getBaseClass( ArrayList<? extends BigInteger>, List ) = List<? extends BigInteger>
Parameters
type:Type

The type that derives from baseType

baseType:Class<T>

The class whose parameterization we are interested in.

Returns:Type

The use of baseType in type. or null if the type is not assignable to the base type.

Annotations
@Nullable
Since
2.0 FCS
getBuildIdback to summary
public abstract String getBuildId()

Gets the build information of the JAXB runtime.

Returns:String

may be null, if the runtime is loaded by a class loader that doesn't support the access to the manifest informatino.

Annotations
@NotNull
getElementNameback to summary
public abstract QName getElementName(Object o) throws JAXBException

If the given object is bound to an element in XML by JAXB, returns the element name.

Returns:QName

null if the object is not bound to an element.

Annotations
@Nullable
Exceptions
JAXBException:
if the object is not known to this context.
Since
2.0 EA1
getElementNameback to summary
public abstract QName getElementName(Class<T> o) throws JAXBException

Allows to retrieve the element name based on Class.

Annotations
@Nullable
Since
2.1.10
getElementPropertyAccessorback to summary
public abstract <B, V> RawAccessor<B, V> getElementPropertyAccessor(Class<B> wrapperBean, String nsUri, String localName) throws JAXBException

Gets a RawAccessor for the specified element property of the specified wrapper bean class.

This method is designed to assist the JAX-RPC RI fill in a wrapper bean (in the doc/lit/wrap mode.) In the said mode, a wrapper bean is supposed to only have properties that match elements, and for each element that appear in the content model there's one property.

Therefore, this method takes a wrapper bean and a tag name that identifies a property on the given wrapper bean, then returns a RawAccessor that allows the caller to set/get a value from the property of the bean.

This method is not designed for a performance. The caller is expected to cache the result.

Parameters
<B>
type of the wrapper bean
<V>
type of the property of the bean
Returns:RawAccessor<B, V>

always return non-null valid accessor object.

Exceptions
JAXBException:
if the specified wrapper bean is not bound by JAXB, or if it doesn't have an element property of the given name.
Since
2.0 EA1
getKnownNamespaceURIsback to summary
public abstract List<String> getKnownNamespaceURIs()

Gets the namespace URIs statically known to this JAXBContext.

When JAXB is used to marshal into sub-trees, it declares these namespace URIs at each top-level element that it marshals. To avoid repeated namespace declarations at sub-elements, the application may declare those namespaces at a higher level.

Returns:List<String>

always non-null.

Annotations
@NotNull
Since
2.0 EA2
getRuntimeTypeInfoSetback to summary
public abstract RuntimeTypeInfoSet getRuntimeTypeInfoSet()

Allows you to access the runtime model information of the JAXB XML/Java binding.

This is useful for doing a deeper integration with the JAXB RI. For more information about the model, see https://jaxb2-reflection.dev.java.net/

Since
2.1.10
getTypeNameback to summary
public abstract QName getTypeName(TypeReference tr)

Returns the name of the XML Type bound to the specified Java type.

Parameters
tr:TypeReference

must not be null. This must be one of the TypeReferences specified in the JAXBRIContext#newInstance method.

Returns:QName

null if the referenced type is an anonymous and therefore doesn't have a name.

Exceptions
IllegalArgumentException:
if the parameter is null or not a part of the TypeReferences specified in the JAXBRIContext#newInstance method.
hasSwaRefback to summary
public abstract boolean hasSwaRef()

Returns true if this context includes a class that has XmlAttachmentRef.

Since
2.1
mangleNameToClassNameback to summary
public static String mangleNameToClassName(String localName)

Computes a Java class name from a local name.

This method faithfully implements the name mangling rule as specified in the JAXB spec.

Returns:String

Typically, this method returns "NameLikeThis".

Annotations
@NotNull
mangleNameToPropertyNameback to summary
public static String mangleNameToPropertyName(String localName)

Computes a Java class name from a local name.

This method faithfully implements the name mangling rule as specified in the JAXB spec. This method works like mangleNameToClassName(String) except that it looks for "getClass" and returns something else.

Returns:String

Typically, this method returns "NameLikeThis".

Annotations
@NotNull
mangleNameToVariableNameback to summary
public static String mangleNameToVariableName(String localName)

Computes a Java identifier from a local name.

This method faithfully implements the name mangling rule as specified in the JAXB spec.

In JAXB, a collision with a Java reserved word (such as "return") never happens. Accordingly, this method may return an identifier that collides with reserved words.

Use JJavaName.isJavaIdentifier(String) to check for such collision.

Returns:String

Typically, this method returns "nameLikeThis".

Annotations
@NotNull
newInstanceback to summary
public static JAXBRIContext newInstance(Class<T>[] classes, Collection<TypeReference> typeRefs, Map<Class<T>, Class<T>> subclassReplacements, String defaultNamespaceRemap, boolean c14nSupport, RuntimeAnnotationReader ar) throws JAXBException

Creates a new .

JAXBContext.newInstance() methods may return other JAXB providers that are not compatible with the JAX-RPC RI. This method guarantees that the JAX-WS RI will finds the JAXB RI.

Parameters
classes:Class<T>[]

Classes to be bound. See JAXBContext#newInstance(Class[]) for the meaning.

typeRefs:Collection<TypeReference>

See TYPE_REFERENCES for the meaning of this parameter. Can be null.

subclassReplacements:Map<Class<T>, Class<T>>

See SUBCLASS_REPLACEMENTS for the meaning of this parameter. Can be null.

defaultNamespaceRemap:String

See DEFAULT_NAMESPACE_REMAP for the meaning of this parameter. Can be null (and should be null for ordinary use of JAXB.)

c14nSupport:boolean

See CANONICALIZATION_SUPPORT for the meaning of this parameter.

ar:RuntimeAnnotationReader

See ANNOTATION_READER for the meaning of this parameter. Can be null.

Since
JAXB 2.1 EA2
newInstanceback to summary
public static JAXBRIContext newInstance(Class<T>[] classes, Collection<TypeReference> typeRefs, Map<Class<T>, Class<T>> subclassReplacements, String defaultNamespaceRemap, boolean c14nSupport, RuntimeAnnotationReader ar, boolean xmlAccessorFactorySupport, boolean allNillable, boolean retainPropertyInfo, boolean supressAccessorWarnings) throws JAXBException

Creates a new .

JAXBContext.newInstance() methods may return other JAXB providers that are not compatible with the JAX-RPC RI. This method guarantees that the JAX-WS RI will finds the JAXB RI.

Parameters
classes:Class<T>[]

Classes to be bound. See JAXBContext#newInstance(Class[]) for the meaning.

typeRefs:Collection<TypeReference>

See TYPE_REFERENCES for the meaning of this parameter. Can be null.

subclassReplacements:Map<Class<T>, Class<T>>

See SUBCLASS_REPLACEMENTS for the meaning of this parameter. Can be null.

defaultNamespaceRemap:String

See DEFAULT_NAMESPACE_REMAP for the meaning of this parameter. Can be null (and should be null for ordinary use of JAXB.)

c14nSupport:boolean

See CANONICALIZATION_SUPPORT for the meaning of this parameter.

ar:RuntimeAnnotationReader

See ANNOTATION_READER for the meaning of this parameter. Can be null.

xmlAccessorFactorySupport:boolean

See XMLACCESSORFACTORY_SUPPORT for the meaning of this parameter.

allNillable:boolean

See TREAT_EVERYTHING_NILLABLE for the meaning of this parameter.

retainPropertyInfo:boolean

See RETAIN_REFERENCE_TO_INFO for the meaning of this parameter.

supressAccessorWarnings:boolean

See SUPRESS_ACCESSOR_WARNINGS for the meaning of this parameter.