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


0001:        /*
0002:         * <copyright>
0003:         *  
0004:         *  Copyright 1997-2004 BBNT Solutions, LLC
0005:         *  under sponsorship of the Defense Advanced Research Projects
0006:         *  Agency (DARPA).
0007:         * 
0008:         *  You can redistribute this software and/or modify it under the
0009:         *  terms of the Cougaar Open Source License as published on the
0010:         *  Cougaar Open Source Website (www.cougaar.org).
0011:         * 
0012:         *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0013:         *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0014:         *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0015:         *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0016:         *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0017:         *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0018:         *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0019:         *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0020:         *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0021:         *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0022:         *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0023:         *  
0024:         * </copyright>
0025:         */
0026:
0027:        package org.cougaar.util;
0028:
0029:        import java.util.*;
0030:        import java.sql.*;
0031:        import java.io.*;
0032:
0033:        // ConfigWriter program : 
0034:        // Read COUGAAR Organization from database and create
0035:        // <Node>.ini, <Cluster>.ini and <Cluster>-prototype-ini.dat files
0036:
0037:        // Note that the file can be read from any JDBC driver for this schema, 
0038:        // including MS EXCEL/ACCESS files or TEXT directories using ODBC/JDBC
0039:
0040:        // Database Schema described in comments per parse routine
0041:        // File formats described in comments per dump routine
0042:
0043:        // slight SQL mods for MS Access DB structure.
0044:        // Also replaced getString(n) with getString("Column Name") to
0045:        // make it more generic and less reliant on column position.
0046:
0047:        public class MDBConfigWriter {
0048:
0049:            // Top level 'main' test program
0050:            // Assumes hard-coded ODBC connection named 'AlpConfig'
0051:            public static void main(String args[]) throws SQLException {
0052:                System.out.println("In ConfigWriter...");
0053:                String community = null;
0054:                String path = null;
0055:                String node = null;
0056:
0057:                for (int ind = 0; ind < args.length; ind++) {
0058:                    if (args[ind].equals("-c")) {
0059:                        // pull only a certain community
0060:                        community = args[++ind];
0061:                    } else if (args[ind].equals("-n")) {
0062:                        // pull only a certain node
0063:                        node = args[++ind];
0064:                    } else if (args[ind].equals("-p")) {
0065:                        // put the files in the specified path
0066:                        path = args[++ind];
0067:                        System.out.println("Path is: " + path);
0068:                    }
0069:                }
0070:
0071:                new MDBConfigWriter().parseConfigData(
0072:                        "sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:odbc:AlpConfig",
0073:                        "", "", community, node, path);
0074:            }
0075:
0076:            // Parse configuration data from given database
0077:            // Read info and write appropriate .ini and .dat files
0078:            // Given classname of JDBC driver, URL of database and user/password
0079:            protected void parseConfigData(String driver_classname,
0080:                    String datasource_url, String username, String password,
0081:                    String community, String node, String path) {
0082:
0083:                System.out.println("Loading driver " + driver_classname);
0084:
0085:                try {
0086:                    Class driver = Class.forName(driver_classname);
0087:                } catch (ClassNotFoundException e) {
0088:                    System.out.println("Could not load driver : "
0089:                            + driver_classname);
0090:                    e.printStackTrace();
0091:                }
0092:
0093:                System.out.println("Connecting to the datasource : "
0094:                        + datasource_url);
0095:                try {
0096:                    Connection conn = DriverManager.getConnection(
0097:                            datasource_url, username, password);
0098:
0099:                    Statement stmt = conn.createStatement();
0100:
0101:                    // Maintain a hashtable of NodeName => Vector of ClusterNames
0102:                    Hashtable all_nodes = new Hashtable();
0103:                    parseNodeInfo(all_nodes, stmt, community, node);
0104:                    dumpNodeInfo(all_nodes, path);
0105:
0106:                    // Maintain a hashtable of ClusterName => Vector of Plugins
0107:                    Hashtable all_clusters = new Hashtable();
0108:                    parseClusterInfo(all_clusters, stmt, community, node);
0109:                    dumpClusterInfo(all_clusters, path);
0110:
0111:                    // Maintain a hashtable of OrganizationName => OrganizationData
0112:                    Hashtable all_organizations = new Hashtable();
0113:                    parseOrganizationInfo(all_organizations, stmt, community,
0114:                            node);
0115:                    dumpOrganizationInfo(all_organizations, path);
0116:
0117:                    conn.close();
0118:                } catch (IOException ioe) {
0119:                    System.out.println("IO Exception");
0120:                    ioe.printStackTrace();
0121:                } catch (SQLException sqle) {
0122:                    System.out.println("SQL Exception");
0123:                    sqle.printStackTrace();
0124:                }
0125:            }
0126:
0127:            // Parse Node Info from into hash table of all node info
0128:            // Schema : 
0129:            // create table Nodes (
0130:            //     NodeName String,  
0131:            //     Cluster  String
0132:            // );
0133:            private void parseNodeInfo(Hashtable all_nodes, Statement stmt,
0134:                    String community, String node) throws SQLException {
0135:                // Query for all Node/Cluster info and populate 'all_nodes' hashtable
0136:
0137:                String sql = "select Node, Name from Organizations";
0138:
0139:                if (community != null && node != null) {
0140:                    sql = sql + " where Community='" + community
0141:                            + "' and Node='" + node + "'";
0142:                } else if (community != null) {
0143:                    sql = sql + " where Community='" + community + "'";
0144:                } else if (node != null) {
0145:                    sql = sql + " where Node='" + node + "'";
0146:                }
0147:
0148:                System.out.println(sql);
0149:                ResultSet rset = stmt.executeQuery(sql);
0150:                int number = 0;
0151:                while (rset.next()) {
0152:                    number++;
0153:                    String node_name = rset.getString("Node");
0154:                    String cluster_name = rset.getString("Name");
0155:                    try {
0156:                        Vector current_node_clusters = (Vector) all_nodes
0157:                                .get(node_name);
0158:                        if (current_node_clusters == null) {
0159:                            current_node_clusters = new Vector();
0160:                            all_nodes.put(node_name, current_node_clusters);
0161:                        }
0162:                        current_node_clusters.addElement(cluster_name);
0163:                    } catch (Exception nullPointer) {
0164:                        System.out.println("WARNING:  Cluster " + cluster_name
0165:                                + " does not have a node!!!");
0166:                    }
0167:                }
0168:                System.out.println("Query returned " + number + " results");
0169:                rset = null;
0170:                System.gc();
0171:            }
0172:
0173:            // Generate files for given node
0174:            // Given Hashtable mapping node_name to Vector of cluster names
0175:            // <Node>.ini File format:
0176:            // [ Clusters ]
0177:            // cluster = <clustername>
0178:            // ...
0179:            private void dumpNodeInfo(Hashtable all_nodes, String path)
0180:                    throws IOException {
0181:                PrintWriter node_file;
0182:                // Iterate over hashtable of nodes and write <Node>.ini file for each
0183:                for (Enumeration e = all_nodes.keys(); e.hasMoreElements();) {
0184:                    String node_name = (String) (e.nextElement());
0185:
0186:                    try {
0187:                        if (path != null) {
0188:                            node_file = createPrintWriter(path + File.separator
0189:                                    + node_name + ".ini");
0190:                        } else {
0191:                            node_file = createPrintWriter(node_name + ".ini");
0192:                        }
0193:                        node_file.println("[ Clusters ]");
0194:                        Vector clusters = (Vector) all_nodes.get(node_name);
0195:                        for (Enumeration c = clusters.elements(); c
0196:                                .hasMoreElements();) {
0197:                            String cluster_name = (String) (c.nextElement());
0198:                            node_file.println("cluster = " + cluster_name);
0199:                        }
0200:                        node_file.close();
0201:                    } catch (IOException exc) {
0202:                        System.out.println("IOException:  " + exc);
0203:                        System.exit(-1);
0204:                    }
0205:
0206:                }
0207:            }
0208:
0209:            // Parse cluster info from Clusters table and 
0210:            // place all cluster=>plugin info into hashtable 
0211:            // Schema :
0212:            // create table Clusters (
0213:            //    Cluster String,
0214:            //    Plugin  String
0215:            // );
0216:            private void parseClusterInfo(Hashtable all_clusters,
0217:                    Statement stmt, String community, String node)
0218:                    throws SQLException {
0219:
0220:                String sql = null;
0221:                ResultSet rset;
0222:                int number = 0;
0223:
0224:                // Grab the plugin groups
0225:                Hashtable plugInGroups = new Hashtable();
0226:                sql = "select GroupName, GroupSequence from GroupMaster";
0227:
0228:                number = 0;
0229:                System.out.println(sql);
0230:
0231:                rset = stmt.executeQuery(sql);
0232:
0233:                while (rset.next()) {
0234:                    number++;
0235:                    String groupName = rset.getString("GroupName");
0236:                    System.out.println(groupName);
0237:                    Integer index = new Integer(rset.getInt("GroupSequence"));
0238:                    System.out.println(index);
0239:                    plugInGroups.put(index, groupName);
0240:
0241:                }
0242:                System.out.println("Query returned " + number + " results");
0243:
0244:                // Grab the group definitions
0245:                Hashtable groupDefinitions = new Hashtable();
0246:                for (int ind = 0; ind < plugInGroups.size(); ind++) {
0247:
0248:                    String group = (String) plugInGroups.get(new Integer(ind));
0249:                    if (group != null) {
0250:                        sql = "select InGroupSequence, Plugin from GroupDefinitions"
0251:                                + " where GroupName='" + group + "'";
0252:                        rset = stmt.executeQuery(sql);
0253:                        System.out.println(sql);
0254:                        groupDefinitions.put(group, new Hashtable());
0255:
0256:                        number = 0;
0257:                        while (rset.next()) {
0258:                            number++;
0259:                            Hashtable plugins = (Hashtable) groupDefinitions
0260:                                    .get(group);
0261:                            int index = rset.getInt("InGroupSequence");
0262:                            String plugIn = rset.getString("Plugin");
0263:                            plugins.put(new Integer(index), plugIn);
0264:                        }
0265:                        System.out.println("Query returned " + number
0266:                                + " results");
0267:                    } else {
0268:                        break;
0269:                    }
0270:                }
0271:
0272:                // Add the plugIn groups per cluster to the plugIn vector
0273:                number = 0;
0274:                sql = "select Cluster, PluginGroup from GroupsInCluster";
0275:
0276:                if (community != null && node != null) {
0277:                    sql = sql
0278:                            + ", Organizations where Cluster=Organizations.Name and"
0279:                            + " Organizations.Community='" + community
0280:                            + "' and Organizations.Node='" + node + "'";
0281:                } else if (community != null) {
0282:                    sql = sql
0283:                            + ", Organizations where Cluster=Organizations.Name and"
0284:                            + " Organizations.Community='" + community + "'";
0285:                } else if (node != null) {
0286:                    sql = sql + ", Organizations where Organizations.Node='"
0287:                            + node + "'";
0288:                }
0289:
0290:                System.out.println(sql);
0291:
0292:                number = 0;
0293:                rset = stmt.executeQuery(sql);
0294:                while (rset.next()) {
0295:                    number++;
0296:                    String cluster_name = rset.getString("Cluster");
0297:                    String pluginGroup = rset.getString("PluginGroup");
0298:
0299:                    Vector current_cluster_plugins = (Vector) all_clusters
0300:                            .get(cluster_name);
0301:                    if (current_cluster_plugins == null) {
0302:                        current_cluster_plugins = new Vector();
0303:                        all_clusters.put(cluster_name, current_cluster_plugins);
0304:                    }
0305:                    Hashtable groupPlugins = (Hashtable) groupDefinitions
0306:                            .get(pluginGroup);
0307:                    for (int ind = 0; ind < groupPlugins.size(); ind++) {
0308:                        current_cluster_plugins.addElement(groupPlugins
0309:                                .get(new Integer(ind)));
0310:                    }
0311:                }
0312:                System.out.println("Query returned " + number + " results");
0313:
0314:                // Grab the plugins that go in every community or every cluster within specific communities
0315:                Vector mdbCommunities = new Vector();
0316:
0317:                sql = "select Community from CommunityMaster";
0318:                number = 0;
0319:                System.out.println(sql);
0320:
0321:                rset = stmt.executeQuery(sql);
0322:
0323:                while (rset.next()) {
0324:                    number++;
0325:                    String community_name = rset.getString("Community");
0326:                    mdbCommunities.addElement(community_name);
0327:
0328:                }
0329:                System.out.println("Query returned " + number + " results");
0330:
0331:                while (!mdbCommunities.isEmpty()) {
0332:                    number = 0;
0333:                    String sCommunity = (String) mdbCommunities.firstElement();
0334:                    mdbCommunities.removeElementAt(0);
0335:
0336:                    sql = "select Organizations.Name, CommunityPlugins.Plugin from Organizations, CommunityPlugins"
0337:                            + " where CommunityPlugins.Community='"
0338:                            + sCommunity + "'";
0339:
0340:                    if (!sCommunity.equals("Society")) {
0341:                        if (community != null) {
0342:                            if (!community.equals(sCommunity)) {
0343:                                continue;
0344:                            }
0345:                        }
0346:                        sql = sql + " and Organizations.Community='"
0347:                                + sCommunity + "'";
0348:                    } else {
0349:                        if (community != null) {
0350:                            sql = sql + " and Organizations.Community='"
0351:                                    + community + "'";
0352:                        }
0353:                    }
0354:
0355:                    if (node != null) {
0356:                        sql = sql + " and Organizations.Node='" + node + "'";
0357:                    }
0358:
0359:                    System.out.println(sql);
0360:                    number = 0;
0361:                    rset = stmt.executeQuery(sql);
0362:                    while (rset.next()) {
0363:                        number++;
0364:                        String cluster_name = rset.getString("Name");
0365:                        String plugin = rset.getString("Plugin");
0366:
0367:                        Vector current_cluster_plugins = (Vector) all_clusters
0368:                                .get(cluster_name);
0369:                        if (current_cluster_plugins == null) {
0370:                            current_cluster_plugins = new Vector();
0371:                            all_clusters.put(cluster_name,
0372:                                    current_cluster_plugins);
0373:                        }
0374:
0375:                        current_cluster_plugins.addElement(plugin);
0376:                    }
0377:                    System.out.println("Query returned " + number + " results");
0378:                }
0379:
0380:                // Query for all Cluster/Plugin info and populate 'all_clusters' hashtable
0381:
0382:                sql = "select Clusters.Cluster, Clusters.Plugin, Clusters.Parameters from Clusters, Organizations"
0383:                        + " where Clusters.Cluster=Organizations.Name";
0384:
0385:                if (community != null && node != null) {
0386:                    sql = sql + "and Organizations.Node='" + node + "'"
0387:                            + " and Organizations.Community='" + community
0388:                            + "'";
0389:                } else if (community != null) {
0390:                    sql = sql + " and Organizations.Community='" + community
0391:                            + "'";
0392:                } else if (node != null) {
0393:                    sql = sql + " and Organizations.Node='" + node + "'";
0394:                }
0395:
0396:                System.out.println(sql);
0397:
0398:                number = 0;
0399:                rset = stmt.executeQuery(sql);
0400:                while (rset.next()) {
0401:                    number++;
0402:                    String cluster_name = rset.getString("Cluster");
0403:                    String plugin = rset.getString("Plugin");
0404:                    String parameters = rset.getString("Parameters");
0405:
0406:                    // put the parameters into the plugin
0407:                    if (parameters != null) {
0408:                        plugin = plugin + "(" + parameters + ")";
0409:                    }
0410:
0411:                    Vector current_cluster_plugins = (Vector) all_clusters
0412:                            .get(cluster_name);
0413:                    if (current_cluster_plugins == null) {
0414:                        current_cluster_plugins = new Vector();
0415:                        all_clusters.put(cluster_name, current_cluster_plugins);
0416:                    }
0417:
0418:                    current_cluster_plugins.addElement(plugin);
0419:                }
0420:                System.out.println("Query returned " + number + " results");
0421:
0422:            }
0423:
0424:            // Write <Cluster>.ini file
0425:            // Given Hashtable mapping cluster name to Vector of plugin names
0426:            // <Cluster>.ini File format:
0427:            // [ Cluster ]
0428:            // uic = <Agentname>
0429:            // cloned = false
0430:            // [ Plugins ]
0431:            // plugin = <pluginname>
0432:            // ...
0433:            // 
0434:            private void dumpClusterInfo(Hashtable all_clusters, String path)
0435:                    throws IOException {
0436:                // Dump hashtable of clusters
0437:                for (Enumeration e = all_clusters.keys(); e.hasMoreElements();) {
0438:                    String cluster_name = (String) e.nextElement();
0439:                    PrintWriter cluster_file;
0440:
0441:                    try {
0442:                        if (path != null) {
0443:                            cluster_file = createPrintWriter(path
0444:                                    + File.separator + cluster_name + ".ini");
0445:                        } else {
0446:                            cluster_file = createPrintWriter(cluster_name
0447:                                    + ".ini");
0448:                        }
0449:
0450:                        cluster_file.println("[ Cluster ]");
0451:                        cluster_file.println("uic = " + cluster_name);
0452:                        cluster_file.println("cloned = false\n");
0453:                        cluster_file.println("[ Plugins ]");
0454:                        Vector plugins = (Vector) (all_clusters
0455:                                .get(cluster_name));
0456:                        for (Enumeration p = plugins.elements(); p
0457:                                .hasMoreElements();) {
0458:                            String plugin = (String) (p.nextElement());
0459:                            cluster_file.println("plugin = " + plugin);
0460:                        }
0461:                        cluster_file.close();
0462:                    } catch (IOException exc) {
0463:                        System.out.println("IOException:  " + exc);
0464:                        System.exit(-1);
0465:                    }
0466:
0467:                }
0468:            }
0469:
0470:            // Inner class to hold organization data (including roles, relationships)
0471:            private class OrganizationData {
0472:                public OrganizationData(String Name, String UIC, String UTC,
0473:                        String SRC, String Superior, Double Echelon,
0474:                        String Agency, String Service, String Nomenclature,
0475:                        String Prototype, boolean IsReserve) {
0476:                    myName = myStringInit(Name);
0477:                    myUIC = myStringInit(UIC);
0478:                    myUTC = myStringInit(UTC);
0479:                    mySRC = myStringInit(SRC);
0480:                    mySuperior = myStringInit(Superior);
0481:                    myEchelon = Echelon;
0482:                    myAgency = myStringInit(Agency);
0483:                    myNomenclature = myStringInit(Nomenclature);
0484:                    myPrototype = myStringInit(Prototype);
0485:                    myIsReserve = IsReserve;
0486:                    myRoles = new Vector();
0487:                    mySupportRelations = new Vector();
0488:                }
0489:
0490:                public void initAssignedLoc(String Location, String Longitude,
0491:                        String Latitude, String GeoLoc, String InstallCode,
0492:                        String CSCode, String CSName, String ICAOCode) {
0493:
0494:                    myAssignedLocation = myStringInit(Location);
0495:                    myAssignedLongitude = myStringInit(Longitude);
0496:                    myAssignedLatitude = myStringInit(Latitude);
0497:                    myAssignedGeoLoc = myStringInit(GeoLoc);
0498:                    myAssignedInstallCode = myStringInit(InstallCode);
0499:                    myAssignedCSCode = myStringInit(CSCode);
0500:                    myAssignedCSName = myStringInit(CSName);
0501:                    myAssignedICAOCode = myStringInit(ICAOCode);
0502:                }
0503:
0504:                public void initHomeLoc(String Location, String Longitude,
0505:                        String Latitude, String GeoLoc, String InstallCode,
0506:                        String CSCode, String CSName, String ICAOCode) {
0507:
0508:                    myHomeLocation = myStringInit(Location);
0509:                    myHomeLongitude = myStringInit(Longitude);
0510:                    myHomeLatitude = myStringInit(Latitude);
0511:                    myHomeGeoLoc = myStringInit(GeoLoc);
0512:                    myHomeInstallCode = myStringInit(InstallCode);
0513:                    myHomeCSCode = myStringInit(CSCode);
0514:                    myHomeCSName = myStringInit(CSName);
0515:                    myHomeICAOCode = myStringInit(ICAOCode);
0516:                }
0517:
0518:                public String myName;
0519:                public String myUIC;
0520:                public String myUTC;
0521:                public String mySRC;
0522:                public String mySuperior;
0523:                public Double myEchelon;
0524:                public String myAgency;
0525:                public String myService;
0526:                public String myNomenclature;
0527:                public String myPrototype;
0528:                public String myAssignedLocation;
0529:                public String myAssignedLongitude;
0530:                public String myAssignedLatitude;
0531:                public String myAssignedGeoLoc;
0532:                public String myAssignedInstallCode;
0533:                public String myAssignedCSCode;
0534:                public String myAssignedCSName;
0535:                public String myAssignedICAOCode;
0536:                public String myHomeLocation;
0537:                public String myHomeLongitude;
0538:                public String myHomeLatitude;
0539:                public String myHomeGeoLoc;
0540:                public String myHomeInstallCode;
0541:                public String myHomeCSCode;
0542:                public String myHomeCSName;
0543:                public String myHomeICAOCode;
0544:                public boolean myIsReserve;
0545:
0546:                public Vector myRoles; // List of roles for organization
0547:                public Vector mySupportRelations; // List of OrganizationSupportRelations
0548:                public Vector myCSSCapabilities; // List of CSSCapabilities
0549:
0550:                public void addRole(String role) {
0551:                    myRoles.addElement(role);
0552:                }
0553:
0554:                public boolean isCivilan() {
0555:                    return myPrototype.equals("Civilian");
0556:                }
0557:
0558:                public void addSupportRelation(SupportRelation rel) {
0559:                    mySupportRelations.addElement(rel);
0560:                }
0561:
0562:                public void addCSSCapabilities(CSSCapabilities cap) {
0563:                    if (myCSSCapabilities == null) {
0564:                        myCSSCapabilities = new Vector();
0565:                    }
0566:                    myCSSCapabilities.addElement(cap);
0567:                }
0568:
0569:                private String myStringInit(String value) {
0570:                    if (value == null) {
0571:                        return "";
0572:                    }
0573:                    return value;
0574:                }
0575:
0576:                public String toString() {
0577:                    String roles_image = "";
0578:                    for (Enumeration e = myRoles.elements(); e
0579:                            .hasMoreElements();) {
0580:                        roles_image = roles_image + "/"
0581:                                + (String) e.nextElement();
0582:                    }
0583:                    String relations_image = "";
0584:                    for (Enumeration e = mySupportRelations.elements(); e
0585:                            .hasMoreElements();) {
0586:                        relations_image = relations_image + "/"
0587:                                + (SupportRelation) e.nextElement();
0588:                    }
0589:                    return "#<Organization " + myName + " " + myUIC + " "
0590:                            + myUTC + " " + mySRC + " " + mySuperior + " "
0591:                            + myEchelon + " " + myAgency + " " + myService
0592:                            + " " + myNomenclature + " " + myPrototype + " "
0593:                            + roles_image + " " + relations_image + ">";
0594:                }
0595:            }
0596:
0597:            // Private inner class to hold SupportRelation info (organization, role)
0598:            private class SupportRelation {
0599:                public SupportRelation(String Name,
0600:                        String SupportedOrganization, String Role) {
0601:                    myName = Name;
0602:                    mySupportedOrganization = SupportedOrganization;
0603:                    myRole = Role;
0604:                }
0605:
0606:                public String myName;
0607:                public String mySupportedOrganization;
0608:                public String myRole;
0609:
0610:                public String toString() {
0611:                    return "#<Relation " + myName + " "
0612:                            + mySupportedOrganization + " " + myRole + ">";
0613:                }
0614:            }
0615:
0616:            private class CSSCapabilities {
0617:                public String name;
0618:                public String capability;
0619:                public String qty;
0620:                public String period;
0621:
0622:                private String myStringInit(String value) {
0623:                    if (value == null) {
0624:                        return "";
0625:                    }
0626:                    return value;
0627:                }
0628:
0629:                public CSSCapabilities(String name, String capability,
0630:                        String qty, String period) {
0631:                    this .name = myStringInit(name);
0632:                    this .capability = myStringInit(capability);
0633:                    this .qty = myStringInit(qty);
0634:                    this .period = myStringInit(period);
0635:                }
0636:
0637:            };
0638:
0639:            // Parse database tables to create organization info, including 
0640:            // organization details (from Organizations table)
0641:            // roles (from Roles table)
0642:            // support relationships (from Relationships table)
0643:            // Schema:
0644:            // create table Organizations (
0645:            //   Name String,
0646:            //   UIC String,
0647:            //   UTC String,
0648:            //   SRC String,
0649:            //   Superior String,
0650:            //   Echelon String,
0651:            //   Agency String,
0652:            //   Service String,
0653:            //   Nomenclature String,
0654:            //   Prototype String,
0655:            // );
0656:            // create table Roles (
0657:            //    Organization String,
0658:            //    Role String -- Capable Role for Organization
0659:            // );
0660:            // create table Relationships (
0661:            //    Organization String,
0662:            //    Supported String, -- Supported Organization
0663:            //    Role String -- Support Role
0664:            // );
0665:            private void parseOrganizationInfo(Hashtable all_organizations,
0666:                    Statement stmt, String community, String node)
0667:                    throws SQLException {
0668:                Double echelon;
0669:                int number = 0;
0670:                /*
0671:                String sql = "select Name, UIC, UTC, SRC, Superior, Echelon, Agency, Service, Nomenclature, "
0672:                    +"Prototype, Location, Longitude, Latitude, Organizations.GeolocCode, InstallationTypeCode, "
0673:                    +"CountryStateCode, CountryStateName, IcaoCode, ReserveOrg from Organizations, "
0674:                    +"LocationMaster where Organizations.GeolocCode=LocationMaster.GeolocCode" ;
0675:                 */
0676:
0677:                String sql = "select Name, UIC, UTC, SRC, Superior, Echelon, Agency, Service, Nomenclature, "
0678:                        + "Prototype, ReserveOrg from Organizations";
0679:
0680:                if (community != null && node != null) {
0681:                    sql = sql + " where Organizations.Community='" + community
0682:                            + "' and Organizations.Node='" + node + "'";
0683:                } else if (community != null) {
0684:                    sql = sql + " where Organizations.Community='" + community
0685:                            + "'";
0686:                } else if (node != null) {
0687:                    sql = sql + " where Organizations.Node='" + node + "'";
0688:                }
0689:                System.out.println(sql);
0690:
0691:                ResultSet rset = stmt.executeQuery(sql);
0692:
0693:                while (rset.next()) {
0694:                    number++;
0695:                    String current_organization = rset.getString("Name");
0696:                    String testEchelon = rset.getString("Echelon");
0697:                    if (testEchelon == null) {
0698:                        echelon = new Double(-1);
0699:                    } else {
0700:                        echelon = new Double(testEchelon);
0701:                    }
0702:                    boolean reserve = false;
0703:                    int res = rset.getInt("ReserveOrg");
0704:                    if (res == 0) {
0705:                        reserve = false;
0706:                    } else {
0707:                        reserve = true;
0708:                    }
0709:
0710:                    OrganizationData org_data = new OrganizationData(
0711:                            current_organization, rset.getString("UIC"), // UIC
0712:                            rset.getString("UTC"), // UTC
0713:                            rset.getString("SRC"), // SRC
0714:                            rset.getString("Superior"), // Superior
0715:                            echelon, // Echelon
0716:                            rset.getString("Agency"), // Agency
0717:                            rset.getString("Service"), // Service
0718:                            rset.getString("Nomenclature"), // Nomenclature
0719:                            rset.getString("Prototype"), // Prototype
0720:                            reserve); // isReserve
0721:                    all_organizations.put(current_organization, org_data);
0722:
0723:                }
0724:                System.out.println("Query returned " + number + " results");
0725:
0726:                rset = null;
0727:                System.gc();
0728:
0729:                // Query for the Assigned Location
0730:                sql = "select Name, Location, Longitude, Latitude, AssignedLoc, InstallationTypeCode, "
0731:                        + "CountryStateCode, CountryStateName, IcaoCode, ReserveOrg from Organizations, "
0732:                        + "LocationMaster where Organizations.AssignedLoc=LocationMaster.GeolocCode";
0733:
0734:                if (community != null && node != null) {
0735:                    sql = sql + " and Organizations.Community='" + community
0736:                            + "' and Organizations.Node='" + node + "'";
0737:                } else if (community != null) {
0738:                    sql = sql + " and Organizations.Community='" + community
0739:                            + "'";
0740:                } else if (node != null) {
0741:                    sql = sql + " and Organizations.Node='" + node + "'";
0742:                }
0743:
0744:                System.out.println(sql);
0745:
0746:                rset = stmt.executeQuery(sql);
0747:
0748:                while (rset.next()) {
0749:                    number++;
0750:                    String current_organization = rset.getString("Name");
0751:                    OrganizationData data = (OrganizationData) all_organizations
0752:                            .get(current_organization);
0753:                    // initialize the assigned location
0754:                    data.initAssignedLoc(rset.getString("Location"), rset
0755:                            .getString("Longitude"),
0756:                            rset.getString("Latitude"), rset
0757:                                    .getString("AssignedLoc"), rset
0758:                                    .getString("InstallationTypeCode"), rset
0759:                                    .getString("CountryStateCode"), rset
0760:                                    .getString("CountryStateName"), rset
0761:                                    .getString("IcaoCode"));
0762:                }
0763:                System.out.println("Query returned " + number + " results");
0764:
0765:                rset = null;
0766:                System.gc();
0767:
0768:                // Query for the home location
0769:                sql = "select Name, Location, Longitude, Latitude, HomeLoc, InstallationTypeCode, "
0770:                        + "CountryStateCode, CountryStateName, IcaoCode, ReserveOrg from Organizations, "
0771:                        + "LocationMaster where Organizations.HomeLoc=LocationMaster.GeolocCode";
0772:
0773:                if (community != null && node != null) {
0774:                    sql = sql + " and Organizations.Community='" + community
0775:                            + "' and Organizations.Node='" + node + "'";
0776:                } else if (community != null) {
0777:                    sql = sql + " and Organizations.Community='" + community
0778:                            + "'";
0779:                } else if (node != null) {
0780:                    sql = sql + " and Organizations.Node='" + node + "'";
0781:                }
0782:
0783:                System.out.println(sql);
0784:
0785:                rset = stmt.executeQuery(sql);
0786:
0787:                while (rset.next()) {
0788:                    number++;
0789:                    String current_organization = rset.getString("Name");
0790:                    OrganizationData data = (OrganizationData) all_organizations
0791:                            .get(current_organization);
0792:                    // initialize the Home location
0793:                    data.initHomeLoc(rset.getString("Location"), rset
0794:                            .getString("Longitude"),
0795:                            rset.getString("Latitude"), rset
0796:                                    .getString("HomeLoc"), rset
0797:                                    .getString("InstallationTypeCode"), rset
0798:                                    .getString("CountryStateCode"), rset
0799:                                    .getString("CountryStateName"), rset
0800:                                    .getString("IcaoCode"));
0801:                }
0802:                System.out.println("Query returned " + number + " results");
0803:
0804:                rset = null;
0805:                System.gc();
0806:
0807:                // Query for all Organization/Role info
0808:
0809:                sql = "select Organization, Role from Roles, Organizations"
0810:                        + " where Organizations.Name=Roles.Organization ";
0811:                number = 0;
0812:                if (community != null && node != null) {
0813:                    sql = sql + " and Organizations.Community='" + community
0814:                            + "' and Organizations.Node='" + node + "'";
0815:                } else if (community != null) {
0816:                    sql = sql + " and Organizations.Community='" + community
0817:                            + "'";
0818:                } else if (node != null) {
0819:                    sql = sql + " and Organizations.Node='" + node + "'";
0820:                }
0821:
0822:                System.out.println(sql);
0823:                rset = stmt.executeQuery(sql);
0824:
0825:                while (rset.next()) {
0826:                    number++;
0827:                    String current_organization = (String) rset
0828:                            .getString("Organization");
0829:                    OrganizationData org_data = (OrganizationData) all_organizations
0830:                            .get(current_organization);
0831:                    if (org_data == null) {
0832:                        System.out.println("No organization defined : "
0833:                                + current_organization);
0834:                        System.exit(0);
0835:                    }
0836:                    org_data.addRole(rset.getString("Role")); // Role
0837:                }
0838:                System.out.println("Query returned " + number + " results");
0839:
0840:                rset = null;
0841:                System.gc();
0842:
0843:                sql = "Select SupportingOrg, SupportedOrg, Role from Relationships, Organizations"
0844:                        + " where Relationships.SupportingOrg=Organizations.Name";
0845:
0846:                if (community != null && node != null) {
0847:                    sql = sql + " and Organizations.Community='" + community
0848:                            + "'" + " and Organizations.Node='" + node + "'";
0849:                } else if (community != null) {
0850:                    sql = sql + " and Organizations.Community='" + community
0851:                            + "'";
0852:
0853:                } else if (node != null) {
0854:                    sql = sql + " and Organizations.Node='" + node + "'";
0855:                }
0856:
0857:                System.out.println(sql);
0858:                rset = stmt.executeQuery(sql);
0859:
0860:                number = 0;
0861:                rset = stmt.executeQuery(sql);
0862:                while (rset.next()) {
0863:                    number++;
0864:                    String current_organization = (String) rset
0865:                            .getString("SupportingOrg");
0866:                    OrganizationData org_data = (OrganizationData) all_organizations
0867:                            .get(current_organization);
0868:                    if (org_data == null) {
0869:                        System.out.println("No organization defined : "
0870:                                + current_organization);
0871:                        System.exit(0);
0872:                    }
0873:                    SupportRelation support = new SupportRelation(
0874:                            current_organization, rset
0875:                                    .getString("SupportedOrg"), // Supported Org
0876:                            rset.getString("Role")); // Role
0877:                    org_data.addSupportRelation(support);
0878:                }
0879:
0880:                System.out.println("Query returned " + number + " results");
0881:
0882:                rset = null;
0883:                System.gc();
0884:
0885:                // get the CSSCapabilities
0886:                sql = "select CSSCapability.Cluster, Capability, QTY, Period"
0887:                        + " from CSSCapability, Organizations"
0888:                        + " where CSSCapability.Cluster=Organizations.Name";
0889:
0890:                if (community != null && node != null) {
0891:                    sql = sql + " and Organizations.Community='" + community
0892:                            + "' and Organizations.Node='" + node + "'";
0893:                } else if (community != null) {
0894:                    sql = sql + " and Organizations.Community='" + community
0895:                            + "'";
0896:                } else if (node != null) {
0897:                    sql = sql + " and Organizations.Node='" + node + "'";
0898:                }
0899:
0900:                System.out.println(sql);
0901:                number = 0;
0902:                rset = stmt.executeQuery(sql);
0903:                while (rset.next()) {
0904:                    number++;
0905:                    String current_organization = (String) rset
0906:                            .getString("Cluster");
0907:                    OrganizationData org_data = (OrganizationData) all_organizations
0908:                            .get(current_organization);
0909:                    if (org_data == null) {
0910:                        System.out.println("No organization defined : "
0911:                                + current_organization);
0912:                        System.exit(0);
0913:                    }
0914:                    CSSCapabilities CSSCap = new CSSCapabilities(
0915:                            current_organization, rset.getString("Capability"), // Capability
0916:                            rset.getString("QTY"), // Count
0917:                            rset.getString("Period"));
0918:                    org_data.addCSSCapabilities(CSSCap);
0919:                }
0920:                System.out.println("Query returned " + number + " results");
0921:
0922:                rset = null;
0923:                System.gc();
0924:
0925:            }
0926:
0927:            // Print <Cluster>-prototype-ini.dat file
0928:            // File format:
0929:            // [Prototype] CombatOrganization|CivilanOrganization
0930:            // [UniqueId] "UTC/CombatOrg"
0931:            // [UIC] "UIC/<OrganizationName>
0932:            // [Relationship]
0933:            // Superior  <Superior> ""
0934:            // Support   <Supported> <Role>
0935:            // [TypeIdentificationPG]
0936:            // TypeIdentification String "UTC/RTOrg"
0937:            // Nomenclature String <Nomenclature>
0938:            // AlternateTypeIdentification String "SRC/<SRC>"
0939:            // [ClusterPG]
0940:            // MessageAddress String <OrganizationName>
0941:            // [OrganizationPG]
0942:            // Roles Collection<Role> <Role>
0943:            // [MilitaryOrgPG]
0944:            // UIC String <UIC>
0945:            // Echelon String <Echelon>
0946:            // UTC String <UTC>
0947:            // SRC String <SRC>
0948:            // 
0949:            private void dumpOrganizationInfo(Hashtable all_organizations,
0950:                    String path) throws IOException {
0951:
0952:                Hashtable supportedOrgRoles = null;
0953:
0954:                for (Enumeration e = all_organizations.keys(); e
0955:                        .hasMoreElements();) {
0956:                    supportedOrgRoles = new Hashtable();
0957:                    String org_name = (String) e.nextElement();
0958:                    OrganizationData org_data = (OrganizationData) all_organizations
0959:                            .get(org_name);
0960:                    PrintWriter org_file;
0961:
0962:                    try {
0963:                        if (path != null) {
0964:                            org_file = createPrintWriter(path + File.separator
0965:                                    + org_name + "-prototype-ini.dat");
0966:                        } else {
0967:                            org_file = createPrintWriter(org_name
0968:                                    + "-prototype-ini.dat");
0969:                        }
0970:                        org_file
0971:                                .println("[Prototype] "
0972:                                        + (org_data.isCivilan() ? "CivilianOrganization"
0973:                                                : "MilitaryOrganization"));
0974:                        org_file.println("\n[UniqueId] " + '"'
0975:                                + "UTC/CombatOrg" + '"');
0976:                        org_file.println("\n[UIC] " + '"' + "UIC/" + org_name
0977:                                + '"');
0978:
0979:                        // Write out Superior/Support Relationships
0980:                        org_file.println("\n[Relationship]");
0981:                        if (org_data.mySuperior != null) {
0982:                            org_file.println("Superior " + '"'
0983:                                    + org_data.mySuperior + '"' + " " + '"'
0984:                                    + '"');
0985:                        }
0986:
0987:                        for (Enumeration rels = org_data.mySupportRelations
0988:                                .elements(); rels.hasMoreElements();) {
0989:                            SupportRelation suprel = (SupportRelation) rels
0990:                                    .nextElement();
0991:
0992:                            if (!supportedOrgRoles
0993:                                    .containsKey(suprel.mySupportedOrganization)) {
0994:                                supportedOrgRoles.put(
0995:                                        suprel.mySupportedOrganization,
0996:                                        suprel.myRole);
0997:                            } else {
0998:                                String role = (String) supportedOrgRoles
0999:                                        .get(suprel.mySupportedOrganization);
1000:                                role = role + ", " + suprel.myRole;
1001:                                supportedOrgRoles.put(
1002:                                        suprel.mySupportedOrganization, role);
1003:                            }
1004:
1005:                        }
1006:
1007:                        for (Enumeration roles = supportedOrgRoles.keys(); roles
1008:                                .hasMoreElements();) {
1009:                            String supportedOrg = (String) roles.nextElement();
1010:                            String role = (String) supportedOrgRoles
1011:                                    .get(supportedOrg);
1012:                            org_file.println("Supporting " + '"' + supportedOrg
1013:                                    + '"' + " " + '"' + role + '"');
1014:                        }
1015:
1016:                        // Print TypeIdentificationPG fields
1017:                        org_file.println("\n[TypeIdentificationPG]");
1018:                        org_file.println("TypeIdentification String " + '"'
1019:                                + "UTC/RTOrg" + '"');
1020:                        org_file.println("Nomenclature String " + '"'
1021:                                + org_data.myNomenclature + '"');
1022:                        org_file.println("AlternateTypeIdentification String "
1023:                                + '"' + "SRC/" + org_data.mySRC + '"');
1024:
1025:                        // Print ClusterPG info
1026:                        org_file.println("\n[ClusterPG]");
1027:                        org_file.println("MessageAddress String " + '"'
1028:                                + org_name + '"');
1029:
1030:                        // Print OrganizationPG (Roles) info
1031:                        org_file.println("\n[OrganizationPG]");
1032:                        org_file.print("Roles Collection<Role> " + '"');
1033:                        boolean is_first = true;
1034:                        for (Enumeration roles = org_data.myRoles.elements(); roles
1035:                                .hasMoreElements();) {
1036:                            String role = (String) roles.nextElement();
1037:                            if (!is_first) {
1038:                                org_file.print(", ");
1039:                            }
1040:                            org_file.print(role);
1041:                            is_first = false;
1042:                        }
1043:                        org_file.println('"');
1044:
1045:                        // Print MilitaryOrgPG info
1046:                        org_file.println("\n[MilitaryOrgPG]");
1047:                        org_file.println("UIC String " + '"' + org_data.myUIC
1048:                                + '"');
1049:                        if (org_data.myEchelon.intValue() != -1) {
1050:                            org_file.println("Echelon String " + '"'
1051:                                    + org_data.myEchelon.intValue() + '"');
1052:                        } else {
1053:                            org_file.println("Echelon String " + '"' + '"');
1054:                        }
1055:                        org_file.println("UTC String " + '"' + org_data.myUTC
1056:                                + '"');
1057:                        org_file.println("SRC String " + '"' + org_data.mySRC
1058:                                + '"');
1059:                        if (org_data.myIsReserve == true) {
1060:                            org_file
1061:                                    .println("IsReserve       boolean     true");
1062:                        } else {
1063:                            org_file
1064:                                    .println("IsReserve       boolean     false");
1065:                        }
1066:
1067:                        // Print HomeLocationPG info under Military Org PG
1068:                        org_file.println("HomeLocation     GeolocLocation   "
1069:                                + "\"GeolocCode=" + org_data.myHomeGeoLoc
1070:                                + ", InstallationTypeCode="
1071:                                + org_data.myHomeInstallCode
1072:                                + ", CountryStateCode=" + org_data.myHomeCSCode
1073:                                + ", CountryStateName=" + org_data.myHomeCSName
1074:                                + ", IcaoCode=" + org_data.myHomeICAOCode
1075:                                + ", Name=" + org_data.myHomeLocation
1076:                                + ", Latitude=Latitude "
1077:                                + org_data.myHomeLatitude
1078:                                + "degrees, Longitude=Longitude "
1079:                                + org_data.myHomeLongitude + "degrees\"");
1080:
1081:                        /*
1082:                        // Print AssignmentPG info
1083:                        org_file.println("\n[AssignmentPG]");
1084:                        org_file.println("GeolocCode            String    "+'"'+org_data.myAssignedGeoLoc+'"');
1085:                        org_file.println("InstallationTypeCode  String    "+'"'+org_data.myAssignedInstallCode+'"');
1086:                        org_file.println("CountryStateCode      String    "+'"'+org_data.myAssignedCSCode+'"');
1087:                        org_file.println("CountryStateName      String    "+'"'+org_data.myAssignedCSName+'"');
1088:                        org_file.println("IcaoCode              String    "+'"'+org_data.myAssignedICAOCode+'"');
1089:                         */
1090:                        // Print CSSCapabilities info
1091:                        if (org_data.myCSSCapabilities != null) {
1092:                            is_first = true;
1093:                            org_file.println("\n[CSSCapabilityPG]");
1094:                            org_file
1095:                                    .print("Capabilities Collection<CSSCapability> " + '"');
1096:                            for (Enumeration eCap = org_data.myCSSCapabilities
1097:                                    .elements(); eCap.hasMoreElements();) {
1098:                                CSSCapabilities cssCap = (CSSCapabilities) eCap
1099:                                        .nextElement();
1100:                                if (!is_first) {
1101:                                    org_file.print(", ");
1102:                                }
1103:                                org_file.print(cssCap.capability);
1104:                                org_file.print(" " + cssCap.qty);
1105:                                if (!cssCap.period.equals("")) {
1106:                                    org_file
1107:                                            .print(" Duration=" + cssCap.period);
1108:                                }
1109:                                is_first = false;
1110:                            }
1111:                            org_file.println('"');
1112:                        }
1113:
1114:                        org_file.close();
1115:                    } catch (IOException exc) {
1116:                        System.out.println("IOException:  " + exc);
1117:                        System.exit(-1);
1118:                    }
1119:                }
1120:            }
1121:
1122:            // Utility functions
1123:
1124:            // Create a PrintWriter class for given filename
1125:            private PrintWriter createPrintWriter(String filename)
1126:                    throws IOException {
1127:                return new PrintWriter(new OutputStreamWriter(
1128:                        new FileOutputStream(filename)));
1129:            }
1130:
1131:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.