01: /*
02: * <copyright>
03: * Copyright 1997-2004 BBNT Solutions, LLC
04: * under sponsorship of the Defense Advanced Research Projects Agency (DARPA).
05: *
06: * This program is free software; you can redistribute it and/or modify
07: * it under the terms of the Cougaar Open Source License as published by
08: * DARPA on the Cougaar Open Source Website (www.cougaar.org).
09: *
10: * THE COUGAAR SOFTWARE AND ANY DERIVATIVE SUPPLIED BY LICENSOR IS
11: * PROVIDED 'AS IS' WITHOUT WARRANTIES OF ANY KIND, WHETHER EXPRESS OR
12: * IMPLIED, INCLUDING (BUT NOT LIMITED TO) ALL IMPLIED WARRANTIES OF
13: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND WITHOUT
14: * ANY WARRANTIES AS TO NON-INFRINGEMENT. IN NO EVENT SHALL COPYRIGHT
15: * HOLDER BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT OR CONSEQUENTIAL
16: * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE OF DATA OR PROFITS,
17: * TORTIOUS CONDUCT, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18: * PERFORMANCE OF THE COUGAAR SOFTWARE.
19: * </copyright>
20: */
21: package org.cougaar.pizza.plugin;
22:
23: import org.cougaar.core.plugin.ComponentPlugin;
24: import org.cougaar.core.service.DomainService;
25: import org.cougaar.pizza.Constants;
26: import org.cougaar.pizza.asset.PizzaAsset;
27: import org.cougaar.planning.ldm.PlanningFactory;
28: import org.cougaar.planning.service.PrototypeRegistryService;
29:
30: /**
31: * This Plugin creates and registers the Pizza Prototype asset. Other plugins will create
32: * instances of Pizza Assets as needed based on this prototype. This plugin does not require any inputs,
33: * it simply creates and registers the prototype. Note that this plugin will only run once since there
34: * are no inputs(subscriptions) that will cause it to run.
35: */
36: public class PizzaPrototypePlugin extends ComponentPlugin {
37:
38: // The domainService provides domain factory services
39: private DomainService domainService = null;
40:
41: // The prototypeRegistryService provides prototype registration services
42: private PrototypeRegistryService prototypeRegistryService = null;
43:
44: // The planning factory we use to create planning objects.
45: private PlanningFactory planningFactory;
46:
47: /**
48: * Used by the binding utility through introspection to set my DomainService
49: * Services that are required for plugin usage should be set through reflection instead of explicitly
50: * getting each service from your ServiceBroker in the load method. The setter methods are called after
51: * the component is constructed but before the state methods such as initialize, load, setupSubscriptions, etc.
52: * If the service is not available at that time the component will be unloaded.
53: */
54: public void setDomainService(DomainService aDomainService) {
55: domainService = aDomainService;
56: }
57:
58: /**
59: * Used by the binding utility through introspection to set my PrototypeRegistryService
60: */
61: public void setPrototypeRegistryService(
62: PrototypeRegistryService aPrototypeRegistryService) {
63: prototypeRegistryService = aPrototypeRegistryService;
64: }
65:
66: /**
67: * Generally used to initalize plugin subscriptions. But in this case, we will just use it to
68: * call our method that will create the prototype.
69: */
70: protected void setupSubscriptions() {
71: planningFactory = (PlanningFactory) domainService
72: .getFactory("planning");
73: // unload the domain service since we only need it to get the planning factory
74: getServiceBroker().releaseService(this , DomainService.class,
75: domainService);
76:
77: // Create our prototype
78: createPizzaPrototype();
79: }
80:
81: /**
82: * Create and register the pizza prototype.
83: */
84: private void createPizzaPrototype() {
85: PizzaAsset new_prototype = (PizzaAsset) planningFactory
86: .createPrototype(PizzaAsset.class, Constants.PIZZA);
87: // Cache the prototype in the LDM so that other plugins can create Pizza instances using the new prototype.
88: prototypeRegistryService.cachePrototype(Constants.PIZZA,
89: new_prototype);
90: }
91:
92: /**
93: * No subscriptions to process so this method does nothing.
94: */
95: protected void execute() {
96: }
97: }
|