Source Code Cross Referenced for GenericDataSource.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:        import java.util.Properties;
006:        import java.util.Vector;
007:
008:        import com.jat.core.config.Config;
009:        import com.jat.core.log.LogManager;
010:        import com.jat.util.OrderVector;
011:
012:        /**
013:         * <p>Title: JAT</p>
014:         * <p>Description:This class is an abstract class that implement Data Sources
015:         * (see {@link com.jat.integration.DataSource}
016:         * It is able to initialize Data Source loading its configured operations
017:         * (see {@link com.jat.integration.GenericOperationDefinition})
018:         * and relative configures fields
019:         * (see {@link com.jat.integration.GenericFieldDefinition})</p>
020:         * <p>Copyright: Copyright (c) 2004 -2005 Stefano Fratini (stefano.fratini@gmail.com)</p>
021:         * <p>Distributed under the terms of the GNU Lesser General Public License, v2.1 or later</p>
022:         * @author stf
023:         * @version 1.0
024:         * @since 1.2
025:         */
026:
027:        public abstract class GenericDataSource implements  DataSource {
028:
029:            /**
030:             * Use this method to initilize your Data Source
031:             * @throws IntegrationException, if any exeption occours
032:             */
033:            protected abstract void initDataSource()
034:                    throws IntegrationException;
035:
036:            /**
037:             * This method is used to get the {@link com.jat.integration.GenericOperationDefinition} implementaion
038:             * of your GenericDataSource
039:             * @return your {@link com.jat.integrationGenericOperationDefinition} implemnation instance
040:             */
041:            public abstract GenericOperationDefinition getEmptyOperationDefinition();
042:
043:            /**
044:             * Save the content of the Data Source
045:             * @throws java.lang.Exception if any exception occour
046:             */
047:            public void persist() throws Exception {
048:                Config config = this .getConfig();
049:                Hashtable origSec = config.removeSection(this .getName());
050:                config.addSection(this .getName());
051:                Hashtable sec = config.getSection(this .getName());
052:                sec = this .putInitProperties(sec);
053:                int index = 1;
054:                for (Enumeration e = this .operations.elements(); e
055:                        .hasMoreElements();) {
056:                    GenericOperationDefinition operation = (GenericOperationDefinition) e
057:                            .nextElement();
058:                    sec = this .getOperationConfig(sec, operation, index);
059:                    index++;
060:                }
061:                config.save();
062:            }
063:
064:            protected abstract Hashtable putInitProperties(Hashtable hash)
065:                    throws Exception;
066:
067:            protected Hashtable getOperationConfig(Hashtable sec,
068:                    GenericOperationDefinition operation, int index) {
069:                sec.put(operation.getConfigKey() + index
070:                        + operation.CONFIG_NAME, operation.getName());
071:                sec.put(operation.getConfigKey() + index
072:                        + operation.CONFIG_VALUE, operation.getValue());
073:                Properties properties = operation.getProperties();
074:                for (Enumeration e = properties.propertyNames(); e
075:                        .hasMoreElements();) {
076:                    String prop = (String) e.nextElement();
077:                    String propVal = properties.getProperty(prop);
078:                    sec.put(operation.getConfigKey() + index + "." + prop,
079:                            propVal);
080:                }
081:                sec = this .getFieldConfig(sec, operation, index);
082:
083:                return sec;
084:            }
085:
086:            protected Hashtable getFieldConfig(Hashtable sec,
087:                    GenericOperationDefinition operation, int index) {
088:                int fieldIndex = 1;
089:                for (Enumeration e = operation.fields(); e.hasMoreElements();) {
090:                    GenericFieldDefinition field = (GenericFieldDefinition) e
091:                            .nextElement();
092:                    sec.put(operation.getConfigKey() + index
093:                            + field.CONFIG_FIELD + fieldIndex
094:                            + field.CONFIG_NAME, field.getName());
095:                    Properties properties = field.getProperties();
096:                    for (Enumeration e2 = properties.propertyNames(); e2
097:                            .hasMoreElements();) {
098:                        String prop = (String) e2.nextElement();
099:                        String propVal = properties.getProperty(prop);
100:                        sec.put(operation.getConfigKey() + index
101:                                + field.CONFIG_FIELD + fieldIndex + "." + prop,
102:                                propVal);
103:                    }
104:                    fieldIndex++;
105:                }
106:                return sec;
107:            }
108:
109:            /**
110:             * This method initializes Data Source properties and Operation Properties
111:             * @param name the Data Source name
112:             * @throws IntegrationException if any exception occours during initialization
113:             */
114:            public void init(String name) throws IntegrationException {
115:                this .name = name;
116:                this .initDataSource();
117:                this .initOperations();
118:            }
119:
120:            /**
121:             * Return the Data Source name
122:             * @return the Data Source name
123:             */
124:            public String getName() {
125:                return this .name;
126:            }
127:
128:            /**
129:             * Get the Operation by name
130:             * @param name the configured operation name
131:             * @return the operation instance
132:             * @throws IntegrationException if the configured operation name does not exist
133:             */
134:            public GenericOperationDefinition getOperation(String name)
135:                    throws IntegrationException {
136:                GenericOperationDefinition god = (GenericOperationDefinition) this .operations
137:                        .get(name);
138:                if (god == null)
139:                    throw new IntegrationException(this .getClass().getName()
140:                            + "::getQueryDefinition: operation '" + name
141:                            + "' does not exist");
142:                return god;
143:            }
144:
145:            public Enumeration operationNames() {
146:                return this .operations.keys();
147:            }
148:
149:            /**
150:             * Get operations
151:             * @return the iterator of operations
152:             */
153:            public Enumeration operations() {
154:                return operations.elements();
155:            }
156:
157:            public int operationSize() {
158:                return this .operations.size();
159:            }
160:
161:            public GenericOperationDefinition removeOperation(String operation) {
162:                return (GenericOperationDefinition) this .operations
163:                        .remove(operation);
164:            }
165:
166:            public void addOperation(GenericOperationDefinition operation) {
167:                this .operations.put(operation.getName(), operation);
168:            }
169:
170:            public String toString() {
171:                String ret = "[NAME=" + this .getName() + "]" + " [OPERATIONS={";
172:                if (this .operations != null) {
173:                    int i = 0;
174:                    for (Enumeration e = this .operations(); e.hasMoreElements();) {
175:                        ret += (e.nextElement()).toString();
176:                        if (i++ < this .operations.size() - 1)
177:                            ret += ";";
178:                    }
179:                }
180:                ret += "}]";
181:                return ret;
182:            }
183:
184:            protected Config getConfig() throws Exception {
185:                String confname = Config.getCurrent().getValue(
186:                        DataSourceFactory.CONFIG_SECTION, "config.name");
187:                Config config = Config.getCurrent().getConfig(confname);
188:                if (config == null) {
189:                    LogManager.sendError(this .getClass().getName()
190:                            + "::getConfig: exception: Config file " + confname
191:                            + " not found");
192:                    throw new Exception("Config file " + confname
193:                            + " not found");
194:                }
195:                return config;
196:            }
197:
198:            /**
199:             * This method initailizes Data Source operations (see {@link com.jat.integration.GenericOperationDefinition})
200:             * @throws IntegrationException if any exception occours during initialization
201:             */
202:            protected void initOperations() throws IntegrationException {
203:                LogManager.sendDebug(this .getClass().getName()
204:                        + "::initOperations: start");
205:                try {
206:                    Config config = this .getConfig();
207:                    this .operations = new Hashtable();
208:                    String configKey = this .getEmptyOperationDefinition()
209:                            .getConfigKey();
210:                    for (Enumeration e = config
211:                            .getSubKeys(this .name, configKey).elements(); e
212:                            .hasMoreElements();) {
213:                        GenericOperationDefinition god = getEmptyOperationDefinition();
214:                        god.init(this .name, (String) e.nextElement());
215:                        this .operations.put(god.getName(), god);
216:                    }
217:                } catch (Exception ex) {
218:                    throw new IntegrationException(this .getClass().getName()
219:                            + "::initOperations:: exception: " + ex);
220:                }
221:                LogManager.sendDebug(this .getClass().getName()
222:                        + "::initOperations: end");
223:            }
224:
225:            private String name;
226:            private Hashtable operations = new Hashtable();
227:
228:            /** @link dependency
229:             * @stereotype use*/
230:            /*# GenericOperationDefinition lnkGenericOperationDefinition; */
231:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.