1 /***************************************************************************************
2 * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
3 * http://aspectwerkz.codehaus.org *
4 * ---------------------------------------------------------------------------------- *
5 * The software in this package is published under the terms of the LGPL license *
6 * a copy of which has been included with this distribution in the license.txt file. *
7 **************************************************************************************/
8 package org.codehaus.aspectwerkz.annotation;
9
10 import org.codehaus.aspectwerkz.exception.DefinitionException;
11 import org.codehaus.aspectwerkz.aspect.AdviceType;
12
13 /***
14 * The 'After' annotation proxy.
15 *
16 * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
17 */
18 public class AfterAnnotationProxy extends AdviceAnnotationProxyBase {
19
20 public static final String RETURNING_PREFIX = "returning(";
21 public static final String THROWING_PREFIX = "throwing(";
22 public static final String FINALLY_PREFIX = "finally ";
23
24 private String m_specialArgumentType;
25
26 public AfterAnnotationProxy() {
27 m_type = AdviceType.AFTER;
28 }
29
30 public void setValue(final String value) {
31 if (value.startsWith(RETURNING_PREFIX)) {
32 m_type = AdviceType.AFTER_RETURNING;
33 int start = value.indexOf('(');
34 int end = value.indexOf(')');
35 m_specialArgumentType = value.substring(start + 1, end).trim();
36 m_pointcut = value.substring(end + 1, value.length()).trim();
37 } else if (value.startsWith(THROWING_PREFIX)) {
38 m_type = AdviceType.AFTER_THROWING;
39 int start = value.indexOf('(');
40 int end = value.indexOf(')');
41 m_specialArgumentType = value.substring(start + 1, end).trim();
42 m_pointcut = value.substring(end + 1, value.length()).trim();
43 } else if (value.startsWith(FINALLY_PREFIX)) {
44 m_type = AdviceType.AFTER_FINALLY;
45 m_pointcut = value.substring(value.indexOf(' ') + 1, value.length()).trim();
46 } else {
47 m_pointcut = value;
48 }
49 if (m_specialArgumentType != null && m_specialArgumentType.indexOf(' ') > 0) {
50 throw new DefinitionException(
51 "argument to after (returning/throwing) can only be a type (parameter name binding should be done using args(..))"
52 );
53 }
54 }
55
56 /***
57 * Returns the special argument type.
58 *
59 * @return
60 */
61 public String getSpecialArgumentType() {
62 return m_specialArgumentType;
63 }
64 }