Source Code Cross Referenced for AdaptivitySupportRecipe.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 2002-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:         */package org.cougaar.tools.csmart.recipe;
026:
027:        import org.cougaar.tools.csmart.core.cdata.ComponentData;
028:        import org.cougaar.tools.csmart.core.cdata.GenericComponentData;
029:        import org.cougaar.tools.csmart.core.db.PopulateDb;
030:        import org.cougaar.tools.csmart.core.property.Property;
031:
032:        import java.io.Serializable;
033:        import java.net.URL;
034:        import java.sql.SQLException;
035:        import java.util.ArrayList;
036:        import java.util.Iterator;
037:        import java.util.Set;
038:
039:        /**
040:         * AdaptivitySupportRecipe: add standard adaptivity Engine pieces
041:         * to selected Agents.
042:         *
043:         *
044:         * Created: Wed May 22 10:22:54 2002
045:         *
046:         */
047:        public class AdaptivitySupportRecipe extends RecipeBase implements 
048:                Serializable {
049:
050:            private static final String DESCRIPTION_RESOURCE_NAME = "adaptivity-support-recipe-description.html";
051:            private static final String BACKUP_DESCRIPTION = "AdaptivitySupportRecipe provides a method for adding Adapitivity pieces to all agents in an experiment";
052:
053:            private static final String PROP_TARGET_AGENT_QUERY = "Target Agent Selection Query";
054:            private static final String PROP_TARGET_AGENT_QUERY_DFLT = "recipeQueryAllAgents";
055:            private static final String PROP_TARGET_AGENT_QUERY_DESC = "The query name for selecting agents to which to add adaptivity support.";
056:
057:            private static final String PROP_PLAYS_FILE = "Playbook File";
058:            private static final String PROP_PLAYS_FILE_DESC = "Name of single file of AE plays, default for per-Agent";
059:            private static final String AGENT_VAR = "<agent>";
060:            private static final String PROP_PLAYS_FILE_DFLT = AGENT_VAR
061:                    + "-plays.txt";
062:
063:            private static final String PROP_VIEWER_SERVLET = "AEViewerServlet";
064:            private static final boolean PROP_VIEWER_SERVLET_DFLT = true;
065:            private static final String PROP_VIEWER_SERVLET_DESC = "Include the AEViewerServlet in the target agent(s)";
066:
067:            private Property propViewerServlet;
068:            private Property propPlaysFile;
069:            private Property propTargetAgentQuery;
070:
071:            public AdaptivitySupportRecipe() {
072:                this ("AdaptivitySupportRecipe");
073:            }
074:
075:            public AdaptivitySupportRecipe(String name) {
076:                super (name);
077:            }
078:
079:            public void initProperties() {
080:
081:                propViewerServlet = addBooleanProperty(PROP_VIEWER_SERVLET,
082:                        PROP_VIEWER_SERVLET_DFLT);
083:                propViewerServlet.setToolTip(PROP_VIEWER_SERVLET_DESC);
084:
085:                propPlaysFile = addProperty(PROP_PLAYS_FILE,
086:                        PROP_PLAYS_FILE_DFLT);
087:                propPlaysFile.setToolTip(PROP_PLAYS_FILE_DESC);
088:
089:                propTargetAgentQuery = addRecipeQueryProperty(
090:                        PROP_TARGET_AGENT_QUERY, PROP_TARGET_AGENT_QUERY_DFLT);
091:                propTargetAgentQuery.setToolTip(PROP_TARGET_AGENT_QUERY_DESC);
092:            }
093:
094:            private Property addRecipeQueryProperty(String name, String dflt) {
095:                Property prop = addProperty(new RecipeQueryProperty(this , name,
096:                        dflt));
097:                prop.setPropertyClass(String.class);
098:                return prop;
099:            }
100:
101:            /**
102:             * Gets the name of the html help file for this component.
103:             *
104:             * @return an <code>URL</code> value
105:             */
106:            public URL getDescription() {
107:                return getClass().getResource(DESCRIPTION_RESOURCE_NAME);
108:            }
109:
110:            public String getRecipeName() {
111:                return getShortName();
112:            }
113:
114:            public ComponentData modifyComponentData(ComponentData data,
115:                    PopulateDb pdb) {
116:                try {
117:                    Set targets = pdb.executeQuery(propTargetAgentQuery
118:                            .getValue().toString());
119:                    modifyComponentData(data, pdb, targets);
120:                } catch (SQLException sqle) {
121:                    if (log.isErrorEnabled()) {
122:                        log.error("Cant run agent target query", sqle);
123:                    }
124:                }
125:                return data;
126:            }
127:
128:            private void modifyComponentData(ComponentData data,
129:                    PopulateDb pdb, Set targets) throws SQLException {
130:                if (targets.contains(pdb.getComponentAlibId(data))) {
131:                    String agent = pdb.getComponentAlibId(data);
132:
133:                    if (log.isDebugEnabled()) {
134:                        log.debug("Adding Adaptivity Support to " + agent);
135:                    }
136:
137:                    Iterator iter = getPlugins();
138:                    while (iter.hasNext()) {
139:                        String pluginName = (String) iter.next();
140:                        GenericComponentData plugin = new GenericComponentData();
141:                        plugin.setType(ComponentData.PLUGIN);
142:                        plugin.setClassName(pluginName);
143:                        plugin.setParent(data);
144:                        plugin.setOwner(this );
145:                        if (GenericComponentData.alreadyAdded(data, plugin)) {
146:                            if (log.isDebugEnabled()) {
147:                                log.debug("Not re-adding" + pluginName);
148:                            }
149:                        } else {
150:                            plugin.setName(GenericComponentData
151:                                    .getSubComponentUniqueName(data, plugin));
152:                            data.addChildDefaultLoc(plugin);
153:                        }
154:                    }
155:
156:                    GenericComponentData plugin = new GenericComponentData();
157:                    plugin.setType(ComponentData.PLUGIN);
158:                    plugin
159:                            .setClassName("org.cougaar.core.adaptivity.PlaybookManager");
160:                    plugin.setOwner(this );
161:                    plugin.setParent(data);
162:
163:                    // Add the plays file parameter
164:                    String playsFile = null;
165:                    if (propPlaysFile == null
166:                            || propPlaysFile.getValue() == null
167:                            || propPlaysFile.getValue().equals("")) {
168:                        playsFile = PROP_PLAYS_FILE_DFLT;
169:                    } else {
170:                        playsFile = (String) propPlaysFile.getValue();
171:                    }
172:
173:                    int index = playsFile.indexOf(AGENT_VAR);
174:                    String param = playsFile;
175:                    if (index != -1)
176:                        param = playsFile.substring(0, index)
177:                                + agent
178:                                + playsFile.substring(index
179:                                        + AGENT_VAR.length());
180:
181:                    plugin.addParameter(param);
182:                    //	plugin.addParameter(agent + "-plays.txt");
183:
184:                    if (GenericComponentData.alreadyAdded(data, plugin)) {
185:                        if (log.isDebugEnabled()) {
186:                            log.debug("Not re-adding PlaybookManager");
187:                        }
188:                    } else {
189:                        plugin.setName(GenericComponentData
190:                                .getSubComponentUniqueName(data, plugin));
191:                        data.addChildDefaultLoc(plugin);
192:                    }
193:
194:                    if (((Boolean) (propViewerServlet.getValue()))
195:                            .booleanValue()) {
196:                        plugin = new GenericComponentData();
197:                        plugin.setType(ComponentData.PLUGIN);
198:                        plugin
199:                                .setClassName("org.cougaar.core.adaptivity.AEViewerServlet");
200:                        plugin.setOwner(this );
201:                        plugin.setParent(data);
202:                        plugin.addParameter("/aeviewer");
203:                        if (GenericComponentData.alreadyAdded(data, plugin)) {
204:                            if (log.isDebugEnabled()) {
205:                                log.debug("Not re-adding AEViewerServlet");
206:                            }
207:                        } else {
208:                            plugin.setName(GenericComponentData
209:                                    .getSubComponentUniqueName(data, plugin));
210:                            data.addChildDefaultLoc(plugin);
211:                        }
212:                    }
213:                }
214:
215:                if (data.childCount() > 0) {
216:                    // for each child, call this same method.
217:                    ComponentData[] children = data.getChildren();
218:                    for (int i = 0; i < children.length; i++) {
219:                        // If the child is a plugins or AgentBinder, no need to look at it
220:                        if (children[i].getType().equals(ComponentData.PLUGIN)
221:                                || children[i].getType().equals(
222:                                        ComponentData.AGENTBINDER))
223:                            continue;
224:                        modifyComponentData(children[i], pdb, targets);
225:                    }
226:                }
227:
228:            }
229:
230:            private Iterator getPlugins() {
231:                ArrayList list = new ArrayList();
232:                list.add("org.cougaar.core.adaptivity.AdaptivityEngine");
233:                list
234:                        .add("org.cougaar.core.adaptivity.ConditionServiceProvider");
235:                list
236:                        .add("org.cougaar.core.adaptivity.OperatingModeServiceProvider");
237:                list
238:                        .add("org.cougaar.core.adaptivity.OperatingModePolicyManager");
239:
240:                return list.iterator();
241:            }
242:
243:        }// AdaptivitySupportRecipe
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.