1 22 package org.jboss.ejb3; 23 24 import org.jboss.injection.Injector; 25 import org.jboss.ejb3.stateful.StatefulBeanContext; 26 import org.jboss.logging.Logger; 27 import org.jboss.util.id.GUID; 28 29 35 public abstract class AbstractPool implements Pool 36 { 37 private static final Logger log = Logger.getLogger(EJBContainer.class); 38 39 protected Class beanClass; 40 protected Class contextClass; 41 protected Injector[] injectors; 42 protected Container container; 43 44 public AbstractPool() 45 { 46 47 } 48 49 public void initialize(Container container, Class contextClass, Class beanClass, int maxSize, long timeout) 50 { 51 this.beanClass = beanClass; 52 this.contextClass = contextClass; 53 this.container = container; 54 } 55 56 public void setMaxSize(int maxSize) 57 { 58 } 59 60 protected BeanContext create() 61 { 62 Object bean; 63 BeanContext ctx; 64 try 65 { 66 bean = container.construct(); 67 ctx = (BeanContext) contextClass.newInstance(); 68 ctx.setContainer(container); 69 ctx.setInstance(bean); 70 } 71 catch (InstantiationException e) 72 { 73 throw new RuntimeException (e); } 75 catch (IllegalAccessException e) 76 { 77 throw new RuntimeException (e); } 79 if (ctx instanceof StatefulBeanContext) 80 { 81 StatefulBeanContext sfctx = (StatefulBeanContext) ctx; 83 sfctx.setId(new GUID()); 84 ctx = sfctx = sfctx.pushContainedIn(); 85 } 86 try 87 { 88 if (injectors != null) 89 { 90 for (int i = 0; i < injectors.length; i++) 91 { 92 injectors[i].inject(ctx); 93 } 94 } 95 96 ctx.initialiseInterceptorInstances(); 97 98 } 99 finally 100 { 101 if (ctx instanceof StatefulBeanContext) 102 { 103 StatefulBeanContext sfctx = (StatefulBeanContext) ctx; 105 sfctx.popContainedIn(); 106 } 107 } 108 109 container.invokeInit(bean); 111 112 container.invokePostConstruct(ctx); 113 return ctx; 114 } 115 116 protected BeanContext create(Class [] initTypes, Object [] initValues) 117 { 118 Object bean; 119 BeanContext ctx; 120 try 121 { 122 bean = container.construct(); 123 ctx = (BeanContext) contextClass.newInstance(); 124 ctx.setContainer(container); 125 ctx.setInstance(bean); 126 } 127 catch (InstantiationException e) 128 { 129 throw new RuntimeException (e); } 131 catch (IllegalAccessException e) 132 { 133 throw new RuntimeException (e); } 135 if (ctx instanceof StatefulBeanContext) 136 { 137 StatefulBeanContext sfctx = (StatefulBeanContext) ctx; 139 sfctx.setId(new GUID()); 140 ctx = sfctx = sfctx.pushContainedIn(); 141 } 142 try 143 { 144 if (injectors != null) 145 { 146 for (int i = 0; i < injectors.length; i++) 147 { 148 injectors[i].inject(ctx); 149 } 150 } 151 152 ctx.initialiseInterceptorInstances(); 153 154 } 155 finally 156 { 157 if (ctx instanceof StatefulBeanContext) 158 { 159 StatefulBeanContext sfctx = (StatefulBeanContext) ctx; 161 sfctx.popContainedIn(); 162 } 163 } 164 container.invokeInit(bean, initTypes, initValues); 166 167 container.invokePostConstruct(ctx); 168 return ctx; 169 } 170 171 public void remove(BeanContext ctx) 172 { 173 try 174 { 175 container.invokePreDestroy(ctx); 176 } 177 finally 178 { 179 ctx.remove(); 180 } 181 } 182 183 public void discard(BeanContext ctx) 184 { 185 remove(ctx); 186 } 187 188 public void setInjectors(Injector[] injectors) 189 { 190 this.injectors = injectors; 191 } 192 } 193 | Popular Tags |