Source Code Cross Referenced for CompleteAgentRecipe.java in  » Science » Cougaar12_4 » org » cougaar » tools » csmart » recipe » 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.tools.csmart.recipe 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * <copyright>
003:         *  
004:         *  Copyright 2001-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:        package org.cougaar.tools.csmart.recipe;
027:
028:        import org.cougaar.core.agent.SimpleAgent;
029:        import org.cougaar.tools.csmart.core.cdata.AgentComponentData;
030:        import org.cougaar.tools.csmart.core.cdata.ComponentData;
031:        import org.cougaar.tools.csmart.core.cdata.GenericComponentData;
032:        import org.cougaar.tools.csmart.core.db.PopulateDb;
033:        import org.cougaar.tools.csmart.core.property.ConfigurableComponent;
034:        import org.cougaar.tools.csmart.society.AgentComponent;
035:        import org.cougaar.util.log.Logger;
036:
037:        import java.io.Serializable;
038:        import java.net.URL;
039:        import java.util.Collection;
040:        import java.util.Iterator;
041:
042:        /**
043:         * Recipe to add a complete Agent to the society.  This agent
044:         * consists of all required plugins relationships and asset data.
045:         */
046:        public class CompleteAgentRecipe extends ComplexRecipeBase implements 
047:                Serializable {
048:            protected static String DESCRIPTION_RESOURCE_NAME = "complete-agent-recipe-description.html";
049:
050:            /**
051:             * Creates a new <code>CompleteAgentRecipe</code> instance.
052:             *
053:             */
054:            public CompleteAgentRecipe() {
055:                this ("Agent Component Recipe");
056:            }
057:
058:            /**
059:             * Creates a new <code>CompleteAgentRecipe</code> instance.
060:             *
061:             * @param name Name of the Component
062:             */
063:            public CompleteAgentRecipe(String name) {
064:                super (name);
065:            }
066:
067:            public CompleteAgentRecipe(String name, String assemblyId) {
068:                super (name, assemblyId);
069:            }
070:
071:            public CompleteAgentRecipe(String name, String assemblyId,
072:                    String recipeId) {
073:                super (name, assemblyId, recipeId);
074:
075:                // recipeId is not needed for this recipe, however the method sig is needed
076:                // so OrganizerHelper can find the class correctly using reflection.
077:            }
078:
079:            public CompleteAgentRecipe(String name, String assemblyId,
080:                    String recipeId, String initName) {
081:                super (name, assemblyId, recipeId, initName);
082:
083:                // recipeId is not needed for this recipe, however the method sig is needed
084:                // so OrganizerHelper can find the class correctly using reflection.
085:            }
086:
087:            public CompleteAgentRecipe(ComponentData cdata, String assemblyId) {
088:                super (cdata, assemblyId);
089:            }
090:
091:            /**
092:             * Gets the name of the html help file for this component.
093:             *
094:             * @return an <code>URL</code> value
095:             */
096:            public URL getDescription() {
097:                return getClass().getResource(DESCRIPTION_RESOURCE_NAME);
098:            }
099:
100:            /**
101:             * Adds any new data to the global <code>ComponentData</code> tree.
102:             * No existing data is modified in this method.
103:             * Warning: Assumes it is handed a ComponentData which contains
104:             * all Agents below it.
105:             *
106:             * @param data Pointer to the Global <code>ComponentData</code> tree
107:             * @return an updated <code>ComponentData</code> value
108:             */
109:            public ComponentData addComponentData(ComponentData data) {
110:                ComponentData[] children = data.getChildren();
111:                for (int i = 0; i < children.length; i++) {
112:                    ComponentData child = children[i];
113:                    // for each child component data, if it's an agent's component data
114:                    if (child.getType() == ComponentData.AGENT) {
115:                        // get all my agent components
116:                        Iterator iter = ((Collection) getDescendentsOfClass(AgentComponent.class))
117:                                .iterator();
118:                        while (iter.hasNext()) {
119:                            AgentComponent agent = (AgentComponent) iter.next();
120:                            // if the component data name matches the agent name
121:                            if (child.getName().equals(
122:                                    agent.getShortName().toString())) {
123:                                if (log.isDebugEnabled())
124:                                    log
125:                                            .debug("addComponentData found my agent "
126:                                                    + child.getName()
127:                                                    + " which currently says isModified="
128:                                                    + child.isModified());
129:
130:                                // then set me as the owner of the component data
131:                                child.setOwner(this );
132:                                // and add the component data
133:                                agent.addComponentData(child);
134:                            }
135:                        }
136:                    } else {
137:                        // FIXME!! Will we support other top-level components?
138:                        // Process children of component data
139:                        addComponentData(child);
140:                    }
141:                }
142:                return data;
143:            }
144:
145:            /**
146:             * Modifies the global <code>ComponentData</code> tree.
147:             * This method is free to make any modifications it needs
148:             * to the global tree, not just to it's own Component.
149:             * <br>
150:             * Currently, this component makes no modifications.
151:             *
152:             * @param data Pointer to the global <code>ComponentData</code>
153:             * @param pdb Access to the database via <code>PopulateDb</code> object
154:             * @return a modified <code>ComponentData</code> value
155:             */
156:            public ComponentData modifyComponentData(ComponentData data,
157:                    PopulateDb pdb) {
158:                return data;
159:            }
160:
161:            protected ComponentData getComponentData() {
162:                ComponentData cd = new GenericComponentData();
163:                cd.setType(ComponentData.RECIPE);
164:                cd.setClassName(RECIPE_CLASS);
165:                cd.setName(getRecipeName());
166:                cd.setOwner(null);
167:                cd.setParent(null);
168:
169:                AgentComponent[] agents = getAgents();
170:                for (int i = 0; i < agents.length; i++) {
171:                    generateAgentComponentData(agents[i], cd, null);
172:                }
173:
174:                // Now let all components add their data.
175:                addComponentData(cd);
176:
177:                return modifyComponentData(cd);
178:
179:                // FIXME: Why call this twice?
180:                //    return addComponentData(cd);
181:            }
182:
183:            private static final void generateAgentComponentData(
184:                    AgentComponent agent, ComponentData parent,
185:                    ConfigurableComponent owner) {
186:
187:                AgentComponentData ac = new AgentComponentData();
188:                ac.setName(agent.getShortName());
189:                ac.setClassName(SimpleAgent.class.getName());
190:                ac.addParameter(agent.getShortName()); // Agents have one parameter, the agent name
191:                ac.setOwner(owner);
192:                ac.setParent(parent);
193:                parent.addChild((ComponentData) ac);
194:            }
195:
196:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.