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


001:        package net.sourceforge.squirrel_sql.fw.datasetviewer;
002:
003:        /*
004:         * Copyright (C) 2001 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:        import java.util.HashMap;
023:        import java.util.ArrayList;
024:        import java.util.Iterator;
025:        import java.util.Collections;
026:        import java.util.Arrays;
027:
028:        //import net.sourceforge.squirrel_sql.fw.util.beanwrapper.StringWrapper;
029:
030:        /**
031:         * @author gwg
032:         *
033:         * Save and return Import/Export file name and command
034:         * based on table+column name.  Also allow for load and dump of all data
035:         * on application startup/shutdown.
036:         * 
037:         * There should be only one mapping from table+column to import/export info
038:         * for the entire application, so this is a singleton class.
039:         * To access the table, other classes must call
040:         * CellImportExportInfoSaver.getInstance() to get the singleton instance to use.
041:         * 
042:         * The loading of this from the file is particularly finicky since it involves
043:         * the XMLBean Reader class creating an empty instance of the class and loading
044:         * that instance from the file, then passing that instance in to become the 
045:         * singleton used by the rest of the framework.  Other loading done during startup
046:         * (e.g. SQLHistory) is simpler because the data is "owned" by the application-level
047:         * code, so the singleton is kept there (e.g. _sqlHistory in Application.java).
048:         * That does not make sense here because this data is "owned" and used only by
049:         * the fw code.
050:         */
051:        public class CellImportExportInfoSaver {
052:
053:            /**
054:             * The map holding the data for lookup.
055:             */
056:            private HashMap<String, CellImportExportInfo> map = new HashMap<String, CellImportExportInfo>();
057:
058:            /**
059:             * The list of commands that user has previously entered
060:             */
061:            private ArrayList<String> cmdList = new ArrayList<String>();
062:
063:            /**
064:             * the singleton instance of this class.
065:             */
066:            private static CellImportExportInfoSaver instance = null;
067:
068:            /**
069:             * Null Constructor:
070:             *  This should be used only by the XMLBean creator when loading from file.
071:             */
072:            public CellImportExportInfoSaver() {
073:            };
074:
075:            /**
076:             * get the singleton instance of this class.
077:             */
078:            static public CellImportExportInfoSaver getInstance() {
079:                if (instance == null)
080:                    instance = new CellImportExportInfoSaver();
081:                return instance;
082:            }
083:
084:            /**
085:             * During application startup, an instance of this class is created by
086:             * the XMLBean reader and loaded by it automatically.  After it is done
087:             * loading the entries into that copy, this method is called to make
088:             * that instance become the singleton used by everyone.
089:             */
090:            static public void setInstance(CellImportExportInfoSaver newInstance) {
091:                if (newInstance == null)
092:                    instance = new CellImportExportInfoSaver(); // better safe than sorry!
093:                else
094:                    instance = newInstance;
095:            }
096:
097:            /**
098:             * Used by fw to save user input for export/import on column.
099:             */
100:            public synchronized void save(String tableColumnName,
101:                    String fileName, String command) {
102:
103:                // If the table+column already has a data object in the map,
104:                // then remove it.
105:                map.remove(tableColumnName);
106:
107:                CellImportExportInfo infoObject = new CellImportExportInfo(
108:                        tableColumnName, fileName, command);
109:
110:                map.put(tableColumnName, infoObject);
111:
112:                if (command != null && command.length() > 0) {
113:                    cmdList.add(command);
114:                    Collections.sort(cmdList);
115:                }
116:
117:            }
118:
119:            /**
120:             * Used by fw to find entries user previously entered for this column.
121:             */
122:            public CellImportExportInfo get(String tableColumnName) {
123:                return map.get(tableColumnName);
124:            }
125:
126:            /**
127:             * Used by fw to get the list of all commands this user has associated
128:             * with columns.
129:             */
130:            public synchronized String[] getCmdList() {
131:                String[] data = new String[cmdList.size()];
132:                return cmdList.toArray(data);
133:            }
134:
135:            /**
136:             * Used by fw to delete an entry or to make sure entry does not
137:             * exist in table, e.g. because it has been reset to defaults.
138:             */
139:            static public void remove(String tableColumnName) {
140:                // make sure there is an instance
141:                if (instance == null)
142:                    instance = new CellImportExportInfoSaver(); // better safe than sorry!
143:                instance.map.remove(tableColumnName);
144:            }
145:
146:            /**
147:             * method used by XMLBeans to add new item.
148:             */
149:            public void add(CellImportExportInfo info) {
150:                map.put(info.getTableColumnName(), info);
151:            }
152:
153:            /**
154:             * Method called by reflection in the XMLBean loading of
155:             * CellImportExportInfo data from
156:             * the files during application startup.
157:             */
158:            public synchronized void setData(CellImportExportInfo[] data) {
159:                for (int i = 0; i < data.length; i++) {
160:                    map.put(data[i].getTableColumnName(), data[i]);
161:                }
162:            }
163:
164:            /**
165:             * Method called by reflection in the XMLBean loading of command list
166:             * data from the files during application startup.
167:             */
168:            public synchronized void setCmdList(String[] data) {
169:                cmdList = new ArrayList<String>(Arrays.asList(data));
170:                Collections.sort(cmdList);
171:            }
172:
173:            /**
174:             * Method used by the application code when unloading this object
175:             * into a file for storage during program shutdown.  It is called
176:             * by reflection in the XMLBean Writer code.
177:             */
178:            public synchronized CellImportExportInfo[] getData() {
179:                if (instance == null)
180:                    instance = new CellImportExportInfoSaver(); // better safe than sorry!
181:
182:                CellImportExportInfo[] array = new CellImportExportInfo[instance.map
183:                        .size()];
184:                Iterator<CellImportExportInfo> iterator = instance.map.values()
185:                        .iterator();
186:                int index = 0;
187:                while (iterator.hasNext()) {
188:                    array[index] = iterator.next();
189:                    index++;
190:                }
191:
192:                return array;
193:            }
194:
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.