01: /*--------------------------------------------------------------------------
02: * <copyright>
03: *
04: * Copyright 1999-2004 BBNT Solutions, LLC
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: package org.cougaar.glm.plugins.projection;
27:
28: import org.cougaar.glm.ldm.asset.ClassVIIMajorEndItem;
29: import org.cougaar.glm.ldm.asset.Organization;
30: import org.cougaar.glm.ldm.plan.Service;
31: import org.cougaar.glm.plugins.PluginDecorator;
32: import org.cougaar.planning.ldm.asset.AggregateAsset;
33: import org.cougaar.util.UnaryPredicate;
34:
35: /** Associates proper SupplyProjector with a given SupplyProjectionPlugin.
36: * @see SupplyProjectionPlugin
37: * @see GenerateSupplyDemandExpander
38: **/
39: public class SupplyProjectionDecorator extends PluginDecorator {
40: private static final String CLASSNAME = "SupplyProjectionDecorator";
41: // move to the plug in
42: Service serv_;
43: SupplyProjectionPlugin this Plugin_;
44: Organization cluster_;
45:
46: /** @param plugin to be configured */
47: public SupplyProjectionDecorator(SupplyProjectionPlugin plugin) {
48: super (plugin);
49: this Plugin_ = plugin;
50: }
51:
52: /** Predicate for MEIs - used to define consumers for Supply projection.
53: * Accepts aggregate assets of MEIs if the environmental variable
54: * "glm_aggregate_mei" is set to "true". **/
55: static class MEIPredicate implements UnaryPredicate {
56: private boolean include_aggregates_ = false;
57:
58: public MEIPredicate() {
59: String val = System.getProperty("glm_aggregate_mei");
60: if (val != null) {
61: if (val.equalsIgnoreCase("true"))
62: include_aggregates_ = true;
63: }
64:
65: }
66:
67: public boolean execute(Object o) {
68: if (o instanceof ClassVIIMajorEndItem) {
69: return true;
70: }
71:
72: if (include_aggregates_) {
73: if (o instanceof AggregateAsset) {
74: if (((AggregateAsset) o).getAsset() instanceof ClassVIIMajorEndItem) {
75: return true;
76: }
77: }
78: }
79: return false;
80: }
81: }
82:
83: /**
84: * Customizes the given SupplyProjectionPlugin with one or more BasicProcessor
85: * depending on information from the organizational asset
86: * this cluster represents.
87: * @param cluster the given plugin is loaded into
88: */
89: public void decoratePlugin(Organization cluster) {
90: cluster_ = cluster;
91: addTaskProcessor(new GenerateSupplyDemandExpander(thisPlugin_,
92: cluster_, thisPlugin_.getPartTypes()));
93: }
94: }
|