1 28 29 package com.caucho.ejb.gen; 30 31 import com.caucho.make.ClassDependency; 32 import com.caucho.vfs.MergePath; 33 import com.caucho.vfs.PersistentDependency; 34 35 import java.io.IOException ; 36 import java.lang.reflect.Method ; 37 import java.util.ArrayList ; 38 39 42 public class JVMObjectStubGenerator extends JVMStubGenerator { 43 private ArrayList <PersistentDependency> _dependList; 44 45 48 public JVMObjectStubGenerator(Class remoteClass, boolean isProxy) 49 { 50 _remoteClass = remoteClass; 51 52 _isProxy = isProxy; 53 54 if (isProxy) 55 setFullClassName(remoteClass.getName() + "__JVMProxy"); 56 else 57 setFullClassName(remoteClass.getName() + "__JVMStub"); 58 59 MergePath mergePath = new MergePath(); 60 setSearchPath(mergePath); 61 62 _dependList = new ArrayList <PersistentDependency>(); 63 64 _dependList.add(new ClassDependency(remoteClass)); 65 } 66 67 70 public Class generateStub() 71 throws Exception 72 { 73 Class object = preload(); 74 if (object != null) 75 return object; 76 77 generate(); 78 79 return compile(); 80 } 81 82 87 public void generateJava() 88 throws IOException 89 { 90 printHeader(); 91 92 Method []methods = _remoteClass.getMethods(); 93 for (int i = 0; i < methods.length; i++) { 94 Method method = methods[i]; 95 String methodName = method.getName(); 96 Class declaringClass = method.getDeclaringClass(); 97 98 if (declaringClass.getName().startsWith("javax.ejb.")) 99 continue; 100 101 Class []exns = method.getExceptionTypes(); 102 for (int j = 0; j < exns.length; j++) { 103 if (exns[j].isAssignableFrom(java.rmi.RemoteException .class)) { 104 printMethod(method.getName(), method); 105 break; 106 } 107 } 108 } 109 110 printRemove(); 111 112 printDependList(_dependList); 113 114 printFooter(); 115 } 116 117 120 protected void printHeader() 121 throws IOException 122 { 123 if (getPackageName() != null) 124 println("package " + getPackageName() + ";"); 125 126 println(); 127 println("import java.io.*;"); 128 println("import java.rmi.*;"); 129 println("import " + _remoteClass.getName() + ";"); 130 131 println(); 132 println("public class " + getClassName()); 133 println(" extends com.caucho.ejb.JVMObject"); 134 println(" implements " + _remoteClass.getName()); 135 136 println("{"); 137 pushDepth(); 138 } 139 140 protected void printRemove() 141 throws IOException 142 { 143 Class ret = void.class; 144 Class []params = new Class [0]; 145 146 println(); 147 println("public void remove() throws java.rmi.RemoteException, javax.ejb.RemoveException"); 148 149 printMethodHead(params, ret); 150 151 printCall("remove", params, void.class); 152 153 printMethodFooter(ret, false); 154 } 155 } 156 | Popular Tags |