Source Code Cross Referenced for ArchiveType.java in  » J2EE » enhydra » org » enhydra » tool » archive » wizard » 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.wizard 
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.wizard;
024:
025:        // ToolBox
026:        import org.enhydra.tool.ToolBoxInfo;
027:        import org.enhydra.tool.archive.Descriptor; //Zeljko Kovacevic 28.10 2003 comment this
028:        /*
029:         import org.enhydra.tool.archive.EarPlan;
030:         import org.enhydra.tool.archive.EjbPlan;
031:         */
032:
033:        import org.enhydra.tool.archive.JarPlan; //Zeljko Kovacevic 28.10 2003 comment this
034:        /*
035:         import org.enhydra.tool.archive.ServicePlan;
036:         */
037:
038:        import org.enhydra.tool.archive.WarPlan;
039:        import org.enhydra.tool.archive.ArchiveException;
040:        import org.enhydra.tool.archive.ArchiveTool;
041:        import org.enhydra.tool.archive.ManifestKeys;
042:        import org.enhydra.tool.common.PathHandle;
043:        import org.enhydra.tool.common.SwingUtil;
044:        import org.enhydra.tool.common.ToolException;
045:
046:        // JDK
047:        import javax.swing.*;
048:        import javax.swing.border.*;
049:        import java.awt.*;
050:        import java.awt.event.ActionEvent;
051:        import java.awt.event.ActionListener;
052:        import java.io.BufferedInputStream;
053:        import java.io.File;
054:        import java.io.FileInputStream;
055:        import java.io.FileNotFoundException;
056:        import java.io.IOException;
057:        import java.util.Properties;
058:        import java.util.ArrayList;
059:        import java.util.ResourceBundle;
060:        import java.util.jar.JarInputStream;
061:        import java.util.jar.JarEntry;
062:        import java.util.jar.Manifest;
063:
064:        //
065:        abstract public class ArchiveType implements  ManifestKeys {
066:            private boolean mru = true;
067:            private JarPlan plan = null;
068:            private ArchivePanel[] panels = new ArchivePanel[0];
069:
070:            static public ArchiveType createType(JarPlan plan) {
071:                ArchiveType type = null;
072:
073:                if (plan instanceof  WarPlan) {
074:                    type = new WarType();
075:                    type.setPlan(plan);
076:                    //Zeljko Kovacevic 28.10 2003 comment this
077:                    /*            
078:                     } else if (plan instanceof EjbPlan) {
079:                     type = new EjbType();
080:                     type.setPlan(plan);
081:                     } else if (plan instanceof EarPlan) {
082:                     type = new EarType();
083:                     type.setPlan(plan);
084:                     } else if (plan instanceof ServicePlan) {
085:                     type = new ServiceType();
086:                     type.setPlan(plan);
087:                     */
088:                } else {
089:
090:                    // default JarPlan
091:                    type = new E3Type();
092:                    type.setPlan(plan);
093:                }
094:                return type;
095:            }
096:
097:            //
098:            static protected ArchiveType[] getAllTypes() {
099:                ArchiveType[] types = new ArchiveType[0];
100:                //Zeljko Kovacevic comment this 30.10 2003 
101:                //        if (ToolBoxInfo.isEnhydra3()) {
102:                types = new ArchiveType[2];
103:                types[0] = new WarType();
104:                types[1] = new E3Type();
105:
106:                //        } else {
107:                //Zeljko Kovacevic 28.10 2003 comment this
108:                /*          	
109:                 types = new ArchiveType[5];
110:                 types[0] = new WarType();
111:                
112:                 types[1] = new EjbType();
113:                 types[2] = new EarType();
114:                 types[3] = new ServiceType();
115:                
116:                 types[4] = new E3Type();
117:                
118:                 }
119:                 */
120:                return types;
121:            }
122:
123:            //
124:            public void setMostRecentlyUsed(boolean b) {
125:                mru = b;
126:            }
127:
128:            public boolean isMostRecentlyUsed() {
129:                return mru;
130:            }
131:
132:            public String toString() {
133:                return getSelectionName();
134:            }
135:
136:            public void readArchive(String archive) {
137:                JarInputStream jar = null;
138:                BufferedInputStream buf = null;
139:                Manifest manifest = null;
140:                JarEntry entry = null;
141:                ArrayList list = new ArrayList();
142:                String[] entries = new String[0];
143:                PathHandle path = PathHandle.createPathHandle(archive);
144:
145:                if (path.isFile()) {
146:                    try {
147:                        getPlan().setArchivePath(path.getPath());
148:                        buf = new BufferedInputStream(new FileInputStream(path
149:                                .getFile()));
150:                        jar = new JarInputStream(buf);
151:                        manifest = jar.getManifest();
152:                        entry = jar.getNextJarEntry();
153:                        while (entry != null) {
154:                            list.add(entry.getName());
155:                            entry = jar.getNextJarEntry();
156:                        }
157:                        list.trimToSize();
158:                        entries = new String[list.size()];
159:                        entries = (String[]) list.toArray(entries);
160:                        list.clear();
161:                        readArchive(manifest, entries);
162:                        jar.close();
163:                        buf.close();
164:                    } catch (FileNotFoundException e) {
165:                        e.printStackTrace(System.err);
166:                    } catch (IOException e) {
167:                        e.printStackTrace(System.err);
168:                    } catch (ArchiveException e) {
169:                        e.printStackTrace(System.err);
170:                    }
171:                }
172:            }
173:
174:            public JarPlan getPlan() throws ArchiveException {
175:                if (plan == null) {
176:                    initPlan();
177:                }
178:                return plan;
179:            }
180:
181:            //
182:            abstract protected String getSelectionName();
183:
184:            abstract protected String getDescription();
185:
186:            abstract protected String getExtension();
187:
188:            abstract protected String getType();
189:
190:            abstract protected void initPanels() throws ArchiveException;
191:
192:            abstract protected void initPlan() throws ArchiveException;
193:
194:            protected void setPlan(JarPlan p) {
195:                plan = p;
196:            }
197:
198:            //
199:            protected String getClassIncludeRoot() {
200:                return new String();
201:            }
202:
203:            protected boolean readArchive(Manifest manifest, String[] entries) {
204:                boolean read = true;
205:                PathHandle root = null;
206:                PathHandle cursor = null;
207:                String[] files = new String[0];
208:                Descriptor[] dd = new Descriptor[0];
209:                ArrayList list = new ArrayList();
210:
211:                if ((manifest == null)) {
212:                    read = false;
213:                } else {
214:                    String value = null;
215:
216:                    try {
217:
218:                        // classes
219:                        value = manifest.getMainAttributes().getValue(
220:                                CLASS_ROOT);
221:                        root = PathHandle.createPathHandle(value);
222:                        if (root.isDirectory()) {
223:                            getPlan().setClassRoot(root.getPath());
224:                            for (int i = 0; i < entries.length; i++) {
225:                                if (entries[i].toUpperCase().startsWith(
226:                                        getClassIncludeRoot())) {
227:                                    cursor = PathHandle
228:                                            .createPathHandle(root.getPath()
229:                                                    + File.separator
230:                                                    + entries[i]
231:                                                            .substring(getClassIncludeRoot()
232:                                                                    .length()));
233:                                    if (cursor.isFile()) {
234:                                        list.add(cursor.getPath());
235:                                    }
236:                                }
237:                            }
238:                            list.trimToSize();
239:                            files = new String[list.size()];
240:                            files = (String[]) list.toArray(files);
241:                            list.clear();
242:                            getPlan().setClassFiles(files);
243:                        }
244:
245:                        // libraries (0 - 99)
246:                        for (int i = 0; i < 100; i++) {
247:                            value = manifest.getMainAttributes().getValue(
248:                                    LIBRARY + i);
249:                            cursor = PathHandle.createPathHandle(value);
250:                            if (cursor.isFile()) {
251:                                list.add(cursor.getPath());
252:                            }
253:                        }
254:                        files = new String[list.size()];
255:                        files = (String[]) list.toArray(files);
256:                        list.clear();
257:                        getPlan().setLibFiles(files);
258:
259:                        // deployment descriptors
260:                        dd = getPlan().getDescriptors();
261:                        for (int i = 0; i < dd.length; i++) {
262:                            value = manifest.getMainAttributes().getValue(
263:                                    dd[i].getType());
264:                            cursor = PathHandle.createPathHandle(value);
265:                            if (cursor.isFile()) {
266:                                dd[i].setPath(cursor.getPath());
267:                            }
268:                        }
269:                        getPlan().setDescriptors(dd);
270:                    } catch (ArchiveException e) {
271:                        e.printStackTrace(System.err);
272:                    }
273:                }
274:                return read;
275:            }
276:
277:            //
278:            protected String getWizardTitle() {
279:                StringBuffer buf = new StringBuffer();
280:
281:                buf.append(getSelectionName());
282:                buf.append(" Wizard");
283:                return buf.toString();
284:            }
285:
286:            //
287:            protected ArchivePanel[] getWizardPanels() throws ArchiveException {
288:                if (panels.length == 0) {
289:                    initPanels();
290:                }
291:                return panels;
292:            }
293:
294:            protected void setWizardPanels(ArchivePanel[] p)
295:                    throws ArchiveException {
296:                panels = p;
297:                for (int i = 0; i < panels.length; i++) {
298:                    panels[i].readPlan(getPlan());
299:                }
300:            }
301:
302:            protected File build() throws ArchiveException {
303:                ArchiveTool tool = new ArchiveTool();
304:
305:                return tool.buildArchive(getPlan());
306:            }
307:
308:            protected void saveDefaults() {
309:                saveDefaultArchivePath();
310:            }
311:
312:            private void saveDefaultArchivePath() {
313:                Properties props = null;
314:
315:                try {
316:                    props = ToolBoxInfo.loadProperties();
317:                    props.setProperty(getType() + ".archive", plan
318:                            .getArchivePath());
319:                    ToolBoxInfo.storeProperties(props);
320:                } catch (ToolException e) {
321:                    e.printStackTrace(System.err);
322:                    props = new Properties();
323:                }
324:            }
325:
326:            protected String getDefaultArchivePath() {
327:                Properties props = null;
328:                StringBuffer def = new StringBuffer();
329:                String path = null;
330:
331:                def.append(System.getProperty("user.dir"));
332:                def.append(File.separator);
333:                def.append("untitled.");
334:                def.append(getExtension());
335:                try {
336:                    props = ToolBoxInfo.loadProperties();
337:                } catch (ToolException e) {
338:                    e.printStackTrace(System.err);
339:                    props = new Properties();
340:                }
341:                if (isMostRecentlyUsed()) {
342:                    path = props.getProperty(getType() + ".archive", def
343:                            .toString());
344:                } else {
345:                    path = def.toString();
346:                }
347:                path = PathHandle.createPathString(path);
348:                return path;
349:            }
350:
351:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.