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.servlet;
028:
029: import java.lang.reflect.Method;
030: import java.lang.ClassNotFoundException;
031: import java.util.List;
032:
033: import org.cougaar.core.service.AlarmService;
034: import org.cougaar.core.service.LoggingService;
035: import org.cougaar.core.component.ServiceBroker;
036: import org.cougaar.core.servlet.SimpleServletSupport;
037: import org.cougaar.core.servlet.SimpleServletComponent;
038:
039: import javax.servlet.Servlet;
040:
041: /**
042: * <pre>
043: * A special servlet component for the LogisticsInventoryServlet.
044: *
045: * Can't use SimpleServletComponent because we need additional services.
046: * Specifically we need the LoggingService and the AlarmService for
047: * current time stamp.
048: *
049: **/
050:
051: public class LogisticsInventoryServletComponent extends
052: SimpleServletComponent {
053:
054: public final static String PRINT_ORG_ACTIVITIES = "PRINT_ORG_ACTIVITIES";
055:
056: protected boolean printOrgActs = false;
057:
058: /**
059: * Save our Servlet's configurable path, for example
060: * "/test".
061: * <p>
062: * This is only set during initialization and is constant
063: * for the lifetime of the Servlet.
064: */
065: public void setParameter(Object o) {
066:
067: super .setParameter(o);
068: List l = (List) o;
069:
070: if (l.size() == 3) {
071: Object o3 = l.get(2);
072: if (!(o3 instanceof String)) {
073: throw new IllegalArgumentException(
074: "Expecting third optional argument as a string, not ("
075: + o3 + ")");
076: }
077: String[] keyAndValue = ((String) o3).split("=");
078: if ((keyAndValue.length == 2)
079: && (keyAndValue[0].trim()
080: .equals(PRINT_ORG_ACTIVITIES))
081: && (!(keyAndValue[1].trim().equals("")))) {
082: printOrgActs = keyAndValue[1].trim().toLowerCase()
083: .equals("true");
084: } else {
085: throw new IllegalArgumentException(
086: "Optional thirg argument should be "
087: + PRINT_ORG_ACTIVITIES
088: + "=<true or false>");
089: }
090:
091: }
092: }
093:
094: protected Servlet createServlet() {
095:
096: LogisticsInventoryServlet invServe = new LogisticsInventoryServlet();
097:
098: AlarmService alarmService = (AlarmService) serviceBroker
099: .getService(invServe, AlarmService.class, null);
100:
101: LoggingService logService = (LoggingService) serviceBroker
102: .getService(invServe, LoggingService.class, null);
103:
104: // create the support
105: SimpleServletSupport support;
106: try {
107: support = createSimpleServletSupport(invServe);
108: } catch (Exception e) {
109: throw new RuntimeException(
110: "Unable to create Servlet support: "
111: + e.getMessage());
112: }
113:
114: // set the support
115: try {
116: invServe.setSimpleServletSupport(support);
117: } catch (Exception e) {
118: throw new RuntimeException(
119: "Unable to set Servlet support: " + e.getMessage());
120: }
121:
122: // set the logging service
123: try {
124: invServe.setLoggingService(logService);
125: } catch (Exception e) {
126: throw new RuntimeException("Unable to set LoggingService: "
127: + e.getMessage());
128: }
129:
130: // set the alarm service
131: try {
132: invServe.setAlarmService(alarmService);
133: } catch (Exception e) {
134: throw new RuntimeException("Unable to set alarm service: "
135: + e.getMessage());
136: }
137:
138: // set the alarm service
139: try {
140: invServe.setPrintOrgActs(printOrgActs);
141: } catch (Exception e) {
142: throw new RuntimeException(
143: "Unable to set print org activities boolean: "
144: + e.getMessage());
145: }
146:
147: return invServe;
148:
149: }
150:
151: }
|