Class DefaultBindingConfiguration

java.lang.Object
dev.metaschema.databind.codegen.config.DefaultBindingConfiguration
All Implemented Interfaces:
IBindingConfiguration

public class DefaultBindingConfiguration extends Object implements IBindingConfiguration
Default implementation of IBindingConfiguration that provides binding configuration for Java class generation from Metaschema modules.

This implementation supports loading configuration from XML files and provides namespace-to-package mappings and definition-specific binding configurations.

  • Constructor Details

    • DefaultBindingConfiguration

      public DefaultBindingConfiguration()
  • Method Details

    • getPackageNameForModule

      public String getPackageNameForModule(IModule module)
      Description copied from interface: IBindingConfiguration
      Generates a Java package name for the provided Module module.
      Specified by:
      getPackageNameForModule in interface IBindingConfiguration
      Parameters:
      module - the Module module to generate a package name for
      Returns:
      a Java package name
    • getBindingConfigurationForDefinition

      @Nullable public IDefinitionBindingConfiguration getBindingConfigurationForDefinition(@NonNull IModelDefinition definition)
      Retrieve the binding configuration for the provided definition.

      This method first checks for a binding by the definition's name. If not found and the definition is inline, it also checks for a binding by the definition's path (using "/" separated ancestor names).

      Specified by:
      getBindingConfigurationForDefinition in interface IBindingConfiguration
      Parameters:
      definition - the definition to get the config for
      Returns:
      the binding configuration or null if there is not configuration
    • getQualifiedBaseClassName

      public String getQualifiedBaseClassName(IModelDefinition definition)
      Description copied from interface: IBindingConfiguration
      Get the Java class name of the base class to use for the class associated with the provided definition.
      Specified by:
      getQualifiedBaseClassName in interface IBindingConfiguration
      Parameters:
      definition - a definition that may be built as a class
      Returns:
      the name of the base class or null if no base class is to be used
    • getClassName

      public String getClassName(IModelDefinition definition)
      Description copied from interface: IBindingConfiguration
      Get the Java class name for the provided field or assembly definition.
      Specified by:
      getClassName in interface IBindingConfiguration
      Parameters:
      definition - the definition to generate the Java class name for
      Returns:
      a Java class name
    • getClassName

      @NonNull public String getClassName(@NonNull IModule module)
      Description copied from interface: IBindingConfiguration
      Get the Java class name for the provided Module module.
      Specified by:
      getClassName in interface IBindingConfiguration
      Parameters:
      module - the Module module to generate the Java class name for
      Returns:
      a Java class name
    • getQualifiedSuperinterfaceClassNames

      public List<String> getQualifiedSuperinterfaceClassNames(IModelDefinition definition)
      Description copied from interface: IBindingConfiguration
      Get the Java class names of the superinterfaces to use for the class associated with the provided definition.
      Specified by:
      getQualifiedSuperinterfaceClassNames in interface IBindingConfiguration
      Parameters:
      definition - a definition that may be built as a class
      Returns:
      a list of superinterface class names
    • getPropertyBindingConfiguration

      @Nullable public IPropertyBindingConfiguration getPropertyBindingConfiguration(@NonNull IModelDefinition definition, @NonNull String propertyName)
      Get the property binding configuration for a specific property within a definition.
      Parameters:
      definition - the containing definition
      propertyName - the name of the property
      Returns:
      the property binding configuration, or null if none is configured
    • addModelBindingConfig

      public void addModelBindingConfig(String namespace, String packageName)
      Binds an XML namespace, which is normally associated with one or more Module, with a provided Java package name.
      Parameters:
      namespace - an XML namespace URI
      packageName - the package name to associate with the namespace
      Throws:
      IllegalStateException - if the binding configuration is changing a previously changed namespace to package binding
    • getPackageNameForNamespace

      @NonNull protected String getPackageNameForNamespace(@NonNull String namespace)
      Based on the current binding configuration, generate a Java package name for the provided namespace. If the namespace is already mapped, such as through the use of addModelBindingConfig(String, String), then the provided package name will be used. If the namespace is not mapped, then the namespace URI will be translated into a Java package name.
      Parameters:
      namespace - the namespace to generate a Java package name for
      Returns:
      a Java package name
    • getMetaschemaBindingConfiguration

      protected DefaultBindingConfiguration.MetaschemaBindingConfiguration getMetaschemaBindingConfiguration(@NonNull IModule module)
      Get the binding configuration for the provided Module.
      Parameters:
      module - the Module module
      Returns:
      the configuration for the Module or null if there is no configuration
    • getMetaschemaBindingConfiguration

      @Nullable protected DefaultBindingConfiguration.MetaschemaBindingConfiguration getMetaschemaBindingConfiguration(@NonNull String moduleUri)
      Get the binding configuration for the Module modulke located at the provided moduleUri.
      Parameters:
      moduleUri - the location of the Module module
      Returns:
      the configuration for the Module module or null if there is no configuration
    • addMetaschemaBindingConfiguration

      public DefaultBindingConfiguration.MetaschemaBindingConfiguration addMetaschemaBindingConfiguration(@NonNull String moduleUri, @NonNull DefaultBindingConfiguration.MetaschemaBindingConfiguration config)
      Set the binding configuration for the Module module located at the provided moduleUri.
      Parameters:
      moduleUri - the location of the Module module
      config - the Module binding configuration
      Returns:
      the old configuration for the Module module or null if there was no previous configuration
    • load

      public void load(Path file) throws IOException, BindingException
      Load the binding configuration from the provided file.
      Parameters:
      file - the configuration resource
      Throws:
      IOException - if an error occurred while reading the file
      BindingException - if an error occurred while processing the binding configuration
    • load

      public void load(File file) throws IOException, BindingException
      Load the binding configuration from the provided file.
      Parameters:
      file - the configuration resource
      Throws:
      IOException - if an error occurred while reading the file
      BindingException - if an error occurred while processing the binding configuration
    • load

      public void load(@NonNull URL resource) throws IOException, BindingException
      Load the binding configuration from the provided resource.
      Parameters:
      resource - the configuration resource
      Throws:
      IOException - if an error occurred while reading the resource
      BindingException - if an error occurred while processing the binding configuration