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.
    • Method Detail

      • instance

        @NonNull
        static IBindingContext instance()
        Get the singleton IBindingContext instance, 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
      • getJavaTypeAdapterInstance

        @Nullable
        <TYPE extends IDataTypeAdapter<?>> TYPE getJavaTypeAdapterInstance​(@NonNull
                                                                           Class<TYPE> clazz)
        Get's the IDataTypeAdapter associated 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 Java Class for the bound type
        Returns:
        the adapter instance or null if 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 Module module.
        Parameters:
        module - the Module module to generate classes for
        compilePath - the path to the directory to generate classes in
        Returns:
        this instance
        Throws:
        IOException - if an error occurred while generating or loading the classes
      • 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 copy
        parentInstance - the object's parent or null
        Returns:
        a deep copy of the provided object
        Throws:
        BindingException - if an error occurred copying content between java instances
        NullPointerException - if the provided object is null
        IllegalArgumentException - if the provided class is not bound to a Module assembly or field
      • validate

        default IValidationResult validate​(@NonNull
                                           INodeItem nodeItem)
        Perform constraint validation on the provided bound object represented as an INodeItem.
        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 validate
        asFormat - the schema format to use to validate the target
        schemaProvider - provides callbacks to get the appropriate schemas
        Returns:
        the validation result
        Throws:
        IOException - if an error occurred while reading the target
        SAXException - if an error occurred when parsing the target as XML
      • validateWithConstraints

        default IValidationResult validateWithConstraints​(@NonNull
                                                          Path target)
                                                   throws IOException
        Load and validate the provided target using 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