1 25 26 27 package org.objectweb.jonas_lib.genclientstub.modifier; 28 29 import java.io.File ; 30 import java.io.IOException ; 31 import java.util.jar.JarFile ; 32 33 import org.objectweb.jonas_lib.I18n; 34 import org.objectweb.jonas_lib.genbase.GenBaseException; 35 import org.objectweb.jonas_lib.genbase.archive.Application; 36 import org.objectweb.jonas_lib.genbase.archive.Archive; 37 import org.objectweb.jonas_lib.genbase.archive.Client; 38 import org.objectweb.jonas_lib.genbase.archive.EjbJar; 39 import org.objectweb.jonas_lib.genbase.archive.FileArchive; 40 import org.objectweb.jonas_lib.genbase.archive.J2EEArchive; 41 import org.objectweb.jonas_lib.genbase.archive.JarArchive; 42 import org.objectweb.jonas_lib.genbase.archive.WebApp; 43 import org.objectweb.jonas_lib.genbase.modifier.AbsModifierFactory; 44 import org.objectweb.jonas_lib.genbase.modifier.ArchiveModifier; 45 import org.objectweb.jonas_lib.genclientstub.ClientStubGenException; 46 47 48 54 public class ModifierFactory extends AbsModifierFactory { 55 56 57 private static I18n i18n = I18n.getInstance(ModifierFactory.class); 58 59 62 private ModifierFactory() { 63 super(); 64 } 65 66 76 public static ArchiveModifier getModifier(String filename) throws GenBaseException { 77 Archive archive = null; 78 J2EEArchive j2eeArchive = null; 79 ArchiveModifier modifier = null; 80 int mode; 81 82 File file = new File (filename); 83 84 if (file.exists()) { 85 if (file.isFile()) { 86 JarFile jarfile; 89 90 try { 91 jarfile = new JarFile (file); 92 } catch (IOException ioe) { 93 String err = i18n.getMessage("ModifierFactory.getModifier.notjar", filename); 95 throw new ClientStubGenException(err); 96 } 97 98 archive = new JarArchive(file); 100 101 if (isApplication(jarfile)) { 103 j2eeArchive = new Application(archive); 105 mode = APPLICATION; 106 107 } else if (isEjbJar(jarfile)) { 108 j2eeArchive = new EjbJar(archive); 110 mode = EJBJAR; 111 112 } else if (isWebApp(jarfile)) { 113 j2eeArchive = new WebApp(archive); 115 mode = WEBAPP; 116 117 } else if (isClient(jarfile)) { 118 j2eeArchive = new Client(archive); 120 mode = CLIENT; 121 122 } else { 123 String err = i18n.getMessage("ModifierFactory.getModifier.unsupported", filename); 125 throw new ClientStubGenException(err); 126 } 127 } else { 128 archive = new FileArchive(file); 131 132 if (isApplication(file)) { 134 j2eeArchive = new Application(archive); 136 mode = APPLICATION; 137 138 } else if (isEjbJar(file)) { 139 j2eeArchive = new EjbJar(archive); 141 mode = EJBJAR; 142 143 } else if (isWebApp(file)) { 144 j2eeArchive = new WebApp(archive); 146 mode = WEBAPP; 147 148 } else if (isClient(file)) { 149 j2eeArchive = new Client(archive); 151 mode = CLIENT; 152 153 } else { 154 String err = i18n.getMessage("ModifierFactory.getModifier.unsupported", filename); 156 throw new ClientStubGenException(err); 157 } 158 } 159 } else { 160 String err = i18n.getMessage("ModifierFactory.getModifier.notfound", filename); 161 throw new ClientStubGenException(err); 162 } 163 164 j2eeArchive.initialize(); 166 167 switch (mode) { 169 case APPLICATION: 170 modifier = new ApplicationModifier((Application) j2eeArchive); 171 172 break; 173 174 case EJBJAR: 175 modifier = new EjbJarModifier((EjbJar) j2eeArchive); 176 177 break; 178 179 case WEBAPP: 180 modifier = new WebAppModifier((WebApp) j2eeArchive); 181 182 break; 183 184 case CLIENT: 185 modifier = new ClientModifier((Client) j2eeArchive); 186 187 break; 188 189 default: 190 } 192 193 return modifier; 194 195 } 196 } | Popular Tags |