Source Code Cross Referenced for DTProperties.java in  » Database-Client » squirrel-sql-2.6.5a » net » sourceforge » squirrel_sql » fw » datasetviewer » cellcomponent » 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 » Database Client » squirrel sql 2.6.5a » net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent;
002:
003:        /*
004:         * Copyright (C) 2001-2003 Colin Bell
005:         * colbell@users.sourceforge.net
006:         *
007:         * This library is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License as published by the Free Software Foundation; either
010:         * version 2.1 of the License, or (at your option) any later version.
011:         *
012:         * This library is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this library; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
020:         */
021:        /**
022:         * @author gwg
023:         * Object to save, manage and restore DataType-specific properties. 
024:         * We expect most of these to be settable
025:         * by the user, but this can be used to save anything that is class-specific
026:         * in the DataType objects.
027:         * <P>
028:         * IMPORTANT: It is the responsibility of the DataType classes to put the
029:         * property/value pair into this class.  This class does not proactively
030:         * go out to the DataTypes looking for properties to be saved.
031:         * <P>
032:         * This object is created from a file during application startup by the code in
033:         * net.sourceforge.squirrel_sql.client.Application
034:         * and saved on application shutdown.
035:         * The application deals with one view of the data, while internally the
036:         * Data Type objects work with an entirely different view of the same data.
037:         * The data is converted from one form to the other during loading and
038:         * getting of the data when requesed by the Application.
039:         * <P>
040:         * The application sees the data as an array of strings.
041:         * <P>
042:         * The Data Types see the data as individual String properties.
043:         * The DataTypes may convert the String to some other form such as
044:         * a number or a boolean, but that is not the concern of this class.
045:         * Individual properties are accessed based on the DataType class name
046:         * and the name of the property.
047:         * DataTypes are free to create new properties at any time.
048:         * This class just stores what is passed to it and returns those values
049:         * when asked.
050:         * <P>
051:         * This is named DTProperties rather than DataTypeProperties because that
052:         * name would indicate that this is another DataType rather than being a 
053:         * set of data items within the other DataTypes.
054:         */
055:
056:        import java.util.HashMap;
057:        import java.util.ArrayList;
058:        import java.util.Iterator;
059:
060:        public class DTProperties {
061:
062:            /**
063:             * The version of the data suitable for loading/unloading from/to files.
064:             * The internal representation is a HashMap containing HashMaps containing strings.
065:             * The XMLReader/Writer Beans in fw.xml do not handle the general case of HashMaps,
066:             * so rather than trying to handle that there, we just convert the data internally into a form
067:             * that those classes can handle, i.e. an array of strings.
068:             * Each string consists of the name of the class, a space, the name of
069:             * a property, an equals, then the contents of the property, which must
070:             * also be a string.
071:             * This is used in an instance of this class created during load/unload.
072:             */
073:            private String[] dataArray = new String[0];
074:
075:            /**
076:             * The mapping from DataType name to object (also a HashMap)
077:             * containing the properties for that DataType.
078:             * There is only one copy of this table for all instances of this class.
079:             */
080:            private static HashMap<String, HashMap<String, String>> dataTypes = new HashMap<String, HashMap<String, String>>();
081:
082:            /**
083:             * ctor
084:             */
085:            public DTProperties() {
086:            }
087:
088:            /**
089:             * get data in form that can be used to output to file.
090:             * This is called from an instance of this class.
091:             */
092:            public String[] getDataArray() {
093:                // first convert internal data into the string array
094:                Iterator<String> keys = dataTypes.keySet().iterator();
095:
096:                ArrayList<String> propertyList = new ArrayList<String>();
097:
098:                // get each DataType's info
099:                while (keys.hasNext()) {
100:                    String tableName = keys.next();
101:                    HashMap<String, String> h = dataTypes.get(tableName);
102:                    Iterator<String> propertyNames = h.keySet().iterator();
103:                    while (propertyNames.hasNext()) {
104:                        String propertyName = propertyNames.next();
105:                        StringBuilder tmp = new StringBuilder(tableName);
106:                        tmp.append(" ");
107:                        tmp.append(propertyName);
108:                        tmp.append("=");
109:                        tmp.append(h.get(propertyName));
110:                        propertyList.add(tmp.toString());
111:                    }
112:                }
113:
114:                dataArray = propertyList.toArray(dataArray);
115:                return dataArray;
116:            }
117:
118:            /**
119:             * Data in the external form (array of strings) is passed in and must be converted
120:             * to the internal form.
121:             * This is called on an instance of this class.
122:             * @param inData array of strings in form "DataTypeClass property=value"
123:             */
124:            public void setDataArray(String[] inData) {
125:                dataTypes = new HashMap<String, HashMap<String, String>>(); // make sure we are starting clean
126:
127:                // convert each string into Classname, prop, & value and fill it into the data
128:                for (int i = 0; i < inData.length; i++) {
129:                    int endIndex = inData[i].indexOf(" ");
130:                    String dataTypeName = inData[i].substring(0, endIndex);
131:
132:                    int startIndex;
133:                    startIndex = endIndex + 1;
134:                    endIndex = inData[i].indexOf("=", startIndex);
135:                    String propertyName = inData[i].substring(startIndex,
136:                            endIndex);
137:                    String propertyValue = inData[i].substring(endIndex + 1);
138:
139:                    // if we have seen a property for this DataType before, then the
140:                    // hashmap already exists.  Otherwise, we need to create it now.
141:                    HashMap<String, String> h = dataTypes.get(dataTypeName);
142:                    if (h == null) {
143:                        h = new HashMap<String, String>();
144:                        dataTypes.put(dataTypeName, h);
145:                    }
146:
147:                    // put the property into the hashmap
148:                    h.put(propertyName, propertyValue);
149:                }
150:            }
151:
152:            /**
153:             * add or replace a table-name/hashmap-of-column-names mapping.
154:             * If map is null, remove the entry from the tables.
155:             */
156:            public static void put(String dataTypeName, String propertyName,
157:                    String propertyValue) {
158:
159:                // get the hashmap for this type, or create it if this is a new property
160:                HashMap<String, String> h = dataTypes.get(dataTypeName);
161:                if (h == null) {
162:                    h = new HashMap<String, String>();
163:                    dataTypes.put(dataTypeName, h);
164:                }
165:                h.put(propertyName, propertyValue);
166:            }
167:
168:            /**
169:             * get the HashMap of column names for the given table name.
170:             * it will be null if the table does not have any limitation on the columns to use.
171:             */
172:            public static String get(String dataTypeName, String propertyName) {
173:                HashMap<String, String> h = dataTypes.get(dataTypeName);
174:                if (h == null)
175:                    return null;
176:
177:                return h.get(propertyName);
178:            }
179:
180:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.