1 29 30 package com.caucho.ejb.cfg; 31 32 import com.caucho.bytecode.JMethod; 33 import com.caucho.config.ConfigException; 34 import com.caucho.ejb.gen.BeanAssembler; 35 import com.caucho.ejb.gen.ViewClass; 36 import com.caucho.java.JavaWriter; 37 import com.caucho.java.gen.BaseMethod; 38 import com.caucho.java.gen.CallChain; 39 import com.caucho.util.L10N; 40 41 import java.io.IOException ; 42 43 46 public class EjbMethod { 47 private static final L10N L = new L10N(EjbMethod.class); 48 49 public static final int TRANS_BEAN = 0; 50 public static final int TRANS_NOT_SUPPORTED = TRANS_BEAN + 1; 51 public static final int TRANS_SUPPORTS = TRANS_NOT_SUPPORTED + 1; 52 public static final int TRANS_REQUIRED = TRANS_SUPPORTS + 1; 53 public static final int TRANS_REQUIRES_NEW = TRANS_REQUIRED + 1; 54 public static final int TRANS_MANDATORY = TRANS_REQUIRES_NEW + 1; 55 public static final int TRANS_NEVER = TRANS_MANDATORY + 1; 56 public static final int TRANS_SINGLE_READ = TRANS_NEVER + 1; 57 58 public final static int RESIN_DATABASE = 0; 59 public final static int RESIN_READ_ONLY = 1; 60 public final static int RESIN_ROW_LOCKING = 2; 61 62 private EjbView _view; 63 64 private JMethod _apiMethod; 65 private JMethod _implMethod; 66 67 74 public EjbMethod(EjbView view, JMethod apiMethod, JMethod implMethod) 75 { 76 if (apiMethod == null) 77 throw new NullPointerException (); 78 79 _view = view; 80 _apiMethod = apiMethod; 81 _implMethod = implMethod; 82 } 83 84 87 public EjbView getView() 88 { 89 return _view; 90 } 91 92 95 public String getViewPrefix() 96 { 97 return _view.getPrefix(); 98 } 99 100 103 public JMethod getApiMethod() 104 { 105 return _apiMethod; 106 } 107 108 111 public JMethod getImplMethod() 112 { 113 return _implMethod; 114 } 115 116 119 public void assembleBean(BeanAssembler beanAssembler, String fullClassName) 120 throws ConfigException 121 { 122 } 123 124 127 public BaseMethod assemble(ViewClass viewAssembler, String fullClassName) 128 throws ConfigException 129 { 130 if (getImplMethod() == null) 131 throw new NullPointerException ("no impl: " + getApiMethod()); 132 133 BaseMethod method = viewAssembler.createBusinessMethod(this); 134 135 method.setCall(assembleCallChain(method.getCall())); 136 137 return method; 138 } 139 140 143 protected CallChain assembleCallChain(CallChain call) 144 { 145 call = getView().getTransactionChain(call, 146 getApiMethod(), 147 getViewPrefix()); 148 149 call = getView().getSecurityChain(call, 150 getApiMethod(), 151 getViewPrefix()); 152 153 return call; 154 } 155 156 159 protected void pushRequired(JavaWriter out) 160 throws IOException 161 { 162 163 out.println("com.caucho.ejb.xa.TransactionContext xa = _xaManager.beginRequired();"); 164 out.println("try {"); 165 out.pushDepth(); 166 } 167 168 171 protected void popRequired(JavaWriter out) 172 throws IOException 173 { 174 out.popDepth(); 175 out.println("} catch (RuntimeException e) {"); 176 out.println(" throw trans.setRollbackOnly(e);"); 177 out.println("} finally {"); 178 out.println(" trans.commit();"); 179 out.println("}"); 180 } 181 182 185 public boolean equals(Object o) 186 { 187 if (! (o instanceof EjbMethod)) 188 return false; 189 190 EjbMethod method = (EjbMethod) o; 191 192 if (_view != method._view) 193 return false; 194 else if (! _apiMethod.equals(method._apiMethod)) 195 return false; 196 else 197 return true; 198 } 199 200 public String toString() 201 { 202 return "EJBMethod[" + _apiMethod + "]"; 203 } 204 } 205 | Popular Tags |