Source Code Cross Referenced for Main.java in  » J2EE » enhydra » org » enhydra » tool » archive » 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 » J2EE » enhydra » org.enhydra.tool.archive 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Enhydra Java Application Server Project
003:         *
004:         * The contents of this file are subject to the Enhydra Public License
005:         * Version 1.1 (the "License"); you may not use this file except in
006:         * compliance with the License. You may obtain a copy of the License on
007:         * the Enhydra web site ( http://www.enhydra.org/ ).
008:         *
009:         * Software distributed under the License is distributed on an "AS IS"
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011:         * the License for the specific terms governing rights and limitations
012:         * under the License.
013:         *
014:         * The Initial Developer of the Enhydra Application Server is Lutris
015:         * Technologies, Inc. The Enhydra Application Server and portions created
016:         * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017:         * All Rights Reserved.
018:         *
019:         * Contributor(s):
020:         * Paul Mahar
021:         *
022:         */
023:        package org.enhydra.tool.archive;
024:
025:        // ToolBox imports
026:        import org.enhydra.tool.ToolBoxInfo;
027:        import org.enhydra.tool.common.SwingUtil;
028:        import org.enhydra.tool.common.PathHandle;
029:        import org.enhydra.tool.common.ResUtil;
030:
031:        // Standard imports
032:        import java.io.File;
033:        import java.util.ResourceBundle;
034:        import java.util.StringTokenizer;
035:        import java.util.ArrayList;
036:
037:        //
038:        public class Main {
039:            static public boolean debug = true;
040:
041:            // not to be resourced
042:            static ResourceBundle res = ResourceBundle
043:                    .getBundle("org.enhydra.tool.archive.Res"); // nores
044:
045:            //
046:            private static final String PARAM_HELP = "-help"; // nores
047:            //Zeljko Kovacevic 28.10 2003 comment this
048:            /*    
049:             private static final String PARAM_EJB_ARCHIVE = "-ejbArchive";    // nores
050:             private static final String PARAM_EAR_ARCHIVE = "-earArchive";    // nores
051:             */
052:
053:            private static final String PARAM_JAR_ARCHIVE = "-jarArchive"; // nores
054:            private static final String PARAM_WEB_ARCHIVE = "-webArchive"; // nores
055:            private static final String PARAM_CLASSPATH = "-classpath"; // nores
056:            private static final String PARAM_FILES = "-files"; // nores
057:            private static final String PARAM_NO_ALT = "-noAlt"; // nores
058:            private static final String PARAM_LIB = "-lib"; // nores
059:
060:            public Main() {
061:                System.out.println("Archive Wizard "
062:                        + ToolBoxInfo.getToolBoxVersion());
063:                System.out.println(ToolBoxInfo.getCopyright());
064:            }
065:
066:            public static void main(String[] args) {
067:                Main main = new Main();
068:
069:                main.init(args);
070:                System.exit(0);
071:            }
072:
073:            private void init(String[] args) {
074:                ArchiveTool packager = null;
075:                File newFile = null;
076:                JarPlan plan = null;
077:
078:                if (args.length < 1) {
079:                    String newArchive = null;
080:
081:                    SwingUtil.setLookAndFeelToSystem();
082:                    newArchive = ArchiveTool.runWizard();
083:                    if (newArchive == null) {
084:                        System.out.println("No archive created.");
085:                    } else {
086:                        System.out.println("Created archive: " + newArchive);
087:                    }
088:                } else if (args[0].equalsIgnoreCase(PARAM_HELP)) {
089:                    showUsage();
090:                } else {
091:                    try {
092:                        plan = parsePlanArgs(args);
093:                        plan.setClassFiltering(true);
094:                        packager = new ArchiveTool();
095:                        newFile = packager.buildArchive(plan);
096:                        System.out.println(ResUtil.format(res
097:                                .getString("Created_file_0_"), newFile));
098:                    } catch (ArgumentException e) {
099:                        System.out.println(ResUtil.format(res
100:                                .getString("Error_0_"), e.getMessage()));
101:                        showUsage();
102:                    } catch (ArchiveException e) {
103:                        System.out.println(ResUtil.format(res
104:                                .getString("Error_0_"), e.getMessage()));
105:                    }
106:                }
107:            }
108:
109:            private JarPlan parsePlanArgs(String[] args)
110:                    throws ArgumentException {
111:                JarPlan plan = null;
112:
113:                if (args.length < 1) {
114:                    throw new ArgumentException(res
115:                            .getString("Too_few_arguments"));
116:                    //Zeljko Kovacevic 28.10 2003 comment this
117:                    /*            
118:                     } else if (args[0].equalsIgnoreCase(PARAM_EJB_ARCHIVE)) {
119:                     plan = parseEjbArgs(args);
120:                     } else if (args[0].equalsIgnoreCase(PARAM_EAR_ARCHIVE)) {
121:                     plan = parseEarArgs(args);
122:                     */
123:                } else if (args[0].equalsIgnoreCase(PARAM_JAR_ARCHIVE)) {
124:                    plan = parseJarArgs(args);
125:                } else if (args[0].equalsIgnoreCase(PARAM_WEB_ARCHIVE)) {
126:                    plan = parseWarArgs(args);
127:                } else {
128:                    throw new ArgumentException(ResUtil.format(res
129:                            .getString("First_argument_must"),
130:                            PARAM_WEB_ARCHIVE, PARAM_JAR_ARCHIVE));
131:                }
132:                return plan;
133:            }
134:
135:            //Zeljko Kovacevic 28.10 2003 comment this
136:            /*
137:             private EjbPlan parseEjbArgs(String[] args) throws ArgumentException {
138:             EjbPlan ejbPlan = null;
139:             int     cursor = 1;
140:
141:             if (args.length < 5) {
142:             throw new ArgumentException(res.getString("Too_few_arguments"));
143:             } else if (args.length >= 8) {
144:             throw new ArgumentException(ResUtil.format(res.getString("Too_many_arguments"),
145:             PARAM_EJB_ARCHIVE));
146:             } else if (!args[1].equals(PARAM_CLASSPATH)) {
147:             throw new ArgumentException(ResUtil.format(res.getString("Missing_parameter_"),
148:             PARAM_CLASSPATH));
149:             } else {
150:             try {
151:             Descriptor[] desc = new Descriptor[1];
152:
153:             desc[0] = new Descriptor(true, Descriptor.EJB);
154:             ejbPlan = new EjbPlan();
155:             cursor = readClasses(ejbPlan, args);
156:             desc[0].setPath(args[cursor++]);
157:             desc[0].validate();
158:             ejbPlan.setDescriptors(desc);
159:             ejbPlan.setArchivePath(args[cursor]);
160:             } catch (ArchiveException e) {
161:             throw new ArgumentException(e.getMessage());
162:             }
163:             }
164:             return ejbPlan;
165:             }
166:
167:             private EarPlan parseEarArgs(String[] args) throws ArgumentException {
168:             EarPlan         earPlan = null;
169:             StringTokenizer tokenizer = null;
170:             PathHandle ph  = null;
171:             int             cursor = 1;
172:
173:             if (args.length < 4) {
174:             throw new ArgumentException(res.getString("Too_few_arguments"));
175:             } else if (args.length > 8) {
176:             throw new ArgumentException(ResUtil.format(res.getString("Too_many_arguments"),
177:             PARAM_EAR_ARCHIVE));
178:             } else {
179:             try {
180:             earPlan = new EarPlan();
181:             {
182:             String[] files = new String[0];
183:
184:             tokenizer = new StringTokenizer(args[cursor++], ":");
185:             while (tokenizer.hasMoreTokens()) {
186:             ph = PathHandle.createPathHandle(tokenizer.nextToken());
187:             if (ph.hasExtension("war")) {
188:             earPlan.addWebApplication(ph.getPath());
189:             } else {
190:             earPlan.addEnterpriseModule(ph.getPath());
191:             }
192:             }
193:             }
194:             cursor = readLibFiles(earPlan, args, cursor);
195:             if (args[cursor].equalsIgnoreCase(PARAM_NO_ALT)) {
196:             earPlan.setAlt(false);
197:             cursor++;
198:             }
199:             earPlan.setAppName(args[cursor++]);
200:             earPlan.setArchivePath(args[cursor]);
201:             } catch (ArchiveException e) {
202:             throw new ArgumentException(e.getMessage());
203:             }
204:             }
205:             return earPlan;
206:             }
207:             */
208:            private JarPlan parseJarArgs(String[] args)
209:                    throws ArgumentException {
210:                JarPlan jarPlan = null;
211:                int cursor = 1;
212:
213:                if (args.length < 4) {
214:                    throw new ArgumentException(res
215:                            .getString("Too_few_arguments"));
216:                } else if (args.length >= 7) {
217:                    throw new ArgumentException(ResUtil
218:                            .format(res.getString("Too_many_arguments"),
219:                                    PARAM_JAR_ARCHIVE));
220:                } else if (!args[1].equals(PARAM_CLASSPATH)) {
221:                    throw new ArgumentException(ResUtil
222:                            .format(res.getString("Second_argument_must"),
223:                                    PARAM_CLASSPATH));
224:                } else {
225:                    try {
226:                        jarPlan = new JarPlan();
227:                        cursor = readClasses(jarPlan, args);
228:                        jarPlan.setArchivePath(args[cursor]);
229:                    } catch (ArchiveException e) {
230:                        throw new ArgumentException(e.getMessage());
231:                    }
232:                }
233:                return jarPlan;
234:            }
235:
236:            private WarPlan parseWarArgs(String[] args)
237:                    throws ArgumentException {
238:                WarPlan warPlan = null;
239:                ArrayList list = new ArrayList();
240:                StringTokenizer tokenizer = null;
241:                StringBuffer buf = new StringBuffer();
242:                PathHandle path = null;
243:                int cursor = 1;
244:
245:                if (args.length < 4) {
246:                    throw new ArgumentException(res
247:                            .getString("Too_few_arguments"));
248:                } else if (args.length > 10) {
249:                    throw new ArgumentException(res
250:                            .getString("Too_many_arguments1"));
251:                } else {
252:                    try {
253:                        Descriptor[] desc = new Descriptor[1];
254:
255:                        desc[0] = new Descriptor(true, Descriptor.WEB);
256:                        warPlan = new WarPlan();
257:                        cursor = readClasses(warPlan, args);
258:                        warPlan.setContentRoot(args[cursor++]);
259:
260:                        // read content
261:                        if (args[cursor].equalsIgnoreCase(PARAM_FILES)) {
262:                            String[] files = new String[0];
263:
264:                            cursor++;
265:                            tokenizer = new StringTokenizer(args[cursor++], ":");
266:                            while (tokenizer.hasMoreTokens()) {
267:                                buf.setLength(0);
268:                                buf.append(warPlan.getContentRoot());
269:                                buf.append(File.separator);
270:                                buf.append(tokenizer.nextToken());
271:                                path = PathHandle.createPathHandle(buf
272:                                        .toString());
273:                                if (path.isFile()) {
274:                                    list.add(path.getPath());
275:                                } else {
276:                                    System.err.println("File not found: "
277:                                            + path.getPath());
278:                                }
279:                            }
280:                            list.trimToSize();
281:                            files = (String[]) list.toArray(files);
282:                            list.clear();
283:                            warPlan.setContentFiles(files);
284:                        }
285:                        cursor = readLibFiles(warPlan, args, cursor);
286:                        desc[0].setPath(args[cursor++]);
287:                        desc[0].validate();
288:                        warPlan.setDescriptors(desc);
289:                        warPlan.setArchivePath(args[cursor]);
290:                    } catch (ArrayIndexOutOfBoundsException e) {
291:                        throw new ArgumentException("Archiving syntax error");
292:                    } catch (ArchiveException e) {
293:                        throw new ArgumentException(e.getMessage());
294:                    }
295:                }
296:                return warPlan;
297:            }
298:
299:            private int readClasses(JarPlan plan, String[] args)
300:                    throws ArchiveException {
301:                StringTokenizer tokenizer = null;
302:                ArrayList list = new ArrayList();
303:                StringBuffer buf = new StringBuffer();
304:                PathHandle path = null;
305:                int cursor = 1;
306:
307:                if (args[1].equalsIgnoreCase(PARAM_CLASSPATH)) {
308:                    plan.setClassRoot(args[2]);
309:                    cursor = 3;
310:                    if (args[cursor].equalsIgnoreCase(PARAM_FILES)) {
311:                        String[] files = new String[0];
312:
313:                        cursor++;
314:                        tokenizer = new StringTokenizer(args[cursor++], ":");
315:                        while (tokenizer.hasMoreTokens()) {
316:                            buf.setLength(0);
317:                            buf.append(args[2]);
318:                            buf.append(File.separator);
319:                            buf.append(tokenizer.nextToken());
320:                            path = PathHandle.createPathHandle(buf.toString());
321:                            if (path.isFile()) {
322:                                list.add(path.getPath());
323:                            } else {
324:                                System.err.println("File not found: "
325:                                        + path.getPath());
326:                            }
327:                        }
328:                        list.trimToSize();
329:                        files = (String[]) list.toArray(files);
330:                        list.clear();
331:                        plan.setClassFiles(files);
332:                    }
333:                }
334:                return cursor;
335:            }
336:
337:            private int readLibFiles(JarPlan plan, String[] args, int cursor)
338:                    throws ArchiveException {
339:                StringTokenizer tokenizer = null;
340:                ArrayList list = new ArrayList();
341:
342:                if (args[cursor].equalsIgnoreCase(PARAM_LIB)) {
343:                    cursor++;
344:                    String[] files = new String[0];
345:
346:                    tokenizer = new StringTokenizer(args[cursor++], ":");
347:                    while (tokenizer.hasMoreTokens()) {
348:                        list.add(tokenizer.nextToken());
349:                    }
350:                    list.trimToSize();
351:                    files = (String[]) list.toArray(files);
352:                    list.clear();
353:                    plan.setLibFiles(files);
354:                }
355:                return cursor;
356:            }
357:
358:            private void showUsage() {
359:                System.out.println(new String());
360:                System.out.println(res.getString("Parameters_"));
361:                //Zeljko Kovacevic 28.10 2003 comment this
362:                /*
363:                 // EJB .jar archive
364:                 System.out.print(' ');
365:                 System.out.println(PARAM_EJB_ARCHIVE);
366:                 System.out.print("     ");
367:                 System.out.println(getClassUsage());
368:                 System.out.print("     ");
369:                 System.out.print("<ejb-jar.xml>");
370:                 System.out.print(' ');
371:                 System.out.println(res.getString("_archive_file_"));
372:                 System.out.println(' ');
373:
374:                 // enterprise
375:                 System.out.print(' ');
376:                 System.out.println(PARAM_EAR_ARCHIVE);
377:                 System.out.print("     ");
378:                 System.out.println("moduleArchive1:moduleArchive2:...");
379:                 System.out.print("     ");
380:                 System.out.println("[" + PARAM_LIB + " jar1:jar2:...]");
381:                 System.out.print("     ");
382:                 System.out.println("[" + PARAM_NO_ALT + "]");
383:                 System.out.print("     ");
384:                 System.out.println("<application-name> <archive-fle>");
385:                 System.out.println("");
386:                 */
387:                // jar archive
388:                System.out.print(' ');
389:                System.out.println(PARAM_JAR_ARCHIVE);
390:                System.out.print("     ");
391:                System.out.print(getClassUsage());
392:                System.out.print(' ');
393:                System.out.println(res.getString("_archive_file_"));
394:                System.out.println("");
395:
396:                // web archive
397:                System.out.print(' ');
398:                System.out.println(PARAM_WEB_ARCHIVE);
399:                System.out.print("     ");
400:                System.out.println("[ " + getClassUsage() + " ]");
401:                System.out.print("     ");
402:                System.out.println("[" + PARAM_LIB + " jar1:jar2:...]");
403:                System.out.print("     ");
404:                System.out.print(res.getString("_content_root_"));
405:                System.out.print(' ');
406:                System.out.print('[');
407:                System.out.print(PARAM_FILES);
408:                System.out.print(' ');
409:                System.out.print("file1:file2...");
410:                System.out.println(']');
411:                System.out.print("     ");
412:                System.out.print(res.getString("_web_xml_"));
413:                System.out.print(' ');
414:                System.out.println(res.getString("_archive_file_"));
415:                System.out.println(' ');
416:            }
417:
418:            private String getClassUsage() {
419:                StringBuffer buf = new StringBuffer();
420:
421:                buf.append(PARAM_CLASSPATH);
422:                buf.append(' ');
423:                buf.append(res.getString("_classes_root_"));
424:                buf.append(' ');
425:                buf.append('[');
426:                buf.append(PARAM_FILES);
427:                buf.append(' ');
428:                buf.append("file1:file2...");
429:                buf.append(']');
430:                return buf.toString();
431:            }
432:
433:            class ArgumentException extends Exception {
434:                public ArgumentException(String msg) {
435:                    super(msg);
436:                }
437:
438:            }
439:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.