1 29 30 package com.caucho.ejb.gen; 31 32 import com.caucho.bytecode.JClass; 33 import com.caucho.java.JavaWriter; 34 import com.caucho.java.gen.CallChain; 35 import com.caucho.util.L10N; 36 37 import java.io.IOException ; 38 39 42 public class SessionView extends ViewClass { 43 private static L10N L = new L10N(SessionView.class); 44 45 private JClass _remoteClass; 46 private String _prefix; 47 private String _contextClassName; 48 private boolean _isStateless; 49 50 public SessionView(JClass remoteClass, 51 String contextClassName, 52 String prefix, 53 boolean isStateless) 54 { 55 super(prefix, isStateless ? "StatelessObject" : "SessionObject"); 56 57 addInterfaceName(remoteClass.getName()); 58 59 _contextClassName = contextClassName; 60 _prefix = prefix; 61 _isStateless = isStateless; 62 63 setStatic(true); 64 } 65 66 69 public CallChain createPoolChain(CallChain call) 70 { 71 if (_isStateless) 72 return new StatelessPoolChain(call); 73 else 74 return new SessionPoolChain(call); 75 } 76 77 public void generate(JavaWriter out) 78 throws IOException 79 { 80 generateGetter(out); 81 82 out.println(); 83 super.generate(out); 84 } 85 86 private void generateGetter(JavaWriter out) 87 throws IOException 88 { 89 out.println("private " + _prefix + " _view" + _prefix + ";"); 90 91 out.println(); 92 if (_prefix.equals("Local")) 93 out.println("public EJBLocalObject getEJBLocalObject()"); 94 else 95 out.println("public EJBObject getRemoteView()"); 96 97 out.println("{"); 98 out.println(" if (_view" + _prefix + " == null)"); 99 out.println(" _view" + _prefix + " = new " + _prefix + "(this);"); 100 101 out.println(); 102 out.println(" return _view" + _prefix + ";"); 103 out.println("}"); 104 } 105 106 protected void generateClassContent(JavaWriter out) 107 throws IOException 108 { 109 out.println("private final " + _contextClassName + " _context;"); 110 out.println("private final EjbTransactionManager _xaManager;"); 111 112 out.println(); 113 out.println(_prefix + "(" + _contextClassName + " context)"); 114 out.println("{"); 115 if (_isStateless) 116 out.println(" super(context.getStatelessServer());"); 117 else 118 out.println(" super(context.getSessionServer());"); 119 out.println(" _context = context;"); 120 out.println(" _xaManager = _server.getTransactionManager();"); 121 out.println("}"); 122 123 out.println(); 124 out.println("private " + _contextClassName + " getContext()"); 125 out.println("{"); 126 out.println(" return _context;"); 127 out.println("}"); 128 129 if (! _isStateless) { 130 out.println(); 131 out.println("public String __caucho_getId()"); 132 out.println("{"); 133 out.println(" return _context.getPrimaryKey();"); 134 out.println("}"); 135 } 136 137 out.println(); 138 generateComponents(out); 139 } 140 } 141 | Popular Tags |