Class FactoryHelper
- All Implemented Interfaces:
groovy.lang.GroovyObject
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Tcreate(Class<T> type, @Nullable Map<String, ?> values, @Nullable String key, @Nullable groovy.lang.Closure<?> body) Creates a new instance of the given type using the provided values, key and config closure.static <T> InternalKlumBuilder<T>createAsBuilder(Class<T> type, @Nullable Map<String, ?> values, @Nullable String key, @Nullable groovy.lang.Closure<?> body, String operation) static <T> TcreateAsTemplate(Class<T> type, File scriptFile, ClassLoader loader) Creates a template of the given type by reading the given resource, compiling it into a delegating script and applying it to a newly created instance.static <T> TcreateAsTemplate(Class<T> type, String text, ClassLoader loader) Creates a template of the given type by reading the given resource, compiling it into a delegating script and applying it to a newly created instance.static <T> TcreateAsTemplate(Class<T> type, URL script, ClassLoader loader) Creates a template of the given type by reading the given resource, compiling it into a delegating script and applying it to a newly created instance.static <T> TcreateAsTemplate(Class<T> type, Map<String, ?> values, @Nullable groovy.lang.Closure<?> closure) Creates a new template instance of the given type using the provided values and config closure.static <T> InternalKlumBuilder<T>createBuilder(Class<T> type, String key) static <T> InternalKlumBuilder<T>createBuilder(Class<T> type, String key, String breadcrumbPathExtension) static <T> TcreateFrom(Class<T> type, @Nullable String name, String text, @Nullable ClassLoader loader) Creates an instance of the given type by compiling the given text into a delegating script and applying it to a newly created instance.static <T> TcreateFrom(Class<T> type, File file, @Nullable Function<File, String> keyProvider, @Nullable ClassLoader loader) Creates an instance of the given type by reading the given file, compiling it into a delegating script and applying it to a newly created instance.static <T> TcreateFrom(Class<T> type, Class<? extends groovy.lang.Script> scriptType) Creates an instance of the given type by running the given script.static <T> TcreateFrom(Class<T> type, URL src, @Nullable Function<URL, String> keyProvider, @Nullable ClassLoader loader) Creates an instance of the given type by reading the given URL, compiling it into a delegating script and applying it to a newly created instance.static <T> InternalKlumBuilder<T>createFromAsBuilder(Class<T> type, Class<? extends groovy.lang.Script> scriptType) static <T> TcreateFromClasspath(Class<T> type) Creates an instance of the given class by reading the model script class from the classpath.static <T> TcreateFromClasspath(Class<T> type, ClassLoader loader) Creates an instance of the given class by reading the model script class from the classpath.static <T> TcreateFromMap(Class<T> type, Map<String, Object> configMap) static <T> InternalKlumBuilder<T>createFromMapAsBuilder(Class<T> type, Map<String, Object> configMap) static <T> TcreateFromSerializedState(Class<T> type, Map<String, Object> serializedState) Restores serialized field state into a Builder and then runs the complete lifecycle.static <T> InternalKlumBuilder<T>createNestedBuilder(Class<T> type, Map<String, ?> values, String key) Creates and configures a composition child without entering another phase lifecycle.static <T> KlumBuilder<T>createTemplateBuilderForImport(Class<T> type) Internal adapter hook for importing a value-only Template without a Groovy configuration source.static <T> KlumBuilder<T>createTemplateBuilderForImport(Class<T> type, String key) Internal adapter hook for a nested Template value imported without a Groovy configuration source.static <T> Class<T>getTypeOrDefaultType(Class<T> type) static <T> TwithTemplateDefinition(Supplier<T> action) Internal scope for Template-definition import paths that need nested Builder composition.Methods inherited from class groovy.lang.GroovyObjectSupport
getMetaClass, setMetaClassMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface groovy.lang.GroovyObject
getProperty, invokeMethod, setProperty
-
Field Details
-
MODEL_CLASS_KEY
- See Also:
-
-
Method Details
-
withTemplateDefinition
Internal scope for Template-definition import paths that need nested Builder composition. -
createBuilder
-
createBuilder
public static <T> InternalKlumBuilder<T> createBuilder(Class<T> type, String key, String breadcrumbPathExtension) -
createTemplateBuilderForImport
Internal adapter hook for importing a value-only Template without a Groovy configuration source. -
createTemplateBuilderForImport
Internal adapter hook for a nested Template value imported without a Groovy configuration source. -
createNestedBuilder
public static <T> InternalKlumBuilder<T> createNestedBuilder(Class<T> type, Map<String, ?> values, String key) Creates and configures a composition child without entering another phase lifecycle. The root Builder traversal will process and materialize it together with its owner. -
createFromClasspath
Creates an instance of the given class by reading the model script class from the classpath.The model script is determined by reading the properties file META-INF/klum-model/<type>.properties, which must contain the key 'model-class' with the fully qualified class name of the model script.
- Type Parameters:
T- The type to create- Parameters:
type- The type to create- Returns:
- The created instance
-
createFromClasspath
Creates an instance of the given class by reading the model script class from the classpath.The model script is determined by reading the properties file META-INF/klum-model/<type>.properties, which must contain the key 'model-class' with the fully qualified class name of the model script. The properties and the script class is loaded using the given class loader.
- Type Parameters:
T- The type to create- Parameters:
type- The type to createloader- The class loader to load the script name and class from- Returns:
- The created instance
-
createFrom
Creates an instance of the given type by running the given script.The script can either be a regular script or a delegating script. A regular script will be instantiated and executed, the result will be returned. If the script returns the wrong type, an error will be thrown. For a delegating script, a new instance of the given type will be created and the script run as a closure on the RW instance.
Basically, a regular script must start with
Type.Create..., while a delegating script should only contain the body of the configuration closure.For a keyed type with a delegating script, the simple name of the script is used as the key, for a regular script, the script itself is responsible to provide the key.
- Type Parameters:
T- The type to create- Parameters:
type- The type to createscriptType- The script to run- Returns:
- The created instance
-
create
public static <T> T create(Class<T> type, @Nullable @Nullable Map<String, ?> values, @Nullable @Nullable String key, @Nullable @Nullable groovy.lang.Closure<?> body) Creates a new instance of the given type using the provided values, key and config closure.First the class is instantiated using the key as constructor argument if keyed. Then the values are applied by using the keys as method names of the RW instance and the values as the single argument of that method. Finally the config closure is applied to the RW instance.
- Type Parameters:
T- The type to create- Parameters:
type- The type to createvalues- The value map to applykey- The key to use for instantiation, ignored if the type is not keyedbody- The config closure to apply- Returns:
- The created instance
-
createAsBuilder
-
createFrom
public static <T> T createFrom(Class<T> type, URL src, @Nullable @Nullable Function<URL, String> keyProvider, @Nullable @Nullable ClassLoader loader) Creates an instance of the given type by reading the given URL, compiling it into a delegating script and applying it to a newly created instance.- Type Parameters:
T- The type to create- Parameters:
type- The type to createsrc- The URL to read- Returns:
- The created instance
-
createFrom
public static <T> T createFrom(Class<T> type, @Nullable @Nullable String name, String text, @Nullable @Nullable ClassLoader loader) Creates an instance of the given type by compiling the given text into a delegating script and applying it to a newly created instance.- Type Parameters:
T- The type to create- Parameters:
type- The type to createname- The name of the script, only relevant for keyed types- Returns:
- The created instance
-
createFrom
public static <T> T createFrom(Class<T> type, File file, @Nullable @Nullable Function<File, String> keyProvider, @Nullable @Nullable ClassLoader loader) Creates an instance of the given type by reading the given file, compiling it into a delegating script and applying it to a newly created instance.- Type Parameters:
T- The type to create- Parameters:
type- The type to createfile- The file to readkeyProvider- The function to provide the key from the file, usually some kind of name extractionloader- The classloader to use for creating the script- Returns:
- The created instance
-
createAsTemplate
Creates a template of the given type by reading the given resource, compiling it into a delegating script and applying it to a newly created instance.Template instance don't run lifecycle phases/methods.
- Type Parameters:
T- The type to create- Parameters:
type- The type to createscriptFile- The resource to read- Returns:
- The created instance
-
createAsTemplate
Creates a template of the given type by reading the given resource, compiling it into a delegating script and applying it to a newly created instance.Template instance don't run lifecycle phases/methods.
- Type Parameters:
T- The type to create- Parameters:
type- The type to createtext- The script text- Returns:
- The created instance
-
createAsTemplate
Creates a template of the given type by reading the given resource, compiling it into a delegating script and applying it to a newly created instance.Template instance don't run lifecycle phases/methods.
- Type Parameters:
T- The type to create- Parameters:
type- The type to createscript- The resource to read- Returns:
- The created instance
-
createAsTemplate
public static <T> T createAsTemplate(Class<T> type, Map<String, ?> values, @Nullable @Nullable groovy.lang.Closure<?> closure) Creates a new template instance of the given type using the provided values and config closure.The values are applied by using the keys as method names of the RW instance and the values as the single argument of that method. Finally the config closure is applied to the RW instance. Template instance don't run lifecycle phases/methods.
- Type Parameters:
T- The type to create- Parameters:
type- The type to createvalues- The value map to applyclosure- The optional config closure to apply- Returns:
- The created instance
-
createFromMap
-
createFromMapAsBuilder
public static <T> InternalKlumBuilder<T> createFromMapAsBuilder(Class<T> type, Map<String, Object> configMap) -
createFromAsBuilder
public static <T> InternalKlumBuilder<T> createFromAsBuilder(Class<T> type, Class<? extends groovy.lang.Script> scriptType) -
createFromSerializedState
Restores serialized field state into a Builder and then runs the complete lifecycle.This ordering is the explicitly provisional Jackson policy from issue #428: mutating callbacks run again after restoration and may therefore be non-idempotent.
-
getTypeOrDefaultType
-