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 EntityView 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 49 public EntityView(JClass remoteClass, 50 String contextClassName, 51 String prefix) 52 { 53 super(prefix, "EntityObject"); 54 55 addInterfaceName(remoteClass.getName()); 56 57 _contextClassName = contextClassName; 58 _prefix = prefix; 59 60 setStatic(true); 61 } 62 63 66 public CallChain createPoolChain(CallChain call) 67 { 68 return new EntityPoolChain(call, false); 69 } 70 71 public void generate(JavaWriter out) 72 throws IOException 73 { 74 generateGetter(out); 75 76 out.println(); 77 super.generate(out); 78 } 79 80 private void generateGetter(JavaWriter out) 81 throws IOException 82 { 83 out.println("private " + _prefix + " _view" + _prefix + ";"); 84 85 out.println(); 86 if (_prefix.equals("Local")) 87 out.println("public EJBLocalObject getEJBLocalObject()"); 88 else 89 out.println("public EJBObject getRemoteView()"); 90 91 out.println("{"); 92 out.println(" if (_view" + _prefix + " == null)"); 93 out.println(" _view" + _prefix + " = new " + _prefix + "(this);"); 94 95 out.println(); 96 out.println(" return _view" + _prefix + ";"); 97 out.println("}"); 98 } 99 100 protected void generateClassContent(JavaWriter out) 101 throws IOException 102 { 103 out.println("private " + _contextClassName + " _context;"); 104 out.println("private EjbTransactionManager _xaManager;"); 105 106 out.println(); 107 out.println(_prefix + "(" + _contextClassName + " context)"); 108 out.println("{"); 109 out.println(" _context = context;"); 110 out.println(" _xaManager = context.getEntityServer().getTransactionManager();"); 111 out.println("}"); 112 113 out.println(); 114 out.println("public QEntityContext getEntityContext()"); 115 out.println("{"); 116 out.println(" return _context;"); 117 out.println("}"); 118 119 generateGetBean(out); 120 121 generateComponents(out); 122 } 123 124 128 protected void generateGetBean(JavaWriter out) 129 throws IOException 130 { 131 out.println(); 132 out.println("public Object _caucho_getBean(com.caucho.ejb.xa.TransactionContext trans, boolean doLoad)"); 133 out.println("{"); 134 out.pushDepth(); 135 136 out.println("return _context._ejb_begin(trans, false, true);"); 137 138 out.popDepth(); 139 out.println("}"); 140 out.println(); 141 142 out.println("public Object _caucho_getBean()"); 143 out.println("{"); 144 out.pushDepth(); 145 146 out.println("com.caucho.ejb.xa.TransactionContext trans;"); 147 out.println("trans = _context._server.getTransactionManager().getTransactionContext();"); 148 out.println("return _context._ejb_begin(trans, false, false);"); 149 150 out.popDepth(); 151 out.println("}"); 152 } 153 } 154 | Popular Tags |