Class DefaultBindingContext
- java.lang.Object
-
- gov.nist.secauto.metaschema.databind.DefaultBindingContext
-
- All Implemented Interfaces:
IBindingContext
public class DefaultBindingContext extends Object implements IBindingContext
The implementation of aIBindingContextprovided 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)andnewDeserializer(Format, Class)methods willThis class is synchronized and is thread-safe.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface gov.nist.secauto.metaschema.databind.IBindingContext
IBindingContext.IValidationSchemaProvider
-
-
Constructor Summary
Constructors Constructor Description DefaultBindingContext()Construct a new binding context.DefaultBindingContext(Set<IConstraintSet> externalConstraintSets)Construct a new binding context.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <CLASS> CLASScopyBoundObject(CLASS other, Object parentInstance)Create a deep copy of the provided bound object.protected List<? extends IBindingMatcher>getBindingMatchers()Get the binding matchers that are associated with this class.Class<?>getBoundClassForJsonName(String rootName)Determine the bound class for the provided JSON/YAML property/item name using any registered matchers.Class<?>getBoundClassForXmlQName(QName rootQName)Determine the bound class for the provided XMLQName.IClassBindinggetClassBinding(Class<?> clazz)Map<Class<?>,IClassBinding>getClassBindingsByClass()<TYPE extends IDataTypeAdapter<?>>
TYPEgetJavaTypeAdapterInstance(Class<TYPE> clazz)Get's theIDataTypeAdapterassociated with the specified Java class, which is used to read and write XML, JSON, and YAML data to and from instances of that class.IModulegetModuleByClass(Class<? extends IModule> clazz)static DefaultBindingContextinstance()Get the singleton instance of this binding context.IBoundLoadernewBoundLoader()Get a newIBoundLoaderinstance.<CLASS> IDeserializer<CLASS>newDeserializer(Format format, Class<CLASS> clazz)Gets a dataIDeserializerwhich can be used to read Java instance data for the provided class from the requested format.<CLASS> ISerializer<CLASS>newSerializer(Format format, Class<CLASS> clazz)Gets a dataISerializerwhich can be used to write Java instance data for the provided class to the requested format.DefaultBindingContextregisterBindingMatcher(IBindingMatcher matcher)Register a matcher used to identify a bound class by the content's root name.-
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
newValidator, registerModule, validate, validate, validateWithConstraints
-
-
-
-
Constructor Detail
-
DefaultBindingContext
public DefaultBindingContext(@NonNull Set<IConstraintSet> externalConstraintSets)
Construct a new binding context.- Parameters:
externalConstraintSets- the set of external constraints to configure this binding to use
-
DefaultBindingContext
public DefaultBindingContext()
Construct a new binding context.
-
-
Method Detail
-
instance
@NonNull public static DefaultBindingContext instance()
Get the singleton instance of this binding context.- Returns:
- the binding context
-
getModuleByClass
public IModule getModuleByClass(@NonNull Class<? extends IModule> clazz)
-
getClassBinding
public IClassBinding getClassBinding(@NonNull Class<?> clazz)
-
getClassBindingsByClass
public Map<Class<?>,IClassBinding> getClassBindingsByClass()
-
getJavaTypeAdapterInstance
public <TYPE extends IDataTypeAdapter<?>> TYPE getJavaTypeAdapterInstance(@NonNull Class<TYPE> clazz)
Description copied from interface:IBindingContextGet's theIDataTypeAdapterassociated with the specified Java class, which is used to read and write XML, JSON, and YAML data to and from instances of that class. Thus, this adapter supports a direct binding between the Java class and structured data in one of the supported formats. Adapters are used to support bindings for simple data objects (e.g.,String,BigInteger,ZonedDateTime, etc).- Specified by:
getJavaTypeAdapterInstancein interfaceIBindingContext- Type Parameters:
TYPE- the class type of the adapter- Parameters:
clazz- the JavaClassfor the bound type- Returns:
- the adapter instance or
nullif the provided class is not bound
-
newSerializer
public <CLASS> ISerializer<CLASS> newSerializer(@NonNull Format format, @NonNull Class<CLASS> clazz)
Gets a dataISerializerwhich can be used to write Java instance data for the provided class to the requested format. The provided class must be a bound Java class with aMetaschemaAssemblyorMetaschemaFieldannotation for which aIClassBindingexists.A serializer returned by this method is thread-safe.
- Specified by:
newSerializerin interfaceIBindingContext- Type Parameters:
CLASS- the Java type this deserializer can write data from- Parameters:
format- the format to serialize intoclazz- the Java data type to serialize- Returns:
- the serializer instance
- See Also:
getClassBinding(Class)
-
newDeserializer
public <CLASS> IDeserializer<CLASS> newDeserializer(@NonNull Format format, @NonNull Class<CLASS> clazz)
Gets a dataIDeserializerwhich 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 aMetaschemaAssemblyorMetaschemaFieldannotation for which aIClassBindingexists.A deserializer returned by this method is thread-safe.
- Specified by:
newDeserializerin 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:
getClassBinding(Class)
-
registerBindingMatcher
public DefaultBindingContext registerBindingMatcher(@NonNull IBindingMatcher matcher)
Description copied from interface:IBindingContextRegister a matcher used to identify a bound class by the content's root name.- Specified by:
registerBindingMatcherin interfaceIBindingContext- Parameters:
matcher- the matcher implementation- Returns:
- this instance
-
getBindingMatchers
@NonNull protected List<? extends IBindingMatcher> getBindingMatchers()
Get the binding matchers that are associated with this class.- Returns:
- the list of matchers
- See Also:
registerBindingMatcher(IBindingMatcher)
-
getBoundClassForXmlQName
public Class<?> getBoundClassForXmlQName(@NonNull QName rootQName)
Description copied from interface:IBindingContextDetermine the bound class for the provided XMLQName.- Specified by:
getBoundClassForXmlQNamein interfaceIBindingContext- Parameters:
rootQName- the root XML element's QName- Returns:
- the bound class or
nullif not recognized - See Also:
IBindingContext.registerBindingMatcher(IBindingMatcher)
-
getBoundClassForJsonName
public Class<?> getBoundClassForJsonName(@NonNull String rootName)
Description copied from interface:IBindingContextDetermine the bound class for the provided JSON/YAML property/item name using any registered matchers.- Specified by:
getBoundClassForJsonNamein interfaceIBindingContext- Parameters:
rootName- the JSON/YAML property/item name- Returns:
- the bound class or
nullif not recognized - See Also:
IBindingContext.registerBindingMatcher(IBindingMatcher)
-
newBoundLoader
public IBoundLoader newBoundLoader()
Description copied from interface:IBindingContextGet a newIBoundLoaderinstance.- Specified by:
newBoundLoaderin interfaceIBindingContext- Returns:
- the instance
-
copyBoundObject
public <CLASS> CLASS copyBoundObject(@NonNull CLASS other, Object parentInstance) throws BindingException
Description copied from interface:IBindingContextCreate a deep copy of the provided bound object.- Specified by:
copyBoundObjectin 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
-
-