1 23 package com.sun.enterprise.deployment; 24 25 import com.sun.enterprise.util.LocalStringManagerImpl; 26 import java.util.*; 27 28 33 34 public final class EjbSessionDescriptor extends EjbDescriptor { 35 private boolean isStateless = false; 36 private int timeout = 0; 37 38 private Set<LifecycleCallbackDescriptor> postActivateDescs = 39 new HashSet<LifecycleCallbackDescriptor>(); 40 private Set<LifecycleCallbackDescriptor> prePassivateDescs = 41 new HashSet<LifecycleCallbackDescriptor>(); 42 43 private Map<MethodDescriptor, EjbRemovalInfo> removeMethods 46 = new HashMap<MethodDescriptor, EjbRemovalInfo>(); 47 48 private Set<EjbInitInfo> initMethods=new HashSet<EjbInitInfo>(); 51 52 53 public final static String TYPE = "Session"; 54 55 public final static String STATELESS = "Stateless"; 56 57 public final static String STATEFUL = "Stateful"; 58 59 private static LocalStringManagerImpl localStrings = 60 new LocalStringManagerImpl(EjbSessionDescriptor.class); 61 62 65 public EjbSessionDescriptor() { 66 } 67 68 71 72 public EjbSessionDescriptor(EjbDescriptor other) { 73 super(other); 74 if (other instanceof EjbSessionDescriptor) { 75 EjbSessionDescriptor session = (EjbSessionDescriptor) other; 76 this.isStateless = session.isStateless; 77 this.timeout = session.timeout; 78 } 79 } 80 81 84 public String getType() { 85 return TYPE; 86 } 87 88 92 93 public String getSessionType() { 94 if (this.isStateless()) { 95 return STATELESS; 96 } else { 97 return STATEFUL; 98 } 99 } 100 101 104 public void setSessionType(String sessionType) { 105 if (STATELESS.equals(sessionType)) { 106 this.setStateless(true); 107 return; 108 } 109 if (STATEFUL.equals(sessionType)) { 110 this.setStateless(false); 111 return; 112 } 113 if (this.isBoundsChecking()) { 114 throw new IllegalArgumentException (localStrings.getLocalString( 115 "enterprise.deployment.exceptionsessiontypenotlegaltype", 116 "{0} is not a legal session type for session ejbs. The type must be {1} or {2}", new Object [] {sessionType, STATEFUL, STATELESS})); 117 } 118 } 119 120 123 public void setType(String type) { 124 throw new IllegalArgumentException (localStrings.getLocalString( 125 "enterprise.deployment.exceptioncannotsettypeofsessionbean", 126 "Cannot set the type of a session bean")); 127 } 128 129 132 133 public void setTimeout(int timeout) { 134 this.timeout = timeout; 135 } 136 137 140 public int getTimeout() { 141 return this.timeout; 142 } 143 144 147 public void setTransactionType(String transactionType) { 148 boolean isValidType = (BEAN_TRANSACTION_TYPE.equals(transactionType) || 149 CONTAINER_TRANSACTION_TYPE.equals(transactionType)); 150 151 if (!isValidType && this.isBoundsChecking()) { 152 throw new IllegalArgumentException (localStrings.getLocalString( 153 "enterprise.deployment..exceptointxtypenotlegaltype", 154 "{0} is not a legal transaction type for session beans", new Object [] {transactionType})); 155 } else { 156 super.transactionType = transactionType; 157 super.setMethodContainerTransactions(new Hashtable()); 158 super.changed(); 159 } 160 } 161 162 165 public boolean isStateless() { 166 return isStateless; 167 } 168 169 public boolean isStateful() { 170 return !isStateless(); 171 } 172 173 176 public void setStateless(boolean isStateless) { 177 this.isStateless = isStateless; 178 super.changed(); 179 } 180 181 public boolean hasRemoveMethods() { 182 return (!removeMethods.isEmpty()); 183 } 184 185 189 public EjbRemovalInfo getRemovalInfo(MethodDescriptor method) { 190 return removeMethods.get(method); 191 } 192 193 public Set<EjbRemovalInfo> getAllRemovalInfo() { 194 return new HashSet<EjbRemovalInfo>(removeMethods.values()); 195 } 196 197 public void addRemoveMethod(EjbRemovalInfo removalInfo) { 198 removeMethods.put(removalInfo.getRemoveMethod(), removalInfo); 199 } 200 201 public boolean hasInitMethods() { 202 return (!initMethods.isEmpty()); 203 } 204 205 public Set<EjbInitInfo> getInitMethods() { 206 return new HashSet<EjbInitInfo>(initMethods); 207 } 208 209 public void addInitMethod(EjbInitInfo initInfo) { 210 initMethods.add(initInfo); 211 } 212 213 public Set<LifecycleCallbackDescriptor> getPostActivateDescriptors() { 214 if (postActivateDescs == null) { 215 postActivateDescs = 216 new HashSet<LifecycleCallbackDescriptor>(); 217 } 218 return postActivateDescs; 219 } 220 221 public void addPostActivateDescriptor(LifecycleCallbackDescriptor 222 postActivateDesc) { 223 String className = postActivateDesc.getLifecycleCallbackClass(); 224 boolean found = false; 225 for (LifecycleCallbackDescriptor next : 226 getPostActivateDescriptors()) { 227 if (next.getLifecycleCallbackClass().equals(className)) { 228 found = true; 229 break; 230 } 231 } 232 if (!found) { 233 getPostActivateDescriptors().add(postActivateDesc); 234 } 235 } 236 237 public LifecycleCallbackDescriptor 238 getPostActivateDescriptorByClass(String className) { 239 240 for (LifecycleCallbackDescriptor next : 241 getPostActivateDescriptors()) { 242 if (next.getLifecycleCallbackClass().equals(className)) { 243 return next; 244 } 245 } 246 return null; 247 } 248 249 public boolean hasPostActivateMethod() { 250 return (getPostActivateDescriptors().size() > 0); 251 } 252 253 public Set<LifecycleCallbackDescriptor> getPrePassivateDescriptors() { 254 if (prePassivateDescs == null) { 255 prePassivateDescs = 256 new HashSet<LifecycleCallbackDescriptor>(); 257 } 258 return prePassivateDescs; 259 } 260 261 public void addPrePassivateDescriptor(LifecycleCallbackDescriptor 262 prePassivateDesc) { 263 String className = prePassivateDesc.getLifecycleCallbackClass(); 264 boolean found = false; 265 for (LifecycleCallbackDescriptor next : 266 getPrePassivateDescriptors()) { 267 if (next.getLifecycleCallbackClass().equals(className)) { 268 found = true; 269 break; 270 } 271 } 272 if (!found) { 273 getPrePassivateDescriptors().add(prePassivateDesc); 274 } 275 } 276 277 public LifecycleCallbackDescriptor 278 getPrePassivateDescriptorByClass(String className) { 279 280 for (LifecycleCallbackDescriptor next : 281 getPrePassivateDescriptors()) { 282 if (next.getLifecycleCallbackClass().equals(className)) { 283 return next; 284 } 285 } 286 return null; 287 } 288 289 public boolean hasPrePassivateMethod() { 290 return (getPrePassivateDescriptors().size() > 0); 291 } 292 293 public Vector getPossibleTransactionAttributes() { 294 Vector txAttributes = super.getPossibleTransactionAttributes(); 295 296 if( isStateful() ) { 299 try { 300 EjbBundleDescriptor ejbBundle = getEjbBundleDescriptor(); 301 302 ClassLoader classLoader = ejbBundle.getClassLoader(); 303 Class ejbClass = classLoader.loadClass(getEjbClassName()); 304 Class sessionSynchClass = 305 javax.ejb.SessionSynchronization .class; 306 if( sessionSynchClass.isAssignableFrom(ejbClass) ) { 307 txAttributes = new Vector(); 308 txAttributes.add(new ContainerTransaction 309 (ContainerTransaction.REQUIRED, "")); 310 txAttributes.add(new ContainerTransaction 311 (ContainerTransaction.REQUIRES_NEW, "")); 312 txAttributes.add(new ContainerTransaction 313 (ContainerTransaction.MANDATORY, "")); 314 } 315 } catch(Exception e) { 316 } 319 } 320 return txAttributes; 321 } 322 323 324 327 public void print(StringBuffer toStringBuffer) { 328 toStringBuffer.append("Session descriptor"); 329 toStringBuffer.append("\n isStateless ").append(isStateless); 330 super.print(toStringBuffer); 331 } 332 333 334 } 335 | Popular Tags |