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.ArrayList;
030: import java.util.Collection;
031:
032: import org.cougaar.core.component.ServiceBroker;
033: import org.cougaar.core.domain.DomainAdapter;
034: import org.cougaar.core.domain.Factory;
035: import org.cougaar.core.domain.RootPlan;
036: import org.cougaar.core.mts.MessageAddress;
037: import org.cougaar.core.service.AgentIdentificationService;
038: import org.cougaar.core.service.DomainService;
039: import org.cougaar.glm.ldm.asset.AssetFactory;
040: import org.cougaar.glm.ldm.asset.PropertyGroupFactory;
041: import org.cougaar.glm.ldm.lps.DetailRequestLP;
042: import org.cougaar.glm.ldm.lps.OPlanWatcherLP;
043: import org.cougaar.glm.ldm.lps.ReceiveTransferableLP;
044: import org.cougaar.glm.ldm.lps.TransferableLP;
045: import org.cougaar.glm.ldm.plan.AlpineAspectType;
046: import org.cougaar.planning.ldm.LDMServesPlugin;
047: import org.cougaar.planning.ldm.PlanningFactory;
048: import org.cougaar.planning.service.LDMService;
049:
050: /**
051: * COUGAAR Domain package definition.
052: **/
053:
054: public class GLMDomain extends DomainAdapter {
055:
056: public static final String GLM_NAME = "glm";
057:
058: private MessageAddress self;
059: private AgentIdentificationService agentIdService;
060: private DomainService domainService;
061: private LDMService ldmService;
062:
063: public String getDomainName() {
064: return GLM_NAME;
065: }
066:
067: public GLMDomain() {
068: super ();
069: }
070:
071: public void setAgentIdentificationService(
072: AgentIdentificationService ais) {
073: this .agentIdService = ais;
074: if (ais == null) {
075: // Revocation
076: } else {
077: this .self = ais.getMessageAddress();
078: }
079: }
080:
081: public void setDomainService(DomainService domainService) {
082: this .domainService = domainService;
083: }
084:
085: public void setLDMService(LDMService ldmService) {
086: this .ldmService = ldmService;
087: }
088:
089: public void initialize() {
090: super .initialize();
091: Constants.Role.init(); // Insure that our Role constants are initted
092: }
093:
094: public void unload() {
095: ServiceBroker sb = getServiceBroker();
096: if (ldmService != null) {
097: sb.releaseService(this , LDMService.class, ldmService);
098: ldmService = null;
099: }
100: if (domainService != null) {
101: sb.releaseService(this , DomainService.class, domainService);
102: domainService = null;
103: }
104: if (agentIdService != null) {
105: sb.releaseService(this , AgentIdentificationService.class,
106: agentIdService);
107: agentIdService = null;
108: }
109: super .unload();
110: }
111:
112: public Collection getAliases() {
113: ArrayList l = new ArrayList(3);
114: l.add("glm");
115: l.add("mlm");
116: l.add("alp");
117: return l;
118: }
119:
120: protected void loadFactory() {
121: LDMServesPlugin ldm = ldmService.getLDM();
122: PlanningFactory ldmf = (PlanningFactory) ldm
123: .getFactory("planning");
124: if (ldmf == null) {
125: throw new RuntimeException("Missing \"planning\" factory!");
126: }
127:
128: // ensure GLM aspect types are reserved in the AspectValue registry
129: AlpineAspectType.init();
130:
131: Factory f = new GLMFactory();
132: ldmf.addAssetFactory(new AssetFactory());
133: ldmf.addPropertyGroupFactory(new PropertyGroupFactory());
134: setFactory(f);
135: }
136:
137: protected void loadXPlan() {
138: // no glm-specific plan
139: }
140:
141: protected void loadLPs() {
142: RootPlan rootplan = (RootPlan) getXPlanForDomain("root");
143: if (rootplan == null) {
144: throw new RuntimeException("Missing \"root\" plan!");
145: }
146:
147: PlanningFactory ldmf = (PlanningFactory) domainService
148: .getFactory("planning");
149: if (ldmf == null) {
150: throw new RuntimeException("Missing \"planning\" factory!");
151: }
152: GLMFactory glmFactory = (GLMFactory) domainService
153: .getFactory("glm");
154:
155: addLogicProvider(new ReceiveTransferableLP(rootplan, ldmf));
156: addLogicProvider(new TransferableLP(rootplan, self, ldmf));
157: addLogicProvider(new DetailRequestLP(rootplan, self, glmFactory));
158: addLogicProvider(new OPlanWatcherLP(rootplan, ldmf));
159: }
160:
161: }
|