Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

AOPAllianceAdapter.aj 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*******************************************************************************
  2. * Copyright (c) 2004 IBM Corporation and others.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors:
  9. * IBM Corporation - initial API and implementation
  10. *******************************************************************************/
  11. package org.aspectj.aopalliance;
  12. import org.aspectj.lang.SoftException;
  13. import org.aopalliance.intercept.MethodInterceptor;
  14. import org.aopalliance.intercept.ConstructorInterceptor;
  15. public abstract aspect AOPAllianceAdapter {
  16. /**
  17. * Return the interceptor to use at method execution join points.
  18. * Must be overriden by subclasses.
  19. * @return MethodInterceptor, or null if no method advice required
  20. */
  21. protected abstract MethodInterceptor getMethodInterceptor();
  22. /**
  23. * Return the interceptor to use at constructor execution join points.
  24. * May be overriden by subclasses.
  25. * @return ConstructorInterceptor, or null if no constructor advice required
  26. */
  27. protected ConstructorInterceptor getConstructorInterceptor() {
  28. return null;
  29. }
  30. protected abstract pointcut targetJoinPoint();
  31. pointcut methodExecution() : execution(* *(..));
  32. pointcut constructorExecution() : execution(new(..));
  33. Object around() : targetJoinPoint() && methodExecution() {
  34. MethodInvocationClosure mic = new MethodInvocationClosure(thisJoinPoint) {
  35. public Object execute() { return proceed();}
  36. };
  37. MethodInterceptor mInt = getMethodInterceptor();
  38. if (mInt != null) {
  39. try {
  40. return mInt.invoke(mic);
  41. } catch (Throwable t) {
  42. throw new SoftException(t);
  43. }
  44. } else {
  45. return proceed();
  46. }
  47. }
  48. Object around() : targetJoinPoint() && constructorExecution() {
  49. ConstructorInvocationClosure cic = new ConstructorInvocationClosure(thisJoinPoint) {
  50. public Object execute() { proceed(); return thisJoinPoint.getThis();}
  51. };
  52. ConstructorInterceptor cInt = getConstructorInterceptor();
  53. if (cInt != null) {
  54. try {
  55. return cInt.construct(cic);
  56. } catch (Throwable t) {
  57. throw new SoftException(t);
  58. }
  59. } else {
  60. return proceed();
  61. }
  62. }
  63. }