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 JVMHomeStubGenerator extends JVMStubGenerator { 43 protected ArrayList <PersistentDependency> _dependList; 44 45 48 public JVMHomeStubGenerator(Class remoteHomeClass, boolean isProxy) 49 { 50 _remoteClass = remoteHomeClass; 51 52 _isProxy = isProxy; 53 54 if (isProxy) 55 setFullClassName(remoteHomeClass.getName() + "__JVMProxy"); 56 else 57 setFullClassName(remoteHomeClass.getName() + "__JVMStub"); 58 59 MergePath mergePath = new MergePath(); 60 setSearchPath(mergePath); 61 62 _dependList = new ArrayList <PersistentDependency>(); 63 64 _dependList.add(new ClassDependency(remoteHomeClass)); 65 } 66 67 70 public Class generateStub() 71 throws Exception 72 { 73 Class home = preload(); 74 if (home != null) 75 return home; 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 printDependList(_dependList); 111 112 printFooter(); 113 } 114 115 118 protected void printHeader() 119 throws IOException 120 { 121 if (getPackageName() != null) 122 println("package " + getPackageName() + ";"); 123 124 println(); 125 println("import java.io.*;"); 126 println("import java.rmi.*;"); 127 println("import " + _remoteClass.getName() + ";"); 128 129 println(); 130 println("public class " + getClassName()); 131 println(" extends com.caucho.ejb.JVMHome"); 132 println(" implements " + _remoteClass.getName()); 133 134 println("{"); 135 pushDepth(); 136 } 137 } 138 | Popular Tags |