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.pizza;
028:
029: import org.cougaar.core.component.ServiceBroker;
030: import org.cougaar.core.domain.DomainAdapter;
031: import org.cougaar.core.mts.MessageAddress;
032: import org.cougaar.core.service.AgentIdentificationService;
033: import org.cougaar.core.service.DomainService;
034: import org.cougaar.pizza.asset.AssetFactory;
035: import org.cougaar.planning.ldm.LDMServesPlugin;
036: import org.cougaar.planning.ldm.PlanningFactory;
037: import org.cougaar.planning.service.LDMService;
038:
039: import java.util.Collection;
040: import java.util.Collections;
041:
042: /**
043: * PizzaDomain definition, initializing our {@link Constants} and loading our AssetFactory.
044: * <p>
045: * Required to ensure that Roles and Assets specific to the pizza
046: * application are initialized correctly. The PizzaDomain does not include any
047: * domain specific LogicProviders. It only initializes our {@link Constants}
048: * and loads our AssetFactory.
049: *<p>
050: * Other applications might have custom objects to transmit between
051: * agents, and therefore need their own LogicProviders. Similarly,
052: * they might want their own XPlan, to have custom-tuned lookup
053: * methods for objects (the Planning LogPlan for example looks up
054: * PlanElements by Task UID).
055: **/
056: public class PizzaDomain extends DomainAdapter {
057:
058: /**
059: * Name of this Domain.
060: * Note the <domain>_NAME variable naming pattern
061: */
062: public static final String PIZZA_NAME = "pizza";
063:
064: private DomainService domainService;
065: private LDMService ldmService;
066:
067: public String getDomainName() {
068: return PIZZA_NAME;
069: }
070:
071: public PizzaDomain() {
072: super ();
073: }
074:
075: // Note the use of the introspection-based service retrieving
076: // methods. These guarantee that the component
077: // will not load if the services are not available.
078:
079: public void setDomainService(DomainService domainService) {
080: this .domainService = domainService;
081: }
082:
083: public void setLDMService(LDMService ldmService) {
084: this .ldmService = ldmService;
085: }
086:
087: /**
088: * Initialize this domain, specifically our {@link Constants.Roles}
089: */
090: public void initialize() {
091: super .initialize();
092:
093: // Domain is loaded before any plugins. Call to Constants.Role.init()
094: // creates all Roles specific to the Pizza domain before they are
095: // accessed by application code. This insures that that the Roles and
096: // their converses are defined consistently.
097: Constants.Roles.init(); // Insure that our Role constants are initted
098: }
099:
100: public void unload() {
101: // Unload any services we loaded earlier
102: ServiceBroker sb = getServiceBroker();
103: if (ldmService != null) {
104: sb.releaseService(this , LDMService.class, ldmService);
105: ldmService = null;
106: }
107: if (domainService != null) {
108: sb.releaseService(this , DomainService.class, domainService);
109: domainService = null;
110: }
111: super .unload();
112: }
113:
114: public Collection getAliases() {
115: return Collections.EMPTY_LIST;
116: }
117:
118: /**
119: * Load the PlanningFactory and our Domain-specify Asset and PropertyGroup Factories
120: **/
121: protected void loadFactory() {
122: LDMServesPlugin ldm = ldmService.getLDM();
123: PlanningFactory ldmf = (PlanningFactory) ldm
124: .getFactory("planning");
125: if (ldmf == null) {
126: throw new RuntimeException("Missing \"planning\" factory!");
127: }
128:
129: // Adding pizza specific AssetFactory and PropertyGroupFactory allows
130: // pizza application code to use ldmf.createAsset(<asset class name>) for
131: // the assets defined in org.cougaar.pizza.asset. For example,
132: // ldmf.createAsset("KitchenAsset")
133: ldmf.addAssetFactory(new AssetFactory());
134: ldmf
135: .addPropertyGroupFactory(new org.cougaar.pizza.asset.PropertyGroupFactory());
136: }
137:
138: protected void loadXPlan() {
139: // no Pizza specific XPlan
140: }
141:
142: protected void loadLPs() {
143: // no Pizza specific LPs
144: }
145:
146: }
|