KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > soto > aop > MethodPointCut


1 package org.sapia.soto.aop;
2
3 import org.sapia.soto.reflect.Matcher;
4
5 import java.util.ArrayList JavaDoc;
6 import java.util.List JavaDoc;
7
8
9 /**
10  * Models a method pointcut: encapsulates advices that are to be called
11  * when given methods are invoked.
12  *
13  * @author Yanick Duchesne
14  * <dl>
15  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
16  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
17  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
18  * </dl>
19  */

20 public class MethodPointCut extends Matcher {
21   private List JavaDoc _adviceRefs = new ArrayList JavaDoc();
22   private List JavaDoc _groupRefs = new ArrayList JavaDoc();
23
24   /**
25    * Constructor for MethodPointCut.
26    */

27   public MethodPointCut() {
28     super();
29   }
30
31   // /**
32
// * Sets the name pattern of the method(s) that is (are) to be
33
// * intercepted.
34
// *
35
// * @param name a method name pattern.
36
// */
37
// public void setName(String name) {
38
// _namePattern = PathPattern.parse(name, true);
39
// }
40
// /**
41
// * Sets the signature (in the form of parameter type name patterns)
42
// * of the method(s) that is (are) to be intercepted.
43
// *
44
// * @param name a method name pattern.
45
// */
46
// public void setSig(String sig) {
47
// String[] sigArr = Utils.split(sig, ',', true);
48
// _sig = new Pattern[sigArr.length];
49
//
50
// for (int i = 0; i < sigArr.length; i++) {
51
// _sig[i] = PathPattern.parse(sigArr[i], true);
52
// }
53
// }
54
// /**
55
// * Sets the access modifiers of the methods that are matched, in
56
// * a comma-delimited list: "protected, public".
57
// *
58
// * @param viz an access modifier name ("protected" and/or "public").s
59
// */
60
// public void setVisibility(String viz){
61
// _visibility = viz;
62
// }
63

64   /**
65    * Creates an <code>AdviceRef</code> instance and returns it.
66    *
67    * @return an <code>AdviceRef</code>.
68    */

69   public AdviceRef createAdviceRef() {
70     AdviceRef ref = new AdviceRef();
71     _adviceRefs.add(ref);
72
73     return ref;
74   }
75
76   /**
77    * Creates a <code>GroupRef</code> instance and returns it.
78    *
79    * @return an <code>GroupRef</code>.
80    */

81   public GroupRef createGroupRef() {
82     GroupRef ref = new GroupRef();
83     _groupRefs.add(ref);
84
85     return ref;
86   }
87
88   /**
89    * Scans the given class and returns the list of methods that
90    * correspond to this instance's properties.
91    *
92    * @return a <code>List</code> of <code>Method</code>s.
93    */

94
95   // List scan(Class toScan) throws ConfigurationException {
96
// List toReturn = new ArrayList();
97
// Method[] methods = toScan.getMethods();
98
//
99
// for (int i = 0; i < methods.length; i++) {
100
// if (_namePattern == null) {
101
// throw new ConfigurationException(
102
// "'name' attribute was not specified on method pointcut");
103
// } else {
104
// if (_namePattern.matches(methods[i].getName())) {
105
// if (matchesSig(methods[i])) {
106
// toReturn.add(methods[i]);
107
// }
108
// }
109
// }
110
// }
111
//
112
// return toReturn;
113
// }
114

115   /**
116    * Returns this instance's advice references.
117    *
118    * @return a <code>List</code> of <code>AdviceRef</code> instances.
119    */

120   List JavaDoc getAdviceRefs() {
121     return _adviceRefs;
122   }
123
124   /**
125    * Returns this instance's advice group references.
126    *
127    * @return a <code>List</code> of <code>GroupRef</code> instances.
128    */

129   List JavaDoc getGroupRefs() {
130     return _groupRefs;
131   }
132
133   // private boolean matchesSig(Method m) {
134
// if (_sig == null) {
135
// return true;
136
// } else if (_sig.length == m.getParameterTypes().length) {
137
// int count = 0;
138
//
139
// for (int i = 0; i < _sig.length; i++) {
140
// if (_sig[i].matches(m.getParameterTypes()[i].getName())) {
141
// count++;
142
// }
143
// }
144
//
145
// return count == _sig.length;
146
// }
147
//
148
// return false;
149
// }
150
}
151
Popular Tags