Class CodeFactory<D extends CodeDelegate>

java.lang.Object
org.praxislive.code.CodeFactory<D>
Type Parameters:
D - base delegate type

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.
  • Field Details

    • 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:
    • 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:
  • Method Details

    • componentType

      public final ComponentType componentType()
      Get the component type.
      Returns:
      component type
    • sourceTemplate

      public final String sourceTemplate()
      The source template corresponding to the default delegate class.
      Returns:
      source template
    • defaultDelegateClass

      public final Optional<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.
      Returns:
      code factory task
    • lookup

      public Lookup lookup()
      Access the lookup associated with this code factory.
      Returns:
      lookup
    • 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 component CodeFactory.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 a CodeContext, and will usually correspond to (task, delegate) -> new XXXCodeContext(new XXXCodeConnector(task, delegate))
      Type Parameters:
      B - base delegate type
      Parameters:
      baseClass - base delegate superclass
      baseImports - default base imports
      contextCreator - 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 container CodeFactory.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 a CodeContext, and will usually correspond to (task, delegate) -> new XXXCodeContext(new XXXCodeConnector(task, delegate))
      Type Parameters:
      B - base delegate type
      Parameters:
      baseClass - base delegate superclass
      baseImports - default base imports
      contextCreator - 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 component CodeFactory.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 a CodeContext, and will usually correspond to (task, delegate) -> new XXXCodeContext(new XXXCodeConnector(task, delegate))
      Type Parameters:
      B - base delegate type
      Parameters:
      baseClass - base delegate superclass
      baseImports - default base imports
      contextCreator - 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 container CodeFactory.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 a CodeContext, and will usually correspond to (task, delegate) -> new XXXCodeContext(new XXXCodeConnector(task, delegate))
      Type Parameters:
      B - base delegate type
      Parameters:
      baseClass - base delegate superclass
      baseImports - default base imports
      contextCreator - create context for delegate
      Returns:
      code factory base