Class DefaultBindingContext
- All Implemented Interfaces:
IBindingContext
IBindingContext
provided by this library.
This implementation caches Module information, which can dramatically improve read and write performance at the cost of some memory use. Thus, using the same singleton of this class across multiple I/O operations will improve overall read and write performance when processing the same types of data.
Serializers and deserializers provided by this class using the
newSerializer(Format, Class)
and
newDeserializer(Format, Class)
methods will
This class is synchronized and is thread-safe.
-
Nested Class Summary
Nested classes/interfaces inherited from interface gov.nist.secauto.metaschema.databind.IBindingContext
IBindingContext.BindingContextBuilder, IBindingContext.IBindingMatcher, IBindingContext.IModuleLoaderStrategy, IBindingContext.ISchemaValidationProvider
-
Constructor Summary
ConstructorDescriptionConstruct a new binding context.Construct a new binding context. -
Method Summary
Modifier and TypeMethodDescription<CLASS extends IBoundObject>
CLASSdeepCopy
(CLASS other, IBoundObject parentInstance) Create a deep copy of the provided bound object.protected Collection<IBindingContext.IBindingMatcher>
Get the binding matchers that are associated with this class.Class<? extends IBoundObject>
getBoundClassForRootJsonName
(String rootName) Determine the bound class for the provided JSON/YAML property/item name using any registered matchers.Class<? extends IBoundObject>
getBoundClassForRootXmlQName
(QName rootQName) Determine the bound class for the provided XMLQName
.getBoundDefinitionForClass
(Class<? extends IBoundObject> clazz) Get theIBoundDefinitionModel
instance associated with the provided Java class.Get the Metaschema module loader strategy used by this binding context to load modules.<CLASS extends IBoundObject>
IDeserializer<CLASS>newDeserializer
(Format format, Class<CLASS> clazz) Gets a dataIDeserializer
which can be used to read Java instance data for the provided class from the requested format.Get a loader that supports loading a Metaschema module from a specified resource.<CLASS extends IBoundObject>
ISerializer<CLASS>newSerializer
(Format format, Class<CLASS> clazz) Gets a dataISerializer
which can be used to write Java instance data for the provided class in the requested format.registerClassBinding
(IBoundDefinitionModelComplex definition) Register a class binding for a given bound class.final IBoundModule
registerModule
(Class<? extends IBoundModule> clazz) Load a bound Metaschema module implemented by the provided class.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface gov.nist.secauto.metaschema.databind.IBindingContext
getJavaTypeAdapterInstance, loadMetaschema, loadMetaschema, newBoundLoader, newConstraintLoader, newValidator, registerModule, validate, validate, validate, validateWithConstraints
-
Constructor Details
-
DefaultBindingContext
public DefaultBindingContext()Construct a new binding context. -
DefaultBindingContext
Construct a new binding context.- Parameters:
strategy
- the behavior class to use for loading Metaschema modules- Since:
- 2.0.0
-
-
Method Details
-
getModuleLoaderStrategy
Description copied from interface:IBindingContext
Get the Metaschema module loader strategy used by this binding context to load modules.- Specified by:
getModuleLoaderStrategy
in interfaceIBindingContext
- Returns:
- the strategy instance
-
newModuleLoader
Description copied from interface:IBindingContext
Get a loader that supports loading a Metaschema module from a specified resource.Modules loaded with this loader are automatically registered with this binding context.
Use of this method requires that the binding context is initialized using a
IBindingContext.IModuleLoaderStrategy
that supports dynamic bound module loading. This can be accomplished using theSimpleModuleLoaderStrategy
initialized using theDefaultModuleBindingGenerator
. * @return the loader- Specified by:
newModuleLoader
in interfaceIBindingContext
- Returns:
- the loader
-
registerModule
Description copied from interface:IBindingContext
Load a bound Metaschema module implemented by the provided class.Also registers any associated bound classes.
Implementations are expected to return the same IModule instance for multiple calls to this method with the same class argument.
- Specified by:
registerModule
in interfaceIBindingContext
- Parameters:
clazz
- the class implementing a bound Metaschema module- Returns:
- the loaded module
-
getBindingMatchers
Get the binding matchers that are associated with this class.- Returns:
- the list of matchers
-
registerClassBinding
public final IBoundDefinitionModelComplex registerClassBinding(IBoundDefinitionModelComplex definition) Description copied from interface:IBindingContext
Register a class binding for a given bound class.- Specified by:
registerClassBinding
in interfaceIBindingContext
- Parameters:
definition
- the bound class information to register- Returns:
- the old bound class information or
null
if no binding existed for the associated class
-
getBoundDefinitionForClass
public final IBoundDefinitionModelComplex getBoundDefinitionForClass(@NonNull Class<? extends IBoundObject> clazz) Description copied from interface:IBindingContext
Get theIBoundDefinitionModel
instance associated with the provided Java class.Typically the class will have a
MetaschemaAssembly
orMetaschemaField
annotation.- Specified by:
getBoundDefinitionForClass
in interfaceIBindingContext
- Parameters:
clazz
- the class binding to load- Returns:
- the associated class binding instance or
null
if the class is not bound
-
newSerializer
public <CLASS extends IBoundObject> ISerializer<CLASS> newSerializer(@NonNull Format format, @NonNull Class<CLASS> clazz) Gets a dataISerializer
which can be used to write Java instance data for the provided class in the requested format.The provided class must be a bound Java class with a
MetaschemaAssembly
orMetaschemaField
annotation for which aIBoundDefinitionModel
exists.A serializer returned by this method is thread-safe.
- Specified by:
newSerializer
in interfaceIBindingContext
- Type Parameters:
CLASS
- the Java type this serializer can write data from- Parameters:
format
- the format to serialize intoclazz
- the Java data object to serialize- Returns:
- the serializer instance
- See Also:
-
newDeserializer
public <CLASS extends IBoundObject> IDeserializer<CLASS> newDeserializer(@NonNull Format format, @NonNull Class<CLASS> clazz) Gets a dataIDeserializer
which can be used to read Java instance data for the provided class from the requested format.The provided class must be a bound Java class with a
MetaschemaAssembly
orMetaschemaField
annotation for which aIBoundDefinitionModel
exists.A deserializer returned by this method is thread-safe.
- Specified by:
newDeserializer
in interfaceIBindingContext
- Type Parameters:
CLASS
- the Java type this deserializer can read data into- Parameters:
format
- the format to serialize intoclazz
- the Java data type to serialize- Returns:
- the deserializer instance
- See Also:
-
getBoundClassForRootXmlQName
Description copied from interface:IBindingContext
Determine the bound class for the provided XMLQName
.- Specified by:
getBoundClassForRootXmlQName
in interfaceIBindingContext
- Parameters:
rootQName
- the root XML element's QName- Returns:
- the bound class or
null
if not recognized
-
getBoundClassForRootJsonName
Description copied from interface:IBindingContext
Determine the bound class for the provided JSON/YAML property/item name using any registered matchers.- Specified by:
getBoundClassForRootJsonName
in interfaceIBindingContext
- Parameters:
rootName
- the JSON/YAML property/item name- Returns:
- the bound class or
null
if not recognized
-
deepCopy
public <CLASS extends IBoundObject> CLASS deepCopy(@NonNull CLASS other, IBoundObject parentInstance) throws BindingException Description copied from interface:IBindingContext
Create a deep copy of the provided bound object.- Specified by:
deepCopy
in interfaceIBindingContext
- Type Parameters:
CLASS
- the bound object type- Parameters:
other
- the object to copyparentInstance
- the object's parent ornull
- Returns:
- a deep copy of the provided object
- Throws:
BindingException
- if an error occurred copying content between java instances
-