KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > tool > archive > wizard > EarType


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  * Paul Mahar
22  *
23  */

24 package org.enhydra.tool.archive.wizard;
25
26 // ToolBox
27
import org.enhydra.tool.archive.Descriptor;
28 import org.enhydra.tool.archive.EarPlan;
29 import org.enhydra.tool.archive.ArchiveException;
30 import org.enhydra.tool.archive.ArchiveTool;
31 import org.enhydra.tool.archive.WebApplication;
32 import org.enhydra.tool.common.PathHandle;
33
34 // JDK
35
import java.util.ArrayList JavaDoc;
36 import java.util.jar.Manifest JavaDoc;
37
38 //
39
public class EarType extends ArchiveType {
40     public final static String JavaDoc EXT = "ear";
41
42     //
43
protected final String JavaDoc getSelectionName() {
44         return "Enterprise Application";
45     }
46
47     protected final String JavaDoc getExtension() {
48         return EXT;
49     }
50
51     protected final String JavaDoc getType() {
52         return getExtension();
53     }
54
55     protected final String JavaDoc getDescription() {
56         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
57
58         buf.append("Create an enterprise application archive ");
59         buf.append("consisting of modules and supporting libraries.");
60         buf.append("The modules can include web archives, enterprise ");
61         buf.append("JavaBean archives and other enterprise applicaion ");
62         buf.append("archives.");
63         return buf.toString();
64     }
65
66     protected void initPanels() throws ArchiveException {
67         ArchivePanel[] newPanels = new ArchivePanel[4];
68         EarFilePanel filePanel = new EarFilePanel();
69         WebAppPanel wPanel = new WebAppPanel();
70         EnterpriseModulePanel ePanel = new EnterpriseModulePanel();
71         MetaPanel metaPanel = new MetaPanel();
72
73         newPanels[0] = filePanel;
74         newPanels[1] = wPanel;
75         newPanels[2] = ePanel;
76         newPanels[3] = metaPanel;
77         setWizardPanels(newPanels);
78     }
79
80     protected void initPlan() throws ArchiveException {
81         EarPlan earPlan = null;
82         PathHandle path = null;
83
84         setPlan(new EarPlan());
85         getEarPlan().setArchivePath(getDefaultArchivePath());
86         path = PathHandle.createPathHandle(getEarPlan().getArchivePath());
87         if (path.isFile()) {
88             readArchive(getEarPlan().getArchivePath());
89         }
90     }
91
92     protected boolean readArchive(Manifest JavaDoc manifest, String JavaDoc[] entries) {
93         boolean read = super.readArchive(manifest, entries);
94         Boolean JavaDoc b = null;
95         PathHandle root = null;
96         PathHandle cursor = null;
97         ArrayList JavaDoc list = new ArrayList JavaDoc();
98         String JavaDoc[] files = new String JavaDoc[0];
99         Descriptor[] dd = new Descriptor[0];
100         WebApplication[] webApps = new WebApplication[0];
101
102         if (read) {
103             String JavaDoc value = null;
104
105             try {
106
107                 // appname
108
value = manifest.getMainAttributes().getValue(APP_NAME);
109                 if (value != null) {
110                     getEarPlan().setAppName(value);
111                 }
112
113                 // description
114
value = manifest.getMainAttributes().getValue(APP_DESC);
115                 if (value != null) {
116                     getEarPlan().setDescription(value);
117                 }
118
119                 // alt-dd
120
value = manifest.getMainAttributes().getValue(ALT_DD);
121                 b = Boolean.valueOf(value);
122                 getEarPlan().setAlt(b.booleanValue());
123
124                 // copy client
125
value = manifest.getMainAttributes().getValue(COPY_CLIENT);
126                 b = Boolean.valueOf(value);
127                 getEarPlan().setCopyClient(b.booleanValue());
128
129                 // enterprise modules (0 - 99)
130
for (int i = 0; i < 100; i++) {
131                     value = manifest.getMainAttributes().getValue(ENTERPRISE_MODULE
132                             + i);
133                     cursor = PathHandle.createPathHandle(value);
134                     if (cursor.isFile()) {
135                         list.add(cursor.getPath());
136                     }
137                 }
138                 files = new String JavaDoc[list.size()];
139                 files = (String JavaDoc[]) list.toArray(files);
140                 list.clear();
141                 getEarPlan().setEnterpriseModules(files);
142
143                 // web apps (0 - 99)
144
for (int i = 0; i < 100; i++) {
145                     value = manifest.getMainAttributes().getValue(WEBAPP_MODULE
146                             + i);
147                     cursor = PathHandle.createPathHandle(value);
148                     if (cursor.isFile()) {
149                         WebApplication webApp = null;
150                         webApp = new WebApplication(cursor.getPath());
151                         value = manifest.getMainAttributes().getValue(WEBAPP_CONTEXT
152                            + i);
153                         if (value != null && value.trim().length() > 0) {
154                           webApp.setContextRoot(value);
155                         }
156                         list.add(webApp);
157                     }
158                 }
159                 webApps = new WebApplication[list.size()];
160                 webApps = (WebApplication[]) list.toArray(webApps);
161                 list.clear();
162                 getEarPlan().setWebApplications(webApps);
163
164
165                 // meta descriptors 0-99
166
for (int i = 0; i < 100; i++) {
167                     value = manifest.getMainAttributes().getValue(APP_META
168                             + i);
169                     cursor = PathHandle.createPathHandle(value);
170                     if (cursor.isFile()) {
171                         Descriptor desc = null;
172
173                         desc = new Descriptor(cursor.getPath());
174                         list.add(desc);
175                     }
176                 }
177                 list.trimToSize();
178                 dd = new Descriptor[list.size()];
179                 dd = (Descriptor[]) list.toArray(dd);
180                 list.clear();
181                 getPlan().setDescriptors(dd);
182             } catch (ArchiveException e) {
183                 e.printStackTrace(System.err);
184             }
185         }
186         return read;
187     }
188
189     private EarPlan getEarPlan() throws ArchiveException {
190         return (EarPlan) getPlan();
191     }
192
193 }
194
Popular Tags