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
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacePlugin implementations should be registered via service loader mechanism to extend behaviour of CodeConnectors. -
Constructor Summary
ConstructorsConstructorDescriptionCodeConnector(CodeFactory.Task<D> task, D delegate) Create a CodeConnector for the provided delegate. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a control descriptor.protected voidCalled during processing to create default controls.protected voidCalled during processing to create default ports.voidaddPort(PortDescriptor port) Add a port descriptor.voidAdd 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 voidBuild base component info.protected voidbuildControlInfo(Info.ComponentInfoBuilder cmp, Map<String, ControlDescriptor<?>> controls) Build control info.protected voidbuildPortInfo(Info.ComponentInfoBuilder cmp, Map<String, PortDescriptor<?>> ports) Build port info.protected final ControlDescriptor<?> createCodeControl(int index) Create the code property control.protected final ControlDescriptorcreateInfoControl(int index) Create the info property control.protected final ControlDescriptor<?> createMetaControl(int index) Create the meta property control.protected final ControlDescriptor<?> createMetaMergeControl(int index) Create the meta-merge function control.final StringFind a suitable ID (control or port) for the provided field.final StringFind a suitable ID (control or port) for the provided method.Access the delegate instance.protected final intReturn next index to use for internal descriptors.getLog()Get theLogBuilderfor logging messages during processing.final intReturn next index to use for synthetic descriptors.protected final StringjavaNameToID(String javaName) Convert a Java name in camelCase to an ID in dash-case.protected booleanCalled 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 Details
-
CodeConnector
Create a CodeConnector for the provided delegate.- Parameters:
task- CodeFactory.Task factory task creating contextdelegate- delegate instance
-
-
Method Details
-
getDelegate
Access the delegate instance.- Returns:
- delegate
-
getLog
Get theLogBuilderfor 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 typeProperty. May be overridden.- Returns:
- whether context should connect to clock
-
buildBaseComponentInfo
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
Build port info. May be overridden to configure / extend.- Parameters:
cmp- component info builderports- map of port descriptors
-
addControl
Add a control descriptor.- Parameters:
ctl- control descriptor
-
addPort
Add a port descriptor.- Parameters:
port- port descriptor
-
addReference
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
Create the info property control.- Parameters:
index- position of control- Returns:
- info control descriptor
-
createCodeControl
Create the code property control.- Parameters:
index- position of control- Returns:
- code control descriptor
-
createMetaControl
Create the meta property control.- Parameters:
index- position of control- Returns:
- code control descriptor
-
createMetaMergeControl
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
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
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
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
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
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
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
Convert a Java name in camelCase to an ID in dash-case.- Parameters:
javaName- Java name to convert- Returns:
- ID for Java name
-
shouldAddPort
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 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
-