Base
pentaho.type.action.Base
The action.Base
class represents a certain model of actions.
This class, the instance class, manages the execution of the action and enforces the multiple phases by which all actions, generically, go through it, including: "init", "will", "do", and "finally".
Note that the associated type class is to be used to configure metadata information about actions. For example: label
and description
metadata are to be used in user interfaces to portray the action to the user.
Synchronous or Asynchronous
An action can be synchronous or asynchronous, as determined by the type property, Base.Type#isSync
. The execution of a synchronous action is completed synchronously. An asynchronous action, however, has an asynchronous "do" phase, and thus only fully completes asynchronously. To support these two kinds of actions, two execution methods exist: execute
and executeAsync
. For an unknown kind of action, use execute if you are not concerned about the outcome of the action execution. Use executeAsync if you are concerned about the outcome of the action.
Action model
The following is a detailed description of the action model:
When an action is constructed, it is in the
candidate
state. It merely represents a possible, or candidate, action that can be executed.At this point, it has no associated
target
or_executor
.Its
label
anddescription
, and anything else that defines exactly what the action ultimately does, can still be freely modified.In this state, the action cannot be marked
done
or berejected
.When either the
execute
or theexecuteAsync
method is called, the action enters the init phase and is set to theinit
state.The action's
target
and_executor
are set to the ones provided as arguments in the said methods.The
_onPhaseInit
method is called, which, by default, delegates to the setexecutor
, if any, by calling itsinit
method.The action's
label
anddescription
, and anything else that defines exactly what the action ultimately does, can still be freely modified.The action can be marked
rejected
, in which case it is set to either thecanceled
or thefailed
state, and the finally phase is entered.Otherwise, the action automatically transits to the will phase.
In the will phase, what the action will do, along with its
label
anddescription
, is now settled and cannot be changed anymore -- an action can now be canceled based on what exactly it will do.The action is set to the
will
state.From now on, calling
isEditable
will returnfalse
and calling_assertEditable
will throw an error.The
_onPhaseWill
method is called, which, by default, delegates to the setexecutor
, if any, by calling itswill
method.The action can be marked
rejected
, in which case it is set to either thecanceled
or thefailed
state, and the finally phase is entered.Otherwise, the action automatically transits to the do phase.
In the do phase, the action execution, proper, is carried out. The action is set to the
do
state.The
_onPhaseDo
method is called, which, by default, delegates to the setexecutor
, if any, by calling itsdo
method.The action cannot be canceled anymore, but can, however, be marked failed, by
rejecting
it with a runtime error, in which case it is set to thefailed
state, and the finally phase is entered.Alternatively, the action can be marked
done
.If after calling
_onPhaseDo
the action is not yet done or rejected, the_doDefault
is called, allowing the action class to provide a default implementation.Finally, the action is set to the
did
state, and the finally phase is entered.When in the finally phase, the action is
finished
, with or without success, and is in one of thecanceled
,failed
ordid
states.The
_onPhaseFinally
method is called, which, by default, delegates to the setexecutor
, if any, by calling itsfinally
method.If the action was
done
, an actionresult
may be available, while if the action wasrejected
, an actionerror
may be available.
AMD Module
require(["pentaho/type/action/base"], function(Base) { /* code goes here */ });
See also: pentaho.type.action.spec.IBase , pentaho.type.action.spec.IBaseProto , pentaho.type.action.spec.IBaseTypeProto
Extends
Constructor
Name | Description |
---|---|
new Base(spec) Abstract | Creates an action instance given its specification. |
Classes
Name | Summary |
---|---|
Type | The base class of action types. |
Members
Name | Description |
---|---|
$isValid : | Determines if this value is a valid instance of its type. |
$key : | Gets the key of the value. |
$type : | Gets the type of this instance. |
_executor : Protected | Gets the executor to which the actual action execution is delegated. |
description : | Gets or sets the description of this action. |
error : | Gets the reason for a rejected action execution, or |
isCanceled : | Gets a value that indicates if the action has been canceled. |
isCandidate : | Gets a value that indicates if the action is in a candidate state. |
isDone : | Gets a value that indicates if the action executed successfully. |
isEditable : | Gets a value that indicates if the action is editable. |
isExecuting : | Gets a value that indicates if the action is executing. |
isFailed : | Gets a value that indicates if the action has failed. |
isFinished : | Gets a value that indicates if the action has finished execution. |
isRejected : | Gets a value that indicates if the action has been rejected. |
label : | Gets or sets the label of this action. |
promise : | Gets a promise for the result (or error) of this action's execution, if ever. |
result : | Gets the result of a successful action execution, if any. |
state : | Gets the current action state. |
target : | Gets the target where the action is executing or has executed. |
Methods
Name | Description |
---|---|
extend(name, instSpec, classSpec, keyArgs) : Class.< Static | Creates a subtype of this one. |
_assertEditable() Protected | Asserts that the action is editable and throws an error if not. |
_configure(config) Protected | Configures this value with a given non-nully configuration. |
_doDefault() : Promise | Performs the default "action" of this action. |
_onPhaseDo() : Promise Protected | Called during the action's do phase. |
_onPhaseFinally() Protected | Called during the action's finally phase. |
_onPhaseInit() Protected | Called during the action's initialize phase. |
_onPhaseWill() Protected | Called during the action's will phase. |
_setTarget(target) Protected | Called to validate and set the action's target, upon execution. |
assertValid() | Ensures that the value is valid, and throws the first validation error if it is not. |
clone() : pentaho.type.Value | Creates a shallow clone of this value. |
configure(config) : pentaho.type.Value | Configures this value with a given configuration. |
done(result) : pentaho.type.action.Base | Called from an action observer to mark the action as being done, optionally given a result value. |
equals(other) : boolean | Determines if a given value, of the same type, represents the same entity. |
execute(target, executor) : pentaho.type.action.Base | Executes the action on a given target and, optionally, with a given executor, and does not wait for its outcome. |
executeAsync(target, executor) : Promise | Executes the action on a given target and, optionally, with a given executor, and waits for its outcome. |
reject(reason) : pentaho.type.action.Base | Called from an action observer to mark the action as rejected. |
toJSON() : UJsonValue | Creates a top-level JSON specification that describes this instance. |
toSpec(keyArgs) : pentaho.type.spec.UInstance | Creates a specification that describes this value. |
toSpecInContext(keyArgs) : any | Creates a specification that describes this instance. |
validate() : Array.< | Determines if this value is a valid instance of its type. |
Constructor Details
new Base(spec) Abstract | ||||||
---|---|---|---|---|---|---|
Creates an action instance given its specification. Source: javascript/web/pentaho/type/action/base.js, line 273
See also: pentaho.type.action.spec.IBase , pentaho.type.action.spec.IBaseProto , pentaho.type.action.spec.IBaseTypeProto |
Members Details
$isValid: |
---|
Determines if this value is a valid instance of its type. This attribute calls Source: javascript/web/pentaho/type/value.js, line 123 Inherited From: pentaho.type.Value#$isValid |
$key: |
---|
Gets the key of the value. The key of a value must identify it among values of the same concrete type. Two values of the same concrete type and with the same key represent the same entity. The default implementation returns the result of calling Source: javascript/web/pentaho/type/value.js, line 82 Inherited From: pentaho.type.Value#$key See also: pentaho.type.Value#equals , pentaho.type.Value.Type#areEqual |
$type: |
---|
Gets the type of this instance. Source: javascript/web/pentaho/type/value.js, line 246 Overrides: pentaho.type.Element#$type |
_executor: Protected |
---|
Gets the executor to which the actual action execution is delegated. This property contains the value of the Source: javascript/web/pentaho/type/action/base.js, line 746 |
description: |
---|
Gets or sets the description of this action. When not set to a non-empty local value, the description of the action type, Can only be set while the action is in an Source: javascript/web/pentaho/type/action/base.js, line 380 |
error: |
---|
Gets the reason for a rejected action execution, or This property can only return a non-null value if Source: javascript/web/pentaho/type/action/base.js, line 464 |
isCanceled: |
---|
Gets a value that indicates if the action has been canceled. Source: javascript/web/pentaho/type/action/base.js, line 510 See also: pentaho.type.action.Base#isRejected |
isCandidate: |
---|
Gets a value that indicates if the action is in a candidate state. Source: javascript/web/pentaho/type/action/base.js, line 532 |
isDone: |
---|
Gets a value that indicates if the action executed successfully. Source: javascript/web/pentaho/type/action/base.js, line 562 See also: pentaho.type.action.Base#result |
isEditable: |
---|
Gets a value that indicates if the action is editable. An action is considered editable if its state is one of Source: javascript/web/pentaho/type/action/base.js, line 478 |
isExecuting: |
---|
Gets a value that indicates if the action is executing. An action is executing if its state is one of Source: javascript/web/pentaho/type/action/base.js, line 550 See also: pentaho.type.action.Base#isCandidate , pentaho.type.action.Base#isFinished |
isFailed: |
---|
Gets a value that indicates if the action has failed. Source: javascript/web/pentaho/type/action/base.js, line 522 See also: pentaho.type.action.Base#isRejected |
isFinished: |
---|
Gets a value that indicates if the action has finished execution. An action has finished execution if its state is one of Source: javascript/web/pentaho/type/action/base.js, line 581 See also: pentaho.type.action.Base#isDone , pentaho.type.action.Base#isCanceled , pentaho.type.action.Base#isFailed |
isRejected: |
---|
Gets a value that indicates if the action has been rejected. An action is considered rejected if its state is one of Source: javascript/web/pentaho/type/action/base.js, line 498 See also: pentaho.type.action.Base#isCanceled , pentaho.type.action.Base#isFailed , pentaho.type.action.Base#isDone , pentaho.type.action.Base#isFinished , pentaho.type.action.Base#error |
label: |
---|
Gets or sets the label of this action. When not set to a non-empty local value, the label of the action type, Can only be set while the action is in an Source: javascript/web/pentaho/type/action/base.js, line 359 |
promise: |
---|
Gets a promise for the result (or error) of this action's execution, if ever. This promise can be requested anytime, before starting execution, during execution, or after finishing execution of this action. Also, it can be requested whether or not the action is The promise is fulfilled with the action's Source: javascript/web/pentaho/type/action/base.js, line 601 |
result: |
---|
Gets the result of a successful action execution, if any. This property can only return a non-undefined value if Source: javascript/web/pentaho/type/action/base.js, line 451 |
state: |
---|
Gets the current action state. Source: javascript/web/pentaho/type/action/base.js, line 399 |
target: |
---|
Gets the target where the action is executing or has executed. This property contains the value of the Source: javascript/web/pentaho/type/action/base.js, line 713 |
Methods Details
extend(name, instSpec, classSpec, keyArgs) : Class.< Static | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Creates a subtype of this one. For more information on class extension, in general, see Source: javascript/web/pentaho/type/action/base.js, line 50
See also: pentaho.type.Instance.extend |
_assertEditable() Protected | ||||
---|---|---|---|---|
Asserts that the action is editable and throws an error if not. Call this helper method at the start of general property setters. Source: javascript/web/pentaho/type/action/base.js, line 412
|
_configure(config) Protected | ||||||
---|---|---|---|---|---|---|
Configures this value with a given non-nully configuration. The default implementation does nothing. Source: javascript/web/pentaho/type/value.js, line 178 Inherited From: pentaho.type.Value#_configure
|
_doDefault() : Promise | ||||
---|---|---|---|---|
Performs the default "action" of this action. When the action is Source: javascript/web/pentaho/type/action/base.js, line 760
|
_onPhaseDo() : Promise Protected | ||||
---|---|---|---|---|
Called during the action's do phase. The default implementation calls the executor's Source: javascript/web/pentaho/type/action/base.js, line 1183
|
_onPhaseFinally() Protected |
---|
Called during the action's finally phase. The default implementation calls the executor's Source: javascript/web/pentaho/type/action/base.js, line 1198 |
_onPhaseInit() Protected |
---|
Called during the action's initialize phase. The default implementation calls the executor's Source: javascript/web/pentaho/type/action/base.js, line 1150 |
_onPhaseWill() Protected |
---|
Called during the action's will phase. The default implementation calls the executor's Source: javascript/web/pentaho/type/action/base.js, line 1165 |
_setTarget(target) Protected | ||||||
---|---|---|---|---|---|---|
Called to validate and set the action's target, upon execution. Override to perform additional validations after calling the base implementation. Source: javascript/web/pentaho/type/action/base.js, line 726
|
assertValid() | ||||
---|---|---|---|---|
Ensures that the value is valid, and throws the first validation error if it is not. This method calls the Source: javascript/web/pentaho/type/value.js, line 152 Inherited From: pentaho.type.Value#assertValid
|
clone() : pentaho.type.Value | ||||
---|---|---|---|---|
Creates a shallow clone of this value. Source: javascript/web/pentaho/type/value.js, line 86 Overrides: pentaho.type.Element#clone
|
configure(config) : pentaho.type.Value | ||
---|---|---|
Configures this value with a given configuration. Source: javascript/web/pentaho/type/value.js, line 165 Inherited From: pentaho.type.Value#configure |
Name | Default Value | Summary |
---|---|---|
config : any | The configuration. |
Name | Description |
---|---|
pentaho.type.Value | This instance. |
done(result) : pentaho.type.action.Base | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Called from an action observer to mark the action as being done, optionally given a result value. Source: javascript/web/pentaho/type/action/base.js, line 775
|
equals(other) : boolean | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
Determines if a given value, of the same type, represents the same entity. The default implementation delegates the operation to the Source: javascript/web/pentaho/type/value.js, line 107 Inherited From: pentaho.type.Value#equals
See also: pentaho.type.Value#$key , pentaho.type.Value.Type#areEqual |
execute(target, executor) : pentaho.type.action.Base | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Executes the action on a given target and, optionally, with a given executor, and does not wait for its outcome. This method can be called on Source: javascript/web/pentaho/type/action/base.js, line 661
See also: pentaho.type.action.ITarget#executeAsync , pentaho.type.action.ITarget#act |
executeAsync(target, executor) : Promise | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Executes the action on a given target and, optionally, with a given executor, and waits for its outcome. This method can be called on Source: javascript/web/pentaho/type/action/base.js, line 688
See also: pentaho.type.action.ITarget#execute , pentaho.type.action.ITarget#actAsync |
reject(reason) : pentaho.type.action.Base | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Called from an action observer to mark the action as rejected. The action is considered failed if Otherwise, the action is considered canceled if Source: javascript/web/pentaho/type/action/base.js, line 843
See also: pentaho.type.action.Base#isRejected , pentaho.type.action.Base#isCanceled , pentaho.type.action.Base#isFailed , pentaho.type.action.Base#error Example define([ "pentaho/lang/UserError", "pentaho/lang/RuntimeError" ], function(UserError, RuntimeError) { // ... target.on("fly", { will: function(action) { // Canceling the action // .. Method 1 action.reject("Cannot do this action now."); // .. Method 2 action.reject(new UserError("Cannot do this action now.")); // Failing the action // .. Method 1 - message is not adequate to be shown to the user. action.reject(new Error("Null Pointer Exception.")); // .. Method 2 - message is adequate to be shown to the user. action.reject(new RuntimeError("The server is currently unreachable.")); } }); // ... }); |
toJSON() : UJsonValue | ||||
---|---|---|---|---|
Creates a top-level JSON specification that describes this instance. Attributes which do not have a JSON-compatible specification are omitted. Specifically, for inline types, attributes with a function value are not supported. This method simply calls Source: javascript/web/pentaho/type/instance.js, line 210 Inherited From: pentaho.type.Instance#toJSON
See also: pentaho.type.Instance#toSpec |
toSpec(keyArgs) : pentaho.type.spec.UInstance | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Creates a specification that describes this value. If an Source: javascript/web/pentaho/type/value.js, line 184 Inherited From: pentaho.type.Value#toSpec |
Name | Default Value | Summary | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
keyArgs : Object Optional | The keyword arguments object. Passed to every value and type serialized within this scope. Please see the documentation of value subclasses for information on additional, supported keyword arguments.
|
Name | Description |
---|---|
pentaho.type.spec.UInstance | A specification of this value. |
toSpecInContext(keyArgs) : any | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
Creates a specification that describes this instance. Source: javascript/web/pentaho/type/instance.js, line 190 Overrides: pentaho.type.Element#toSpecInContext
See also: pentaho.type.Instance#toSpec |
validate() : Array.< | ||||
---|---|---|---|---|
Determines if this value is a valid instance of its type. The default implementation delegates to Source: javascript/web/pentaho/type/value.js, line 137 Inherited From: pentaho.type.Value#validate
See also: pentaho.type.Value#$isValid |