|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.werken.werkz.Goal
public class Goal
Abstract Goal to attain.
A Goal
embodies both an action and the
precursors for that action. A Goal
's
precursors will be satisfied before attempting to
perform the target Goal
's action. There
may be a case that once precursors have been satisfied
there is no further action required to be perform for
a particular Goal
.
A Goal
's postcursors are also tracked
so that if a Goal
's state has been changed
and the Goal
s ahead of it in the hierarchy
need to be notified, it can percolate
forward
and have it's postcursors satisfied.
WerkzProject
,
Action
Field Summary | |
---|---|
private Action |
action
Action to perform. |
private java.lang.String |
description
Description of the goal (for auto-documenting). |
static Goal[] |
EMPTY_ARRAY
Empty Goal array. |
private org.apache.commons.logging.Log |
log
Log. |
private java.lang.String |
name
Unique name. |
private java.util.List |
postActionCallbacks
Post-action callbacks. |
private java.util.List |
postcursors
Ordered list of postcursor Goal s. |
private java.util.List |
postGoalCallbacks
Post-goal callbacks. |
private java.util.List |
preActionCallbacks
Pre-action callbacks. |
private java.util.List |
precursors
Ordered list of precursor Goal s. |
private java.util.List |
preGoalCallbacks
Pre-goal callbacks. |
Constructor Summary | |
---|---|
Goal(java.lang.String name)
Construct a new Goal with the specified name. |
|
Goal(java.lang.String name,
Action action)
Construct a new Goal with the specified name
and Action . |
Method Summary | |
---|---|
private void |
addInternalPostcursor(Goal postcursor)
Adds a postcursor Goal without looping back to the
postcursor.addPrecursor and entering an infinite loop. |
void |
addPostActionCallback(PostActionCallback callback)
Add a post-action callback to this Goal . |
void |
addPostcursor(Goal postcursor)
Add a postcursor Goal to this Goal . |
void |
addPostGoalCallback(PostGoalCallback callback)
Add a post-goal callback to this Goal . |
void |
addPreActionCallback(PreActionCallback callback)
Add a pre-action callback to this Goal . |
void |
addPrecursor(Goal precursor)
Add a precursor Goal to this Goal . |
void |
addPreGoalCallback(PreGoalCallback callback)
Add a pre-goal callback to this Goal . |
void |
attain(Session session)
Attempt to attain this Goal . |
(package private) void |
attainPrecursors(Session session)
Attempt to attain this Goal 's precursor Goal s. |
(package private) void |
checkForCycles()
Perform a cyclic dependency check. |
(package private) void |
checkForCycles(Goal initialGoal,
java.util.Set visited)
Perform a cyclic dependency check. |
boolean |
equals(java.lang.Object thatObj)
Determine if two Goal objects are
equivelant. |
private void |
fire(Session session)
Fires pre-goal callbacks, the Goal 's action, if need be, and
the post-goal callbacks. |
(package private) void |
firePostActionCallbacks()
Fire the post-action callbacks. |
(package private) void |
firePostGoalCallbacks()
Fire the post-goal callbacks. |
(package private) void |
firePreActionCallbacks()
Fire the pre-action callbacks. |
(package private) void |
firePreGoalCallbacks()
Fire the pre-goal callbacks. |
Action |
getAction()
Retrieve the Action of this Goal . |
java.lang.String |
getDescription()
Retrieve the description of this Goal . |
java.lang.String |
getName()
Retrieve the name of this Goal . |
java.util.List |
getPostActionCallbacks()
Retrieve an unmodifiable list of the post-action callbacks. |
java.util.List |
getPostcursors()
Retrive an unmodifiable List of this Goal 's
postcursor Goal s. |
java.util.List |
getPostGoalCallbacks()
Retrieve an unmodifiable list of the post-goal callbacks. |
java.util.List |
getPreActionCallbacks()
Retrieve an unmodifiable list of the pre-action callbacks. |
java.util.List |
getPrecursors()
Retrieve an unmodifiable List of this Goal 's
precursor Goal s. |
java.util.List |
getPreGoalCallbacks()
Retrieve an unmodifiable list of the pre-goal callbacks. |
int |
hashCode()
Retrieve the hash-code of this object. |
boolean |
isSatisfied(Session session)
Determine if this Goal has been satisfied
for the specified Session . |
void |
percolate(Session session)
Attempt to percolate this Goal through to its Postcursors. |
(package private) void |
percolatePostcursors(Session session)
Attempt to attain this Goal 's postcursor Goal s. |
void |
removePostActionCallback(PostActionCallback callback)
Remove all occurences of a post-action callback from this Goal . |
void |
removePostGoalCallback(PostGoalCallback callback)
Remove all occurences of a post-goal callback from this Goal . |
void |
removePreActionCallback(PreActionCallback callback)
Remove all occurences of a pre-action callback from this Goal . |
void |
removePreGoalCallback(PreGoalCallback callback)
Remove all occurences of a pre-goal callback from this Goal . |
void |
setAction(Action action)
Set the Action of this Goal . |
void |
setDescription(java.lang.String description)
Set the description for this Goal . |
java.lang.String |
toString()
Produce a textual representation suitable for debugging. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final Goal[] EMPTY_ARRAY
Goal
array.
private org.apache.commons.logging.Log log
private java.lang.String name
private java.util.List precursors
Goal
s.
private java.util.List postcursors
Goal
s.
private Action action
private java.util.List preGoalCallbacks
private java.util.List postGoalCallbacks
private java.util.List preActionCallbacks
private java.util.List postActionCallbacks
private java.lang.String description
Constructor Detail |
---|
public Goal(java.lang.String name)
Goal
with the specified name.
name
- The name of the Goal
.public Goal(java.lang.String name, Action action)
Goal
with the specified name
and Action
.
name
- The name of the Goal
.action
- The Action
for this Goal
.Method Detail |
---|
public java.lang.String getName()
Goal
.
Goal
's name.public java.lang.String getDescription()
Goal
.
public void setDescription(java.lang.String description)
Goal
.
description
- The description of this goal.public Action getAction()
Action
of this Goal
.
Action
of this Goal
.public void setAction(Action action)
Action
of this Goal
.
action
- The Action
of this Goal
.public void addPreGoalCallback(PreGoalCallback callback)
Goal
.
callback
- The callback to add.public void removePreGoalCallback(PreGoalCallback callback)
Goal
.
callback
- The callback to remove.public java.util.List getPreGoalCallbacks()
List
of PreGoalCallback
s.public void addPostGoalCallback(PostGoalCallback callback)
Goal
.
callback
- The callback to add.public void removePostGoalCallback(PostGoalCallback callback)
Goal
.
callback
- The callback to remove.public java.util.List getPostGoalCallbacks()
List
of PostGoalCallback
s.public void addPreActionCallback(PreActionCallback callback)
Goal
.
callback
- The callback to add.public void removePreActionCallback(PreActionCallback callback)
Goal
.
callback
- The callback to remove.public java.util.List getPreActionCallbacks()
List
of PreActionCallback
s.public void addPostActionCallback(PostActionCallback callback)
Goal
.
callback
- The callback to add.public void removePostActionCallback(PostActionCallback callback)
Goal
.
callback
- The callback to remove.public java.util.List getPostActionCallbacks()
List
of PostActionCallback
s.public boolean isSatisfied(Session session)
Goal
has been satisfied
for the specified Session
.
session
- The Session
context in which
to test for goal satisfaction.
true
if this Goal
has been
satisfied within the Session
, otherwise
false
.public void addPrecursor(Goal precursor) throws CyclicGoalChainException
Goal
to this Goal
.
precursor
- The precursor Goal
that must
be satisfied before performing this Goal
.
CyclicGoalChainException
- if adding the precursor would
result in a cyclic dependency.public void addPostcursor(Goal postcursor) throws CyclicGoalChainException
Goal
to this Goal
.
postcursor
- The postcursor Goal
that
depends on this Goal
.
CyclicGoalChainException
- if adding the postcursor would
result in a cyclic dependency.private void addInternalPostcursor(Goal postcursor)
Goal
without looping back to the
postcursor.addPrecursor
and entering an infinite loop.
postcursor
- The postcursor Goal
that is already
tracking this Goal as a precursor and is letting this
Goal
know that it is a postcursor.
public java.util.List getPrecursors()
List
of this Goal
's
precursor Goal
s.
List of precursor Goal
s.
public java.util.List getPostcursors()
List
of this Goal
's
postcursor Goal
s.
List
of postcursor Goal
s.void attainPrecursors(Session session) throws UnattainableGoalException, NoActionDefinitionException
Goal
's precursor Goal
s.
session
- The context in which to attain goals.
UnattainableGoalException
- if unable to satisfy a precursor.
NoActionDefinitionException
- if this goal contains no action definition.void percolatePostcursors(Session session) throws UnattainableGoalException, NoActionDefinitionException
Goal
's postcursor Goal
s.
session
- The context in which to attain goals.
UnattainableGoalException
- if unable to satisfy a postcursor.
NoActionDefinitionException
- if this goal contains no action definition.void checkForCycles() throws CyclicGoalChainException
CyclicGoalChainException
- if a dependency cycle is discovered.void checkForCycles(Goal initialGoal, java.util.Set visited) throws CyclicGoalChainException
initialGoal
- The root Goal
initiating the cycle check.visited
- The Set
of all Goal
s visited
between the root initialGoal
and this Goal
.
CyclicGoalChainException
- if a cyclic dependency is detected.public final void attain(Session session) throws UnattainableGoalException, NoActionDefinitionException
Goal
.
session
- The context in which to attain goals.
UnattainableGoalException
- if unable to attain this Goal
or one of its precursor Goal
s.
NoActionDefinitionException
- if this goal contains no action definition.public final void percolate(Session session) throws UnattainableGoalException, NoActionDefinitionException
Goal
through to its Postcursors.
session
- The context in which to percolate goals.
UnattainableGoalException
- if unable to attain this Goal
or one of its precursor Goal
s.
NoActionDefinitionException
- if this goal contains no action definition.private final void fire(Session session) throws UnattainableGoalException, NoActionDefinitionException
Goal
's action, if need be, and
the post-goal callbacks.
session
- The context in which to fire the goal.
UnattainableGoalException
- if unable to attain this Goal
or one of its precursor Goal
s.
NoActionDefinitionException
- if this goal contains no action definition.void firePreGoalCallbacks() throws java.lang.Exception
java.lang.Exception
- if an error occurs while firing a callback.void firePostGoalCallbacks() throws java.lang.Exception
java.lang.Exception
- if an error occurs while firing a callback.void firePreActionCallbacks() throws java.lang.Exception
java.lang.Exception
- if an error occurs while firing a callback.void firePostActionCallbacks() throws java.lang.Exception
java.lang.Exception
- if an error occurs while firing a callback.public int hashCode()
The hash-code is derrived only from the name of
the Goal
as returned by getName()
.
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object thatObj)
Goal
objects are
equivelant.
Equivelancy is determined only from the names
of the Goal
s as return by getName()
.
equals
in class java.lang.Object
thatObj
- The object to compare to this object.
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |