Source Code Cross Referenced for LoadJobWriter.java in  » Database-JDBC-Connection-Pool » octopus » org » webdocwf » util » loader » generator » 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 JDBC Connection Pool » octopus » org.webdocwf.util.loader.generator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:             LoaderGenerator - tool for generated xml, sql and doml file needed for Octopus.
003:            Copyright (C) 2003  Together
004:            This library is free software; you can redistribute it and/or
005:            modify it under the terms of the GNU Lesser General Public
006:            License as published by the Free Software Foundation; either
007:            version 2.1 of the License, or (at your option) any later version.
008:            This library is distributed in the hope that it will be useful,
009:            but WITHOUT ANY WARRANTY; without even the implied warranty of
010:            MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
011:            Lesser General Public License for more details.
012:            You should have received a copy of the GNU Lesser General Public
013:            License along with this library; if not, write to the Free Software
014:            Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
015:         */
016:
017:        package org.webdocwf.util.loader.generator;
018:
019:        import javax.xml.parsers.DocumentBuilder;
020:        import javax.xml.parsers.DocumentBuilderFactory;
021:        import javax.xml.parsers.ParserConfigurationException;
022:
023:        import java.util.Enumeration;
024:        import java.util.Hashtable;
025:        import java.io.File;
026:        import java.io.*;
027:        import java.util.*;
028:        import org.apache.xml.serialize.OutputFormat;
029:        import org.apache.xml.serialize.XMLSerializer;
030:        import org.apache.xml.serialize.Method;
031:
032:        import org.w3c.dom.Document;
033:
034:        import org.w3c.dom.Element;
035:
036:        import org.webdocwf.util.loader.LoaderException;
037:        import org.webdocwf.util.loader.logging.Logger;
038:        import org.webdocwf.util.loader.logging.StandardLogger;
039:
040:        /**
041:         * Class LoadJobWriter creates and loads LoaderJob.xml file from the input
042:         * parameters and source database.
043:         * @author Radoslav Dutina
044:         * @version 1.0
045:         */
046:        public class LoadJobWriter {
047:
048:            private Document document;
049:            private Logger logger;
050:
051:            /**
052:             * Construct object LoadJobWriter with associated parameter.
053:             * @param generatorParameters represents the references to InputParameter object.
054:             * @throws LoaderException
055:             */
056:
057:            public LoadJobWriter(InputParameters generatorParameters)
058:                    throws LoaderException {
059:
060:                DocumentBuilderFactory factory = DocumentBuilderFactory
061:                        .newInstance();
062:                try {
063:                    setLogger();
064:                    this .logger.write("normal",
065:                            "Generating of LoaderJob.olj file is started.");
066:                    loadJobWriter(generatorParameters, factory);
067:                    this .logger.write("normal",
068:                            "Generating of LoaderJob.olj file is finished.");
069:                } catch (ParserConfigurationException pce) {
070:                    // Parser with specified options can't be built
071:                    String msg = "Parser with specified options can't be built! Exception has occurred when parser is"
072:                            + "try to parse the LoaderJob.olj file!";
073:                    LoaderException le = new LoaderException(msg + "\n"
074:                            + pce.getMessage(), (Throwable) pce);
075:                    throw le;
076:                }
077:            }
078:
079:            /**
080:             * This method generate LoaderJob.olj fajl
081:             * @param generatorParameters
082:             * @param factory
083:             * @throws ParserConfigurationException
084:             * @throws LoaderException
085:             */
086:            private void loadJobWriter(InputParameters generatorParameters,
087:                    DocumentBuilderFactory factory)
088:                    throws ParserConfigurationException, LoaderException {
089:
090:                this .logger.write("normal",
091:                        "\tloadJobWriter method is started.");
092:                DocumentBuilder builder = factory.newDocumentBuilder();
093:                document = builder.newDocument(); // Create from whole cloth
094:
095:                // Create root element (loaderJob)
096:                Element root = (Element) document.createElement("loaderJob");
097:                document.appendChild(root);
098:
099:                LoaderJobAttributes loaderJob = new LoaderJobAttributes();
100:
101:                root.setAttribute("logMode", loaderJob.getLogMode());
102:                root.setAttribute("objectIDIncrement", loaderJob
103:                        .getObjectIDIncrement());
104:                root.setAttribute("objectIDTableName", loaderJob
105:                        .getObjectIDTableName());
106:                root.setAttribute("objectIDColumnName", loaderJob
107:                        .getObjectIDColumnName());
108:
109:                // Create child (jdbcDefaultParameters)
110:                Element childRoot = (Element) document
111:                        .createElement("jdbcDefaultParameters");
112:                root.appendChild(childRoot);
113:
114:                // Create child  (jdbcSourceParameters)
115:                Element childRoot2 = (Element) document
116:                        .createElement("jdbcSourceParameters");
117:                childRoot.appendChild(childRoot2);
118:
119:                JdbcParameters sourceJdbc = new JdbcParameters("source",
120:                        generatorParameters);
121:
122:                childRoot2.setAttribute("dbVendor", sourceJdbc.getDbVendor());
123:                childRoot2.setAttribute("driverName", sourceJdbc
124:                        .getDriverName());
125:
126:                // Create child (jdbcSourceParameter)
127:                Hashtable sourceTable = sourceJdbc.getAllParameters();
128:                Enumeration enumSource = sourceTable.keys();
129:                while (enumSource.hasMoreElements()) {
130:                    Element childRoot3 = (Element) document
131:                            .createElement("jdbcSourceParameter");
132:                    childRoot2.appendChild(childRoot3);
133:                    String key = (String) enumSource.nextElement();
134:                    childRoot3.setAttribute("name", key);
135:                    childRoot3.setAttribute("value", (String) sourceTable
136:                            .get(key));
137:                }
138:
139:                // Create child (jdbcTargetParameters)
140:                Element childRoot5 = (Element) document
141:                        .createElement("jdbcTargetParameters");
142:                childRoot.appendChild(childRoot5);
143:
144:                JdbcParameters targetJdbc = new JdbcParameters("target",
145:                        generatorParameters);
146:
147:                //Reading the value of AlterTablePrimaryKey parameter.
148:                //      generatorParameters.setAlterTablePrimaryKey(targetJdbc.getAlterTablePrimaryKey());
149:
150:                childRoot5.setAttribute("dbVendor", targetJdbc.getDbVendor());
151:                childRoot5.setAttribute("driverName", targetJdbc
152:                        .getDriverName());
153:
154:                // Create child (jdbcTargetParameter)
155:                Hashtable targetTable = targetJdbc.getAllParameters();
156:                Enumeration enumTarget = targetTable.keys();
157:                while (enumTarget.hasMoreElements()) {
158:                    Element childRoot6 = (Element) document
159:                            .createElement("jdbcTargetParameter");
160:                    childRoot5.appendChild(childRoot6);
161:                    String key = (String) enumTarget.nextElement();
162:                    childRoot6.setAttribute("name", key);
163:                    childRoot6.setAttribute("value", (String) targetTable
164:                            .get(key));
165:                }
166:
167:                Vector sqlStatement = generatorParameters.getSqlToGenerate();
168:                int sqlFileType = 0;
169:                while (sqlFileType < 6) {
170:                    // Create child (sql)
171:                    if (sqlFileType == 3) {
172:                        // Create child (definitionInclude)
173:                        Element childRoot20 = (Element) document
174:                                .createElement("definitionInclude");
175:                        root.appendChild(childRoot20);
176:                        // Create child (include)
177:                        Element childRoot21 = (Element) document
178:                                .createElement("include");
179:                        childRoot20.appendChild(childRoot21);
180:
181:                        IncludeTagAttributes includeTagAttributes = new IncludeTagAttributes();
182:
183:                        //relative path from LoaderJob.olj file
184:                        String pathXml = includeTagAttributes.getHref();
185:                        pathXml.trim();
186:                        childRoot21.setAttribute("href", pathXml);
187:                        childRoot21.setAttribute("parse", includeTagAttributes
188:                                .getParse());
189:                    }
190:                    if (sqlFileType == 4
191:                            && generatorParameters.getAlterTablePrimaryKey()
192:                                    .equalsIgnoreCase("false")) {
193:                        // only for hsql database
194:                    } else {
195:                        if (generatorParameters.getRestoreMode()
196:                                .equalsIgnoreCase("false")) {
197:                            if (sqlStatement.get(sqlFileType) != null) {
198:                                Element childRoot10 = (Element) document
199:                                        .createElement("sql");
200:                                root.appendChild(childRoot10);
201:                                SqlTagAttributes sqlTagAttributes = new SqlTagAttributes(
202:                                        sqlFileType);
203:                                childRoot10.setAttribute("name",
204:                                        sqlTagAttributes.getName());
205:                                //              childRoot10.setAttribute("logMode", sqlTagAttributes.getLogMode());
206:                                childRoot10.setAttribute("commit",
207:                                        sqlTagAttributes.getCommit());
208:                                //ZK added next line 7.5.2004
209:                                childRoot10.setAttribute("onErrorContinue",
210:                                        sqlTagAttributes.getOnErrorContinue());
211:
212:                                // Create child (sqlStmt)
213:                                Element childRoot11 = (Element) document
214:                                        .createElement("sqlStmt");
215:                                childRoot10.appendChild(childRoot11);
216:
217:                                // Create child (include)
218:                                Element childRoot12 = (Element) document
219:                                        .createElement("include");
220:                                childRoot11.appendChild(childRoot12);
221:
222:                                //relative path from LoaderJob.olj file
223:                                String pathSql = sqlTagAttributes.getHref();
224:                                pathSql.trim();
225:                                childRoot12.setAttribute("href", pathSql);
226:                                childRoot12.setAttribute("parse",
227:                                        sqlTagAttributes.getParse());
228:                            } //end of sqlStatement.get(sqlFileType)
229:
230:                        } else if (generatorParameters.getRestoreMode()
231:                                .equalsIgnoreCase("true")) {
232:                            //this is use only for restoring the database
233:                            Element childRoot10 = (Element) document
234:                                    .createElement("sql");
235:                            root.appendChild(childRoot10);
236:                            SqlTagAttributes sqlTagAttributes = new SqlTagAttributes(
237:                                    sqlFileType);
238:                            childRoot10.setAttribute("name", sqlTagAttributes
239:                                    .getName());
240:                            //              childRoot10.setAttribute("logMode", sqlTagAttributes.getLogMode());
241:                            childRoot10.setAttribute("commit", sqlTagAttributes
242:                                    .getCommit());
243:                            //ZK added next line 10.5.2004
244:                            childRoot10.setAttribute("onErrorContinue",
245:                                    sqlTagAttributes.getOnErrorContinue());
246:                            // Create child (sqlStmt)
247:                            Element childRoot11 = (Element) document
248:                                    .createElement("sqlStmt");
249:                            childRoot10.appendChild(childRoot11);
250:
251:                            // Create child (include)
252:                            Element childRoot12 = (Element) document
253:                                    .createElement("include");
254:                            childRoot11.appendChild(childRoot12);
255:                            //relative path from LoaderJob.olj file
256:                            String pathSql = sqlTagAttributes.getHref();
257:                            pathSql.trim();
258:                            childRoot12.setAttribute("href", pathSql);
259:                            childRoot12.setAttribute("parse", sqlTagAttributes
260:                                    .getParse());
261:                        }
262:                    }
263:                    sqlFileType++;
264:                }
265:                if (generatorParameters.getGenerateXml().equalsIgnoreCase(
266:                        "true")) {
267:                    try {
268:                        File file = null;
269:                        String slash = null;
270:                        if (generatorParameters.getGeneratorOutput()
271:                                .equalsIgnoreCase("")) {
272:                            file = new File("");
273:                            slash = "";
274:                        } else {
275:                            file = new File(generatorParameters
276:                                    .getGeneratorOutput());
277:                            slash = "/";
278:                        }
279:                        if (!file.exists())
280:                            file.mkdirs();
281:
282:                        FileOutputStream os = new FileOutputStream(file + slash
283:                                + "LoaderJob.olj");
284:                        OutputFormat of = new OutputFormat(); //xerces apache.xml.serializer
285:                        of.setIndenting(true);
286:                        of.setIndent(4);
287:                        of.setMethod(Method.XML);
288:                        of.setPreserveSpace(false);
289:                        of.setLineWidth(0);
290:                        XMLSerializer out = new XMLSerializer(os, of);
291:
292:                        //IOException
293:                        out.serialize(document);
294:                    } catch (Exception e) {
295:                        String msg = "Exception has occurred when we try to set output format for LoaderJob.olj file.";
296:                        //if (this.logger != null) {
297:                        LoaderException le = new LoaderException(msg + "\n"
298:                                + e.getMessage(), (Throwable) e);
299:                        this .logger
300:                                .write(
301:                                        "full",
302:                                        "Exception has occurred when we try to set output format for LoaderJob.olj file."
303:                                                + "\n"
304:                                                + le.getStackTraceAsString());
305:                        //}
306:                        throw le;
307:                    }
308:                }
309:                this .logger.write("normal",
310:                        "\tloadJobWriter method is finished.");
311:            }
312:
313:            /**
314:             * This method will set logger object
315:             * @param logger
316:             */
317:            private void setLogger() {
318:                this.logger = StandardLogger.getCentralLogger();
319:            }
320:
321:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.