1 2 24 package org.enhydra.tool.archive.wizard; 25 26 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 import java.util.ArrayList ; 36 import java.util.jar.Manifest ; 37 38 public class EarType extends ArchiveType { 40 public final static String EXT = "ear"; 41 42 protected final String getSelectionName() { 44 return "Enterprise Application"; 45 } 46 47 protected final String getExtension() { 48 return EXT; 49 } 50 51 protected final String getType() { 52 return getExtension(); 53 } 54 55 protected final String getDescription() { 56 StringBuffer buf = new StringBuffer (); 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 manifest, String [] entries) { 93 boolean read = super.readArchive(manifest, entries); 94 Boolean b = null; 95 PathHandle root = null; 96 PathHandle cursor = null; 97 ArrayList list = new ArrayList (); 98 String [] files = new String [0]; 99 Descriptor[] dd = new Descriptor[0]; 100 WebApplication[] webApps = new WebApplication[0]; 101 102 if (read) { 103 String value = null; 104 105 try { 106 107 value = manifest.getMainAttributes().getValue(APP_NAME); 109 if (value != null) { 110 getEarPlan().setAppName(value); 111 } 112 113 value = manifest.getMainAttributes().getValue(APP_DESC); 115 if (value != null) { 116 getEarPlan().setDescription(value); 117 } 118 119 value = manifest.getMainAttributes().getValue(ALT_DD); 121 b = Boolean.valueOf(value); 122 getEarPlan().setAlt(b.booleanValue()); 123 124 value = manifest.getMainAttributes().getValue(COPY_CLIENT); 126 b = Boolean.valueOf(value); 127 getEarPlan().setCopyClient(b.booleanValue()); 128 129 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 [list.size()]; 139 files = (String []) list.toArray(files); 140 list.clear(); 141 getEarPlan().setEnterpriseModules(files); 142 143 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 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 |