01: /*
02: * <copyright>
03: *
04: * Copyright 1999-2004 Honeywell Inc
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26:
27: package org.cougaar.glm.packer;
28:
29: import org.cougaar.planning.ldm.PlanningFactory;
30: import org.cougaar.planning.ldm.plan.NewMPTask;
31: import org.cougaar.planning.ldm.plan.Task;
32:
33: /**
34: * This class is used to wrap up an aggregation's state into an
35: * object that is able to generate new MPTasks on demand. These
36: * MPTasks will be used as the "right-hand-side" of Aggregations
37: * constructed by the GenericPlugin.<br>
38: * A standard strategy for writing AggregationClosures is to provide
39: * a constructor that sets a number of instance variables. Then the newTask method
40: * will use these instance variables to appropriately construct the MPTask it
41: * returns.<br>
42: * The name of this class is a trifle unfortunate --- it would be
43: * better if it and the GenericTemplate were renamed to MPTaskTemplate
44: * and WorkflowTemplate, respectively, but this has not been done in the
45: * interests of backward-compatibility.
46: * @see GenericPlugin
47: */
48: public abstract class AggregationClosure {
49: protected GenericPlugin _gp = null;
50: protected PlanningFactory _factory = null;
51:
52: /**
53: * This method will be called by aggregation and packing scripts of
54: * the scripting Plugin. It is guaranteed to be called before the
55: * newTask method is called, so that writers of newTask methods may
56: * feel free to use the variables _gp and _factory, that point to the
57: * GenericPlugin and its PlanningFactory, respectively.
58: * @see #newTask
59: */
60: public void setGenericPlugin(GenericPlugin gp) {
61: _gp = gp;
62: _factory = _gp.getGPFactory();
63: }
64:
65: /**
66: * Developers of aggregation and packing rules should supply an
67: * AggregationClosure subclass that provides an instantiation of this
68: * method. This method should return a NewMPTask, but need not publish
69: * it (this will be done by the GenericPlugin) or set its Preferences
70: * (this is the job of the PreferenceAggregator.
71: * @see PreferenceAggregator
72: */
73: public abstract NewMPTask newTask();
74:
75: /**
76: * getQuantity - return the amount this container can hold
77: */
78: public abstract double getQuantity();
79:
80: /**
81: * return true if task is valid for this AggregationClosure.
82: */
83: public abstract boolean validTask(Task task);
84: }
|