Source Code Cross Referenced for ModelStorerAdapter.java in  » Database-ORM » ODAL » com » completex » objective » components » persistency » meta » adapter » 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.components.persistency.meta.adapter 
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.components.persistency.meta.adapter;
010:
011:        import com.completex.objective.components.log.Log;
012:        import com.completex.objective.components.log.adapter.StdErrorLogAdapter;
013:        import com.completex.objective.components.persistency.UserDefinedTypeMetaModel;
014:        import com.completex.objective.components.persistency.meta.MetaModel;
015:        import com.completex.objective.components.persistency.meta.ModelStorer;
016:        import com.completex.objective.components.persistency.meta.ModelStorerPlugin;
017:        import com.completex.objective.components.persistency.meta.impl.FileModelStorerImpl;
018:        import com.completex.objective.components.persistency.meta.impl.NullModelStorerImpl;
019:        import com.completex.objective.components.persistency.meta.impl.UdtModelStorerPlugin;
020:        import com.completex.objective.components.sdl.writer.SdlWriter;
021:        import com.completex.objective.components.sdl.writer.impl.SdlPrinterImpl;
022:
023:        import java.io.IOException;
024:        import java.io.Writer;
025:        import java.util.LinkedHashMap;
026:        import java.util.Map;
027:
028:        /**
029:         * @author Gennady Krizhevsky
030:         */
031:        public class ModelStorerAdapter {
032:
033:            private Log logger = StdErrorLogAdapter.newLogInstance();
034:            private Map plugins = new LinkedHashMap();
035:            private static final SdlWriter sdlWriter = new SdlPrinterImpl();
036:            private ModelStorer externalFileModelStorerAdapter = new NullModelStorerImpl();
037:            private ModelStorer internalFileModelStorerAdapter;
038:
039:            public ModelStorerAdapter(String outputDir,
040:                    String internalFileName, String externalFileName) {
041:                //  assert outputDir != null;
042:
043:                this .internalFileModelStorerAdapter = new InternalFileModelStorerAdapter(
044:                        outputDir, internalFileName);
045:                if (externalFileName != null) {
046:                    this .externalFileModelStorerAdapter = new ExternalFileModelStorerAdapter(
047:                            outputDir, externalFileName);
048:                }
049:            }
050:
051:            public void store(MetaModel model) throws Exception {
052:                store(model, model);
053:            }
054:
055:            protected void store(MetaModel internalModel,
056:                    MetaModel externalModel) throws Exception {
057:                //  assert internalModel != null;
058:                if (externalModel == null) {
059:                    externalModel = internalModel;
060:                }
061:                internalFileModelStorerAdapter.store(internalModel);
062:                externalFileModelStorerAdapter.store(externalModel);
063:
064:                storePluginsData(internalModel);
065:            }
066:
067:            private void storePluginsData(MetaModel model) throws IOException {
068:                //
069:                // plugins related stuff here:
070:                //
071:                if (plugins != null) {
072:                    ModelStorerPlugin plugin = (ModelStorerPlugin) plugins
073:                            .get(UdtModelStorerPlugin.PLUGIN_KEY);
074:                    if (plugin != null) {
075:                        UserDefinedTypeMetaModel userDefinedTypeMetaModel = model
076:                                .getUserDefinedTypeMetaModel();
077:                        plugin.store(userDefinedTypeMetaModel);
078:                    }
079:                }
080:            }
081:
082:            public void registerPlugin(ModelStorerPlugin plugin) {
083:                String key = plugin.getPluginKey();
084:                if (plugins.containsKey(key)) {
085:                    throw new RuntimeException(
086:                            "There is already storer plugin with key " + key);
087:                }
088:                plugins.put(key, plugin);
089:            }
090:
091:            public void unregisterPlugin(String key, ModelStorerPlugin plugin) {
092:                plugins.remove(key);
093:            }
094:
095:            public Log getLogger() {
096:                return logger;
097:            }
098:
099:            private void error(String s, Exception e) {
100:                logger.error(s, e);
101:            }
102:
103:            //
104:            //
105:            //  Auxilliary adapters
106:            //
107:            //
108:            class ExternalFileModelStorerAdapter extends FileModelStorerImpl {
109:
110:                public ExternalFileModelStorerAdapter(String outputDir,
111:                        String fileName) {
112:                    super (outputDir, fileName);
113:                }
114:
115:                protected Map toMap(MetaModel model) {
116:                    return model.toExternalMap();
117:                }
118:
119:                protected void writeModel(Map modelMap, Writer writer)
120:                        throws IOException {
121:                    try {
122:                        sdlWriter.write(writer, modelMap);
123:                    } finally {
124:                        try {
125:                            writer.flush();
126:                        } catch (IOException e) {
127:                            error("Cannot flush", e);
128:                        }
129:                        try {
130:                            writer.close();
131:                        } catch (IOException e) {
132:                            error("Cannot close", e);
133:                        }
134:                    }
135:                }
136:            }
137:
138:            class InternalFileModelStorerAdapter extends FileModelStorerImpl {
139:
140:                public InternalFileModelStorerAdapter(String outputDir,
141:                        String fileName) {
142:                    super (outputDir, fileName);
143:                }
144:
145:                protected Map toMap(MetaModel model) {
146:                    return model.toInternalMap();
147:                }
148:
149:                protected void writeModel(Map modelMap, Writer writer)
150:                        throws IOException {
151:                    try {
152:                        sdlWriter.write(writer, modelMap);
153:                    } finally {
154:                        try {
155:                            writer.flush();
156:                        } catch (IOException e) {
157:                            error("Cannot flush", e);
158:                        }
159:                        try {
160:                            writer.close();
161:                        } catch (IOException e) {
162:                            error("Cannot close", e);
163:                        }
164:                    }
165:                }
166:            }
167:        }
w_w___w_.j__a___v_a___2___s_.___c__o___m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.