edu.indiana.dde.mylead.common
Class MyLeadQueryPlan

java.lang.Object
  extended byedu.indiana.dde.mylead.common.MyLeadQueryPlan
All Implemented Interfaces:
MyLeadContextQuery

public class MyLeadQueryPlan
extends java.lang.Object
implements MyLeadContextQuery

Each myLEAD query has a target and then optionally one or more chains above the target that it is within and/or one or more chains below the target that it contains. The chains above the target must be a disjunctive set since any myLEAD object has only one parent - so if the chains above the target were in a conjunctive set, they would in fact be the same chain. The chains or chain sets below the target are contained within the target, and unlike the chains above the target, the relationship between these chains can be conjunctive or disjunctive.
This class defines a query plan for a situation such as the following:

  [P]      [P]      [P]
   |   OR   |   OR   |
   |       [E]       |
   -------------------
            |
    Target [T]
            |
      -------------
      |           |
     [C]   AND    |
      |           |
     [F]         [F]

This example illustrates a case where we are looking for a target collection that is within one of three project/experiment combinations and also contains both a collection of files of some type and afile of another type. The target and all of the project, experiment, collection, and file criteria can also have both static and dynamic attributes associated with them in the query. The target is defined seperately as an instance of a MyLeadQuery object, but the rest of the query is included in this query plan class. The reason that the target is defined seperately is that each myLEAD query is looking for a target, but it may be looking for that target in the context of any number of alternate query plans. Each myLEAD query thus is required to have a target and optionally a set of query plans.

See Also:
MyLeadQuerySet, MyLeadChainSet, MyLeadQueryChain

Constructor Summary
MyLeadQueryPlan()
          The constructor does not take any parameters, so both the chains it is contained within and the chain or chainset it contains are added in other method calls.
 
Method Summary
 void addWithinChain(MyLeadQueryChain chain)
          This method takes an instance of MyLeadQueryChain as a parameter and adds it to the list of chains that the target could be contained within.
 int containsCount()
          This method returns the number of chains and/or chain sets in this query plan that are contained within the target.
 ChainMember getContainsMember()
          This method can be used to get the chain or chain set that is contained in the target.
 MyLeadQueryChain getWithinChain(int chain)
          This method can be used to get a chain that is part of the set of chains above the target that the target is within.
 void setContainsChain(ChainMember member)
          This method is used to set the chain or chain set to be directly contained in the target of a myLEAD query.
 int withinCount()
          This method returns the number of chains included in this query plan that the target could be within.
 java.lang.String wrapQuery()
          This method is called if this MyLeadQueryPlan is not part of a MyLeadQuerySet but is instead the entire query portion of a myLEAD query and thus is the entire LeadQueryType in the leadActivity.xsd schema's leadQuery.
 java.lang.String wrapQueryPlan(boolean singlePlan)
          This method wraps the query plan up as an XML String that can be included in the myLEAD query's OGSA-DAI perform document which validates against the leadActivity.xsd schema.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MyLeadQueryPlan

public MyLeadQueryPlan()
The constructor does not take any parameters, so both the chains it is contained within and the chain or chainset it contains are added in other method calls.

Method Detail

withinCount

public int withinCount()
This method returns the number of chains included in this query plan that the target could be within.

Returns:
integer count of the number of chains in this plan that the target is within.

containsCount

public int containsCount()
This method returns the number of chains and/or chain sets in this query plan that are contained within the target. The direct number of chains/chain sets will be either 1 or 0, but a chain set can then contain any number of chains or additional chain sets.

Returns:
integer count of the number of members in this plan that are directly contained in the target.

getWithinChain

public MyLeadQueryChain getWithinChain(int chain)
This method can be used to get a chain that is part of the set of chains above the target that the target is within. The index parameter indicates which chain or chain set should be returned - the first chain has a 0 index. If an index less than zero or greater than withinCount-1 is specified, then null is returned.

Parameters:
chain - integer with position of the chain to return. Must be in the range from zero to withinCount-1.
Returns:
The MyLeadQueryChain at the position specified if the position is valid - otherwise null.

getContainsMember

public ChainMember getContainsMember()
This method can be used to get the chain or chain set that is contained in the target. There will be at most one direct chain or chain set.

Returns:
The ChainMember if one was set - otherwise null.

addWithinChain

public void addWithinChain(MyLeadQueryChain chain)
This method takes an instance of MyLeadQueryChain as a parameter and adds it to the list of chains that the target could be contained within. When adding a chain, this method only requires that the parameter be a chain - the user is responsible for making sure that the chain could contain the target that will be passed in the myLEAD query.

For example, since collections cannot contain experiments, if a chain with a collection at its lowest level was added using this method, and then the query plan was used with a target experiment, the query would return no results since an experiment cannot be within a collection.

Parameters:
chain - The instance of MyLeadQueryChain to add to the chains above the target in the query plan.

setContainsChain

public void setContainsChain(ChainMember member)
This method is used to set the chain or chain set to be directly contained in the target of a myLEAD query. Unlike the chains above a target, there is a single direct chain or chain set below a target - although a set could contain multiple chains or sets.
Since both chains and chain sets implement the ChainMember interface, this method takes a chain member parameter and then calls the chain member interface's isChainSet method to determine if the parameter is a chain or chain set.

Parameters:
member - ChainMember that is either a MyLeadQueryChain or MyLeadChainSet.

wrapQuery

public java.lang.String wrapQuery()
This method is called if this MyLeadQueryPlan is not part of a MyLeadQuerySet but is instead the entire query portion of a myLEAD query and thus is the entire LeadQueryType in the leadActivity.xsd schema's leadQuery. This is essentially the same as a single plan in a call to the wrapQueryPlan method, but the result needs to be wrapped in <query> tags.

Specified by:
wrapQuery in interface MyLeadContextQuery
Returns:
String containing the XML fragment for the query.

wrapQueryPlan

public java.lang.String wrapQueryPlan(boolean singlePlan)
This method wraps the query plan up as an XML String that can be included in the myLEAD query's OGSA-DAI perform document which validates against the leadActivity.xsd schema. The singlePlan parameter is needed because a plan could have multiple within chains but no contains type chains or chain sets. In that case, each within chain is essentially a separate plan. If this is the only query plan, then the OR set tags should be added in this method, but if this is one of multiple plans then the OR tags should only be added by the query plan set. This method is called by the wrapQuery method in the MyLeadQuerySet class.

Parameters:
singlePlan - boolean to indicate if this is the only plan in the query plan set.
Returns:
String containing the XML fragment for the query plan.
See Also:
MyLeadQuerySet