Source Code Cross Referenced for JDBCDatastorePlugin.java in  » ERP-CRM-Financial » jmoney » net » sf » jmoney » jdbcdatastore » 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 » ERP CRM Financial » jmoney » net.sf.jmoney.jdbcdatastore 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         *  JMoney - A Personal Finance Manager
004:         *  Copyright (c) 2004 Nigel Westbury <westbury@users.sourceforge.net>
005:         *
006:         *
007:         *  This program is free software; you can redistribute it and/or modify
008:         *  it under the terms of the GNU General Public License as published by
009:         *  the Free Software Foundation; either version 2 of the License, or
010:         *  (at your option) any later version.
011:         *
012:         *  This program 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
015:         *  GNU General Public License for more details.
016:         *
017:         *  You should have received a copy of the GNU General Public License
018:         *  along with this program; if not, write to the Free Software
019:         *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
020:         *
021:         */
022:
023:        package net.sf.jmoney.jdbcdatastore;
024:
025:        import java.sql.Connection;
026:        import java.sql.DriverManager;
027:        import java.sql.SQLException;
028:        import java.util.MissingResourceException;
029:        import java.util.ResourceBundle;
030:
031:        import org.eclipse.core.runtime.Platform;
032:        import org.eclipse.jface.dialogs.IDialogConstants;
033:        import org.eclipse.jface.dialogs.MessageDialog;
034:        import org.eclipse.ui.IWorkbenchWindow;
035:        import org.eclipse.ui.plugin.AbstractUIPlugin;
036:        import org.osgi.framework.BundleContext;
037:
038:        /**
039:         * The main plugin class to be used in the desktop.
040:         *
041:         * @author Nigel Westbury
042:         */
043:        public class JDBCDatastorePlugin extends AbstractUIPlugin {
044:
045:            public static final boolean DEBUG = "true"
046:                    .equalsIgnoreCase(Platform
047:                            .getDebugOption("net.sf.jmoney.jdbcdatastore/debug"));
048:
049:            //The shared instance.
050:            private static JDBCDatastorePlugin plugin;
051:            //Resource bundle.
052:            private ResourceBundle resourceBundle;
053:
054:            /**
055:             * The constructor.
056:             */
057:            public JDBCDatastorePlugin() {
058:                super ();
059:                plugin = this ;
060:                try {
061:                    resourceBundle = ResourceBundle
062:                            .getBundle("net.sf.jmoney.jdbcdatastore.Language");
063:                } catch (MissingResourceException x) {
064:                    resourceBundle = null;
065:                }
066:            }
067:
068:            /**
069:             * This method is called upon plug-in activation
070:             */
071:            @Override
072:            public void start(BundleContext context) throws Exception {
073:                super .start(context);
074:            }
075:
076:            /**
077:             * This method is called when the plug-in is stopped
078:             */
079:            @Override
080:            public void stop(BundleContext context) throws Exception {
081:                super .stop(context);
082:            }
083:
084:            /**
085:             * Returns the shared instance.
086:             */
087:            public static JDBCDatastorePlugin getDefault() {
088:                return plugin;
089:            }
090:
091:            /**
092:             * Returns the string from the plugin's resource bundle,
093:             * or 'key' if not found.
094:             */
095:            public static String getResourceString(String key) {
096:                ResourceBundle bundle = JDBCDatastorePlugin.getDefault()
097:                        .getResourceBundle();
098:                try {
099:                    return (bundle != null) ? bundle.getString(key) : key;
100:                } catch (MissingResourceException e) {
101:                    return key;
102:                }
103:            }
104:
105:            /**
106:             * Returns the plugin's resource bundle,
107:             */
108:            public ResourceBundle getResourceBundle() {
109:                return resourceBundle;
110:            }
111:
112:            /**
113:             * @param window
114:             * @return
115:             */
116:            public SessionManager readSession(IWorkbenchWindow window) {
117:                SessionManager result = null;
118:
119:                // The following lines cannot return a null value because if
120:                // no value is set then the default value set in
121:                // the above initializeDefaultPreferences method will be returned.
122:                String driver = getPreferenceStore().getString("driver");
123:                String subprotocol = getPreferenceStore().getString(
124:                        "subProtocol");
125:                String subprotocolData = getPreferenceStore().getString(
126:                        "subProtocolData");
127:
128:                String url = "jdbc:" + subprotocol + ":" + subprotocolData;
129:
130:                String user = getPreferenceStore().getString("user");
131:                String password = getPreferenceStore().getString("password");
132:
133:                if (getPreferenceStore().getBoolean("promptEachTime")) {
134:                    // TODO: Put up a dialog box so the user can change
135:                    // the connection options for this connection only.
136:                }
137:
138:                try {
139:                    Class.forName(driver).newInstance();
140:                } catch (InstantiationException e2) {
141:                    // TODO Auto-generated catch block
142:                    e2.printStackTrace();
143:                } catch (IllegalAccessException e2) {
144:                    // TODO Auto-generated catch block
145:                    e2.printStackTrace();
146:                } catch (ClassNotFoundException e2) {
147:                    String title = JDBCDatastorePlugin
148:                            .getResourceString("errorTitle");
149:                    String message = JDBCDatastorePlugin
150:                            .getResourceString("driverNotFound");
151:                    MessageDialog waitDialog = new MessageDialog(window
152:                            .getShell(), title,
153:                            null, // accept the default window icon
154:                            message, MessageDialog.ERROR,
155:                            new String[] { IDialogConstants.OK_LABEL }, 0);
156:                    waitDialog.open();
157:                    return null;
158:                }
159:
160:                try {
161:                    Connection connection = DriverManager.getConnection(url,
162:                            user, password);
163:                    result = new SessionManager(connection);
164:                } catch (SQLException e3) {
165:                    if (e3.getSQLState().equals("08000")) {
166:                        // A connection error which means the database server is probably not running.
167:                        String title = JDBCDatastorePlugin
168:                                .getResourceString("errorTitle");
169:                        String message = JDBCDatastorePlugin
170:                                .getResourceString("connectionFailed");
171:                        MessageDialog waitDialog = new MessageDialog(window
172:                                .getShell(), title,
173:                                null, // accept the default window icon
174:                                message, MessageDialog.ERROR,
175:                                new String[] { IDialogConstants.OK_LABEL }, 0);
176:                        waitDialog.open();
177:                    } else {
178:                        e3.printStackTrace();
179:                        throw new RuntimeException(e3.getMessage());
180:                    }
181:                }
182:
183:                return result;
184:            }
185:
186:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.