Class CodeConnector<D extends CodeDelegate>

java.lang.Object
org.praxislive.code.CodeConnector<D>
Type Parameters:
D - type of CodeDelegate this connector works with
Direct Known Subclasses:
AudioCodeConnector, CodeContainer.Connector, CodeRoot.Connector, P2DCodeConnector, P3DCodeConnector, VideoCodeConnector

public abstract class CodeConnector<D extends CodeDelegate> extends Object
Base class for analysing a CodeDelegate and creating the resources required for its wrapping CodeContext. An instance of a CodeConnector subclass should be passed in to the CodeContext constructor.
  • Constructor Details

    • CodeConnector

      public CodeConnector(CodeFactory.Task<D> task, D delegate)
      Create a CodeConnector for the provided delegate.
      Parameters:
      task - CodeFactory.Task factory task creating context
      delegate - delegate instance
  • Method Details

    • getDelegate

      public D getDelegate()
      Access the delegate instance.
      Returns:
      delegate
    • getLog

      public LogBuilder getLog()
      Get the LogBuilder for logging messages during processing.
      Returns:
      log builder
    • requiresClock

      protected boolean requiresClock()
      Called by the CodeContext to control whether the context should be attached to the execution clock. This method returns true if the delegate has any fields of type Property or Trigger. May be overridden.
      Returns:
      whether context should connect to clock
    • buildBaseComponentInfo

      protected void buildBaseComponentInfo(Info.ComponentInfoBuilder cmp)
      Build base component info. Called before control and port info is added. May be overridden to configure / extend.
      Parameters:
      cmp - component info builder
    • buildControlInfo

      protected void buildControlInfo(Info.ComponentInfoBuilder cmp, Map<String,ControlDescriptor<?>> controls)
      Build control info. May be overridden to configure / extend.
      Parameters:
      cmp - component info builder
      controls - map of control descriptors
    • buildPortInfo

      protected void buildPortInfo(Info.ComponentInfoBuilder cmp, Map<String,PortDescriptor<?>> ports)
      Build port info. May be overridden to configure / extend.
      Parameters:
      cmp - component info builder
      ports - map of port descriptors
    • addControl

      public void addControl(ControlDescriptor ctl)
      Add a control descriptor.
      Parameters:
      ctl - control descriptor
    • addPort

      public void addPort(PortDescriptor port)
      Add a port descriptor.
      Parameters:
      port - port descriptor
    • addReference

      public void addReference(ReferenceDescriptor ref)
      Add a reference descriptor.
      Parameters:
      ref - reference descriptor
    • addDefaultControls

      protected void addDefaultControls()
      Called during processing to create default controls. May be overridden to configure or extend. By default this method adds the info and code properties, and a hidden control used by logging support.
    • createInfoControl

      protected final ControlDescriptor createInfoControl(int index)
      Create the info property control.
      Parameters:
      index - position of control
      Returns:
      info control descriptor
    • createCodeControl

      protected final ControlDescriptor<?> createCodeControl(int index)
      Create the code property control.
      Parameters:
      index - position of control
      Returns:
      code control descriptor
    • createMetaControl

      protected final ControlDescriptor<?> createMetaControl(int index)
      Create the meta property control.
      Parameters:
      index - position of control
      Returns:
      code control descriptor
    • createMetaMergeControl

      protected final ControlDescriptor<?> createMetaMergeControl(int index)
      Create the meta-merge function control.
      Parameters:
      index - position of control
      Returns:
      code control descriptor
    • addDefaultPorts

      protected void addDefaultPorts()
      Called during processing to create default ports. May be overridden to extend. By default this method does nothing.
    • analyseFields

      protected void analyseFields(Field[] fields)
      Called during processing to analyse all discovered fields in the delegate class. May be overridden, but usually better to override the more specific analysis methods.
      Parameters:
      fields - discovered fields
    • analyseMethods

      protected void analyseMethods(Method[] methods)
      Called during processing to analyse all discovered methods in the delegate class. May be overridden, but usually better to override the more specific analysis methods.
      Parameters:
      methods - discovered methods
    • analyseField

      protected void analyseField(Field field)
      Called during processing to analyse each discovered field. May be overridden to extend. The default behaviour will first pass to available plugins (see CodeConnector.Plugin), then check for property, trigger, in, aux-in, out, aux-out, inject, proxy and persist annotations, in that order. First valid match wins.
      Parameters:
      field - discovered field
    • analyseMethod

      protected void analyseMethod(Method method)
      Called during processing to analyse each discovered method. May be overridden to extend. The default behaviour will first pass to available plugins (see CodeConnector.Plugin), then check for trigger, in, aux-in and function annotations in that order. First valid match wins.
      Parameters:
      method - discovered method
    • findID

      public final String findID(Field field)
      Find a suitable ID (control or port) for the provided field. Will first look for ID annotation, and if not found convert the field name from camelCase to dash-case.
      Parameters:
      field - field to find ID for
      Returns:
      ID
    • findID

      public final String findID(Method method)
      Find a suitable ID (control or port) for the provided method. Will first look for ID annotation, and if not found convert the method name from camelCase to dash-case.
      Parameters:
      method - method to find ID for
      Returns:
      ID
    • javaNameToID

      protected final String javaNameToID(String javaName)
      Convert a Java name in camelCase to an ID in dash-case.
      Parameters:
      javaName - Java name to convert
      Returns:
      ID for Java name
    • shouldAddPort

      public boolean shouldAddPort(AnnotatedElement element)
      Check whether a port should be added for provided element (field or method). By default returns true unless the element is marked ReadOnly, or with Config.Port and value false.
      Parameters:
      element - annotated element to analyse
      Returns:
      whether to add a port
    • getSyntheticIndex

      public final int getSyntheticIndex()
      Return next index to use for synthetic descriptors. Increments and returns an int on each call, not based on registered descriptors.
      Returns:
      next index
    • getInternalIndex

      protected final int getInternalIndex()
      Return next index to use for internal descriptors. Increments and returns an int on each call, not based on registered descriptors.
      Returns:
      next index