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


001:        package net.sourceforge.squirrel_sql.plugins.dataimport.prefs;
002:
003:        /*
004:         * Copyright (C) 2007 Thorsten Mürell
005:         *
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU General Public License
008:         * as published by the Free Software Foundation; either version 2
009:         * of the License, or any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:         * GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
019:         */
020:
021:        import java.io.File;
022:        import java.io.FileNotFoundException;
023:        import java.io.IOException;
024:        import java.util.Iterator;
025:
026:        import net.sourceforge.squirrel_sql.client.plugin.IPlugin;
027:        import net.sourceforge.squirrel_sql.client.plugin.PluginException;
028:        import net.sourceforge.squirrel_sql.client.plugin.PreferenceUtil;
029:        import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
030:        import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
031:        import net.sourceforge.squirrel_sql.fw.xml.XMLBeanReader;
032:        import net.sourceforge.squirrel_sql.fw.xml.XMLBeanWriter;
033:
034:        /**
035:         * This class manages the preferences.
036:         * 
037:         * @author Thorsten Mürell
038:         */
039:        public class PreferencesManager {
040:
041:            /** Logger for this class. */
042:            private final static ILogger s_log = LoggerController
043:                    .createLogger(PreferencesManager.class);
044:
045:            /** Name of preferences file. */
046:            private static final String USER_PREFS_FILE_NAME = "prefs.xml";
047:
048:            /** Folder to store user settings in. */
049:            private static File _userSettingsFolder;
050:
051:            private static DataImportPreferenceBean _prefs = null;
052:
053:            private static IPlugin plugin = null;
054:
055:            /**
056:             * Initializes the PreferencesManager
057:             * 
058:             * @param thePlugin
059:             * @throws PluginException
060:             */
061:            public static void initialize(IPlugin thePlugin)
062:                    throws PluginException {
063:                plugin = thePlugin;
064:
065:                // Folder to store user settings.
066:                try {
067:                    _userSettingsFolder = plugin.getPluginUserSettingsFolder();
068:                } catch (IOException ex) {
069:                    throw new PluginException(ex);
070:                }
071:
072:                loadPrefs();
073:            }
074:
075:            /**
076:             * Returns the preferences holder
077:             * 
078:             * @return The bean holding the preferences for the dataimport plugin.
079:             */
080:            public static DataImportPreferenceBean getPreferences() {
081:                return _prefs;
082:            }
083:
084:            /**
085:             * Saves the preferences.
086:             */
087:            public static void unload() {
088:                savePrefs();
089:            }
090:
091:            /**
092:             * Save preferences to disk.  Always write to the user settings folder, not
093:             * the application settings folder.
094:             */
095:            public static void savePrefs() {
096:                try {
097:                    XMLBeanWriter wtr = new XMLBeanWriter(_prefs);
098:                    wtr
099:                            .save(new File(_userSettingsFolder,
100:                                    USER_PREFS_FILE_NAME));
101:                } catch (Exception ex) {
102:                    s_log.error("Error occured writing to preferences file: "
103:                            + USER_PREFS_FILE_NAME, ex);
104:                }
105:            }
106:
107:            /**
108:             * Load from preferences file.
109:             */
110:            private static void loadPrefs() {
111:                try {
112:                    XMLBeanReader doc = new XMLBeanReader();
113:
114:                    File prefFile = PreferenceUtil
115:                            .getPreferenceFileToReadFrom(plugin);
116:
117:                    doc.load(prefFile, DataImportPreferenceBean.class
118:                            .getClassLoader());
119:
120:                    Iterator<?> it = doc.iterator();
121:                    if (it.hasNext()) {
122:                        _prefs = (DataImportPreferenceBean) it.next();
123:                    }
124:                } catch (FileNotFoundException ignore) {
125:                    s_log.info(USER_PREFS_FILE_NAME
126:                            + " not found - will be created");
127:                } catch (Exception ex) {
128:                    s_log.error("Error occured reading from preferences file: "
129:                            + USER_PREFS_FILE_NAME, ex);
130:                }
131:                if (_prefs == null) {
132:                    _prefs = new DataImportPreferenceBean();
133:                }
134:            }
135:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.