Source Code Cross Referenced for ETLBLPackager.java in  » IDE-Netbeans » etl.project » org » netbeans » modules » etlbulkloader » packager » 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 » IDE Netbeans » etl.project » org.netbeans.modules.etlbulkloader.packager 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * To change this template, choose Tools | Templates
003:         * and open the template in the editor.
004:         */
005:        package org.netbeans.modules.etlbulkloader.packager;
006:
007:        import org.netbeans.modules.etlbulkloader.tools.ETLBLUtils;
008:        import org.netbeans.modules.etlbulkloader.tools.CopyFile;
009:        import java.io.BufferedWriter;
010:        import java.io.File;
011:        import java.io.FileWriter;
012:        import java.io.IOException;
013:        import java.util.ArrayList;
014:        import java.util.HashMap;
015:        import java.util.Iterator;
016:        import net.java.hulp.i18n.Logger;
017:        import org.netbeans.modules.etl.logger.Localizer;
018:        import org.netbeans.modules.etl.logger.LogUtil;
019:
020:        /**
021:         *
022:         * @author Manish
023:         */
024:        public class ETLBLPackager {
025:
026:            String projecthome = null;
027:            HashMap<String, String> modelAndEngineFilesMap = new HashMap();
028:            ArrayList triggerStrings = new ArrayList();
029:            private static transient final Logger mLogger = LogUtil
030:                    .getLogger(ETLBLPackager.class.getName());
031:            private static transient final Localizer mLoc = Localizer.get();
032:
033:            public ETLBLPackager() {
034:                mLogger.infoNoloc(mLoc.t("Init ETL Bulk Loader Packaging ..."));
035:            }
036:
037:            public ETLBLPackager(String projecthome) {
038:                this ();
039:                this .projecthome = projecthome;
040:                createETLExecutableDir();
041:            }
042:
043:            private void createETLExecutableDir() {
044:                String packageContainer = this .projecthome
045:                        + ETLBLPkgConstants.fs + ETLBLPkgConstants.toplevelpkg;
046:                boolean statusL = ETLBLUtils.checkIfPackageExists(
047:                        packageContainer, true);
048:                if (!statusL) {
049:                    mLogger
050:                            .infoNoloc(mLoc
051:                                    .t("ERROR: Unable To Create ETLLoader Package in the project home : "
052:                                            + packageContainer));
053:                    System.exit(0);
054:                }
055:                String eTLProcessContainer = packageContainer
056:                        + ETLBLPkgConstants.fs + ETLBLPkgConstants.toplevelrt;
057:                boolean statusP = ETLBLUtils.checkIfPackageExists(
058:                        eTLProcessContainer, true);
059:                if (!statusP) {
060:                    mLogger
061:                            .infoNoloc(mLoc
062:                                    .t("ERROR: Unable To Create ETLProcess Package in the project home : "
063:                                            + eTLProcessContainer));
064:                    System.exit(0);
065:                }
066:            }
067:
068:            public void createExecutablePackage() {
069:                String pathToeTLDefinitionFiles = this .projecthome
070:                        + ETLBLPkgConstants.fs
071:                        + ETLBLPkgConstants.collabFolderName;
072:                String pathToeTLEngineFiles = this .projecthome
073:                        + ETLBLPkgConstants.fs
074:                        + ETLBLPkgConstants.buildFolderName;
075:                mLogger
076:                        .infoNoloc(mLoc
077:                                .t("Building package for artifacts under package :: \n"
078:                                        + "ETL Definition file :: "
079:                                        + pathToeTLDefinitionFiles
080:                                        + "\n"
081:                                        + "ETL Engine file :: "
082:                                        + pathToeTLEngineFiles));
083:
084:                //Validate if each model file has an engine file generated, build a list
085:                correlateModelAndEngineFiles(pathToeTLDefinitionFiles,
086:                        pathToeTLEngineFiles);
087:
088:                //Copy Model and Engine files in respective packages
089:                if (this .modelAndEngineFilesMap != null) {
090:                    Iterator i = this .modelAndEngineFilesMap.keySet()
091:                            .iterator();
092:                    while (i.hasNext()) {
093:                        String modelfilename = (String) i.next();
094:                        String enginefilename = (String) this .modelAndEngineFilesMap
095:                                .get(modelfilename);
096:                        copyETLArtifactsToPackage(pathToeTLDefinitionFiles
097:                                + ETLBLPkgConstants.fs + modelfilename,
098:                                pathToeTLEngineFiles + ETLBLPkgConstants.fs
099:                                        + enginefilename);
100:                    }
101:
102:                    //Copy Libs
103:                    copyRequiredLibsToPackage();
104:
105:                    //Copy and Create Triggers
106:                    copyAndAppendTriggers();
107:                }
108:            }
109:
110:            private void correlateModelAndEngineFiles(String modelp,
111:                    String enginep) {
112:                boolean statusModelp = ETLBLUtils.checkIfPackageExists(modelp,
113:                        false);
114:                boolean statusEnginep = ETLBLUtils.checkIfPackageExists(
115:                        enginep, false);
116:                if (!statusModelp) {
117:                    mLogger
118:                            .infoNoloc(mLoc
119:                                    .t("ERROR: Missing Source package from eTL Project : "
120:                                            + modelp));
121:                    System.exit(0);
122:                } else if (!statusEnginep) {
123:                    mLogger
124:                            .infoNoloc(mLoc
125:                                    .t("ERROR: Missing Source package from eTL Project : "
126:                                            + enginep));
127:                    System.exit(0);
128:                } else {
129:                    //Read All the Model Files available under model files path.
130:                    File models = new File(modelp);
131:                    File engines = new File(enginep);
132:                    String[] modelfiles = models.list();
133:                    String[] enginefiles = engines.list();
134:
135:                    for (int i = 0; i < modelfiles.length; i++) {
136:                        boolean matchfound = false;
137:                        if (modelfiles[i]
138:                                .indexOf(ETLBLPkgConstants.modelFileSuffix) != -1) {
139:                            String predictedEngineFileName = modelfiles[i]
140:                                    .substring(
141:                                            0,
142:                                            modelfiles[i]
143:                                                    .indexOf(ETLBLPkgConstants.modelFileSuffix))
144:                                    + ETLBLPkgConstants.engineFileSuffix;
145:                            mLogger
146:                                    .infoNoloc(mLoc
147:                                            .t("Predicted engine file name for model [ "
148:                                                    + modelfiles[i]
149:                                                    + " ] is : "
150:                                                    + predictedEngineFileName));
151:                            // This model must have corresponding engine file built
152:                            for (int j = 0; j < enginefiles.length; j++) {
153:                                if (enginefiles[j]
154:                                        .equals(predictedEngineFileName)) {
155:                                    matchfound = true;
156:                                    this .modelAndEngineFilesMap.put(
157:                                            modelfiles[i],
158:                                            predictedEngineFileName);
159:                                    break;
160:                                }
161:                            }
162:                            if (!matchfound) {
163:                                mLogger
164:                                        .warnNoloc(mLoc
165:                                                .t("WARNING: Engine file does not exist for model : "
166:                                                        + modelfiles[i]
167:                                                        + ".\n"
168:                                                        + "This will be excluded from the eTL Bulk Loader Package"));
169:                            }
170:                        }
171:                    }
172:                }
173:            }
174:
175:            private void copyETLArtifactsToPackage(String absmodelf,
176:                    String absenginef) {
177:                File etlmodel = new File(absmodelf);
178:                String sourcefilename = etlmodel.getName();
179:                String sourcepackage = null;
180:                if ((sourcefilename.indexOf(".")) != -1) {
181:                    sourcepackage = sourcefilename.substring(0,
182:                            sourcefilename.indexOf(".")).toUpperCase();
183:                } else {
184:                    sourcepackage = sourcefilename.toUpperCase();
185:                }
186:
187:                //Output Directory
188:                String outdir = this .projecthome + ETLBLPkgConstants.fs
189:                        + ETLBLPkgConstants.toplevelpkg + ETLBLPkgConstants.fs
190:                        + ETLBLPkgConstants.toplevelrt + ETLBLPkgConstants.fs
191:                        + sourcepackage;
192:                boolean outpackageStatus = ETLBLUtils.checkIfPackageExists(
193:                        outdir, true);
194:
195:                if (outpackageStatus) {
196:                    ETLBLUtils.copyFile(absmodelf, outdir);
197:                    ETLBLUtils.copyFile(absenginef, outdir);
198:
199:                    //Build an entry for inserting into the trigger
200:                    buildTriggerEntry(sourcepackage, new File(absenginef)
201:                            .getName());
202:                } else {
203:                    mLogger
204:                            .infoNoloc(mLoc
205:                                    .t("ERROR: Unable to create output package for eTL process : "
206:                                            + outdir));
207:                }
208:            }
209:
210:            private void buildTriggerEntry(String srcfoldername,
211:                    String enginefilename) {
212:                StringBuilder sb = new StringBuilder();
213:                sb
214:                        .append("java -cp %CP% -Xms256M -Xmx1024M %JAVA_OPTS% ETLEngineInvoker .");
215:                sb.append(ETLBLPkgConstants.fs + "ETLProcess"
216:                        + ETLBLPkgConstants.fs);
217:                sb.append(srcfoldername + ETLBLPkgConstants.fs);
218:                sb.append(enginefilename);
219:                this .triggerStrings.add(sb.toString());
220:            }
221:
222:            private void copyRequiredLibsToPackage() {
223:                //Create a lib folder if not exists
224:                String trgtLibdir = this .projecthome + ETLBLPkgConstants.fs
225:                        + ETLBLPkgConstants.pkglibs;
226:                String srcLibPath = ETLBLPkgConstants.srclibs;
227:                mLogger.infoNoloc(mLoc.t("copyRequiredLibsToPackage****** "
228:                        + srcLibPath));
229:                boolean status = ETLBLUtils.checkIfPackageExists(trgtLibdir,
230:                        true);
231:                if (status) {
232:                    //NOTE : ***** Check if some of these libs can be copied from project system directly *****
233:                    File srclibs = new File(srcLibPath);
234:                    String[] libnames = srclibs.list();
235:                    for (int i = 0; i < libnames.length; i++) {
236:                        mLogger.infoNoloc(mLoc.t("Copying Lib [ " + libnames[i]
237:                                + " ] ..."));
238:                        //eTLBLUtils.copyFile(srcLibPath + eTLBLPkgConstants.fs + libnames[i], trgtLibdir);
239:                        try {
240:                            CopyFile.copyFile(new File(srcLibPath
241:                                    + ETLBLPkgConstants.fs + libnames[i]),
242:                                    new File(trgtLibdir + ETLBLPkgConstants.fs
243:                                            + libnames[i]));
244:                        } catch (IOException e) {
245:                            e.printStackTrace();
246:                        }
247:                    }
248:                } else {
249:                    mLogger.infoNoloc(mLoc
250:                            .t("ERROR: Unable to create lib package : "
251:                                    + trgtLibdir));
252:                }
253:            }
254:
255:            private void copyAndAppendTriggers() {
256:                //Copy the triggers first to the root dir
257:                File triggertempl = new File(ETLBLPkgConstants.srctriggertempl);
258:                String[] triggerstemp = triggertempl.list();
259:                for (int i = 0; i < triggerstemp.length; i++) {
260:                    ETLBLUtils.copyFile(ETLBLPkgConstants.srctriggertempl
261:                            + ETLBLPkgConstants.fs + triggerstemp[i],
262:                            this .projecthome + ETLBLPkgConstants.fs
263:                                    + ETLBLPkgConstants.toplevelpkg);
264:                }
265:
266:                //Modicy trigger with invocation calls
267:                String triggerpkg = this .projecthome + ETLBLPkgConstants.fs
268:                        + ETLBLPkgConstants.toplevelpkg;
269:                File finaltrigfiles = new File(triggerpkg);
270:                String[] triggers = finaltrigfiles.list();
271:                for (int i = 0; i < triggers.length; i++) {
272:                    if ((triggers[i].indexOf(".bat") != -1)
273:                            || (triggers[i].indexOf(".sh") != -1)) {
274:                        BufferedWriter out = null;
275:                        try {
276:                            mLogger.infoNoloc(mLoc
277:                                    .t("Creating eTL Invocation trigger : "
278:                                            + triggers[i]));
279:                            out = new BufferedWriter(new FileWriter(triggerpkg
280:                                    + ETLBLPkgConstants.fs + triggers[i], true));
281:                            for (int j = 0; j < this .triggerStrings.size(); j++) {
282:                                out
283:                                        .write("\n"
284:                                                + this .triggerStrings.get(j)
285:                                                        .toString());
286:                            }
287:                        } catch (IOException ex) {
288:                            mLogger.errorNoloc(
289:                                    mLoc.t("PRSR023: Exception :{0}", ex
290:                                            .getMessage()), ex);
291:                        } finally {
292:                            try {
293:                                out.close();
294:                            } catch (IOException ex) {
295:                                mLogger.errorNoloc(mLoc.t(
296:                                        "PRSR024: Exception :{0}", ex
297:                                                .getMessage()), ex);
298:                            }
299:                        }
300:                    }
301:                }
302:            }
303:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.