1 25 package org.objectweb.jonas_lib.genclientstub.modifier; 26 27 import java.util.ArrayList ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 31 import org.objectweb.jonas_lib.genbase.GenBaseException; 32 import org.objectweb.jonas_lib.genbase.archive.Archive; 33 import org.objectweb.jonas_lib.genbase.archive.J2EEArchive; 34 import org.objectweb.jonas_lib.genbase.archive.WebApp; 35 import org.objectweb.jonas_lib.genbase.generator.Config; 36 import org.objectweb.jonas_lib.genbase.modifier.ArchiveModifier; 37 import org.objectweb.jonas_lib.genclientstub.ClientStubGenException; 38 import org.objectweb.jonas_lib.genclientstub.generator.Generator; 39 40 43 public abstract class AbsArchiveModifier extends ArchiveModifier { 44 45 49 public AbsArchiveModifier(J2EEArchive archive) { 50 super(archive); 51 } 52 53 58 public abstract Archive modify() throws GenBaseException; 59 60 66 protected void generateFoundStubs(Config config, Archive archive) throws ClientStubGenException { 67 68 List classesStub = new ArrayList (); 70 try { 71 List files = archive.getContainedFiles(); 72 73 for (Iterator itFiles = files.iterator(); itFiles.hasNext();) { 74 String clName = (String ) itFiles.next(); 75 if (clName.endsWith("_Stub.class") || clName.endsWith("_Tie.class")) { 76 if (archive instanceof WebApp) { 78 if (clName.startsWith("WEB-INF/classes/")) { 79 classesStub.add(clName.substring("WEB-INF/classes/".length())); 80 } 81 } else { 82 classesStub.add(clName); 83 } 84 } 85 } 86 87 for (Iterator itClass = classesStub.iterator(); itClass.hasNext();) { 89 String clName = (String ) itClass.next(); 90 91 int removeStubIdx = 0; 93 if (clName.endsWith("_Stub.class")) { 94 removeStubIdx = clName.length() - "_Stub.class".length(); 95 } else if (clName.endsWith("_Tie.class")) { 96 removeStubIdx = clName.length() - "_Tie.class".length(); 97 } else { 98 continue; 99 } 100 clName = clName.substring(0, removeStubIdx); 101 102 int idx = clName.lastIndexOf('/') + 1; 104 if (clName.charAt(idx) == '_') { 105 String pkgName = clName.substring(0, idx); 106 clName = pkgName + clName.substring(idx + 1, clName.length()); 107 } 108 109 clName = clName.replaceAll("/", "."); 111 112 if (clName.indexOf("javax.") != -1 || clName.indexOf("org.omg.stub") != -1) { 114 continue; 115 } 116 117 118 if (clName.indexOf("Home") != -1 || clName.indexOf("Remote") != -1) { 120 continue; 121 } 122 123 Generator g = new Generator(config, null, clName, archive); 124 try { 125 g.generate(); 126 g.compile(); 127 } catch (ClientStubGenException cstge) { 128 continue; 129 } 130 g.addFiles(archive); 132 } 133 } catch (Exception e) { 134 throw new ClientStubGenException("Cannot find/build stubs from the file " + archive.getRootFile(), e); 135 } 136 137 } 138 139 } | Popular Tags |