Source Code Cross Referenced for DataSourceFactory.java in  » Web-Framework » JAT » com » jat » integration » 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 » Web Framework » JAT » com.jat.integration 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.jat.integration;
002:
003:        import java.util.Enumeration;
004:        import java.util.Hashtable;
005:
006:        import com.jat.core.config.Config;
007:        import com.jat.core.init.Initable;
008:        import com.jat.core.log.LogManager;
009:        import java.util.Vector;
010:
011:        /**
012:         * <p>Title: JAT</p>
013:         * <p>Description: this class handle configurable data sources {@link com.jat.integration.DataSource}.
014:         * </p>
015:         * <p><b>Configuration:</b><br/>
016:         * Put data source list into "data_source" section with:
017:         * <ul>
018:         * <li>data source name</li>
019:         * <li>data source class (a {@link com.jat.integration.DataSource} implementation class)</li>
020:         * </ul>
021:         * <i>Example:</i>
022:         * <blockquote>
023:         * [data_source]<br>
024:         * data_source1.name = <i>myDataSource</i><br>
025:         * data_source1.class = <i>myDataSourceClass</i><br>
026:         * data_source2.name = <i>mySecondDataSource</i><br>
027:         * data_source2.class = <i>mySecondDataSourceClass</i><br>
028:         * </blockquote>
029:         * <br>For each data source name create a new section named as the data source name.
030:         * <br>Put properties into this section according with your data source class
031:         * </p>
032:         * <p>Copyright: Copyright (c) 2004 -2005 Stefano Fratini (stefano.fratini@gmail.com)</p>
033:         * <p>Distributed under the terms of the GNU Lesser General Public License, v2.1 or later</p>
034:         * @author stf
035:         * @version 1.2
036:         * @since 1.2
037:         * @see com.jat.integration.DataSource
038:         */
039:
040:        public final class DataSourceFactory implements  Initable {
041:
042:            public final static String CONFIG_SECTION = "data_source";
043:            public final static String CONFIG_DATA_SOURCE_KEY = "data_source";
044:            public final static String CONFIG_CLASS_KEY = ".class";
045:            public final static String CONFIG_NAME_KEY = ".name";
046:            public final static String CONFIG_ENABLED = ".enabled";
047:
048:            public DataSourceFactory() {
049:            }
050:
051:            public void init() throws Exception {
052:                LogManager.sendDebug(this .getClass().getName()
053:                        + "::init: start");
054:                dataSourceFactory = this ;
055:                dataSources = new Hashtable();
056:                Vector keys = Config.getCurrent().getSubKeys(CONFIG_SECTION,
057:                        CONFIG_DATA_SOURCE_KEY);
058:                for (Enumeration e = keys.elements(); e.hasMoreElements();) {
059:                    String key = (String) e.nextElement();
060:                    String className = Config.getCurrent().getValue(
061:                            CONFIG_SECTION, key + CONFIG_CLASS_KEY);
062:                    String name = Config.getCurrent().getValue(CONFIG_SECTION,
063:                            key + CONFIG_NAME_KEY);
064:                    boolean enabled = true;
065:                    try {
066:                        enabled = Config.getCurrent().getValue(CONFIG_SECTION,
067:                                key + CONFIG_ENABLED).equalsIgnoreCase("true");
068:                    } catch (Exception ignored) {
069:                    }
070:                    if (enabled) {
071:                        LogManager.sendDebug(this .getClass().getName()
072:                                + "::init: initing data source " + name);
073:                        try {
074:                            DataSource dataSource = (DataSource) Class.forName(
075:                                    className).newInstance();
076:                            dataSource.init(name);
077:                            dataSources.put(name, dataSource);
078:                            LogManager.sendDebug(this .getClass().getName()
079:                                    + "::init: data source '" + name + "'("
080:                                    + className + ") successfully inited");
081:                        } catch (Exception ex) {
082:                            LogManager.sendError(this .getClass().getName()
083:                                    + "::init: exception loading data source '"
084:                                    + name + "': " + ex);
085:                        }
086:                    } else
087:                        LogManager.sendDebug(this .getClass().getName()
088:                                + "::init: data source '" + name
089:                                + "' is disabled");
090:                }
091:                LogManager.sendDebug(this .getClass().getName() + "::init: end");
092:            }
093:
094:            public DataSource getDataSource(String name)
095:                    throws IntegrationException {
096:                DataSource ds = (DataSource) dataSources.get(name);
097:                if (ds == null) {
098:                    LogManager.sendWarning(this .getClass().getName()
099:                            + "::getDataSource: Data source '" + name
100:                            + "' not found");
101:                    throw new IntegrationException("Data source '" + name
102:                            + "' not found");
103:                }
104:                return ds;
105:            }
106:
107:            public static DataSourceFactory getFactory() {
108:                return dataSourceFactory;
109:            }
110:
111:            public Enumeration names() {
112:                return this .dataSources.keys();
113:            }
114:
115:            private static Hashtable dataSources = null;
116:            private static DataSourceFactory dataSourceFactory = null;
117:
118:            /** @link dependency
119:             * @stereotype instantiate*/
120:            /*# DataSource lnkDataSource; */
121:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.