00001
00027 package org.objectweb.jonas_lib.genclientstub.modifier;
00028
00029 import java.io.File;
00030 import java.io.IOException;
00031 import java.util.jar.JarFile;
00032
00033 import org.objectweb.jonas_lib.I18n;
00034 import org.objectweb.jonas_lib.genbase.GenBaseException;
00035 import org.objectweb.jonas_lib.genbase.archive.Application;
00036 import org.objectweb.jonas_lib.genbase.archive.Archive;
00037 import org.objectweb.jonas_lib.genbase.archive.Client;
00038 import org.objectweb.jonas_lib.genbase.archive.EjbJar;
00039 import org.objectweb.jonas_lib.genbase.archive.FileArchive;
00040 import org.objectweb.jonas_lib.genbase.archive.J2EEArchive;
00041 import org.objectweb.jonas_lib.genbase.archive.JarArchive;
00042 import org.objectweb.jonas_lib.genbase.archive.WebApp;
00043 import org.objectweb.jonas_lib.genbase.modifier.AbsModifierFactory;
00044 import org.objectweb.jonas_lib.genbase.modifier.ArchiveModifier;
00045 import org.objectweb.jonas_lib.genclientstub.ClientStubGenException;
00046
00047
00054 public class ModifierFactory extends AbsModifierFactory {
00055
00057 private static I18n i18n = I18n.getInstance(ModifierFactory.class);
00058
00062 private ModifierFactory() {
00063 super();
00064 }
00065
00076 public static ArchiveModifier getModifier(String filename) throws GenBaseException {
00077 Archive archive = null;
00078 J2EEArchive j2eeArchive = null;
00079 ArchiveModifier modifier = null;
00080 int mode;
00081
00082 File file = new File(filename);
00083
00084 if (file.exists()) {
00085 if (file.isFile()) {
00086
00087
00088 JarFile jarfile;
00089
00090 try {
00091 jarfile = new JarFile(file);
00092 } catch (IOException ioe) {
00093
00094 String err = i18n.getMessage("ModifierFactory.getModifier.notjar", filename);
00095 throw new ClientStubGenException(err);
00096 }
00097
00098
00099 archive = new JarArchive(file);
00100
00101
00102 if (isApplication(jarfile)) {
00103
00104 j2eeArchive = new Application(archive);
00105 mode = APPLICATION;
00106
00107 } else if (isEjbJar(jarfile)) {
00108
00109 j2eeArchive = new EjbJar(archive);
00110 mode = EJBJAR;
00111
00112 } else if (isWebApp(jarfile)) {
00113
00114 j2eeArchive = new WebApp(archive);
00115 mode = WEBAPP;
00116
00117 } else if (isClient(jarfile)) {
00118
00119 j2eeArchive = new Client(archive);
00120 mode = CLIENT;
00121
00122 } else {
00123
00124 String err = i18n.getMessage("ModifierFactory.getModifier.unsupported", filename);
00125 throw new ClientStubGenException(err);
00126 }
00127 } else {
00128
00129
00130 archive = new FileArchive(file);
00131
00132
00133 if (isApplication(file)) {
00134
00135 j2eeArchive = new Application(archive);
00136 mode = APPLICATION;
00137
00138 } else if (isEjbJar(file)) {
00139
00140 j2eeArchive = new EjbJar(archive);
00141 mode = EJBJAR;
00142
00143 } else if (isWebApp(file)) {
00144
00145 j2eeArchive = new WebApp(archive);
00146 mode = WEBAPP;
00147
00148 } else if (isClient(file)) {
00149
00150 j2eeArchive = new Client(archive);
00151 mode = CLIENT;
00152
00153 } else {
00154
00155 String err = i18n.getMessage("ModifierFactory.getModifier.unsupported", filename);
00156 throw new ClientStubGenException(err);
00157 }
00158 }
00159 } else {
00160 String err = i18n.getMessage("ModifierFactory.getModifier.notfound", filename);
00161 throw new ClientStubGenException(err);
00162 }
00163
00164
00165 j2eeArchive.initialize();
00166
00167
00168 switch (mode) {
00169 case APPLICATION:
00170 modifier = new ApplicationModifier((Application) j2eeArchive);
00171
00172 break;
00173
00174 case EJBJAR:
00175 modifier = new EjbJarModifier((EjbJar) j2eeArchive);
00176
00177 break;
00178
00179 case WEBAPP:
00180 modifier = new WebAppModifier((WebApp) j2eeArchive);
00181
00182 break;
00183
00184 case CLIENT:
00185 modifier = new ClientModifier((Client) j2eeArchive);
00186
00187 break;
00188
00189 default:
00190
00191 }
00192
00193 return modifier;
00194
00195 }
00196 }