KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > internal > lang > reflect > PointcutImpl


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
14 import java.lang.reflect.Method JavaDoc;
15 import java.util.StringTokenizer JavaDoc;
16
17 import org.aspectj.lang.reflect.AjType;
18 import org.aspectj.lang.reflect.AjTypeSystem;
19 import org.aspectj.lang.reflect.Pointcut;
20 import org.aspectj.lang.reflect.PointcutExpression;
21
22 /**
23  * @author colyer
24  *
25  */

26 public class PointcutImpl implements Pointcut {
27
28     private final String JavaDoc name;
29     private final PointcutExpression pc;
30     private final Method JavaDoc baseMethod;
31     private final AjType declaringType;
32     private String JavaDoc[] parameterNames = new String JavaDoc[0];
33     
34     protected PointcutImpl(String JavaDoc name, String JavaDoc pc, Method JavaDoc method, AjType declaringType, String JavaDoc pNames) {
35         this.name = name;
36         this.pc = new PointcutExpressionImpl(pc);
37         this.baseMethod = method;
38         this.declaringType = declaringType;
39         this.parameterNames = splitOnComma(pNames);
40     }
41     
42     /* (non-Javadoc)
43      * @see org.aspectj.lang.reflect.Pointcut#getPointcutExpression()
44      */

45     public PointcutExpression getPointcutExpression() {
46         return pc;
47     }
48     
49     public String JavaDoc getName() {
50         return name;
51     }
52
53     public int getModifiers() {
54         return baseMethod.getModifiers();
55     }
56
57     public AjType<?>[] getParameterTypes() {
58         Class JavaDoc<?>[] baseParamTypes = baseMethod.getParameterTypes();
59         AjType<?>[] ajParamTypes = new AjType<?>[baseParamTypes.length];
60         for (int i = 0; i < ajParamTypes.length; i++) {
61             ajParamTypes[i] = AjTypeSystem.getAjType(baseParamTypes[i]);
62         }
63         return ajParamTypes;
64     }
65
66     public AjType getDeclaringType() {
67         return declaringType;
68     }
69     
70     public String JavaDoc[] getParameterNames() {
71         return parameterNames;
72     }
73
74     private String JavaDoc[] splitOnComma(String JavaDoc s) {
75         StringTokenizer JavaDoc strTok = new StringTokenizer JavaDoc(s,",");
76         String JavaDoc[] ret = new String JavaDoc[strTok.countTokens()];
77         for (int i = 0; i < ret.length; i++) {
78             ret[i] = strTok.nextToken().trim();
79         }
80         return ret;
81     }
82     
83     public String JavaDoc toString() {
84         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
85         sb.append(getName());
86         sb.append("(");
87         AjType<?>[] ptypes = getParameterTypes();
88         for (int i = 0; i < ptypes.length; i++) {
89             sb.append(ptypes[i].getName());
90             if (this.parameterNames != null && this.parameterNames[i] != null) {
91                 sb.append(" ");
92                 sb.append(this.parameterNames[i]);
93             }
94             if (i+1 < ptypes.length) sb.append(",");
95         }
96         sb.append(") : ");
97         sb.append(getPointcutExpression().asString());
98         return sb.toString();
99     }
100 }
101
Popular Tags