1 25 package org.objectweb.jonas_ws.wsgen.modifier; 26 27 import java.io.File ; 28 import java.io.IOException ; 29 import java.util.jar.JarFile ; 30 31 import org.objectweb.jonas_lib.I18n; 32 import org.objectweb.jonas_lib.genbase.GenBaseException; 33 import org.objectweb.jonas_lib.genbase.archive.Application; 34 import org.objectweb.jonas_lib.genbase.archive.Archive; 35 import org.objectweb.jonas_lib.genbase.archive.Client; 36 import org.objectweb.jonas_lib.genbase.archive.EjbJar; 37 import org.objectweb.jonas_lib.genbase.archive.FileArchive; 38 import org.objectweb.jonas_lib.genbase.archive.J2EEArchive; 39 import org.objectweb.jonas_lib.genbase.archive.JarArchive; 40 import org.objectweb.jonas_lib.genbase.archive.WebApp; 41 import org.objectweb.jonas_lib.genbase.modifier.AbsModifierFactory; 42 import org.objectweb.jonas_lib.genbase.modifier.ArchiveModifier; 43 44 import org.objectweb.jonas_ws.wsgen.WsGenException; 45 46 47 53 public class ModifierFactory extends AbsModifierFactory { 54 55 56 private static I18n i18n = I18n.getInstance(ModifierFactory.class); 57 58 61 private ModifierFactory() { 62 } 63 64 75 public static ArchiveModifier getModifier(String filename) throws GenBaseException, WsGenException { 76 Archive archive = null; 77 J2EEArchive j2eeArchive = null; 78 ArchiveModifier modifier = null; 79 int mode; 80 81 File file = new File (filename); 82 83 if (file.exists()) { 84 if (file.isFile()) { 85 JarFile jarfile; 88 89 try { 90 jarfile = new JarFile (file); 91 } catch (IOException ioe) { 92 String err = i18n.getMessage("ModifierFactory.getModifier.notjar", filename); 94 throw new WsGenException(err); 95 } 96 97 archive = new JarArchive(file); 99 100 if (isApplication(jarfile)) { 102 j2eeArchive = new Application(archive); 104 mode = APPLICATION; 105 106 } else if (isEjbJar(jarfile)) { 107 j2eeArchive = new EjbJar(archive); 109 mode = EJBJAR; 110 111 } else if (isWebApp(jarfile)) { 112 j2eeArchive = new WebApp(archive); 114 mode = WEBAPP; 115 116 } else if (isClient(jarfile)) { 117 j2eeArchive = new Client(archive); 119 mode = CLIENT; 120 121 } else { 122 String err = i18n.getMessage("ModifierFactory.getModifier.unsupported", filename); 124 throw new WsGenException(err); 125 } 126 } else { 127 archive = new FileArchive(file); 130 131 if (isApplication(file)) { 133 j2eeArchive = new Application(archive); 135 mode = APPLICATION; 136 137 } else if (isEjbJar(file)) { 138 j2eeArchive = new EjbJar(archive); 140 mode = EJBJAR; 141 142 } else if (isWebApp(file)) { 143 j2eeArchive = new WebApp(archive); 145 mode = WEBAPP; 146 147 } else if (isClient(file)) { 148 j2eeArchive = new Client(archive); 150 mode = CLIENT; 151 152 } else { 153 String err = i18n.getMessage("ModifierFactory.getModifier.unsupported", filename); 155 throw new WsGenException(err); 156 } 157 } 158 } else { 159 String err = i18n.getMessage("ModifierFactory.getModifier.notfound", filename); 160 throw new WsGenException(err); 161 } 162 163 j2eeArchive.initialize(); 165 166 switch (mode) { 168 case APPLICATION: 169 modifier = new ApplicationModifier((Application) j2eeArchive); 170 171 break; 172 173 case EJBJAR: 174 modifier = new EjbJarModifier((EjbJar) j2eeArchive); 175 176 break; 177 178 case WEBAPP: 179 modifier = new WebAppModifier((WebApp) j2eeArchive); 180 181 break; 182 183 case CLIENT: 184 modifier = new ClientModifier((Client) j2eeArchive); 185 186 break; 187 188 default: 189 } 191 192 return modifier; 193 194 } 195 } | Popular Tags |