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.servicediscovery;
028:
029: import org.cougaar.core.component.ServiceBroker;
030: import org.cougaar.core.domain.DomainAdapter;
031: import org.cougaar.core.domain.RootPlan;
032: import org.cougaar.core.mts.MessageAddress;
033: import org.cougaar.core.service.AgentIdentificationService;
034: import org.cougaar.core.service.DomainService;
035: import org.cougaar.planning.ldm.LDMServesPlugin;
036: import org.cougaar.planning.ldm.LogPlan;
037: import org.cougaar.planning.ldm.LogPlanImpl;
038: import org.cougaar.planning.ldm.PlanningFactory;
039: import org.cougaar.planning.service.LDMService;
040: import org.cougaar.servicediscovery.lp.ServiceContractLP;
041:
042: import java.util.ArrayList;
043: import java.util.Collection;
044:
045: /**
046: * Service discovery Domain package definition.
047: **/
048:
049: public class SDDomain extends DomainAdapter {
050: public static final String SD_NAME = "servicediscovery".intern();
051:
052: private AgentIdentificationService agentIdService;
053: private MessageAddress self;
054: private LDMService ldmService;
055: private DomainService domainService;
056:
057: public String getDomainName() {
058: return SD_NAME;
059: }
060:
061: public SDDomain() {
062: super ();
063: }
064:
065: public void setAgentIdentificationService(
066: AgentIdentificationService ais) {
067: this .agentIdService = ais;
068: if (ais == null) {
069: // Revocation
070: } else {
071: this .self = ais.getMessageAddress();
072: }
073: }
074:
075: public void setLDMService(LDMService ldmService) {
076: this .ldmService = ldmService;
077: }
078:
079: public void setDomainService(DomainService domainService) {
080: this .domainService = domainService;
081: }
082:
083: public void initialize() {
084: super .initialize();
085: Constants.Roles.init(); // Insure that our Role constants are initted
086: }
087:
088: public void unload() {
089: ServiceBroker sb = getBindingSite().getServiceBroker();
090: if (agentIdService != null) {
091: sb.releaseService(this , AgentIdentificationService.class,
092: agentIdService);
093: agentIdService = null;
094: }
095: if (ldmService != null) {
096: sb.releaseService(this , LDMService.class, ldmService);
097: ldmService = null;
098: }
099: if (domainService != null) {
100: sb.releaseService(this , DomainService.class, domainService);
101: domainService = null;
102: }
103: super .unload();
104: }
105:
106: public Collection getAliases() {
107: ArrayList l = new ArrayList(1);
108: l.add("sd");
109: return l;
110: }
111:
112: protected void loadFactory() {
113: LDMServesPlugin ldm = ldmService.getLDM();
114: setFactory(new SDFactory(ldm));
115: }
116:
117: protected void loadXPlan() {
118: LogPlan logplan = new LogPlanImpl();
119: setXPlan(logplan);
120: }
121:
122: protected void loadLPs() {
123: RootPlan rootplan = (RootPlan) getXPlanForDomain("root");
124: if (rootplan == null) {
125: throw new RuntimeException("Missing \"root\" plan!");
126: }
127: PlanningFactory ldmf = (PlanningFactory) domainService
128: .getFactory("planning");
129: LogPlan logPlan = (LogPlan) getXPlan();
130:
131: addLogicProvider(new ServiceContractLP(logPlan, rootplan, self,
132: ldmf));
133: }
134:
135: }
|