You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DeclareSoftImpl.java 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* *******************************************************************
  2. * Copyright (c) 2005 Contributors.
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Adrian Colyer Initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.internal.lang.reflect;
  13. import org.aspectj.lang.reflect.AjType;
  14. import org.aspectj.lang.reflect.AjTypeSystem;
  15. import org.aspectj.lang.reflect.DeclareSoft;
  16. import org.aspectj.lang.reflect.PointcutExpression;
  17. /**
  18. * @author colyer
  19. *
  20. */
  21. public class DeclareSoftImpl implements DeclareSoft {
  22. private AjType<?> declaringType;
  23. private PointcutExpression pointcut;
  24. private AjType<?> exceptionType;
  25. private String missingTypeName;
  26. public DeclareSoftImpl(AjType<?> declaringType, String pcut, String exceptionTypeName) {
  27. this.declaringType = declaringType;
  28. this.pointcut = new PointcutExpressionImpl(pcut);
  29. try {
  30. ClassLoader cl = declaringType.getJavaClass().getClassLoader();
  31. this.exceptionType = AjTypeSystem.getAjType(Class.forName(exceptionTypeName,false,cl));
  32. } catch (ClassNotFoundException ex) {
  33. this.missingTypeName = exceptionTypeName;
  34. }
  35. }
  36. /* (non-Javadoc)
  37. * @see org.aspectj.lang.reflect.DeclareSoft#getDeclaringType()
  38. */
  39. public AjType getDeclaringType() {
  40. return this.declaringType;
  41. }
  42. /* (non-Javadoc)
  43. * @see org.aspectj.lang.reflect.DeclareSoft#getSoftenedExceptionType()
  44. */
  45. public AjType getSoftenedExceptionType() throws ClassNotFoundException {
  46. if (this.missingTypeName != null) throw new ClassNotFoundException(this.missingTypeName);
  47. return this.exceptionType;
  48. }
  49. /* (non-Javadoc)
  50. * @see org.aspectj.lang.reflect.DeclareSoft#getPointcutExpression()
  51. */
  52. public PointcutExpression getPointcutExpression() {
  53. return this.pointcut;
  54. }
  55. public String toString() {
  56. StringBuffer sb = new StringBuffer();
  57. sb.append("declare soft : ");
  58. if (this.missingTypeName != null) {
  59. sb.append(this.exceptionType.getName());
  60. } else {
  61. sb.append(this.missingTypeName);
  62. }
  63. sb.append(" : ");
  64. sb.append(getPointcutExpression().asString());
  65. return sb.toString();
  66. }
  67. }