- java.lang.Object
-
- org.praxislive.code.CodeFactory<D>
-
- Type Parameters:
D
- base delegate type
- Direct Known Subclasses:
AudioCodeFactory
,CoreCodeFactory
,P2DCodeFactory
,P3DCodeFactory
,TFCodeFactory
,VideoCodeFactory
public class CodeFactory<D extends CodeDelegate> extends Object
A CodeFactory wraps configuration and task creation for creating code components and contexts for a given delegate base type.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CodeFactory.Base<B extends CodeDelegate>
Base code factory for a given base delegate class.static class
CodeFactory.Task<D extends CodeDelegate>
A task for creating a component or context for a given delegate.
-
Field Summary
Fields Modifier and Type Field Description static String
BASE_CLASS_KEY
Key for use in control info properties with the name of the base delegate type (class) as the value.static String
BASE_IMPORTS_KEY
Key for use in control info properties with the base imports that should be available in source code.
-
Constructor Summary
Constructors Modifier Constructor Description protected
CodeFactory(ClassBodyContext<D> cbc, ComponentType type, Class<? extends D> defaultCls, String template)
Deprecated.protected
CodeFactory(ClassBodyContext<D> cbc, ComponentType type, String template)
Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <B extends CodeDelegate>
CodeFactory.Base<B>base(Class<B> baseClass, List<String> baseImports, BiFunction<CodeFactory.Task<B>,B,CodeContext<B>> contextCreator)
Create a componentCodeFactory.Base
for the given base delegate class, from which can be created individual CodeFactory instances.Class<D>
baseClass()
Query the base delegate class.List<String>
baseImports()
Query the base imports to be automatically added to the source body.ComponentType
componentType()
Get the component type.static <B extends CodeContainerDelegate>
CodeFactory.Base<B>containerBase(Class<B> baseClass, List<String> baseImports, BiFunction<CodeFactory.Task<B>,B,CodeContext<B>> contextCreator)
Create a containerCodeFactory.Base
for the given base delegate class, from which can be created individual CodeFactory instances.Class<? extends D>
defaultDelegateClass()
Query the default delegate class.ClassBodyContext<D>
getClassBodyContext()
Deprecated.ComponentType
getComponentType()
Deprecated.Optional<Class<? extends D>>
getDefaultDelegateClass()
Deprecated.String
getSourceTemplate()
Deprecated.static <B extends CodeRootDelegate>
CodeFactory.Base<B>rootBase(Class<B> baseClass, List<String> baseImports, BiFunction<CodeFactory.Task<B>,B,CodeContext<B>> contextCreator)
Create a root componentCodeFactory.Base
for the given base delegate class, from which can be created individual CodeFactory instances.static <B extends CodeRootContainerDelegate>
CodeFactory.Base<B>rootContainerBase(Class<B> baseClass, List<String> baseImports, BiFunction<CodeFactory.Task<B>,B,CodeContext<B>> contextCreator)
Create a root containerCodeFactory.Base
for the given base delegate class, from which can be created individual CodeFactory instances.String
sourceTemplate()
The source template corresponding to the default delegate class.CodeFactory.Task<D>
task()
Create a task for constructing a context or component from a delegate class.
-
-
-
Field Detail
-
BASE_CLASS_KEY
public static final String BASE_CLASS_KEY
Key for use in control info properties with the name of the base delegate type (class) as the value.- See Also:
- Constant Field Values
-
BASE_IMPORTS_KEY
public static final String BASE_IMPORTS_KEY
Key for use in control info properties with the base imports that should be available in source code. The value should be a PArray of import lines, each containing a full import declaration.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CodeFactory
@Deprecated protected CodeFactory(ClassBodyContext<D> cbc, ComponentType type, Class<? extends D> defaultCls, String template)
Deprecated.Construct CodeFactory for a type extending the base code delegate type. This constructor allows for a precompiled default delegate class to be provided. This must correspond to the code compiled from wrapping the provided class body template in the provided class body context.- Parameters:
cbc
- class body context that will wrap source codetype
- the component typedefaultCls
- precompiled default delegatetemplate
- code template reflecting default delegate
-
CodeFactory
@Deprecated protected CodeFactory(ClassBodyContext<D> cbc, ComponentType type, String template)
Deprecated.Construct CodeFactory for a type extending the base code delegate type. This constructor is used where the default delegate is compiled from the template at runtime.- Parameters:
cbc
- class body context that will wrap source codetype
- the component typetemplate
- code template reflecting default delegate
-
-
Method Detail
-
getComponentType
@Deprecated public final ComponentType getComponentType()
Deprecated.Get the component type.- Returns:
- component type
-
componentType
public final ComponentType componentType()
Get the component type.- Returns:
- component type
-
getClassBodyContext
@Deprecated public final ClassBodyContext<D> getClassBodyContext()
Deprecated.Class body context used to create wrapping class for source code.- Returns:
- class body context
-
getSourceTemplate
@Deprecated public final String getSourceTemplate()
Deprecated.The source template corresponding to the default delegate class.- Returns:
- source template
-
sourceTemplate
public final String sourceTemplate()
The source template corresponding to the default delegate class.- Returns:
- source template
-
getDefaultDelegateClass
@Deprecated public final Optional<Class<? extends D>> getDefaultDelegateClass()
Deprecated.Optional precompiled version of the default delegate class.- Returns:
- optional precompiled default delegate
-
defaultDelegateClass
public final Class<? extends D> defaultDelegateClass()
Query the default delegate class.- Returns:
- default delegate class
-
baseClass
public final Class<D> baseClass()
Query the base delegate class. This is the superclass for the source template and any derived code body.- Returns:
- base delegate class
-
baseImports
public final List<String> baseImports()
Query the base imports to be automatically added to the source body.- Returns:
- base imports
-
task
public CodeFactory.Task<D> task()
Create a task for constructing a context or component from a delegate class. This will return a suitable Task subclass that should be configured and used to create a context or component.- Returns:
- code factory task
-
base
public static <B extends CodeDelegate> CodeFactory.Base<B> base(Class<B> baseClass, List<String> baseImports, BiFunction<CodeFactory.Task<B>,B,CodeContext<B>> contextCreator)
Create a componentCodeFactory.Base
for the given base delegate class, from which can be created individual CodeFactory instances. The base class and default imports will be used to wrap user sources passed across to the compiler. The context creator function is used to wrap the compiled delegate in aCodeContext
, and will usually correspond to(task, delegate) -> new XXXCodeContext(new XXXCodeConnector(task, delegate))
- Type Parameters:
B
- base delegate type- Parameters:
baseClass
- base delegate superclassbaseImports
- default base importscontextCreator
- create context for delegate- Returns:
- code factory base
-
containerBase
public static <B extends CodeContainerDelegate> CodeFactory.Base<B> containerBase(Class<B> baseClass, List<String> baseImports, BiFunction<CodeFactory.Task<B>,B,CodeContext<B>> contextCreator)
Create a containerCodeFactory.Base
for the given base delegate class, from which can be created individual CodeFactory instances. The base class and default imports will be used to wrap user sources passed across to the compiler. The context creator function is used to wrap the compiled delegate in aCodeContext
, and will usually correspond to(task, delegate) -> new XXXCodeContext(new XXXCodeConnector(task, delegate))
- Type Parameters:
B
- base delegate type- Parameters:
baseClass
- base delegate superclassbaseImports
- default base importscontextCreator
- create context for delegate- Returns:
- code factory base
-
rootBase
public static <B extends CodeRootDelegate> CodeFactory.Base<B> rootBase(Class<B> baseClass, List<String> baseImports, BiFunction<CodeFactory.Task<B>,B,CodeContext<B>> contextCreator)
Create a root componentCodeFactory.Base
for the given base delegate class, from which can be created individual CodeFactory instances. The base class and default imports will be used to wrap user sources passed across to the compiler. The context creator function is used to wrap the compiled delegate in aCodeContext
, and will usually correspond to(task, delegate) -> new XXXCodeContext(new XXXCodeConnector(task, delegate))
- Type Parameters:
B
- base delegate type- Parameters:
baseClass
- base delegate superclassbaseImports
- default base importscontextCreator
- create context for delegate- Returns:
- code factory base
-
rootContainerBase
public static <B extends CodeRootContainerDelegate> CodeFactory.Base<B> rootContainerBase(Class<B> baseClass, List<String> baseImports, BiFunction<CodeFactory.Task<B>,B,CodeContext<B>> contextCreator)
Create a root containerCodeFactory.Base
for the given base delegate class, from which can be created individual CodeFactory instances. The base class and default imports will be used to wrap user sources passed across to the compiler. The context creator function is used to wrap the compiled delegate in aCodeContext
, and will usually correspond to(task, delegate) -> new XXXCodeContext(new XXXCodeConnector(task, delegate))
- Type Parameters:
B
- base delegate type- Parameters:
baseClass
- base delegate superclassbaseImports
- default base importscontextCreator
- create context for delegate- Returns:
- code factory base
-
-