Source Code Cross Referenced for PersistentDescriptorGenerator.java in  » Database-ORM » ODAL » com » completex » objective » tools » generators » 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 ORM » ODAL » com.completex.objective.tools.generators 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *  Objective Database Abstraction Layer (ODAL)
003:         *  Copyright (c) 2004, The ODAL Development Group
004:         *  All rights reserved.
005:         *  For definition of the ODAL Development Group please refer to LICENCE.txt file
006:         *
007:         *  Distributable under LGPL license.
008:         *  See terms of license at gnu.org.
009:         */package com.completex.objective.tools.generators;
010:
011:        import com.completex.objective.components.persistency.JavaToMetaType;
012:        import com.completex.objective.components.persistency.meta.ModelLoader;
013:        import com.completex.objective.components.persistency.meta.ModelLoaderPlugin;
014:        import com.completex.objective.components.persistency.meta.ModelStorerPlugin;
015:        import com.completex.objective.components.persistency.meta.adapter.ModelLoaderAdapter;
016:        import com.completex.objective.components.persistency.meta.impl.UdtBaseModelLoaderPlugin;
017:        import com.completex.objective.util.PropertyMap;
018:
019:        import java.io.FileReader;
020:        import java.io.IOException;
021:        import java.io.InputStream;
022:        import java.sql.SQLException;
023:        import java.util.Iterator;
024:        import java.util.List;
025:        import java.util.Map;
026:
027:        /**
028:         * Args[0]:      persistent-descriptor-config.properties
029:         * 
030:         * @author Gennady Krizhevsky
031:         */
032:        public class PersistentDescriptorGenerator extends
033:                AbstractPersistentDescriptorGenerator {
034:            public static final String DEFAULT_INTERNAL_DESC_FILE_NAME = "internal_desc_file.sdl";
035:            public static final String DEFAULT_EXTERNAL_DESC_FILE_NAME = "external_desc_file.sdl";
036:            public static final String TAG_TRANSFORMERS = "transformers";
037:
038:            public PersistentDescriptorGenerator() {
039:            }
040:
041:            public PersistentDescriptorGenerator(String propertiesPath)
042:                    throws IOException, IllegalAccessException,
043:                    ClassNotFoundException, InstantiationException,
044:                    SQLException {
045:                this (propertiesPath, null);
046:            }
047:
048:            public PersistentDescriptorGenerator(String propertiesPath,
049:                    String envPath) throws IOException, IllegalAccessException,
050:                    ClassNotFoundException, InstantiationException,
051:                    SQLException {
052:                setup(propertiesPath, envPath);
053:            }
054:
055:            /*
056:              {
057:                   plugins = {
058:                       PLUGIN_01 = {
059:                           loader = {
060:                               class = <className> # Required, must be of ModelLoaderPlugin type
061:                               # config = {} # Optional 
062:                           }
063:                           
064:                           storer = {
065:                               class = <className> # Required, must be of ModelStorerPlugin type
066:                               # config = {} # Optional 
067:                           }
068:                         # ...
069:                       }
070:                   }
071:                   
072:                   transform = { 
073:                      transformers = [
074:                           {
075:                               class = <className> # Required, must be of ModelTransformer type
076:                               # config = {} # Optional 
077:                           }
078:                       ]
079:                   }
080:              }
081:             */
082:            public PersistentDescriptorGenerator(PropertyMap propertyMap)
083:                    throws IOException, IllegalAccessException,
084:                    ClassNotFoundException, InstantiationException,
085:                    SQLException {
086:                setup(propertyMap);
087:            }
088:
089:            public PersistentDescriptorGenerator(InputStream inputStream)
090:                    throws IOException, IllegalAccessException,
091:                    InstantiationException, ClassNotFoundException,
092:                    SQLException {
093:                setup(inputStream);
094:            }
095:
096:            protected void beforeInitModelLoader(PropertyMap propertyMap) {
097:            }
098:
099:            protected void extractExternalFileName(PropertyMap propertyMap) {
100:                externalFileName = propertyMap
101:                        .getProperty(TAG_EXTERNAL_DESC_FILE,
102:                                DEFAULT_EXTERNAL_DESC_FILE_NAME);
103:            }
104:
105:            protected void extractInternalFileName(PropertyMap propertyMap) {
106:                internalFileName = propertyMap
107:                        .getProperty(TAG_INTERNAL_DESC_FILE,
108:                                DEFAULT_INTERNAL_DESC_FILE_NAME);
109:            }
110:
111:            protected ModelLoader getDatabaseModelLoaderAdapter(
112:                    String filterPattern, JavaToMetaType javaToMetaType,
113:                    String schema, String catalog) throws SQLException {
114:                return new ModelLoaderAdapter.DatabaseModelLoaderAdapter(
115:                        schema, catalog, filterPattern, getConnection(), logger);
116:            }
117:
118:            protected void setupTransformers(Map map)
119:                    throws ClassNotFoundException, IllegalAccessException,
120:                    InstantiationException {
121:                ModelTransformer[] transformers = null;
122:                PropertyMap configPropertyMap = PropertyMap.toPropertyMap(map);
123:                if (configPropertyMap != null) {
124:                    PropertyMap config = configPropertyMap
125:                            .getPropertyMap(ModelTransformer.KEY);
126:                    if (config != null) {
127:                        List transformerMaps = config.getList(TAG_TRANSFORMERS);
128:                        if (transformerMaps != null
129:                                && transformerMaps.size() > 0) {
130:                            transformers = new ModelTransformer[transformerMaps
131:                                    .size()];
132:                            for (int i = 0; i < transformerMaps.size(); i++) {
133:                                PropertyMap transformerConfig = PropertyMap
134:                                        .toPropertyMap(((Map) transformerMaps
135:                                                .get(i)));
136:                                String className = transformerConfig
137:                                        .getProperty("class", true);
138:                                Class clazz = Class.forName(className);
139:                                transformers[i] = (ModelTransformer) clazz
140:                                        .newInstance();
141:                                transformers[i].configure(transformerConfig
142:                                        .getPropertyMap("config"));
143:                            }
144:                        }
145:                    }
146:                }
147:                this .transformers = transformers;
148:            }
149:
150:            protected void setupUdtTransformers(Map udtMap)
151:                    throws ClassNotFoundException, IllegalAccessException,
152:                    InstantiationException {
153:                UserDefinedTypeModelTransformer[] transformers = null;
154:                PropertyMap configPropertyMap = PropertyMap
155:                        .toPropertyMap(udtMap);
156:                if (configPropertyMap != null) {
157:                    PropertyMap config = configPropertyMap
158:                            .getPropertyMap(UdtBaseModelLoaderPlugin.PLUGIN_KEY);
159:                    if (config != null) {
160:                        List transformerMaps = config.getList(TAG_TRANSFORMERS);
161:                        if (transformerMaps != null
162:                                && transformerMaps.size() > 0) {
163:                            transformers = new UserDefinedTypeModelTransformer[transformerMaps
164:                                    .size()];
165:                            for (int i = 0; i < transformerMaps.size(); i++) {
166:                                PropertyMap transformerConfig = PropertyMap
167:                                        .toPropertyMap(((Map) transformerMaps
168:                                                .get(i)));
169:                                String className = transformerConfig
170:                                        .getProperty("class", true);
171:                                Class clazz = Class.forName(className);
172:                                transformers[i] = (UserDefinedTypeModelTransformer) clazz
173:                                        .newInstance();
174:                                transformers[i].configure(transformerConfig
175:                                        .getPropertyMap("config"));
176:                            }
177:                        }
178:                    }
179:                }
180:                udtTransformers = transformers;
181:            }
182:
183:            protected Map setupPlugins(PropertyMap propertyMap)
184:                    throws IOException, ClassNotFoundException,
185:                    InstantiationException, IllegalAccessException {
186:                Map map = null;
187:                String pluginsConfigPath = propertyMap
188:                        .getProperty(TAG_PLUGINS_CONFIG_PATH);
189:                if (pluginsConfigPath != null) {
190:                    map = (Map) sdlReader
191:                            .read(new FileReader(pluginsConfigPath));
192:                    setupPlugins0(map);
193:                }
194:                return map;
195:            }
196:
197:            private void setupPlugins0(Map map) throws ClassNotFoundException,
198:                    InstantiationException, IllegalAccessException, IOException {
199:                PropertyMap configPropertyMap = PropertyMap.toPropertyMap(map);
200:                if (configPropertyMap != null) {
201:                    PropertyMap pluginsConfig = configPropertyMap
202:                            .getPropertyMap("plugins");
203:                    if (pluginsConfig != null) {
204:                        //
205:                        // Register plugins:
206:                        //
207:                        registerPlugins(pluginsConfig);
208:                    }
209:                }
210:            }
211:
212:            private void registerPlugins(PropertyMap configPropertyMap)
213:                    throws ClassNotFoundException, InstantiationException,
214:                    IllegalAccessException, IOException {
215:                for (Iterator it = configPropertyMap.keySet().iterator(); it
216:                        .hasNext();) {
217:                    String key = (String) it.next();
218:                    PropertyMap config = configPropertyMap.getPropertyMap(key,
219:                            true);
220:                    //
221:                    // Loader:
222:                    //
223:                    PropertyMap loaderConfig = config.getPropertyMap("loader");
224:                    if (loaderConfig != null) {
225:                        String classString = loaderConfig.getProperty("class",
226:                                true);
227:                        Class loaderClass = Class.forName(classString);
228:                        ModelLoaderPlugin loaderPlugin = (ModelLoaderPlugin) loaderClass
229:                                .newInstance();
230:                        modelLoaderAdapter.registerPlugin(loaderPlugin);
231:                        PropertyMap pluginConfig = loaderConfig
232:                                .getPropertyMap("config");
233:                        loaderPlugin.configure(pluginConfig);
234:                        if (loaderPlugin.needsConnection()) {
235:                            loaderPlugin.setConnection(transaction
236:                                    .getConnection());
237:                        }
238:                    }
239:                    //
240:                    // Storer:
241:                    //
242:                    PropertyMap storerConfig = config.getPropertyMap("storer");
243:                    if (storerConfig != null) {
244:                        String classString = storerConfig.getProperty("class",
245:                                true);
246:                        Class storerClass = Class.forName(classString);
247:                        ModelStorerPlugin storerPlugin = (ModelStorerPlugin) storerClass
248:                                .newInstance();
249:                        modelStorerAdapter.registerPlugin(storerPlugin);
250:                        PropertyMap pluginConfig = storerConfig
251:                                .getPropertyMap("config");
252:                        storerPlugin.configure(pluginConfig);
253:                    }
254:                }
255:            }
256:
257:            public static void main(String[] args) throws Exception {
258:                if (args.length < 1) {
259:                    System.out
260:                            .println("Usage: [persisent-descriptor-generator] <persistent-descriptor-config.properties> <env.properties>\n"
261:                                    + "  where <persistent-descriptor-config.properties> - required configuration file path;\n"
262:                                    + "        <env.properties> - optional token resolution file path.");
263:                    System.exit(1);
264:                }
265:                String envPath = args.length > 1 ? args[1] : null;
266:
267:                PersistentDescriptorGenerator generator = new PersistentDescriptorGenerator(
268:                        args[0], envPath);
269:                generator.generate();
270:                generator.dispose();
271:            }
272:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.