br.pucrio.inf.les.bdijade.plan
Class Plan

java.lang.Object
  extended by br.pucrio.inf.les.bdijade.util.MetadataElement
      extended by br.pucrio.inf.les.bdijade.plan.Plan
Direct Known Subclasses:
SimplePlan

public abstract class Plan
extends MetadataElement

This class represents the plan abstraction. It defines the goals that the plan can achieve, in which context, and knows which is its plan body.

Author:
ingrid

Field Summary
private  java.util.Set<java.lang.Class<? extends Goal>> goals
           
protected  java.lang.String id
           
private  java.util.Set<jade.lang.acl.MessageTemplate> messageTemplates
           
private  PlanLibrary planLibrary
           
 
Fields inherited from class br.pucrio.inf.les.bdijade.util.MetadataElement
metadata
 
Constructor Summary
Plan(java.lang.String id)
          Constructs a new Plan.
Plan(java.lang.String id, java.lang.Class<? extends Goal> goalClass)
          Constructs a new Plan.
Plan(java.lang.String id, java.lang.Class<? extends Goal> goalClass, jade.lang.acl.MessageTemplate messageTemplate)
          Constructs a new Plan.
Plan(java.lang.String id, jade.lang.acl.MessageTemplate messageTemplate)
          Constructs a new Plan.
 
Method Summary
 void addGoal(java.lang.Class<? extends Goal> goalClass)
          Adds a goal class that this plan may achieve.
 void addMessageTemplate(jade.lang.acl.MessageTemplate messageTemplate)
          Adds a message template of messages that this plan can process.
 boolean canAchieve(Goal goal)
          Verifies if a given goal can be achieved by this plan.
 boolean canProcess(jade.lang.acl.ACLMessage message)
          Verifies if the message received matches with any of the message templates of this plan.
abstract  jade.core.behaviours.Behaviour createPlanBody()
          Instantiate the plan body of this plan.
 boolean equals(java.lang.Object obj)
           
 java.lang.String getId()
           
 PlanLibrary getPlanLibrary()
           
 int hashCode()
           
protected  void initGoals()
          This method is invoked in the Plan constructor.
protected  void initMessageTemplates()
          This method is invoked in the Plan constructor.
protected  boolean matchesContext(Goal goal)
          Verifies that this plan can be executed in the current context.
 void setPlanLibrary(PlanLibrary planLibrary)
           
 java.lang.String toString()
           
 
Methods inherited from class br.pucrio.inf.les.bdijade.util.MetadataElement
getMetadata, getMetadata, hasMetadata, putMetadata, removeMetadata
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

goals

private final java.util.Set<java.lang.Class<? extends Goal>> goals

id

protected final java.lang.String id

messageTemplates

private final java.util.Set<jade.lang.acl.MessageTemplate> messageTemplates

planLibrary

private PlanLibrary planLibrary
Constructor Detail

Plan

public Plan(java.lang.String id)
Constructs a new Plan. It sets the plan library and plan body class of this plan, and initializes the goals that it can achieve and message templates of messages it can process.

Parameters:
id - plan identifier

Plan

public Plan(java.lang.String id,
            java.lang.Class<? extends Goal> goalClass)
Constructs a new Plan. It sets the plan library and plan body class of this plan, and initializes the goals that it can achieve and messages it can process. The goals are initialized with the provided goal class.

Parameters:
id - plan identifier
goalClass - the goal that this plan can achieve

Plan

public Plan(java.lang.String id,
            java.lang.Class<? extends Goal> goalClass,
            jade.lang.acl.MessageTemplate messageTemplate)
Constructs a new Plan. It sets the plan library and plan body class of this plan, and initializes the goals that it can achieve and messages it can process. The goals are initialized with the provided goal class. The message templates is initialized with the provided template.

Parameters:
id - plan identifier
goalClass - the goal that this plan can achieve
messageTemplate - the template of messages that this plan can process.

Plan

public Plan(java.lang.String id,
            jade.lang.acl.MessageTemplate messageTemplate)
Constructs a new Plan. It sets the plan library and plan body class of this plan, and initializes the goals that it can achieve and message templates of messages it can process. The message templates is initialized with the provided template.

Parameters:
id - the plan identifier
messageTemplate - the template of messages that this plan can process.
Method Detail

addGoal

public void addGoal(java.lang.Class<? extends Goal> goalClass)
Adds a goal class that this plan may achieve.

Parameters:
goalClass - the goal class that can be achieved by this plan.

addMessageTemplate

public void addMessageTemplate(jade.lang.acl.MessageTemplate messageTemplate)
Adds a message template of messages that this plan can process.

Parameters:
messageTemplate - the message template of messages that can be processed.

canAchieve

public boolean canAchieve(Goal goal)
Verifies if a given goal can be achieved by this plan. When the goal is a MessageGoal, it invokes the method canProcess(ACLMessage). Otherwise, it checks if the class of this goal is contained in the goal set of this plan.

Parameters:
goal - the goal to be verified.
Returns:
true if the given goal can be achieved by this plan, false otherwise.

canProcess

public boolean canProcess(jade.lang.acl.ACLMessage message)
Verifies if the message received matches with any of the message templates of this plan.

Parameters:
message - the message to be checked.
Returns:
true if this plan can process the message.

createPlanBody

public abstract jade.core.behaviours.Behaviour createPlanBody()
                                                       throws PlanInstantiationException
Instantiate the plan body of this plan. It must be an instance of Behaviour and also implements the PlanBody interface.

Returns:
the instantiated plan body.
Throws:
PlanInstantiationException - if an error occurred during the instantiation process.

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

getId

public java.lang.String getId()
Returns:
the id

getPlanLibrary

public PlanLibrary getPlanLibrary()
Returns:
the planLibrary

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

initGoals

protected void initGoals()
This method is invoked in the Plan constructor. It is responsible for initializing the goals that this plan can achieve. The method should be overridden by subclasses.


initMessageTemplates

protected void initMessageTemplates()
This method is invoked in the Plan constructor. It is responsible for initializing the message templates that this plan can process. The method should be overridden by subclasses.


matchesContext

protected boolean matchesContext(Goal goal)
Verifies that this plan can be executed in the current context. The method should be overridden by subclasses.

Parameters:
goal - the goal to be achieved
Returns:
true if the context matches with the conditions needed for this plan execution.

setPlanLibrary

public void setPlanLibrary(PlanLibrary planLibrary)
Parameters:
planLibrary - the planLibrary to set

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()