Class ExtensionFunction
java.lang.Object
com.inductiveautomation.vision.api.client.components.model.ExtensionFunction
An extension function is a Python script that can be used to extend the functionality of a
component. It encapsulates the script itself and whether or not it is enabled.
-
Constructor Summary
ConstructorsConstructorDescriptionExtensionFunction(boolean enabled, String script) Constructs a new ExtensionFunction. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns the Python script for this extension function.static <T> Tinvoke(ExtensibleComponent self, LoggerEx log, String methodName, Class<T> returnType, T defaultValue, Object... args) Helper function to invoke an extension function.static booleanisDefined(ExtensibleComponent self, String methodName) Tests whether the given extensible component has an enabled extension function for the given method name.booleanReturns whether this extension function is enabled.
-
Constructor Details
-
ExtensionFunction
Constructs a new ExtensionFunction.- Parameters:
enabled- whether this function is enabled.script- the Python script content.
-
-
Method Details
-
isEnabled
public boolean isEnabled()Returns whether this extension function is enabled.- Returns:
- true if enabled, false otherwise.
-
getScript
Returns the Python script for this extension function.- Returns:
- the script content.
-
equals
-
isDefined
Tests whether the given extensible component has an enabled extension function for the given method name.- Parameters:
self- The component to check.methodName- The name of the extension function to look for.- Returns:
- true if an enabled extension function with the given name exists on the component.
-
invoke
public static <T> T invoke(ExtensibleComponent self, LoggerEx log, String methodName, Class<T> returnType, T defaultValue, Object... args) Helper function to invoke an extension function.- Parameters:
self- The component that is invokinglog- A logger to log any errors to. This function never throws an exception. Any problems are logged to this logger and the default will be returned.methodName- The name of the extension function. Must match the associated ExtensionFunctionDescriptor's method name.returnType- The type to coerce the script's return value into. For functions that don't need to return anything, use Void.classdefaultValue- The default return value. This will be returned if this extension function isn't implemented on self.args- Arguments to pass to the function.- Returns:
- whatever value the extensible function returned, or defaultValue if there was no extension function defined
-