- 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
,CoreCodeConnector
,P2DCodeConnector
,P3DCodeConnector
,VideoCodeConnector
public abstract class CodeConnector<D extends CodeDelegate> extends Object
Base class for analysing aCodeDelegate
and creating the resources required for its wrappingCodeContext
. An instance of a CodeConnector subclass should be passed in to the CodeContext constructor.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
CodeConnector.Plugin
Plugin implementations should be registered via service loader mechanism to extend behaviour of CodeConnectors.
-
Constructor Summary
Constructors Constructor Description CodeConnector(CodeFactory.Task<D> task, D delegate)
Create a CodeConnector for the provided delegate.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addControl(ControlDescriptor ctl)
Add a control descriptor.protected void
addDefaultControls()
Called during processing to create default controls.protected void
addDefaultPorts()
Called during processing to create default ports.void
addPort(PortDescriptor port)
Add a port descriptor.void
addReference(ReferenceDescriptor ref)
Add a reference descriptor.protected void
analyseField(Field field)
Called during processing to analyse each discovered field.protected void
analyseFields(Field[] fields)
Called during processing to analyse all discovered fields in the delegate class.protected void
analyseMethod(Method method)
Called during processing to analyse each discovered method.protected void
analyseMethods(Method[] methods)
Called during processing to analyse all discovered methods in the delegate class.protected void
buildBaseComponentInfo(Info.ComponentInfoBuilder cmp)
Build base component info.protected ComponentInfo
buildComponentInfo(Map<String,ControlDescriptor> controls, Map<String,PortDescriptor> ports)
Called during processing to generate the component info from the control and port maps.protected void
buildControlInfo(Info.ComponentInfoBuilder cmp, Map<String,ControlDescriptor> controls)
Build control info.protected void
buildPortInfo(Info.ComponentInfoBuilder cmp, Map<String,PortDescriptor> ports)
Build port info.protected ControlDescriptor
createCodeControl(int index)
Called to create the code property control.protected ControlDescriptor
createInfoControl(int index)
Called to create the info property control.protected Map<String,ControlDescriptor>
extractControls()
Called by the CodeContext to access all processed control descriptors.protected ComponentInfo
extractInfo()
Called by the CodeContext to access the generatedComponentInfo
for the delegate.protected Map<String,PortDescriptor>
extractPorts()
Called by the CodeContext to access all processed port descriptors.protected Map<String,ReferenceDescriptor>
extractRefs()
Called by the CodeContext to access all processed reference descriptors.String
findID(Field field)
Find a suitable ID (control or port) for the provided field.String
findID(Method method)
Find a suitable ID (control or port) for the provided method.D
getDelegate()
Access the delegate instance.protected int
getInternalIndex()
Return next index to use for internal descriptors.LogBuilder
getLog()
Get theLogBuilder
for logging messages during processing.int
getSyntheticIndex()
Return next index to use for synthetic descriptors.protected String
javaNameToID(String javaName)
Convert a Java name in camelCase to an ID in dash-case.protected void
process()
Process will be called by the CodeContext.protected boolean
requiresClock()
Called by the CodeContext to control whether the context should be attached to the execution clock.boolean
shouldAddPort(AnnotatedElement element)
Check whether a port should be added for provided element (field or method).
-
-
-
Constructor Detail
-
CodeConnector
public CodeConnector(CodeFactory.Task<D> task, D delegate)
Create a CodeConnector for the provided delegate.- Parameters:
task
- CodeFactory.Task factory task creating contextdelegate
- delegate instance
-
-
Method Detail
-
process
protected void process()
Process will be called by the CodeContext. Subclasses may override to extend, but should ensure to call the superclass method.
-
getDelegate
public D getDelegate()
Access the delegate instance.- Returns:
- delegate
-
getLog
public LogBuilder getLog()
Get theLogBuilder
for logging messages during processing.- Returns:
- log builder
-
extractControls
protected Map<String,ControlDescriptor> extractControls()
Called by the CodeContext to access all processed control descriptors. Subclasses may override to extend, but should ensure to call the superclass method.- Returns:
- map of control descriptors by ID
-
extractPorts
protected Map<String,PortDescriptor> extractPorts()
Called by the CodeContext to access all processed port descriptors. Subclasses may override to extend, but should ensure to call the superclass method.- Returns:
- map of port descriptors by ID
-
extractRefs
protected Map<String,ReferenceDescriptor> extractRefs()
Called by the CodeContext to access all processed reference descriptors. Subclasses may override to extend, but should ensure to call the superclass method.- Returns:
- map of reference descriptors by ID
-
extractInfo
protected ComponentInfo extractInfo()
Called by the CodeContext to access the generatedComponentInfo
for the delegate.- Returns:
- component info
-
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 typeProperty
. May be overridden.- Returns:
- whether context should connect to clock
-
buildComponentInfo
protected ComponentInfo buildComponentInfo(Map<String,ControlDescriptor> controls, Map<String,PortDescriptor> ports)
Called during processing to generate the component info from the control and port maps. May be overridden to configure / extend, although better to overridebuildBaseComponentInfo(org.praxislive.core.Info.ComponentInfoBuilder)
,buildComponentInfo(java.util.Map, java.util.Map)
orbuildPortInfo(org.praxislive.core.Info.ComponentInfoBuilder, java.util.Map)
.- Parameters:
controls
- map of control IDs and descriptorsports
- map of port IDs and descriptors- Returns:
- component info
-
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 buildercontrols
- 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 builderports
- 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 ControlDescriptor createInfoControl(int index)
Called to create the info property control.- Parameters:
index
- position of control- Returns:
- info control descriptor
-
createCodeControl
protected ControlDescriptor createCodeControl(int index)
Called to create the code property 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 (seeCodeConnector.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 (seeCodeConnector.Plugin
), then check for trigger, in, aux-in and function annotations in that order. First valid match wins.- Parameters:
method
- discovered method
-
findID
public String findID(Field field)
Find a suitable ID (control or port) for the provided field. Will first look forID
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 String findID(Method method)
Find a suitable ID (control or port) for the provided method. Will first look forID
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 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 markedReadOnly
, or withConfig.Port
and value false.- Parameters:
element
- annotated element to analyse- Returns:
- whether to add a port
-
getSyntheticIndex
public 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 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
-
-