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.Collection;
030:
031: import org.cougaar.core.mts.MessageAddress;
032: import org.cougaar.glm.ldm.asset.Organization;
033: import org.cougaar.planning.ldm.plan.RelationshipSchedule;
034: import org.cougaar.planning.ldm.plan.Role;
035: import org.cougaar.util.TimeSpan;
036: import org.cougaar.util.UnaryPredicate;
037:
038: /**
039: * DestinationPredicate - Unary Predicate describing the
040: * destination cluster of an Oplan or Policy that is being forwarded
041: *
042: */
043:
044: public class DestinationPredicate implements UnaryPredicate {
045: protected String roles[];
046:
047: protected MessageAddress clusterId;
048:
049: DestinationPredicate(String[] roles, MessageAddress clusterId) {
050: this .roles = roles;
051: this .clusterId = clusterId;
052:
053: if (roles == null)
054: roles = new String[0];
055: }
056:
057: public String[] getRoles() {
058: return roles;
059: }
060:
061: public int hashCode() {
062: String hashstring = "";
063: for (int i = 0; i < roles.length; i++)
064: hashstring += roles[i];
065:
066: return hashstring.hashCode();
067: }
068:
069: public boolean equals(Object obj) {
070: if (obj instanceof DestinationPredicate) {
071: DestinationPredicate dp = (DestinationPredicate) obj;
072: String[] otherRoles = dp.getRoles();
073: if (otherRoles.length != roles.length)
074: return false;
075:
076: int matchcount = 0;
077: for (int i = 0; i < roles.length; i++)
078: for (int j = 0; j < otherRoles.length; j++)
079: if (roles[i].equals(otherRoles[j]))
080: matchcount++;
081: if (matchcount == roles.length)
082: return true;
083: }
084: return false;
085: }
086:
087: public boolean execute(Object o) {
088: // Screen out self org
089: if (o instanceof Organization) {
090: if (((Organization) o).isSelf()) {
091: return false;
092: }
093:
094: RelationshipSchedule schedule = ((Organization) o)
095: .getRelationshipSchedule();
096:
097: // Does this org have all the roles we need?
098: // BOGUS - time phased aspect ignored
099: for (int i = 0; i < roles.length; i++) {
100: // Need to drop self org
101: Collection matchRoles = schedule
102: .getMatchingRelationships(Role
103: .getRole(roles[i]).getConverse(),
104: TimeSpan.MIN_VALUE, TimeSpan.MAX_VALUE);
105:
106: if (matchRoles.size() == 0) {
107: return false;
108: }
109: }
110: return true;
111: }
112: return false;
113: }
114: }
|