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.util.L10N; 35 36 import java.io.IOException ; 37 38 41 public class StatelessBean extends SessionBean { 42 private static final L10N L = new L10N(StatelessBean.class); 43 44 public StatelessBean(JClass ejbClass, String contextClassName) 45 { 46 super(ejbClass, contextClassName); 47 } 48 49 protected void generateContext(JavaWriter out) 50 throws IOException 51 { 52 String shortContextName = _contextClassName; 53 int p = shortContextName.lastIndexOf('.'); 54 55 if (p > 0) 56 shortContextName = shortContextName.substring(p + 1); 57 58 int freeStackMax = 16; 59 60 out.println("protected static final java.util.logging.Logger __caucho_log = com.caucho.log.Log.open(" + _contextClassName + ".class);"); 61 out.println(); 62 out.println("com.caucho.ejb.xa.EjbTransactionManager _xaManager;"); 63 64 out.println("private Bean []_freeBeanStack = new Bean[" + freeStackMax + "];"); 65 out.println("private int _freeBeanTop;"); 66 out.println(); 67 out.println("public " + shortContextName + "(com.caucho.ejb.session.StatelessServer server)"); 68 out.println("{"); 69 out.println(" super(server);"); 70 out.println(" _xaManager = server.getContainer().getTransactionManager();"); 71 out.println("}"); 72 73 out.println(); 74 out.println("Bean _ejb_begin(com.caucho.ejb.xa.TransactionContext trans)"); 75 out.println(" throws javax.ejb.EJBException"); 76 out.println("{"); 77 out.pushDepth(); 78 out.println("Bean bean;"); 79 out.println("synchronized (this) {"); 80 out.println(" if (_freeBeanTop > 0) {"); 81 out.println(" bean = _freeBeanStack[--_freeBeanTop];"); 82 out.println(" return bean;"); 83 out.println(" }"); 84 out.println("}"); 85 out.println(); 86 out.println("try {"); 87 out.println(" bean = new Bean(this);"); 88 89 if (hasMethod("ejbCreate", new JClass[0])) { 90 out.println(" bean.ejbCreate();"); 91 } 92 93 out.println(" return bean;"); 94 out.println("} catch (Exception e) {"); 95 out.println(" throw com.caucho.ejb.EJBExceptionWrapper.create(e);"); 96 out.println("}"); 97 out.popDepth(); 98 out.println("}"); 99 100 out.println(); 101 out.println("void _ejb_free(Bean bean)"); 102 out.println(" throws javax.ejb.EJBException"); 103 out.println("{"); 104 out.pushDepth(); 105 out.println("if (bean == null)"); 106 out.println(" return;"); 107 out.println(); 108 out.println("synchronized (this) {"); 109 out.println(" if (_freeBeanTop < _freeBeanStack.length) {"); 110 out.println(" _freeBeanStack[_freeBeanTop++] = bean;"); 111 out.println(" return;"); 112 out.println(" }"); 113 out.println("}"); 114 115 if (hasMethod("ejbRemove", new JClass[0])) { 116 out.println(); 117 out.println("bean.ejbRemove();"); 118 } 119 120 out.popDepth(); 121 out.println("}"); 122 123 out.println(); 124 out.println("public void destroy()"); 125 out.println("{"); 126 out.pushDepth(); 127 out.println("Bean ptr;"); 128 out.println("Bean []freeBeanStack;"); 129 out.println("int freeBeanTop;"); 130 131 out.println("synchronized (this) {"); 132 out.println(" freeBeanStack = _freeBeanStack;"); 133 out.println(" freeBeanTop = _freeBeanTop;"); 134 out.println(" _freeBeanStack = null;"); 135 out.println(" _freeBeanTop = 0;"); 136 out.println("}"); 137 138 if (hasMethod("ejbRemove", new JClass[0])) { 139 out.println(); 140 out.println("for (int i = 0; i < freeBeanTop; i++) {"); 141 out.pushDepth(); 142 143 out.println("try {"); 144 out.println(" if (freeBeanStack[i] != null)"); 145 out.println(" freeBeanStack[i].ejbRemove();"); 146 out.println("} catch (Throwable e) {"); 147 out.println(" __caucho_log.log(java.util.logging.Level.FINE, e.toString(), e);"); 148 out.println("}"); 149 150 out.popDepth(); 151 out.println("}"); 152 } 153 out.popDepth(); 154 out.println("}"); 155 } 156 157 protected void generateNewInstance(JavaWriter out) 158 throws IOException 159 { 160 } 161 } 162 | Popular Tags |