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


001:        /*
002:         * <copyright>
003:         *  
004:         *  Copyright 2000-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.society.file;
027:
028:        import org.cougaar.core.component.ComponentDescription;
029:        import org.cougaar.tools.csmart.core.cdata.ComponentConnector;
030:        import org.cougaar.tools.csmart.core.property.BaseComponent;
031:        import org.cougaar.tools.csmart.society.AgentBase;
032:        import org.cougaar.tools.csmart.society.AgentComponent;
033:        import org.cougaar.tools.csmart.society.BinderBase;
034:        import org.cougaar.tools.csmart.society.ComponentBase;
035:        import org.cougaar.tools.csmart.society.ContainerBase;
036:        import org.cougaar.tools.csmart.society.PluginBase;
037:        import org.cougaar.tools.csmart.ui.viewer.CSMART;
038:        import org.cougaar.tools.csmart.ui.viewer.SocietyFinder;
039:        import org.cougaar.util.log.Logger;
040:
041:        import java.util.Iterator;
042:
043:        /**
044:         * Basic component to hold the definition of a society
045:         * read in from Files.
046:         */
047:        public class AgentFileComponent extends AgentBase implements 
048:                AgentComponent {
049:
050:            private transient Logger log;
051:            private String filename; // that defines this agent
052:
053:            /**
054:             * Creates a new <code>AgentFileComponent</code> instance.
055:             *
056:             * @param name name of the agent
057:             * @param filename complete pathname of file that defines agent
058:             * @param classname Classname for the agent
059:             */
060:            public AgentFileComponent(String name, String filename,
061:                    String classname) {
062:                super (name);
063:                this .classname = classname;
064:                this .filename = filename;
065:                createLogger();
066:            }
067:
068:            private void createLogger() {
069:                log = CSMART.createLogger(this .getClass().getName());
070:            }
071:
072:            public void initProperties() {
073:                super .initProperties();
074:
075:                addPlugins();
076:                addBinders();
077:                addComponents();
078:                addAssetData();
079:            }
080:
081:            protected void addAssetData() {
082:                String assetFile = filename.substring(0, filename
083:                        .lastIndexOf('.'));
084:                assetFile = assetFile + "-prototype-ini.dat";
085:                if (log.isDebugEnabled()) {
086:                    log.debug("Trying asset file " + assetFile);
087:                }
088:                // Check to see if the file exists before we do anything!
089:                if (SocietyFinder.getInstance().locateFile(assetFile) != null) {
090:                    BaseComponent asset = (BaseComponent) new AssetFileComponent(
091:                            filename, getShortName());
092:                    asset.initProperties();
093:                    addChild(asset);
094:                }
095:            }
096:
097:            protected void addPlugins() {
098:                ContainerBase container = new ContainerBase("Plugins");
099:                container.initProperties();
100:                addChild(container);
101:
102:                ComponentDescription[] desc = ComponentConnector
103:                        .parseFile(filename);
104:                if (desc == null) {
105:                    if (log.isWarnEnabled()) {
106:                        log.warn("No data found in file " + filename);
107:                    }
108:                    return;
109:                }
110:                for (int i = 0; i < desc.length; i++) {
111:                    StringBuffer name = new StringBuffer(desc[i].getName());
112:                    StringBuffer className = new StringBuffer(desc[i]
113:                            .getClassname());
114:                    String insertionPoint = desc[i].getInsertionPoint();
115:                    String priority = desc[i].priorityToString(desc[i]
116:                            .getPriority());
117:                    //       if(log.isDebugEnabled()) {
118:                    //         log.debug("Insertion Point: " + insertionPoint);
119:                    //       }
120:
121:                    if (insertionPoint.endsWith("Plugin")) {
122:                        int start = 0;
123:                        if ((start = name.indexOf("OrgRTData")) != -1) {
124:                            name.delete(start, start + 2);
125:                            start = className.indexOf("RT");
126:                            className.delete(start, start + 2);
127:                        }
128:
129:                        // HACK!
130:                        // When dumping INIs we add an extra parameter to the GLSInitServlet,
131:                        // so strip it off here
132:                        boolean isGLS = false;
133:                        if (className.indexOf("GLSInitServlet") != -1) {
134:                            isGLS = true;
135:                        }
136:
137:                        int index = name.lastIndexOf(".");
138:                        if (index != -1)
139:                            name.delete(0, index + 1);
140:                        PluginBase plugin = new PluginBase(name.substring(0),
141:                                className.substring(0), priority);
142:                        plugin.initProperties();
143:                        Iterator iter = ComponentConnector
144:                                .getPluginProps(desc[i]);
145:                        while (iter.hasNext()) {
146:                            if (isGLS) {
147:                                String param = (String) iter.next();
148:                                if (param.startsWith("exptid="))
149:                                    continue;
150:                                else
151:                                    plugin.addParameter(param);
152:                            } else
153:                                plugin.addParameter((String) iter.next());
154:                        }
155:                        container.addChild(plugin);
156:                    }
157:                }
158:            }
159:
160:            protected void addBinders() {
161:                ContainerBase container = new ContainerBase("Binders");
162:                container.initProperties();
163:                addChild(container);
164:
165:                ComponentDescription[] desc = ComponentConnector
166:                        .parseFile(filename);
167:                if (desc == null) {
168:                    if (log.isWarnEnabled()) {
169:                        log.warn("No data found in file " + filename);
170:                    }
171:                    return;
172:                }
173:                for (int i = 0; i < desc.length; i++) {
174:                    String name = desc[i].getName();
175:                    String insertionPoint = desc[i].getInsertionPoint();
176:                    //       if(log.isDebugEnabled()) {
177:                    //         log.debug("Insertion Point: " + insertionPoint);
178:                    //       }
179:
180:                    if (insertionPoint.endsWith("Binder")) {
181:                        if (log.isDebugEnabled()) {
182:                            log.debug("Create Binder: " + name);
183:                        }
184:                        int index = name.lastIndexOf('.');
185:                        if (index != -1)
186:                            name = name.substring(index + 1);
187:                        BinderBase binder = new BinderBase(name, desc[i]
188:                                .getClassname(), desc[i]
189:                                .priorityToString(desc[i].getPriority()),
190:                                insertionPoint);
191:                        binder.initProperties();
192:
193:                        // FIXME: Must I change ComponentConnector in some way here?
194:                        Iterator iter = ComponentConnector
195:                                .getPluginProps(desc[i]);
196:                        while (iter.hasNext())
197:                            binder.addParameter((String) iter.next());
198:                        container.addChild(binder);
199:                    }
200:                }
201:            }
202:
203:            protected void addComponents() {
204:                ContainerBase container = new ContainerBase("Other Components");
205:                container.initProperties();
206:                addChild(container);
207:
208:                ComponentDescription[] desc = ComponentConnector
209:                        .parseFile(filename);
210:                if (desc == null) {
211:                    if (log.isWarnEnabled()) {
212:                        log.warn("No data found in file " + filename);
213:                    }
214:                    return;
215:                }
216:                for (int i = 0; i < desc.length; i++) {
217:                    String name = desc[i].getName();
218:                    String insertionPoint = desc[i].getInsertionPoint();
219:                    //       if(log.isDebugEnabled()) {
220:                    //         log.debug("Insertion Point: " + insertionPoint);
221:                    //       }
222:
223:                    if (!insertionPoint.endsWith(".Binder")
224:                            && !insertionPoint.endsWith(".Plugin")) {
225:                        if (log.isDebugEnabled()) {
226:                            log.debug("Create Component: " + name);
227:                        }
228:                        int index = name.lastIndexOf('.');
229:                        if (index != -1)
230:                            name = name.substring(index + 1);
231:                        ComponentBase binder = new ComponentBase(name, desc[i]
232:                                .getClassname(), desc[i]
233:                                .priorityToString(desc[i].getPriority()),
234:                                insertionPoint);
235:                        binder.initProperties();
236:
237:                        // FIXME: Must I change ComponentConnector in some way here?
238:                        Iterator iter = ComponentConnector
239:                                .getPluginProps(desc[i]);
240:                        while (iter.hasNext())
241:                            binder.addParameter((String) iter.next());
242:                        container.addChild(binder);
243:                    }
244:                }
245:            }
246:
247:        } // end of AgentFileComponent
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.