001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.mlm.plugin.generic;
028:
029: import java.util.Enumeration;
030:
031: import org.cougaar.glm.ldm.Constants;
032: import org.cougaar.glm.ldm.asset.Organization;
033: import org.cougaar.planning.ldm.asset.Asset;
034: import org.cougaar.planning.ldm.plan.Expansion;
035: import org.cougaar.planning.ldm.plan.PrepositionalPhrase;
036: import org.cougaar.planning.ldm.plan.Task;
037: import org.cougaar.planning.ldm.plan.Workflow;
038: import org.cougaar.util.UnaryPredicate;
039:
040: public class GenericScriptHelper {
041:
042: public static UnaryPredicate getAllocatableGLSPredicate() {
043: UnaryPredicate allocGLSPred = new UnaryPredicate() {
044: public boolean execute(Object o) {
045: if (o instanceof Task) {
046: Task t = (Task) o;
047: if (t.getPlanElement() == null) {
048: if (t.getVerb().toString().equals(
049: Constants.Verb.GETLOGSUPPORT)) {
050: Enumeration pp = t
051: .getPrepositionalPhrases();
052: while (pp.hasMoreElements()) {
053: PrepositionalPhrase app = (PrepositionalPhrase) pp
054: .nextElement();
055: if ((app.getPreposition()
056: .equals(Constants.Preposition.FOR))
057: && (app.getIndirectObject() instanceof Asset)) {
058: String name = null;
059: try {
060: name = ((Asset) app
061: .getIndirectObject())
062: .getTypeIdentificationPG()
063: .getTypeIdentification();
064: } catch (Exception e) {
065: System.out
066: .println("GLSAlloc error while trying to get the TypeIdentification of an asset");
067: e.printStackTrace();
068: }
069: if (name.equals("Subordinates")) {
070: return true;
071: }
072: }
073: }
074: }
075: }
076: }
077: return false;
078: }
079: };
080: return ((UnaryPredicate) allocGLSPred);
081: }
082:
083: public static UnaryPredicate getExpChangePred() {
084: UnaryPredicate myExpsPred = new UnaryPredicate() {
085: public boolean execute(Object o) {
086: if (o instanceof Expansion) {
087: Workflow wf = ((Expansion) o).getWorkflow();
088: Enumeration wftasks = wf.getTasks();
089: while (wftasks.hasMoreElements()) {
090: Task t = (Task) wftasks.nextElement();
091: if (t.getVerb().toString().equals(
092: Constants.Verb.GETLOGSUPPORT)) {
093: Enumeration pp = t
094: .getPrepositionalPhrases();
095: while (pp.hasMoreElements()) {
096: PrepositionalPhrase app = (PrepositionalPhrase) pp
097: .nextElement();
098: if ((app.getPreposition()
099: .equals(Constants.Preposition.FOR))
100: && (app.getIndirectObject() instanceof Organization)) {
101: return true;
102: }
103: }
104: }
105: }
106: }
107: return false;
108: }
109: };
110: return myExpsPred;
111: }
112:
113: }
|