1 28 29 package com.caucho.ejb.gen; 30 31 import com.caucho.bytecode.JClass; 32 import com.caucho.bytecode.JMethod; 33 import com.caucho.java.JavaWriter; 34 import com.caucho.java.gen.BaseMethod; 35 import com.caucho.util.L10N; 36 37 import java.io.IOException ; 38 39 42 public class SessionCreateMethod extends BaseMethod { 43 private static final L10N L = new L10N(StatelessCreateMethod.class); 44 45 private JMethod _method; 46 private String _contextClassName; 47 private String _prefix; 48 49 public SessionCreateMethod(JMethod apiMethod, 50 JMethod implMethod, 51 String contextClassName, 52 String prefix) 53 { 54 super(apiMethod, implMethod); 55 56 _method = apiMethod; 57 _contextClassName = contextClassName; 58 _prefix = prefix; 59 } 60 61 64 public JClass []getParameterTypes() 65 { 66 return _method.getParameterTypes(); 67 } 68 69 72 public JClass getReturnType() 73 { 74 return _method.getReturnType(); 75 } 76 77 82 public void generateCall(JavaWriter out, String []args) 83 throws IOException 84 { 85 out.println("Thread thread = Thread.currentThread();"); 86 out.println("ClassLoader oldLoader = thread.getContextClassLoader();"); 87 out.println(); 88 out.println("try {"); 89 out.pushDepth(); 90 out.println("thread.setContextClassLoader(_server.getClassLoader());"); 91 out.println(); 92 93 out.println(_contextClassName + " cxt = new " + _contextClassName + "(_server);"); 94 95 out.println("Bean bean = new Bean(cxt);"); 96 97 getCall().generateCall(out, null, "bean", args); 98 99 out.println("cxt._ejb_free(bean);"); 100 101 out.println(); 102 out.println("_server.createSessionKey(cxt);"); 103 104 JClass retType = getReturnType(); 105 if ("RemoteHome".equals(_prefix)) 106 out.println("return (" + retType.getName() + ") cxt.getRemoteView();"); 107 else if ("LocalHome".equals(_prefix)) 108 out.println("return (" + retType.getName() + ") cxt.getEJBLocalObject();"); 109 else 110 throw new IOException (L.l("trying to create unknown type {0}", 111 _prefix)); 112 113 out.popDepth(); 114 out.println("} finally {"); 115 out.println(" thread.setContextClassLoader(oldLoader);"); 116 out.println("}"); 117 } 118 } 119 | Popular Tags |