1 25 26 package org.objectweb.easybeans.tests.enhancer.interceptors.business.bean; 27 28 import static javax.ejb.TransactionAttributeType.NEVER ; 29 30 import javax.ejb.Local ; 31 import javax.ejb.Remote ; 32 import javax.ejb.Stateless ; 33 import javax.ejb.TransactionAttribute ; 34 import javax.interceptor.AroundInvoke; 35 import javax.interceptor.ExcludeClassInterceptors; 36 import javax.interceptor.Interceptors; 37 import javax.interceptor.InvocationContext; 38 39 43 @Stateless (name = "HelloWorldbean") 44 @Remote (StatelessRemoteItf.class) 45 @Local ({StatelessLocalItf.class, StatelessLocalBisItf.class}) 46 @Interceptors({Interceptor.class}) 47 @TransactionAttribute (NEVER) 48 public class StatelessBean implements StatelessRemoteItf, StatelessLocalItf, StatelessLocalBisItf { 49 50 53 private int counter; 54 55 56 59 private int otherInterceptorCounter = 0; 60 61 62 65 private int singleMethodInterceptedCounter = 0; 66 67 68 69 73 78 public boolean getBoolean(final boolean b) { 79 return b; 80 } 81 82 83 88 public boolean[] getBooleans(final boolean[] booleans) { 89 return booleans; 90 } 91 92 93 94 98 103 public byte getByte(final byte i) { 104 return i; 105 } 106 107 108 113 public byte[] getBytes(final byte[] bytes) { 114 return bytes; 115 } 116 117 121 122 127 public char getChar(final char c) { 128 return c; 129 } 130 131 132 137 public char[] getChars(final char[] chars) { 138 return chars; 139 } 140 141 145 146 151 public double getDouble(final double d) { 152 return d; 153 } 154 155 156 161 public double[] getDoubles(final double[] doubles) { 162 return doubles; 163 } 164 165 166 170 171 176 public float getFloat(final float f) { 177 return f; 178 } 179 180 181 186 public float[] getFloats(final float[] floats) { 187 return floats; 188 } 189 190 191 192 196 197 198 203 public int getInt(final int i) { 204 return i; 205 } 206 207 213 public int addInt(final int i, final int j) { 214 return i + j; 215 } 216 217 218 223 public int[] getInts(final int[] ints) { 224 return ints; 225 } 226 227 228 229 233 234 239 public long getLong(final long l) { 240 return l; 241 } 242 243 244 249 public long[] getLongs(final long[] longs) { 250 return longs; 251 } 252 253 254 258 263 public short getShort(final short s) { 264 return s; 265 } 266 267 268 273 public short[] getShorts(final short[] shorts) { 274 return shorts; 275 } 276 277 278 279 283 295 public Object [] getPrimitive(final boolean flag, final byte b, final char c, 296 final double d, final float f, final int i, final long l, final Object o) { 297 return new Object [] {Boolean.valueOf(flag), Byte.valueOf(b), Character.valueOf(c), 299 Double.valueOf(d), Float.valueOf(f), Integer.valueOf(i), Long.valueOf(l), o}; 300 } 301 302 303 304 305 306 307 308 313 public void methodNotInAllInterface() { 314 315 } 316 317 318 319 323 327 public void someCustomizedExceptions() throws TestException { 328 throw new TestException("someCustomizedExceptions"); 329 } 330 331 337 public void someCustomizedExceptions2(final int value) throws TestException, TestException2 { 338 switch (value) { 339 case 1: 340 throw new TestException("someCustomizedExceptions2.TestException"); 341 case 2: 342 throw new TestException2("someCustomizedExceptions2.TestException2"); 343 default: 344 break; 345 } 346 } 347 348 349 354 public void someCustomizedExceptions3(final int value) throws Exception { 355 final int one = 1; 356 final int two = 2; 357 final int three = 3; 358 switch (value) { 359 case one: 360 throw new TestException("someCustomizedExceptions3.TestException"); 361 case two: 362 throw new TestException2("someCustomizedExceptions3.TestException2"); 363 case three: 364 throw new Exception ("someCustomizedExceptions3.Exception"); 365 default: 366 throw new RuntimeException ("someCustomizedExceptions3.RuntimeException"); 367 } 368 } 369 370 371 374 public void throwExceptionByInterceptor() { 375 376 } 377 378 379 384 public int valueDoubledByInterceptor(final int i) { 385 return i; 386 } 387 388 389 395 @AroundInvoke 396 public Object intercepted(final InvocationContext invocationContext) throws Exception { 397 counter++; 399 400 if (invocationContext.getMethod().getName().equals("throwExceptionByInterceptor")) { 402 throw new Exception ("Throw an exception on throwExceptionByInterceptor"); 403 } 404 405 if (invocationContext.getMethod().getName().equals("valueDoubledByInterceptor")) { 406 Object value = null; 407 try { 408 value = invocationContext.proceed(); 409 } finally { 410 if (value instanceof Integer ) { 411 return Integer.valueOf(((Integer ) value).intValue()* 2); 412 } 413 } 414 } 415 416 return invocationContext.proceed(); 417 } 418 419 420 423 public int getCounter() { 424 return counter; 425 } 426 427 428 431 public int getOtherInterceptorCounter() { 432 return otherInterceptorCounter; 433 } 434 435 438 public void incrementOtherInterceptorCounter() { 439 otherInterceptorCounter++; 440 } 441 442 443 446 @Interceptors({SingleMethodInterceptor.class}) 447 public void singleMethodIntercepted() { 448 449 } 450 451 454 public void incrementSingleMethodInterceptedCounter() { 455 singleMethodInterceptedCounter++; 456 } 457 458 461 public int getIncrementSingleMethodInterceptedCounter() { 462 return singleMethodInterceptedCounter; 463 } 464 465 466 469 @ExcludeClassInterceptors 470 public void excludedInterceptorsMethod() { 471 472 } 473 474 475 480 public void sameMethodName(final int i) { 481 482 } 483 484 489 public void sameMethodName(final double d) { 490 491 } 492 } 493 | Popular Tags |