public class BeanShell extends ScriptEngineActor
There are several differences between this actor and the Java actor. The Java actor requires:
The following example defines an actor in BeanShell Java that computes factorials:
1. import ptolemy.data.IntToken;
2.
3. public class Actor {
4. public void fire() {
5. int val = ((IntToken)super.in.get(0)).intValue();
6.
7. if(val < 0) {
8. actor.error("Input must be non-negative");
9. }
10. int total = 1;
11. while(val > 1) {
12. total *= val;
13. val--;
14. }
15. out.broadcast(new IntToken(total));
16. }
17.}
Line 1 imports the Java class used by the actor. Line 3 defines the Actor object. Lines 4-16 define the fire() method of the actor; this method is called each time this actor executes in the workflow. Line 5 reads an integer from the input port called "input". A port or parameter called "foo" can be accessed in the Java code by simply using "foo". Lines 10-14 compute the factorial of the integer read from the port. Line 15 writes the result to the output port called "output".
Entity.ContainedObjectsIterator_ACTOR_INSTANCE_NAME, _actorObject, _editorFactory, _engine, _evaluatedScriptObject, _invokeMethodWithReflection, _manager, actorClassName, language, script_typesValid_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKSCOMPLETED, NOT_READY, STOP_ITERATING| Constructor and Description |
|---|
BeanShell(CompositeEntity container,
java.lang.String name) |
BeanShell(Workspace workspace) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
_putObjectToActorInstance(java.lang.String name,
java.lang.Object object)
Put the given object to the actor instance in the script.
|
_createActorInstance, _evaluateScript, _registerEngineFactory, attributeChanged, clone, debug, error, fire, initialize, postfire, prefire, preinitialize, stop, stopFire, terminate, wrapup_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName_addPort, _description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspaceequals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitcreateReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortListisFireFunctional, isStrict, iterateaddInitializable, removeInitializabledescription, getContainer, getDisplayName, getFullName, getName, getName, setNamegetDerivedLevel, getDerivedList, propagateValuepublic BeanShell(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
protected void _putObjectToActorInstance(java.lang.String name, java.lang.Object object) throws javax.script.ScriptException
_putObjectToActorInstance in class ScriptEngineActorname - the name of the object to put.object - the object to put.javax.script.ScriptException