00001
00025 package org.objectweb.jonas_lib.genclientstub.modifier;
00026
00027 import java.util.ArrayList;
00028 import java.util.Iterator;
00029 import java.util.List;
00030
00031 import org.objectweb.jonas_lib.genbase.GenBaseException;
00032 import org.objectweb.jonas_lib.genbase.archive.Archive;
00033 import org.objectweb.jonas_lib.genbase.archive.J2EEArchive;
00034 import org.objectweb.jonas_lib.genbase.archive.WebApp;
00035 import org.objectweb.jonas_lib.genbase.generator.Config;
00036 import org.objectweb.jonas_lib.genbase.modifier.ArchiveModifier;
00037 import org.objectweb.jonas_lib.genclientstub.ClientStubGenException;
00038 import org.objectweb.jonas_lib.genclientstub.generator.Generator;
00039
00043 public abstract class AbsArchiveModifier extends ArchiveModifier {
00044
00049 public AbsArchiveModifier(J2EEArchive archive) {
00050 super(archive);
00051 }
00052
00058 public abstract Archive modify() throws GenBaseException;
00059
00066 protected void generateFoundStubs(Config config, Archive archive) throws ClientStubGenException {
00067
00068
00069 List classesStub = new ArrayList();
00070 try {
00071 List files = archive.getContainedFiles();
00072
00073 for (Iterator itFiles = files.iterator(); itFiles.hasNext();) {
00074 String clName = (String) itFiles.next();
00075 if (clName.endsWith("_Stub.class") || clName.endsWith("_Tie.class")) {
00076
00077 if (archive instanceof WebApp) {
00078 if (clName.startsWith("WEB-INF/classes/")) {
00079 classesStub.add(clName.substring("WEB-INF/classes/".length()));
00080 }
00081 } else {
00082 classesStub.add(clName);
00083 }
00084 }
00085 }
00086
00087
00088 for (Iterator itClass = classesStub.iterator(); itClass.hasNext();) {
00089 String clName = (String) itClass.next();
00090
00091
00092 int removeStubIdx = 0;
00093 if (clName.endsWith("_Stub.class")) {
00094 removeStubIdx = clName.length() - "_Stub.class".length();
00095 } else if (clName.endsWith("_Tie.class")) {
00096 removeStubIdx = clName.length() - "_Tie.class".length();
00097 } else {
00098 continue;
00099 }
00100 clName = clName.substring(0, removeStubIdx);
00101
00102
00103 int idx = clName.lastIndexOf('/') + 1;
00104 if (clName.charAt(idx) == '_') {
00105 String pkgName = clName.substring(0, idx);
00106 clName = pkgName + clName.substring(idx + 1, clName.length());
00107 }
00108
00109
00110 clName = clName.replaceAll("/", ".");
00111
00112
00113 if (clName.indexOf("javax.") != -1 || clName.indexOf("org.omg.stub") != -1) {
00114 continue;
00115 }
00116
00117
00118
00119 if (clName.indexOf("Home") != -1 || clName.indexOf("Remote") != -1) {
00120 continue;
00121 }
00122
00123 Generator g = new Generator(config, null, clName, archive);
00124 try {
00125 g.generate();
00126 g.compile();
00127 } catch (ClientStubGenException cstge) {
00128 continue;
00129 }
00130
00131 g.addFiles(archive);
00132 }
00133 } catch (Exception e) {
00134 throw new ClientStubGenException("Cannot find/build stubs from the file " + archive.getRootFile(), e);
00135 }
00136
00137 }
00138
00139 }