Interface IBindingContext
-
- All Known Implementing Classes:
DefaultBindingContext
public interface IBindingContext
Provides information supporting a binding between a set of Module models and corresponding Java classes.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceIBindingContext.IValidationSchemaProvider
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description <CLASS> CLASScopyBoundObject(CLASS other, Object parentInstance)Create a deep copy of the provided bound object.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)Get theIClassBindinginstance for aMetaschemaAssemblyorMetaschemaFieldassociated with a Java class.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)Get the Metaschema module identified by the provided class.static IBindingContextinstance()Get the singletonIBindingContextinstance, which can be used to load information that binds a model to a set of Java classes.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.default IConstraintValidatornewValidator(IConstraintValidationHandler handler)Get a new single use constraint validator.IBindingContextregisterBindingMatcher(IBindingMatcher matcher)Register a matcher used to identify a bound class by the content's root name.default IBindingContextregisterModule(IModule module, Path compilePath)Generate, compile, and load a set of generated Module annotated Java classes based on the provided Modulemodule.default IValidationResultvalidate(INodeItem nodeItem)Perform constraint validation on the provided bound object represented as anINodeItem.default IValidationResultvalidate(Path target, Format asFormat, IBindingContext.IValidationSchemaProvider schemaProvider)Load and perform schema and constraint validation on the target.default IValidationResultvalidateWithConstraints(Path target)Load and validate the providedtargetusing the associated Module module constraints.
-
-
-
Method Detail
-
instance
@NonNull static IBindingContext instance()
Get the singletonIBindingContextinstance, which can be used to load information that binds a model to a set of Java classes.- Returns:
- a new binding context
-
registerBindingMatcher
@NonNull IBindingContext registerBindingMatcher(@NonNull IBindingMatcher matcher)
Register a matcher used to identify a bound class by the content's root name.- Parameters:
matcher- the matcher implementation- Returns:
- this instance
-
getBoundClassForXmlQName
@Nullable Class<?> getBoundClassForXmlQName(@NonNull QName rootQName)
Determine the bound class for the provided XMLQName.- Parameters:
rootQName- the root XML element's QName- Returns:
- the bound class or
nullif not recognized - See Also:
registerBindingMatcher(IBindingMatcher)
-
getBoundClassForJsonName
@Nullable Class<?> getBoundClassForJsonName(@NonNull String rootName)
Determine the bound class for the provided JSON/YAML property/item name using any registered matchers.- Parameters:
rootName- the JSON/YAML property/item name- Returns:
- the bound class or
nullif not recognized - See Also:
registerBindingMatcher(IBindingMatcher)
-
getJavaTypeAdapterInstance
@Nullable <TYPE extends IDataTypeAdapter<?>> TYPE getJavaTypeAdapterInstance(@NonNull 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. 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).- 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
-
registerModule
@NonNull default IBindingContext registerModule(@NonNull IModule module, @NonNull Path compilePath) throws IOException
Generate, compile, and load a set of generated Module annotated Java classes based on the provided Modulemodule.- Parameters:
module- the Module module to generate classes forcompilePath- the path to the directory to generate classes in- Returns:
- this instance
- Throws:
IOException- if an error occurred while generating or loading the classes
-
newSerializer
@NonNull <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.- 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
- Throws:
NullPointerException- if any of the provided arguments, except the configuration, arenullIllegalArgumentException- if the provided class is not bound to a Module assembly or fieldUnsupportedOperationException- if the requested format is not supported by the implementation- See Also:
getClassBinding(Class)
-
newDeserializer
@NonNull <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.- 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
- Throws:
NullPointerException- if any of the provided arguments, except the configuration, arenullIllegalArgumentException- if the provided class is not bound to a Module assembly or fieldUnsupportedOperationException- if the requested format is not supported by the implementation- See Also:
getClassBinding(Class)
-
newBoundLoader
@NonNull IBoundLoader newBoundLoader()
Get a newIBoundLoaderinstance.- Returns:
- the instance
-
copyBoundObject
@NonNull <CLASS> CLASS copyBoundObject(@NonNull CLASS other, Object parentInstance) throws BindingException
Create a deep copy of the provided bound object.- 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 instancesNullPointerException- if the provided object isnullIllegalArgumentException- if the provided class is not bound to a Module assembly or field
-
newValidator
default IConstraintValidator newValidator(@NonNull IConstraintValidationHandler handler)
Get a new single use constraint validator.- Parameters:
handler- the validation handler to use to process the validation results- Returns:
- the validator
-
validate
default IValidationResult validate(@NonNull INodeItem nodeItem)
Perform constraint validation on the provided bound object represented as anINodeItem.- Parameters:
nodeItem- the node item to validate- Returns:
- the validation result
- Throws:
IllegalArgumentException- if the provided class is not bound to a Module assembly or field
-
validate
default IValidationResult validate(@NonNull Path target, @NonNull Format asFormat, @NonNull IBindingContext.IValidationSchemaProvider schemaProvider) throws IOException, SAXException
Load and perform schema and constraint validation on the target. The constraint validation will only be performed if the schema validation passes.- Parameters:
target- the target to validateasFormat- the schema format to use to validate the targetschemaProvider- provides callbacks to get the appropriate schemas- Returns:
- the validation result
- Throws:
IOException- if an error occurred while reading the targetSAXException- if an error occurred when parsing the target as XML
-
validateWithConstraints
default IValidationResult validateWithConstraints(@NonNull Path target) throws IOException
Load and validate the providedtargetusing the associated Module module constraints.- Parameters:
target- the file to load and validate- Returns:
- the validation results
- Throws:
IOException- if an error occurred while loading the document
-
getModuleByClass
@NonNull IModule getModuleByClass(@NonNull Class<? extends IModule> clazz)
Get the Metaschema module identified by the provided class.- Parameters:
clazz- the Module class- Returns:
- the module
- Throws:
IllegalStateException- if an error occurred while processing the associated module information
-
getClassBinding
@Nullable IClassBinding getClassBinding(@NonNull Class<?> clazz)
Get theIClassBindinginstance for aMetaschemaAssemblyorMetaschemaFieldassociated with a Java class.- Parameters:
clazz- the class binding to load- Returns:
- the associated class binding instance or
nullif the class is not bound
-
getClassBindingsByClass
@NonNull Map<Class<?>,IClassBinding> getClassBindingsByClass()
-
-