1 28 29 package com.caucho.ejb.gen; 30 31 import com.caucho.java.AbstractGenerator; 32 33 import java.io.IOException ; 34 import java.lang.reflect.Method ; 35 36 39 class EJBObjectGenerator extends AbstractGenerator { 40 protected Class _skelClass; 41 protected Class _remoteClass; 42 protected String prefix = "_ejb_lo_"; 43 44 47 public EJBObjectGenerator(Class remoteClass, Class skelClass) 48 { 49 _remoteClass = remoteClass; 50 _skelClass = skelClass; 51 52 setFullClassName("_ejb." + _remoteClass.getName() + "__Stub"); 53 } 54 55 60 public void generateJava() 61 throws IOException 62 { 63 printHeader(); 64 65 Method []methods = _remoteClass.getMethods(); 66 for (int i = 0; i < methods.length; i++) { 67 Method method = methods[i]; 68 String methodName = method.getName(); 69 Class declaringClass = method.getDeclaringClass(); 70 71 if (declaringClass.getName().startsWith("javax.ejb.")) 72 continue; 73 74 printMethod(method.getName(), method); 75 } 76 77 printFooter(); 78 } 79 80 83 protected void printHeader() 84 throws IOException 85 { 86 if (getPackageName() != null) 87 println("package " + getPackageName() + ";"); 88 89 println(); 90 println("import java.io.*;"); 91 println("import java.rmi.*;"); 92 println("import " + _skelClass.getName() + ";"); 93 println("import " + _remoteClass.getName() + ";"); 94 95 println(); 96 println("public class " + getClassName()); 97 println(" extends com.caucho.ejb.SessionObject"); 98 println(" implements " + _remoteClass.getName()); 99 100 println("{"); 101 pushDepth(); 102 103 println("private " + _skelClass.getName() + " _obj;"); 104 105 println(); 106 println("public javax.ejb.SessionBean _getObject()"); 107 println("{"); 108 println(" return _obj;"); 109 println("}"); 110 111 println(); 112 println("public void _setObject(javax.ejb.SessionBean bean)"); 113 println("{"); 114 println(" _obj = (" + _skelClass.getName() + ") bean;"); 115 println("}"); 116 } 117 118 123 protected void printMethod(String name, Method method) 124 throws IOException 125 { 126 Class ret = method.getReturnType(); 127 Class []params = method.getParameterTypes(); 128 129 printMethodHeader(name, method); 130 131 println("{"); 132 pushDepth(); 133 134 if (! ret.getName().equals("void")) { 135 printClass(ret); 136 println(" _ret;"); 137 } 138 139 if (! ret.getName().equals("void")) 140 print("_ret = "); 141 142 print("_obj." + prefix + method.getName() + "("); 143 for (int i = 0; i < params.length; i++) { 144 if (i != 0) 145 print(", "); 146 print("a" + i); 147 } 148 println(");"); 149 150 if (! ret.getName().equals("void")) 151 println("return _ret;"); 152 153 popDepth(); 154 println("}"); 155 } 156 157 160 void printFooter() 161 throws IOException 162 { 163 popDepth(); 164 println("}"); 165 } 166 } 167 | Popular Tags |