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: /* hand generated! */
028:
029: package org.cougaar.glm.ldm.asset;
030:
031: import org.cougaar.core.mts.MessageAddress;
032: import org.cougaar.glm.ldm.Constants;
033: import org.cougaar.planning.ldm.asset.ClusterPG;
034: import org.cougaar.planning.ldm.asset.NewRelationshipPG;
035: import org.cougaar.planning.ldm.asset.RelationshipBG;
036: import org.cougaar.planning.ldm.plan.HasRelationships;
037: import org.cougaar.util.TimeSpan;
038:
039: import java.beans.IntrospectionException;
040: import java.beans.PropertyDescriptor;
041: import java.util.Collection;
042:
043: public abstract class OrganizationAdapter extends GLMAsset {
044:
045: public OrganizationAdapter() {
046: super ();
047: }
048:
049: protected OrganizationAdapter(OrganizationAdapter prototype) {
050: super (prototype);
051: }
052:
053: private transient MessageAddress cid = null;
054: private transient boolean cidComputed = false;
055:
056: public MessageAddress getMessageAddress() {
057: synchronized (this ) {
058: if (cidComputed)
059: return cid;
060:
061: ClusterPG cpg = getClusterPG();
062: if (cpg != null)
063: cid = cpg.getMessageAddress();
064: cidComputed = true;
065: return cid;
066: }
067: }
068:
069: /**
070: * getSuperiors - returns superior relationships.
071: * Performs a 2 stage search, returns all SUPERIOR relationships if they
072: * exist, if none exist returns all ADMINISTRATIVESUPERIOR relationships.
073: */
074: public Collection getSuperiors(long startTime, long endTime) {
075: Collection super iors = getRelationshipPG()
076: .getRelationshipSchedule().getMatchingRelationships(
077: Constants.Role.SUPERIOR, startTime, endTime);
078:
079: if (super iors.isEmpty()) {
080: super iors = getRelationshipPG().getRelationshipSchedule()
081: .getMatchingRelationships(
082: Constants.Role.ADMINISTRATIVESUPERIOR,
083: startTime, endTime);
084: }
085:
086: return super iors;
087: }
088:
089: public Collection getSuperiors(TimeSpan timeSpan) {
090: return getSuperiors(timeSpan.getStartTime(), timeSpan
091: .getEndTime());
092: }
093:
094: /**
095: * getSubordinates - returns subordinate relationships.
096: * Performs a 2 stage search, returns all SUBORDINATE relationships if they
097: * exist, if none exist returns all ADMINISTRATIVESUBORDINATE relationships.
098: */
099: public Collection getSubordinates(long startTime, long endTime) {
100: Collection subordinates = getRelationshipPG()
101: .getRelationshipSchedule().getMatchingRelationships(
102: Constants.Role.SUBORDINATE, startTime, endTime);
103:
104: if (subordinates.isEmpty()) {
105: subordinates = getRelationshipPG()
106: .getRelationshipSchedule()
107: .getMatchingRelationships(
108: Constants.Role.ADMINISTRATIVESUBORDINATE,
109: startTime, endTime);
110: }
111: return subordinates;
112: }
113:
114: public Collection getSubordinates(TimeSpan timeSpan) {
115: return getSubordinates(timeSpan.getStartTime(), timeSpan
116: .getEndTime());
117: }
118:
119: private static PropertyDescriptor properties[];
120: static {
121: try {
122: properties = new PropertyDescriptor[1];
123: properties[0] = new PropertyDescriptor("MessageAddress",
124: OrganizationAdapter.class, "getMessageAddress",
125: null);
126: } catch (IntrospectionException ie) {
127: }
128: }
129:
130: public PropertyDescriptor[] getPropertyDescriptors() {
131: PropertyDescriptor[] pds = super .getPropertyDescriptors();
132: PropertyDescriptor[] ps = new PropertyDescriptor[pds.length
133: + properties.length];
134: System.arraycopy(pds, 0, ps, 0, pds.length);
135: System.arraycopy(properties, 0, ps, pds.length,
136: properties.length);
137: return ps;
138: }
139:
140: public Object clone() throws CloneNotSupportedException {
141: OrganizationAdapter clone = (OrganizationAdapter) super .clone();
142: clone.initRelationshipSchedule();
143: return clone;
144: }
145:
146: public void initRelationshipSchedule() {
147: NewRelationshipPG relationshipPG = (NewRelationshipPG) PropertyGroupFactory
148: .newRelationshipPG();
149: RelationshipBG bg = new RelationshipBG();
150: bg.init(relationshipPG, (HasRelationships) this);
151: setRelationshipPG(relationshipPG);
152: }
153: }
|