1 23 24 29 30 package com.sun.enterprise.deployment.archivist; 31 32 import java.io.File ; 33 import java.io.IOException ; 34 import java.io.FileNotFoundException ; 35 import java.util.logging.Level ; 36 import javax.enterprise.deploy.shared.ModuleType ; 37 38 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive; 39 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 40 import com.sun.enterprise.deployment.deploy.shared.InputJarArchive; 41 import com.sun.enterprise.deployment.util.DOLUtils; 42 import com.sun.enterprise.util.i18n.StringManager; 43 44 45 49 public class PluggableArchivistsHelper implements PluggableArchivists { 50 51 private Archivist[] archivists = new Archivist[0]; 56 57 58 private static StringManager localStrings = 59 StringManager.getManager( PluggableArchivistsHelper.class ); 60 61 62 63 public PluggableArchivistsHelper() { 64 } 65 66 70 public Archivist getArchivistForArchive(String path) throws IOException { 71 File f = new File (path); 72 if (!f.exists()) { 73 throw new FileNotFoundException (path); 74 } 75 AbstractArchive archive; 76 if (f.isDirectory()) { 77 archive = new FileArchive(); 78 ((FileArchive) archive).open(path); 79 } else { 80 archive = new InputJarArchive(); 81 ((InputJarArchive) archive).open(path); 82 } 83 Archivist archivist=null; 84 try { 85 archivist = getArchivistForArchive(archive); 86 } finally { 87 archive.close(); 88 } 89 return archivist; 90 } 91 92 96 public Archivist getArchivistForArchive(File jarFileOrDirectory) throws IOException { 97 return getArchivistForArchive(jarFileOrDirectory.getAbsolutePath()); 98 } 99 100 101 105 public Archivist getArchivistForArchive(AbstractArchive archive) throws IOException { 106 107 Archivist a = handles(archive); 108 if (a != null) { 109 try { 110 Archivist archivist = (Archivist) a.getClass().newInstance(); 111 archivist.setPluggableArchivists(this); 112 return archivist; 113 } catch (Exception e) { 114 DOLUtils.getDefaultLogger().log( 115 Level.SEVERE, 116 "enterprise.deployment.backend.archivistInstantiationFailure", 117 new Object [] {a.getClass(), archive}); 118 e.printStackTrace(); 119 } 120 } else { 121 String msg = localStrings.getString( 122 "enterprise.deployment.unknown.application.type", 123 archive.getArchiveUri()); 124 throw new IOException (msg); 125 } 126 return null; 127 } 128 129 private Archivist handles(AbstractArchive archive) throws IOException { 130 131 for (Archivist a : archivists) { 133 if (a.hasStandardDeploymentDescriptor(archive) || 134 a.hasRuntimeDeploymentDescriptor(archive)) { 135 return a; 136 } 137 } 138 139 141 String uri = archive.getArchiveUri(); 144 File file = new File (uri); 145 if (!file.isDirectory() && !uri.endsWith(Archivist.EJB_EXTENSION)) { 146 for (Archivist a : archivists) { 147 if (uri.endsWith(a.getArchiveExtension())) { 148 return a; 149 } 150 } 151 } 152 153 for (Archivist a : archivists) { 155 if (a.postHandles(archive)) { 156 return a; 157 } 158 } 159 160 return null; 161 } 162 163 167 public Archivist getArchivistForType(ModuleType type) { 168 169 for (int i=0;i<archivists.length;i++) { 170 if (archivists[i].getModuleType().equals(type)) { 171 try { 172 Archivist archivist = (Archivist) archivists[i].getClass().newInstance(); 173 archivist.setPluggableArchivists(this); 174 return archivist; 175 } catch (Exception e) { 176 DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.archivistInstantiationFailure", 177 new Object [] {archivists[i].getClass(), type}); 178 e.printStackTrace(); 179 } 180 } 181 } 182 DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.archivistInstantiationFailure", 183 new Object [] {null, type}); 184 return null; 185 } 186 187 191 public void registerArchivist(Archivist archivist) { 192 for (int i=0;i<archivists.length;i++) { 193 if (archivists[i].getModuleType().equals(archivist.getModuleType())) { 194 archivists[i]=archivist; 196 return; 197 } 198 } 199 Archivist[] newArchivists = new Archivist[archivists.length+1]; 201 System.arraycopy(archivists, 0, newArchivists, 0, archivists.length); 202 newArchivists[archivists.length]=archivist; 203 archivists = newArchivists; 204 } 205 206 209 public Archivist[] getRegisteredArchivists() { 210 Archivist[] newArchivists = new Archivist[archivists.length+1]; 211 System.arraycopy(archivists, 0, newArchivists, 0, archivists.length); 212 return newArchivists; 213 } 214 215 } 216 | Popular Tags |