Source Code Cross Referenced for SocietyComponentCreator.java in  » Science » Cougaar12_4 » org » cougaar » tools » csmart » society » 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 
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.society;
026:
027:        import org.cougaar.core.agent.SimpleAgent;
028:        import org.cougaar.tools.csmart.core.cdata.AgentAssetData;
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.property.BaseComponent;
033:        import org.cougaar.tools.csmart.core.property.ConfigurableComponent;
034:        import org.cougaar.tools.csmart.core.property.Property;
035:        import org.cougaar.tools.csmart.ui.viewer.CSMART;
036:        import org.cougaar.util.log.Logger;
037:
038:        import java.io.PrintStream;
039:        import java.util.Collection;
040:        import java.util.Iterator;
041:
042:        /**
043:         * Get a ComponentData tree for a Society, plus helper methods.
044:         *
045:         * Created: Thu Mar 28 11:35:40 2002
046:         *
047:         */
048:        public class SocietyComponentCreator {
049:
050:            public static final String PROP_PREFIX = "PROP$";
051:
052:            public SocietyComponentCreator() {
053:            }
054:
055:            /**
056:             * Given a SocietyComponent, this method will
057:             * return a complete ComponentData tree.
058:             *
059:             * @param society
060:             * @return a <code>ComponentData</code> value
061:             */
062:            public static final ComponentData getComponentData(
063:                    SocietyComponent society) {
064:                //    Logger log = CSMART.createLogger("org.cougaar.tools.csmart.society.SocietyComponentCreator");
065:
066:                ComponentData cData = new GenericComponentData();
067:
068:                cData.setType(ComponentData.SOCIETY);
069:                cData.setClassName("java.lang.Object");
070:                cData.setName(society.getSocietyName());
071:                cData.setOwner(null);
072:                cData.setParent(null);
073:
074:                AgentComponent[] agents = society.getAgents();
075:                for (int i = 0; i < agents.length; i++) {
076:                    generateAgentComponentData(agents[i], cData, null);
077:                }
078:
079:                // Now let all components add their data.
080:                society.addComponentData(cData);
081:
082:                society.modifyComponentData(cData);
083:
084:                return cData;
085:            }
086:
087:            private static final void generateAgentComponentData(
088:                    AgentComponent agent, ComponentData parent,
089:                    ConfigurableComponent owner) {
090:
091:                AgentComponentData ac = new AgentComponentData();
092:                ac.setName(agent.getShortName());
093:                ac.setClassName(SimpleAgent.class.getName());
094:                ac.addParameter(agent.getShortName()); // Agents have one parameter, the agent name
095:                ac.setOwner(owner);
096:                ac.setParent(parent);
097:                parent.addChild((ComponentData) ac);
098:            }
099:
100:            private static final void addContainer(ComponentData cd,
101:                    BaseComponent cp, String name) {
102:                //    Logger log = CSMART.createLogger("org.cougaar.tools.csmart.society.SocietyComponentCreator");
103:
104:                Iterator iter = ((Collection) cp
105:                        .getDescendentsOfClass(ContainerBase.class)).iterator();
106:                while (iter.hasNext()) {
107:                    ContainerBase container = (ContainerBase) iter.next();
108:                    if (container.getShortName().equals(name)) {
109:                        for (int i = 0; i < container.getChildCount(); i++) {
110:                            BaseComponent base = (BaseComponent) container
111:                                    .getChild(i);
112:                            base.addComponentData(cd);
113:                        }
114:                    }
115:                }
116:            }
117:
118:            private static final void addPropertiesAsParameters(
119:                    ComponentData cd, BaseComponent cp) {
120:                Logger log = CSMART
121:                        .createLogger("org.cougaar.tools.csmart.society.SocietyComponentCreator");
122:                for (Iterator it = cp.getProperties(); it.hasNext();) {
123:                    Property prop = (Property) it.next();
124:                    if (prop != null) {
125:                        Object pvalue = prop.getValue();
126:                        if (pvalue instanceof  String)
127:                            if (log.isWarnEnabled()) {
128:                                log.warn("Adding Parameter.");
129:                            }
130:                        cd.addParameter(PROP_PREFIX + prop.getName().last()
131:                                + "=" + pvalue);
132:                    }
133:                }
134:            }
135:
136:            public static final void dumpComponentData(ComponentData data,
137:                    PrintStream stream, int sp) {
138:                ComponentData[] children = data.getChildren();
139:                for (int i = 0; i < children.length; i++) {
140:                    ComponentData child = children[i];
141:                    dumpChild(child, stream, sp);
142:                    if (child.childCount() > 0) {
143:                        dumpComponentData(child, stream, sp + 2);
144:                    }
145:                }
146:
147:            }
148:
149:            private static final void dumpChild(ComponentData child,
150:                    PrintStream stream, int sp) {
151:                stream.println(repeat(sp, " ") + "Name: " + child.getName());
152:                stream.println(repeat(sp, " ") + "Type: " + child.getType());
153:                stream.println(repeat(sp, " ") + "Classname: "
154:                        + child.getClassName());
155:
156:                if (child instanceof  AgentComponentData) {
157:                    AgentAssetData aad = child.getAgentAssetData();
158:
159:                    if (aad != null) {
160:                        stream.println(repeat(sp + 2, " ") + "UIC: "
161:                                + aad.getUIC());
162:                        stream.println(repeat(sp + 2, " ") + "UniqueName: "
163:                                + aad.getUniqueID());
164:                        stream.println(repeat(sp + 2, " ") + "Unit Name: "
165:                                + aad.getUnitName());
166:                    }
167:                }
168:
169:            }
170:
171:            private static final String repeat(int count, String str) {
172:                StringBuffer buf = new StringBuffer(count);
173:                for (int i = 0; i < count; i++) {
174:                    buf.append(str);
175:                }
176:                return buf.toString();
177:            }
178:
179:        }// SocietyComponentCreator
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.