Class KlumFactory<T>

java.lang.Object
com.blackbuild.klum.ast.runtime.KlumFactory<T>
Type Parameters:
T - The type of the DSL model object.
Direct Known Subclasses:
KlumFactory.Keyed, KlumFactory.Unkeyed

public class KlumFactory<T> extends Object
Factory to create DSL model objects.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Active-session Builder-producing operations shared by keyed and unkeyed factories.
    static interface 
    Public factory capability used by generated polymorphic relationship methods.
    static class 
    Factory for keyed models.
    static final class 
    Builder-producing operations for keyed model types.
    static class 
    Factory for unkeyed models.
    static final class 
    Builder-producing operations for unkeyed model types.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final Class<T>
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the active-session factory used to create owned child Builders.
    From(File configurationFile)
    Creates a new instance of the model type by instantiating the class and applying the text content of the given file to it.
    From(File configurationFile, ClassLoader loader)
    Creates a new instance of the model type by instantiating the class and applying the text content of the given file to it.
    From(File configurationFile, Function<File,String> keyProvider)
    Creates a new instance of the model type by instantiating the class and applying the text content of the given file to it.
    From(File configurationFile, Function<File,String> keyProvider, ClassLoader loader)
    Creates a new instance of the model type by instantiating the class and applying the text content of the given file to it.
    From(Class<? extends groovy.lang.Script> configurationScript)
    Creates a new instance of the model type by running the given script class.
    From(URL configurationUrl)
    Creates a new instance of the model type by instantiating the class and applying the text content of the given url to it.
    From(URL configurationUrl, ClassLoader loader)
    Creates a new instance of the model type by instantiating the class and applying the text content of the given url to it.
    From(URL configurationUrl, Function<URL,String> keyProvider)
    Creates a new instance of the model type by instantiating the class and applying the text content of the given url to it.
    From(URL configurationUrl, Function<URL,String> keyProvider, ClassLoader loader)
    Creates a new instance of the model type by instantiating the class and applying the text content of the given url to it.
    Creates a new instance of this owner's model type by reading the script from a well-defined properties file placed in '/META-INF/klum-model/"schema-classname".properties'.
    Creates a new instance of this owner's model type by reading the script from a well-defined properties file placed in '/META-INF/klum-model/"schema-classname".properties'.
    FromMap(Map<String,Object> configMap)
    Creates a new instance of the model type by applying the given configuration map.
    final Class<T>
    Returns the DSL Object type selected by this factory.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • type

      protected final Class<T> type
  • Constructor Details

    • KlumFactory

      protected KlumFactory(Class<T> type)
  • Method Details

    • getModelType

      public final Class<T> getModelType()
      Returns the DSL Object type selected by this factory.
    • AsBuilder

      public KlumFactory.BuilderFactory<T,KlumBuilder<T>> AsBuilder()
      Returns the active-session factory used to create owned child Builders.
    • FromClasspath

      public T FromClasspath()
      Creates a new instance of this owner's model type by reading the script from a well-defined properties file placed in '/META-INF/klum-model/"schema-classname".properties'. The properties file must contain a property name "model-class" which contains the name of the compiled script to run, which must return an instance of the model class.
      Returns:
      The created model object.
      See Also:
    • FromClasspath

      public T FromClasspath(ClassLoader loader)
      Creates a new instance of this owner's model type by reading the script from a well-defined properties file placed in '/META-INF/klum-model/"schema-classname".properties'. The properties file must contain a property name "model-class" which contains the name of the compiled script to run, which must return an instance of the model class.
      Parameters:
      loader - The classloader to use to load the properties file.
      Returns:
      The created model object.
      See Also:
    • From

      public T From(Class<? extends groovy.lang.Script> configurationScript)
      Creates a new instance of the model type by running the given script class. The script must either return an instance of the model (i.e. contain something like 'MyClass.Create.With {...}') or must be a DelegatingScript whose contents are the same as create/apply closure for this model class.

      Note that in case of a Keyed object in combination with a DelegatingScript, the simple name of the script class is used as key.

      Parameters:
      configurationScript - The script class to run.
      Returns:
      The instantiated object.
    • From

      public T From(URL configurationUrl)
      Creates a new instance of the model type by instantiating the class and applying the text content of the given url to it. In case of a keyed model, the last part of the URL is used as the key.
      Parameters:
      configurationUrl - The URL where to take the configuration text from.
      Returns:
      The instantiated object.
      See Also:
    • From

      public T From(URL configurationUrl, Function<URL,String> keyProvider)
      Creates a new instance of the model type by instantiating the class and applying the text content of the given url to it. In case of a keyed model, the last part of the URL is used as the key.
      Parameters:
      configurationUrl - The URL where to take the configuration text from.
      keyProvider - A function that derives the key from the URL.
      Returns:
      The instantiated object.
      See Also:
    • From

      public T From(URL configurationUrl, ClassLoader loader)
      Creates a new instance of the model type by instantiating the class and applying the text content of the given url to it. In case of a keyed model, the last part of the URL is used as the key.
      Parameters:
      configurationUrl - The URL where to take the configuration text from.
      loader - The classloader to use for compiling the configuration text.
      Returns:
      The instantiated object.
    • From

      public T From(URL configurationUrl, Function<URL,String> keyProvider, ClassLoader loader)
      Creates a new instance of the model type by instantiating the class and applying the text content of the given url to it. In case of a keyed model, the key is derived from the URL using the provided keyProvider.
      Parameters:
      configurationUrl - The URL where to take the configuration text from.
      keyProvider - A function that derives the key from the URL.
      loader - The classloader to use for compiling the configuration text.
      Returns:
      The instantiated object.
    • From

      public T From(File configurationFile)
      Creates a new instance of the model type by instantiating the class and applying the text content of the given file to it. In case of a keyed model, the filename is used as the key.
      Parameters:
      configurationFile - The file where to take the configuration text from.
      Returns:
      The instantiated object.
      See Also:
    • From

      public T From(File configurationFile, Function<File,String> keyProvider, ClassLoader loader)
      Creates a new instance of the model type by instantiating the class and applying the text content of the given file to it. In case of a keyed model, provided keyProvider is used to derive the key from the file object.
      Parameters:
      configurationFile - The file where to take the configuration text from.
      keyProvider - A function that derives the key from the file.
      loader - The classloader to use for compiling the configuration text.
      Returns:
      The instantiated object.
    • From

      public T From(File configurationFile, Function<File,String> keyProvider)
      Creates a new instance of the model type by instantiating the class and applying the text content of the given file to it. In case of a keyed model, the filename is used as the key.
      Parameters:
      configurationFile - The file where to take the configuration text from.
      Returns:
      The instantiated object.
      See Also:
    • From

      public T From(File configurationFile, ClassLoader loader)
      Creates a new instance of the model type by instantiating the class and applying the text content of the given file to it. In case of a keyed model, the filename is used as the key.
      Parameters:
      configurationFile - The file where to take the configuration text from.
      loader - The classloader to use for compiling the configuration text.
      Returns:
      The instantiated object.
    • FromMap

      public T FromMap(Map<String,Object> configMap)
      Creates a new instance of the model type by applying the given configuration map. By default, this takes the key from a map entry that is named as the key field, other values of the map are set to their respective fields.
      Parameters:
      configMap - a map containing the values to set on the model.
      Returns:
      The instantiated object.