001: /*
002: * <copyright>
003: *
004: * Copyright 2002-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.planning.servlet;
028:
029: import javax.servlet.Servlet;
030:
031: import org.cougaar.core.blackboard.BlackboardClient;
032: import org.cougaar.core.service.BlackboardService;
033: import org.cougaar.core.service.SchedulerService;
034: import org.cougaar.core.servlet.SimpleServletComponent;
035: import org.cougaar.core.servlet.SimpleServletSupport;
036: import org.cougaar.planning.ldm.PlanningFactory;
037: import org.cougaar.planning.service.LDMService;
038: import org.cougaar.util.ConfigFinder;
039:
040: /**
041: * Basic servlet base class for servlets that need blackboard access.
042: **/
043: public class BlackboardServletComponent extends SimpleServletComponent
044: implements BlackboardClient {
045:
046: protected BlackboardService blackboard;
047: private LDMService ldmService = null;
048: private SchedulerService scheduler;
049:
050: public final void setBlackboardService(BlackboardService s) {
051: blackboard = s;
052: }
053:
054: protected final BlackboardService getBlackboardService() {
055: return blackboard;
056: }
057:
058: public final void setLDMService(LDMService s) {
059: ldmService = s;
060: }
061:
062: protected final LDMService getLDMService() {
063: return ldmService;
064: }
065:
066: protected ConfigFinder getConfigFinder() {
067: return ConfigFinder.getInstance();
068: }
069:
070: // rely upon load-time introspection to set these services -
071: // don't worry about revokation.
072: public final void setSchedulerService(SchedulerService ss) {
073: scheduler = ss;
074: }
075:
076: public SchedulerService getSchedulerService() {
077: return scheduler;
078: }
079:
080: /** just like the core, except I can create a servlet support subclass */
081: protected SimpleServletSupport createSimpleServletSupport(
082: Servlet servlet) {
083: super .createSimpleServletSupport(servlet);
084:
085: // throw original support object away
086: // create a new "SimpleServletSupport" instance
087: return makeServletSupport();
088: }
089:
090: /**
091: * so a subclass can create a different servlet support just by overriding this method
092: * perhaps the core should work like this?
093: */
094: protected SimpleServletSupport makeServletSupport() {
095: if (log.isInfoEnabled())
096: log.info("Creating BlackboardServletSupport");
097:
098: // create a new "SimpleServletSupport" instance
099: // FIXME - deprecation: Should replace getLDMService().getFactory() with
100: // getDomainService().getFactory()
101: return new BlackboardServletSupport(path, agentId,
102: blackboardQuery, log, blackboard, getConfigFinder(),
103: ((PlanningFactory) getLDMService().getFactory(
104: "planning")), getLDMService().getLDM(),
105: scheduler);
106: }
107:
108: // odd BlackboardClient method:
109: public String getBlackboardClientName() {
110: return toString();
111: }
112:
113: // odd BlackboardClient method:
114: public long currentTimeMillis() {
115: throw new UnsupportedOperationException(this
116: + " asked for the current time???");
117: }
118:
119: // unused BlackboardClient method:
120: public boolean triggerEvent(Object event) {
121: // if we had Subscriptions we'd need to implement this.
122: //
123: // see "ComponentPlugin" for details.
124: throw new UnsupportedOperationException(this
125: + " only supports Blackboard queries, but received "
126: + "a \"trigger\" event: " + event);
127: }
128: }
|