- java.lang.Object
-
- org.praxislive.code.CodeConnector<D>
-
- Type Parameters:
D- type of CodeDelegate this connector works with
- Direct Known Subclasses:
AudioCodeConnector,CoreCodeConnector,P2DCodeConnector,P3DCodeConnector,VideoCodeConnector
public abstract class CodeConnector<D extends CodeDelegate> extends Object
Base class for analysing aCodeDelegateand 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 interfaceCodeConnector.Plugin
-
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 voidaddControl(ControlDescriptor ctl)Add a control descriptor.protected voidaddDefaultControls()Called during processing to create default controls.protected voidaddDefaultPorts()Called during processing to create default ports.voidaddPort(PortDescriptor port)Add a port descriptor.voidaddReference(ReferenceDescriptor ref)Add a reference descriptor.protected voidanalyseField(Field field)Called during processing to analyse each discovered field.protected voidanalyseFields(Field[] fields)Called during processing to analyse all discovered fields in the delegate class.protected voidanalyseMethod(Method method)Called during processing to analyse each discovered method.protected voidanalyseMethods(Method[] methods)Called during processing to analyse all discovered methods in the delegate class.protected ComponentInfobuildComponentInfo(Map<String,ControlDescriptor> controls, Map<String,PortDescriptor> ports)Called during processing to generate the component info from the control and port maps.protected ControlDescriptorcreateCodeControl(int index)Called to create the code property control.protected ControlDescriptorcreateInfoControl(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 ComponentInfoextractInfo()Called by the CodeContext to access the generatedComponentInfofor 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.StringfindID(Field field)Find a suitable ID (control or port) for the provided field.StringfindID(Method method)Find a suitable ID (control or port) for the provided method.DgetDelegate()Access the delegate instance.protected intgetInternalIndex()LogBuildergetLog()Get theLogBuilderfor logging messages during processing.intgetSyntheticIndex()Return next index to use for synthetic descriptors.protected StringjavaNameToID(String javaName)Convert a Java name in camelCase to an ID in dash-case.protected voidprocess()Process will be called by the CodeContext.protected booleanrequiresClock()Called by the CodeContext to control whether the context should be attached to the execution clock.booleanshouldAddPort(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 theLogBuilderfor 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 generatedComponentInfofor 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.- Parameters:
controls- map of control IDs and descriptorsports- map of port IDs and descriptors- Returns:
- component info
-
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 and inject 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 and aux-in 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 forIDannotation, 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 forIDannotation, 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.Portand 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()
-
-