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.logistics.plugin.inventory;
028:
029: import org.cougaar.planning.ldm.policy.BooleanRuleParameter;
030: import org.cougaar.planning.ldm.policy.IntegerRuleParameter;
031: import org.cougaar.planning.ldm.policy.DoubleRuleParameter;
032: import org.cougaar.planning.ldm.policy.LongRuleParameter;
033: import org.cougaar.planning.ldm.policy.Policy;
034: import org.cougaar.planning.ldm.policy.RuleParameter;
035: import org.cougaar.planning.ldm.policy.RuleParameterIllegalValueException;
036: import org.cougaar.planning.ldm.policy.StringRuleParameter;
037: import org.cougaar.util.log.Logging;
038: import org.cougaar.util.log.Logger;
039:
040: import java.text.SimpleDateFormat;
041: import java.util.TimeZone;
042: import java.util.Date;
043:
044: import java.io.ObjectInputStream;
045: import java.io.IOException;
046:
047: public class InventoryPolicy extends Policy {
048: public static final String AgentID = "AgentID";
049: public static final String ResourceType = "ResourceType";
050: public static final String InventoryManagerSpecifier = "InventoryManagerSpecifier";
051: public static final String CriticalLevel = "CriticalLevel";
052: public static final String SupplierAdvanceNoticeTime = "SupplierAdvanceNoticeTime";
053: public static final String ReorderPeriod = "ReorderPeriod";
054: public static final String HandlingTime = "HandlingTime";
055: public static final String TransportTime = "TransportTime";
056: public static final String OrderShipTime = "OrderShipTime";
057: public static final String BucketSize = "BucketSize";
058: public static final String FillToCapacity = "FillToCapacity";
059: public static final String SupplierArrivalTime = "SupplierArrivalTime";
060:
061: public SimpleDateFormat dateFormatter;
062: private transient Logger logger;
063:
064: public InventoryPolicy() {
065: dateFormatter = new SimpleDateFormat("MM/dd/yyyy HH:mm");
066: dateFormatter.setTimeZone(TimeZone.getTimeZone("GMT"));
067:
068: logger = Logging.getLogger(this );
069:
070: StringRuleParameter id = new StringRuleParameter(AgentID);
071: String exception;
072: try {
073: id.setValue(new String());
074: } catch (RuleParameterIllegalValueException ex) {
075: if (logger.isErrorEnabled()) {
076: logger.error(ex.toString());
077: }
078: // Print exception, waiting for a static logger
079: }
080: Add(id);
081: StringRuleParameter type = new StringRuleParameter(ResourceType);
082: try {
083: type.setValue(new String());
084: } catch (RuleParameterIllegalValueException ex) {
085: if (logger.isErrorEnabled()) {
086: logger.error("ResourceType-" + ex.toString());
087: }
088: // Print exception, waiting for a static logger
089: }
090: Add(type);
091: StringRuleParameter arrivalDate = new StringRuleParameter(
092: SupplierArrivalTime);
093: try {
094: arrivalDate.setValue(null);
095: } catch (RuleParameterIllegalValueException ex) {
096: if (logger.isDebugEnabled()) {
097: logger.debug("SupplierArrivalTime-" + ex.toString());
098: }
099: // Print exception, waiting for a static logger
100: }
101: Add(arrivalDate);
102: StringRuleParameter specifier = new StringRuleParameter(
103: InventoryManagerSpecifier);
104: try {
105: type.setValue(new String());
106: } catch (RuleParameterIllegalValueException ex) {
107: if (logger.isErrorEnabled()) {
108: logger.error("InventoryManagerSpecifier-"
109: + ex.toString());
110: }
111: // Print exception, waiting for a static logger
112: }
113: Add(specifier);
114: IntegerRuleParameter cl = new IntegerRuleParameter(
115: CriticalLevel, 1, 40);
116: try {
117: cl.setValue(new Integer(3));
118: } catch (RuleParameterIllegalValueException ex) {
119: if (logger.isErrorEnabled()) {
120: logger.error("CriticalLevel-" + ex.toString());
121: }
122: // Print exception, waiting for a static logger
123: }
124: Add(cl);
125: IntegerRuleParameter st = new IntegerRuleParameter(
126: SupplierAdvanceNoticeTime, 1, 100);
127: try {
128: st.setValue(new Integer(1));
129: } catch (RuleParameterIllegalValueException ex) {
130: if (logger.isErrorEnabled()) {
131: logger.error("SupplierAdvanceNoticeTime-"
132: + ex.toString());
133: }
134: // Print exception, waiting for a static logger
135: }
136: Add(st);
137: IntegerRuleParameter of = new IntegerRuleParameter(
138: ReorderPeriod, 1, 40);
139: try {
140: of.setValue(new Integer(3));
141: } catch (RuleParameterIllegalValueException ex) {
142: if (logger.isErrorEnabled()) {
143: logger.error("ReorderPeriod-" + ex.toString());
144: }
145: // Print exception, waiting for a static logger
146: }
147: Add(of);
148: IntegerRuleParameter ht = new IntegerRuleParameter(
149: HandlingTime, 0, 40);
150: try {
151: ht.setValue(new Integer(0));
152: } catch (RuleParameterIllegalValueException ex) {
153: if (logger.isErrorEnabled()) {
154: logger.error("HandlingTime-" + ex.toString());
155: }
156: // Print exception, waiting for a static logger
157: }
158: Add(ht);
159: IntegerRuleParameter tt = new IntegerRuleParameter(
160: TransportTime, 1, 40);
161: try {
162: tt.setValue(new Integer(3));
163: } catch (RuleParameterIllegalValueException ex) {
164: if (logger.isErrorEnabled()) {
165: logger.error("TransportTime-" + ex.toString());
166: }
167: // Print exception, waiting for a static logger
168: }
169: Add(tt);
170: IntegerRuleParameter ost = new IntegerRuleParameter(
171: OrderShipTime, 1, 40);
172: try {
173: ost.setValue(new Integer(3));
174: } catch (RuleParameterIllegalValueException ex) {
175: if (logger.isErrorEnabled()) {
176: logger.error("OrderShipTime-" + ex.toString());
177: }
178: // Print exception, waiting for a static logger
179: }
180: Add(ost);
181: LongRuleParameter bucket = new LongRuleParameter(BucketSize,
182: TimeUtils.MSEC_PER_HOUR, Long.MAX_VALUE);
183: try {
184: bucket.setValue(new Long(TimeUtils.MSEC_PER_DAY));
185: } catch (RuleParameterIllegalValueException ex) {
186: if (logger.isErrorEnabled()) {
187: logger.error("BucketSize-" + ex.toString());
188: }
189: }
190: Add(bucket);
191: BooleanRuleParameter fillToCap = new BooleanRuleParameter(
192: FillToCapacity, false);
193: try {
194: fillToCap.setValue(new Boolean(false));
195: } catch (RuleParameterIllegalValueException ex) {
196: if (logger.isErrorEnabled()) {
197: logger.error("FillToCapacity-" + ex.toString());
198: }
199: }
200: Add(fillToCap);
201: }
202:
203: public String getAgentID() {
204: StringRuleParameter param = (StringRuleParameter) Lookup(AgentID);
205: return (String) param.getValue();
206: }
207:
208: public void setAgentID(String name) {
209: String exception;
210: StringRuleParameter param = (StringRuleParameter) Lookup(AgentID);
211: try {
212: param.setValue(name);
213: } catch (RuleParameterIllegalValueException ex) {
214: if (logger.isErrorEnabled()) {
215: logger.error("Setting AgentID-" + ex.toString());
216: }
217: // Print exception, waiting for a static logger
218: }
219: }
220:
221: public String getResourceType() {
222: StringRuleParameter param = (StringRuleParameter) Lookup(ResourceType);
223: return (String) param.getValue();
224: }
225:
226: public void setResourceType(String name) {
227: String exception;
228: StringRuleParameter param = (StringRuleParameter) Lookup(ResourceType);
229: try {
230: param.setValue(name);
231: } catch (RuleParameterIllegalValueException ex) {
232: if (logger.isErrorEnabled()) {
233: logger.error("Setting ResourceType-" + ex.toString());
234: }
235: // Print exception, waiting for a static logger
236: }
237: }
238:
239: public long getSupplierArrivalTime() {
240: StringRuleParameter param = (StringRuleParameter) Lookup(SupplierArrivalTime);
241: if (param == null) {
242: return -1;
243: }
244: String arrivalDateStr = (String) param.getValue();
245: if ((arrivalDateStr == null)
246: || (arrivalDateStr.trim().equals(""))) {
247: return -1;
248: }
249: try {
250: Date arrivalDate = dateFormatter.parse(arrivalDateStr);
251: return arrivalDate.getTime();
252: } catch (Exception ex) {
253: logger.error(ex.toString());
254: return -1;
255: }
256: }
257:
258: public void setSupplierArrivalTime(long arrivalTime) {
259: String exception;
260: StringRuleParameter param = (StringRuleParameter) Lookup(SupplierArrivalTime);
261: String arrivalTimeStr = dateFormatter.format(new Date(
262: arrivalTime));
263: try {
264: param.setValue(arrivalTimeStr);
265: } catch (RuleParameterIllegalValueException ex) {
266: if (logger.isErrorEnabled()) {
267: logger.error("Setting SupplierArrivalTime-"
268: + ex.toString());
269: }
270: // Print exception, waiting for a static logger
271: }
272: }
273:
274: public String getInventoryManagerSpecifier() {
275: StringRuleParameter param = (StringRuleParameter) Lookup(InventoryManagerSpecifier);
276: return (String) param.getValue();
277: }
278:
279: public void setInventoryManagerSpecifier(String name) {
280: String exception;
281: StringRuleParameter param = (StringRuleParameter) Lookup(InventoryManagerSpecifier);
282: try {
283: param.setValue(name);
284: } catch (RuleParameterIllegalValueException ex) {
285: if (logger.isErrorEnabled()) {
286: logger.error("Setting InventoryManagerSpecifier-"
287: + ex.toString());
288: }
289: // Print exception, waiting for a static logger
290: }
291: }
292:
293: public int getCriticalLevel() {
294: IntegerRuleParameter param = (IntegerRuleParameter) Lookup(CriticalLevel);
295: return ((Integer) (param.getValue())).intValue();
296: }
297:
298: public void setCriticalLevel(int i) {
299: String exception;
300: IntegerRuleParameter param = (IntegerRuleParameter) Lookup(CriticalLevel);
301: try {
302: param.setValue(new Integer(i));
303: } catch (RuleParameterIllegalValueException ex) {
304: if (logger.isErrorEnabled()) {
305: logger.error("Setting CriticalLevel-" + ex.toString());
306: }
307: // Print exception, waiting for a static logger
308: }
309: }
310:
311: public int getSupplierAdvanceNoticeTime() {
312: IntegerRuleParameter param = (IntegerRuleParameter) Lookup(SupplierAdvanceNoticeTime);
313: return ((Integer) (param.getValue())).intValue();
314: }
315:
316: public void setSupplierAdvanceNoticeTime(int i) {
317: String exception;
318: IntegerRuleParameter param = (IntegerRuleParameter) Lookup(SupplierAdvanceNoticeTime);
319: try {
320: param.setValue(new Integer(i));
321: } catch (RuleParameterIllegalValueException ex) {
322: if (logger.isErrorEnabled()) {
323: logger.error("Setting SupplierAdvanceNoticeTime-"
324: + ex.toString());
325: }
326: // Print exception, waiting for a static logger
327: }
328: }
329:
330: public int getReorderPeriod() {
331: IntegerRuleParameter param = (IntegerRuleParameter) Lookup(ReorderPeriod);
332: return ((Integer) (param.getValue())).intValue();
333: }
334:
335: public void setReorderPeriod(int i) {
336: String exception;
337: IntegerRuleParameter param = (IntegerRuleParameter) Lookup(ReorderPeriod);
338: try {
339: param.setValue(new Integer(i));
340: } catch (RuleParameterIllegalValueException ex) {
341: if (logger.isErrorEnabled()) {
342: logger.error("Setting ReorderPeriod-" + ex.toString());
343: }
344: // Print exception, waiting for a static logger
345: }
346: }
347:
348: public int getHandlingTime() {
349: IntegerRuleParameter param = (IntegerRuleParameter) Lookup(HandlingTime);
350: return ((Integer) (param.getValue())).intValue();
351: }
352:
353: public void setHandlingTime(int i) {
354: String exception;
355: IntegerRuleParameter param = (IntegerRuleParameter) Lookup(HandlingTime);
356: try {
357: param.setValue(new Integer(i));
358: } catch (RuleParameterIllegalValueException ex) {
359: if (logger.isErrorEnabled()) {
360: logger.error("Setting HandlingTime-" + ex.toString());
361: }
362: // Print exception, waiting for a static logger
363: }
364: }
365:
366: public int getTransportTime() {
367: IntegerRuleParameter param = (IntegerRuleParameter) Lookup(TransportTime);
368: return ((Integer) (param.getValue())).intValue();
369: }
370:
371: public void setTransportTime(int i) {
372: String exception;
373: IntegerRuleParameter param = (IntegerRuleParameter) Lookup(TransportTime);
374: try {
375: param.setValue(new Integer(i));
376: } catch (RuleParameterIllegalValueException ex) {
377: if (logger.isErrorEnabled()) {
378: logger.error("Setting TransportTime-" + ex.toString());
379: }
380: // Print exception, waiting for a static logger
381: }
382: }
383:
384: public int getOrderShipTime() {
385: IntegerRuleParameter param = (IntegerRuleParameter) Lookup(OrderShipTime);
386: return ((Integer) (param.getValue())).intValue();
387: }
388:
389: public void setOrderShipTime(int i) {
390: String exception;
391: IntegerRuleParameter param = (IntegerRuleParameter) Lookup(OrderShipTime);
392: try {
393: param.setValue(new Integer(i));
394: } catch (RuleParameterIllegalValueException ex) {
395: if (logger.isErrorEnabled()) {
396: logger.error("Settting OrderShipTime-" + ex.toString());
397: }
398: // Print exception, waiting for a static logger
399: }
400: }
401:
402: public long getBucketSize() {
403: LongRuleParameter param = (LongRuleParameter) Lookup(BucketSize);
404: return ((Long) (param.getValue())).longValue();
405: }
406:
407: public void setBucketSize(long l) {
408: String exception;
409: LongRuleParameter param = (LongRuleParameter) Lookup(BucketSize);
410: try {
411: param.setValue(new Long(l));
412: } catch (RuleParameterIllegalValueException ex) {
413: if (logger.isErrorEnabled()) {
414: logger.error("Setting BucketSize-" + ex.toString());
415: }
416: // Print exception, waiting for a static logger
417: }
418: }
419:
420: public boolean getFillToCapacity() {
421: BooleanRuleParameter param = (BooleanRuleParameter) Lookup(FillToCapacity);
422: return ((Boolean) (param.getValue())).booleanValue();
423: }
424:
425: public void setFillToCapacity(boolean b) {
426: String exception;
427: BooleanRuleParameter param = (BooleanRuleParameter) Lookup(FillToCapacity);
428: try {
429: param.setValue(new Boolean(b));
430: } catch (RuleParameterIllegalValueException ex) {
431: if (logger.isErrorEnabled()) {
432: logger.error("Setting FillToCapacity-" + ex.toString());
433: }
434: // Print exception, waiting for a static logger
435: }
436: }
437:
438: private void readObject(ObjectInputStream stream)
439: throws ClassNotFoundException, IOException {
440: stream.defaultReadObject();
441: logger = Logging.getLogger(this);
442: }
443:
444: }
|