Source Code Cross Referenced for SocietyDBComponent.java in  » Science » Cougaar12_4 » org » cougaar » tools » csmart » society » db » 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.db 
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.society.db;
027:
028:        import org.cougaar.core.agent.Agent;
029:        import org.cougaar.tools.csmart.core.db.DBUtils;
030:        import org.cougaar.tools.csmart.core.property.ModificationEvent;
031:        import org.cougaar.tools.csmart.society.SocietyBase;
032:        import org.cougaar.tools.csmart.ui.viewer.CSMART;
033:        import org.cougaar.util.log.Logger;
034:
035:        import java.io.IOException;
036:        import java.io.ObjectInputStream;
037:        import java.io.Serializable;
038:        import java.sql.Connection;
039:        import java.sql.ResultSet;
040:        import java.sql.Statement;
041:        import java.util.HashMap;
042:        import java.util.Map;
043:
044:        /**
045:         * A Society created from the CFW portion of the CSMART configuration
046:         * database.
047:         * @see org.cougaar.tools.csmart.core.db.CMT
048:         */
049:        public class SocietyDBComponent extends SocietyBase implements 
050:                Serializable {
051:            protected static final String DESCRIPTION_RESOURCE_NAME = "/org/cougaar/tools/csmart/society/society-base-description.html";
052:            protected static final String BACKUP_DESCRIPTION = "A Society created from the database: Agents, Binders, Plugins, etc.";
053:
054:            private static final String QUERY_AGENT_NAMES = "queryAgentNames";
055:
056:            private Map substitutions;
057:            private transient Logger log;
058:
059:            public SocietyDBComponent(String name) {
060:                super (name);
061:                createLogger();
062:            }
063:
064:            public SocietyDBComponent(String name, String assemblyId) {
065:                super (name);
066:                this .assemblyId = assemblyId;
067:                createLogger();
068:            }
069:
070:            private void createLogger() {
071:                log = CSMART.createLogger(this .getClass().getName());
072:            }
073:
074:            public void initProperties() {
075:                Map substitutions = new HashMap();
076:                if (assemblyId != null) {
077:                    substitutions.put(":assemblyMatch", DBUtils
078:                            .getListMatch(assemblyId));
079:                    substitutions
080:                            .put(":insertion_point", Agent.INSERTION_POINT);
081:
082:                    // FIXME:
083:                    // It would be really nice to be able to handle Binders and other non-Agent
084:                    // top-level things
085:
086:                    try {
087:                        Connection conn = DBUtils.getConnection();
088:                        try {
089:                            Statement stmt = conn.createStatement();
090:                            String query = DBUtils.getQuery(QUERY_AGENT_NAMES,
091:                                    substitutions);
092:                            ResultSet rs = stmt.executeQuery(query);
093:                            while (rs.next()) {
094:                                String agentName = DBUtils.getNonNullString(rs,
095:                                        1, query);
096:                                AgentDBComponent agent = new AgentDBComponent(
097:                                        agentName, assemblyId);
098:                                agent.initProperties();
099:                                addChild(agent);
100:                            }
101:                            rs.close();
102:                            stmt.close();
103:                        } finally {
104:                            conn.close();
105:                        }
106:                    } catch (Exception e) {
107:                        if (log.isErrorEnabled()) {
108:                            log.error("Exception", e);
109:                        }
110:                        throw new RuntimeException("Error" + e);
111:                    }
112:                    // After reading the soc from the DB, it is not modified.
113:                    //      modified = false;
114:                    modified = false;
115:                    fireModification(new ModificationEvent(this , SOCIETY_SAVED));
116:                }
117:            }
118:
119:            //    public void modified(ModificationEvent e) {
120:            //      fireModification();
121:            //    }
122:
123:            public void setName(String newName) {
124:                super .setName(newName);
125:                fireModification();
126:            }
127:
128:            /**
129:             * Returns whether the society is self terminating or must
130:             * be manually terminated.
131:             * Self terminating nodes cause the app-server to send back
132:             * a "process-destroyed" message when the node terminates.
133:             * @return true if society is self terminating
134:             */
135:            public boolean isSelfTerminating() {
136:                return false;
137:            }
138:
139:            //   public ModifiableComponent copy(String name) {
140:            //     // FIXME: I'd like to do the normal copy,
141:            //     // but my children only get created in initproperties
142:            //     // if I have an assemblyId, and by reading from the DB, so I don't
143:            //     // know if it would work
144:            //     //ModifiableComponent component = super.copy(name);
145:            //     if (log.isDebugEnabled()) {
146:            //       log.debug("Copying society " + this.getSocietyName() + " with assembly " + getAssemblyId() + " into new name " + name);
147:            //     }
148:            //     String assemblyID = getAssemblyId();
149:            //     ModifiableComponent sc = new SocietyDBComponent(name, assemblyID);
150:            //     sc.initProperties();
151:
152:            //     // If I re-init from DB, it is not modified, per se.
153:            //     // But we're putting it under a new assembly ID, and not saving it
154:            //     // so to that extent, it is modified.
155:            //     // Otherwise, set to the old value (= this.modified)
156:            //     ((SocietyBase)sc).modified = true;
157:            //     ((SocietyBase)sc).oldAssemblyId = assemblyID;
158:            //     ((SocietyBase)sc).setAssemblyId(null); // so it will save under new ID
159:
160:            //     return sc;
161:            //   }
162:
163:            private void readObject(ObjectInputStream ois) throws IOException,
164:                    ClassNotFoundException {
165:                ois.defaultReadObject();
166:                createLogger();
167:            }
168:
169:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.