Source Code Cross Referenced for KitchenPrototypePlugin.java in  » Science » Cougaar12_4 » org » cougaar » pizza » plugin » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » Cougaar12_4 » org.cougaar.pizza.plugin 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * <copyright>
003:         *  Copyright 1997-2004 BBNT Solutions, LLC
004:         *  under sponsorship of the Defense Advanced Research Projects Agency
005:         *  (DARPA).
006:         *
007:         *  This program is free software; you can redistribute it and/or modify
008:         *  it under the terms of the Cougaar Open Source License as published by
009:         *  DARPA on the Cougaar Open Source Website (www.cougaar.org).
010:         *
011:         *  THE COUGAAR SOFTWARE AND ANY DERIVATIVE SUPPLIED BY LICENSOR IS
012:         *  PROVIDED 'AS IS' WITHOUT WARRANTIES OF ANY KIND, WHETHER EXPRESS OR
013:         *  IMPLIED, INCLUDING (BUT NOT LIMITED TO) ALL IMPLIED WARRANTIES OF
014:         *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND WITHOUT
015:         *  ANY WARRANTIES AS TO NON-INFRINGEMENT.  IN NO EVENT SHALL COPYRIGHT
016:         *  HOLDER BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT OR CONSEQUENTIAL
017:         *  DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE OF DATA OR PROFITS,
018:         *  TORTIOUS CONDUCT, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
019:         *  PERFORMANCE OF THE COUGAAR SOFTWARE.
020:         * </copyright>
021:         */
022:        package org.cougaar.pizza.plugin;
023:
024:        import org.cougaar.core.plugin.ComponentPlugin;
025:        import org.cougaar.core.service.DomainService;
026:        import org.cougaar.planning.ldm.PlanningFactory;
027:        import org.cougaar.planning.ldm.asset.NewItemIdentificationPG;
028:        import org.cougaar.planning.service.PrototypeRegistryService;
029:        import org.cougaar.pizza.asset.KitchenAsset;
030:        import org.cougaar.pizza.asset.PropertyGroupFactory;
031:        import org.cougaar.util.Arguments;
032:
033:        /**
034:         * This Plugin creates and publishes the Pizza Provider Kitchen Asset object which identifies
035:         * what kind of pizza a provider's kitchen can make. This plugin does not require any inputs,
036:         * it simply creates and registers the prototype and then publishes the kitchen asset instances.
037:         * Note that this plugin will only run once since there are no inputs(subscriptions) to cause it to run.
038:         */
039:        public class KitchenPrototypePlugin extends ComponentPlugin {
040:
041:            // The domainService provides domain factory services
042:            private DomainService domainService = null;
043:
044:            // The prototypeRegistryService provides prototype registration services
045:            private PrototypeRegistryService prototypeRegistryService = null;
046:
047:            // The planning factory we use to create planning objects.
048:            private PlanningFactory planningFactory;
049:
050:            // Initialize the plugin args to an empty instance
051:            private Arguments args = Arguments.EMPTY_INSTANCE;
052:
053:            /**
054:             * Variables for storing plugin arguments that determine whether the kitchen assets are
055:             * capable of creating meat and/or veggie pizzas. Default is to create both.
056:             */
057:            private boolean createVeggie = true;
058:            private boolean createMeat = true;
059:            private final String PIZZA_TYPE_PARAM = "PIZZA_TYPES_PROVIDED";
060:
061:            /**
062:             * Used by the binding utility through introspection to set my DomainService
063:             * Services that are required for plugin usage should be set through reflection instead of explicitly
064:             * getting each service from your ServiceBroker in the load method. The setter methods are called after
065:             * the component is constructed but before the state methods such as initialize, load, setupSubscriptions, etc.
066:             * If the service is not available at that time the component will be unloaded.
067:             */
068:            public void setDomainService(DomainService aDomainService) {
069:                domainService = aDomainService;
070:            }
071:
072:            /**
073:             * Used by the binding utility through introspection to set my PrototypeRegistryService
074:             */
075:            public void setPrototypeRegistryService(
076:                    PrototypeRegistryService aPrototypeRegistryService) {
077:                prototypeRegistryService = aPrototypeRegistryService;
078:            }
079:
080:            /**
081:             * Get the plugin parameters and our planning factory when our component is loaded.
082:             * If we want additional services that are not required for the plugin, we should get them in load.
083:             * However, if the component gets a service in load, it should override the unload() method and
084:             * release the services.
085:             */
086:            public void load() {
087:                super .load();
088:                planningFactory = (PlanningFactory) domainService
089:                        .getFactory("planning");
090:                // unload the domain service since we only need it to get the planning factory
091:                getServiceBroker().releaseService(this , DomainService.class,
092:                        domainService);
093:
094:                // Process the plugin params
095:                args = new Arguments(getParameter());
096:                setKitchenParameters();
097:            }
098:
099:            /**
100:             * Generally used to initalize plugin subscriptions. But in this case, we will use it to
101:             * create our Kitchen assets since we have no subscriptions and we want to publish the assets
102:             * as soon as we can.
103:             */
104:            protected void setupSubscriptions() {
105:                createKitchenAssets();
106:            }
107:
108:            /**
109:             * Create the Kitchen prototype and asset instances with the appropriate
110:             * veggie and/or meat PGs based on the existing kitchen prototype and the plugin arguments.
111:             */
112:            private void createKitchenAssets() {
113:                KitchenAsset new_prototype = (KitchenAsset) planningFactory
114:                        .createPrototype(KitchenAsset.class, "kitchen");
115:                // Cache the prototype in the LDM so that it can be used to create
116:                // instances of Kitchen assets when asked for by prototype name
117:                prototypeRegistryService.cachePrototype("kitchen",
118:                        new_prototype);
119:                KitchenAsset kitchen_asset = (KitchenAsset) planningFactory
120:                        .createInstance("kitchen");
121:                // Check the plugin arguments to see if this plugin should create a Kitchen asset that can make veggie pizza.
122:                if (createVeggie) {
123:                    kitchen_asset.addOtherPropertyGroup(PropertyGroupFactory
124:                            .newVeggiePG());
125:                }
126:                // Check the plugin arguments to see if this plugin should create a Kitchen asset that can make meat pizza.
127:                if (createMeat) {
128:                    kitchen_asset.addOtherPropertyGroup(PropertyGroupFactory
129:                            .newMeatPG());
130:                }
131:                NewItemIdentificationPG itemIDPG = PropertyGroupFactory
132:                        .newItemIdentificationPG();
133:                itemIDPG.setItemIdentification("Pizza Kitchen");
134:                kitchen_asset.setItemIdentificationPG(itemIDPG);
135:                getBlackboardService().publishAdd(kitchen_asset);
136:            }
137:
138:            /**
139:             * No subscriptions to process, so this method does nothing.
140:             */
141:            protected void execute() {
142:            }
143:
144:            /**
145:             * Set the createVeggie and createMeat plugin variables according to the plugin parameter
146:             */
147:            private void setKitchenParameters() {
148:                String paramValue = args.getString(PIZZA_TYPE_PARAM);
149:                if (paramValue != null) {
150:                    if ("all".equals(paramValue)) {
151:                        createVeggie = true;
152:                        createMeat = true;
153:                    } else if ("veggie_only".equals(paramValue)) {
154:                        createVeggie = true;
155:                        createMeat = false;
156:                    } else if ("meat_only".equals(paramValue)) {
157:                        createVeggie = false;
158:                        createMeat = true;
159:                    }
160:                }
161:            }
162:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.