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.glm.ldm;
028:
029: import java.util.Collection;
030: import java.util.Enumeration;
031: import java.util.Vector;
032:
033: import org.cougaar.core.domain.Factory;
034: import org.cougaar.core.mts.MessageAddress;
035: import org.cougaar.core.util.UID;
036: import org.cougaar.core.util.UniqueObject;
037: import org.cougaar.glm.ldm.plan.Capability;
038: import org.cougaar.glm.ldm.plan.CapabilityImpl;
039: import org.cougaar.glm.ldm.plan.CapacityScheduleElement;
040: import org.cougaar.glm.ldm.plan.CapacityScheduleElementImpl;
041: import org.cougaar.glm.ldm.plan.CasRepChangeIndicatorImpl;
042: import org.cougaar.glm.ldm.plan.CasRepImpl;
043: import org.cougaar.glm.ldm.plan.DetailReplyAssignment;
044: import org.cougaar.glm.ldm.plan.DetailRequest;
045: import org.cougaar.glm.ldm.plan.DetailRequestAssignment;
046: import org.cougaar.glm.ldm.plan.DetailRequestImpl;
047: import org.cougaar.glm.ldm.plan.GeolocLocationImpl;
048: import org.cougaar.glm.ldm.plan.IcaoLocationImpl;
049: import org.cougaar.glm.ldm.plan.LaborSchedule;
050: import org.cougaar.glm.ldm.plan.LaborScheduleImpl;
051: import org.cougaar.glm.ldm.plan.NamedPositionImpl;
052: import org.cougaar.glm.ldm.plan.NewCapacityScheduleElement;
053: import org.cougaar.glm.ldm.plan.NewCasRep;
054: import org.cougaar.glm.ldm.plan.NewGeolocLocation;
055: import org.cougaar.glm.ldm.plan.NewIcaoLocation;
056: import org.cougaar.glm.ldm.plan.NewNamedPosition;
057: import org.cougaar.glm.ldm.plan.NewPosition;
058: import org.cougaar.glm.ldm.plan.NewQuantityRangeScheduleElement;
059: import org.cougaar.glm.ldm.plan.NewQuantityScheduleElement;
060: import org.cougaar.glm.ldm.plan.NewRateScheduleElement;
061: import org.cougaar.glm.ldm.plan.PlanScheduleElementType;
062: import org.cougaar.glm.ldm.plan.PositionImpl;
063: import org.cougaar.glm.ldm.plan.QuantityRangeScheduleElement;
064: import org.cougaar.glm.ldm.plan.QuantityRangeScheduleElementImpl;
065: import org.cougaar.glm.ldm.plan.QuantityScheduleElement;
066: import org.cougaar.glm.ldm.plan.QuantityScheduleElementImpl;
067: import org.cougaar.glm.ldm.plan.QueryReplyAssignment;
068: import org.cougaar.glm.ldm.plan.QueryRequest;
069: import org.cougaar.glm.ldm.plan.QueryRequestAssignment;
070: import org.cougaar.glm.ldm.plan.QueryRequestImpl;
071: import org.cougaar.glm.ldm.plan.RateScheduleElement;
072: import org.cougaar.glm.ldm.plan.RateScheduleElementImpl;
073: import org.cougaar.planning.ldm.measure.Latitude;
074: import org.cougaar.planning.ldm.measure.Longitude;
075: import org.cougaar.planning.ldm.plan.Location;
076: import org.cougaar.planning.ldm.plan.NewSchedule;
077: import org.cougaar.planning.ldm.plan.Schedule;
078: import org.cougaar.planning.ldm.plan.ScheduleElement;
079: import org.cougaar.planning.ldm.plan.ScheduleImpl;
080: import org.cougaar.util.UnaryPredicate;
081:
082: /**
083: * FGI Domain package definition.
084: **/
085:
086: public class GLMFactory implements Factory {
087:
088: //
089: // factory methods for COUGAAR LDM objects
090: //
091:
092: /**@param c - Pass a valid string representation of the Capability
093: * @return Capability
094: * @see org.cougaar.glm.ldm.plan.Capability for a list of valid values
095: **/
096: public static Capability getCapability(String c) {
097: return new CapabilityImpl(c);
098: }
099:
100: public static NewCapacityScheduleElement newCapacityScheduleElement() {
101: return new CapacityScheduleElementImpl();
102: }
103:
104: /** Create a capacity schedule. This schedule has a container of
105: * CapacityScheduleElements.
106: * @param capacityElements Enumeration{CapacityScheduleElement}
107: * @see org.cougaar.glm.ldm.plan.CapacityScheduleElement
108: **/
109: public static NewSchedule newCapacitySchedule(
110: Enumeration capacityElements) {
111: Vector rse = new Vector();
112: while (capacityElements.hasMoreElements()) {
113: ScheduleElement se = (ScheduleElement) capacityElements
114: .nextElement();
115: if (se instanceof CapacityScheduleElement) {
116: rse.addElement(se);
117: } else {
118: throw new IllegalArgumentException(
119: "Error in creating newCapacitySchedule - an element was passed in the Enumeration that was not a CapacityScheduleElement");
120: }
121: }
122: ScheduleImpl s = new ScheduleImpl();
123: s.setScheduleElementType(PlanScheduleElementType.CAPACITY);
124: s.setScheduleElements(rse.elements());
125: return s;
126: }
127:
128: /** Create a labor schedule. LaborSchedules contain a schedule that
129: * has QuantityScheduleElements and a schedule that has RateScheduleElements.
130: * @param qtySchedule The schedule with scheduleelementtype QUANTITY created by
131: * factory.newQuantitySchedule
132: * @param rateSchedule The schedule with scheduleelementtype RATE created by
133: * factory.newRateSchedule
134: * @return LaborSchedule
135: * @see org.cougaar.glm.ldm.plan.LaborSchedule
136: * @see org.cougaar.glm.ldm.plan.QuantityScheduleElement
137: * @see org.cougaar.glm.ldm.plan.RateScheduleElement
138: **/
139:
140: public static LaborSchedule newLaborSchedule(Schedule qtySchedule,
141: Schedule rateSchedule) {
142: if (qtySchedule != null
143: && rateSchedule != null
144: && qtySchedule.getScheduleElementType().equals(
145: PlanScheduleElementType.QUANTITY)
146: && rateSchedule.getScheduleElementType().equals(
147: PlanScheduleElementType.RATE)) {
148: LaborSchedule ls = new LaborScheduleImpl(qtySchedule,
149: rateSchedule);
150: return ls;
151: } else {
152: throw new IllegalArgumentException(
153: "Error in creating newLaborSchedule");
154: }
155: }
156:
157: public static NewCasRep newCasRep() {
158: return new CasRepImpl();
159: }
160:
161: public static NewCasRep newCasRepChangeInd() {
162: return new CasRepChangeIndicatorImpl();
163: }
164:
165: public static NewGeolocLocation newGeolocLocation() {
166: return new GeolocLocationImpl();
167: }
168:
169: public static NewIcaoLocation newIcaoLocation() {
170: return new IcaoLocationImpl();
171: }
172:
173: public static NewNamedPosition newNamedPosition() {
174: return new NamedPositionImpl();
175: }
176:
177: /** Build a new empty Position object with a Latitude and Longitude **/
178: public static NewPosition newPosition() {
179: return new PositionImpl();
180: }
181:
182: /** Build a new Position object with a Latitude and Longitude
183: * @param alatitude
184: * @param alongitude
185: * @return Location
186: **/
187: public static Location createPosition(Latitude alatitude,
188: Longitude alongitude) {
189: return new PositionImpl(alatitude, alongitude);
190: }
191:
192: public static NewQuantityRangeScheduleElement newQuantityRangeScheduleElement() {
193: return new QuantityRangeScheduleElementImpl();
194: }
195:
196: public static NewQuantityScheduleElement newQuantityScheduleElement() {
197: return new QuantityScheduleElementImpl();
198: }
199:
200: /** Create a quantity schedule. This schedule has a container of
201: * QuantityScheduleElements.
202: * @param qtyElements
203: * @param scheduleType Pass in they type of Schedule
204: * @see org.cougaar.planning.ldm.plan.ScheduleType
205: * @see org.cougaar.glm.ldm.plan.QuantityScheduleElement
206: **/
207: public static NewSchedule newQuantitySchedule(
208: Enumeration qtyElements, String scheduleType) {
209: Vector qtyse = new Vector();
210: while (qtyElements.hasMoreElements()) {
211: ScheduleElement se = (ScheduleElement) qtyElements
212: .nextElement();
213: if (se instanceof QuantityScheduleElement) {
214: qtyse.addElement(se);
215: } else {
216: throw new IllegalArgumentException(
217: "Error in creating newQuantitySchedule - an element was passed in the Enumeration that was not a QuantityScheduleElement");
218: }
219: }
220: ScheduleImpl s = new ScheduleImpl();
221: s.setScheduleType(scheduleType);
222: s.setScheduleElementType(PlanScheduleElementType.QUANTITY);
223: s.setScheduleElements(qtyse.elements());
224:
225: return s;
226: }
227:
228: /** Create a quantity range schedule. This schedule has a container
229: * of QuantityRangeScheduleElements.
230: * @param qtyRangeElements Enumeration{QuantityRangeScheduleElement}
231: * @param scheduleType Pass in the type of Schedule
232: * @see org.cougaar.planning.ldm.plan.ScheduleType
233: * @see org.cougaar.glm.ldm.plan.QuantityRangeScheduleElement
234: **/
235: public static NewSchedule newQuantityRangeSchedule(
236: Enumeration qtyRangeElements, String scheduleType) {
237: Vector qtyrse = new Vector();
238: while (qtyRangeElements.hasMoreElements()) {
239: ScheduleElement se = (ScheduleElement) qtyRangeElements
240: .nextElement();
241: if (se instanceof QuantityRangeScheduleElement) {
242: qtyrse.addElement(se);
243: } else {
244: throw new IllegalArgumentException(
245: "Error in creating newQuantityRangeSchedule - an element was passed in the Enumeration that was not a QuantityRangeScheduleElement");
246: }
247: }
248: ScheduleImpl s = new ScheduleImpl();
249: s.setScheduleType(scheduleType);
250: s.setScheduleElementType(PlanScheduleElementType.QUANTITYRANGE);
251: s.setScheduleElements(qtyrse.elements());
252: return s;
253: }
254:
255: /** Create a rate schedule. This schedule has a container of
256: * RateScheduleElements.
257: * @param rateElements Enumeration{RateScheduleElement}
258: * @see org.cougaar.glm.ldm.plan.RateScheduleElement
259: **/
260: public static NewSchedule newRateSchedule(Enumeration rateElements) {
261: Vector rse = new Vector();
262: while (rateElements.hasMoreElements()) {
263: ScheduleElement se = (ScheduleElement) rateElements
264: .nextElement();
265: if (se instanceof RateScheduleElement) {
266: rse.addElement(se);
267: } else {
268: throw new IllegalArgumentException(
269: "Error in creating newRateSchedule - an element was passed in the Enumeration that was not a RateScheduleElement");
270: }
271: }
272: ScheduleImpl s = new ScheduleImpl();
273: s.setScheduleElementType(PlanScheduleElementType.RATE);
274: s.setScheduleElements(rse.elements());
275: return s;
276: }
277:
278: public static NewRateScheduleElement newRateScheduleElement() {
279: return new RateScheduleElementImpl();
280: }
281:
282: public static DetailRequestAssignment newDetailRequestAssignment(
283: DetailRequest request) {
284: return new DetailRequestAssignment(request);
285: }
286:
287: public static DetailReplyAssignment newDetailReplyAssignment(
288: UniqueObject replyObj, UID requestedUID,
289: MessageAddress replyFrom, MessageAddress replyTo) {
290: return new DetailReplyAssignment(replyObj, requestedUID,
291: replyFrom, replyTo);
292: }
293:
294: public static DetailRequest newDetailRequest(UID desiredObject,
295: MessageAddress sourceCluster,
296: MessageAddress requestingCluster) {
297: return new DetailRequestImpl(desiredObject, sourceCluster,
298: requestingCluster);
299: }
300:
301: public static QueryRequestAssignment newQueryRequestAssignment(
302: QueryRequest request) {
303: return new QueryRequestAssignment(request);
304: }
305:
306: public static QueryReplyAssignment newQueryReplyAssignment(
307: Collection reply, UnaryPredicate requestQuery,
308: MessageAddress replyFrom, MessageAddress replyTo) {
309: return new QueryReplyAssignment(reply, requestQuery, replyFrom,
310: replyTo);
311: }
312:
313: public static QueryReplyAssignment newQueryReplyAssignment(
314: Collection reply, UnaryPredicate requestQuery,
315: UnaryPredicate localQuery, MessageAddress replyFrom,
316: MessageAddress replyTo) {
317: return new QueryReplyAssignment(reply, requestQuery,
318: localQuery, replyFrom, replyTo);
319: }
320:
321: public static QueryRequest newQueryRequest(
322: UnaryPredicate queryPredicate,
323: MessageAddress sourceCluster,
324: MessageAddress requestingCluster) {
325: return new QueryRequestImpl(queryPredicate, sourceCluster,
326: requestingCluster);
327: }
328:
329: public static QueryRequest newQueryRequest(
330: UnaryPredicate queryPredicate,
331: UnaryPredicate localPredicate,
332: MessageAddress sourceCluster,
333: MessageAddress requestingCluster) {
334: return new QueryRequestImpl(queryPredicate, localPredicate,
335: sourceCluster, requestingCluster);
336: }
337: }
|