KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > dynamicgenadvisor > Interceptions


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.aop.dynamicgenadvisor;
23
24 import java.lang.reflect.Constructor JavaDoc;
25 import java.lang.reflect.Field JavaDoc;
26 import java.lang.reflect.Method JavaDoc;
27 import java.util.ArrayList JavaDoc;
28
29 public class Interceptions
30 {
31    private static ArrayList JavaDoc interceptions = new ArrayList JavaDoc();
32    
33    public static void clear()
34    {
35       interceptions.clear();
36    }
37    
38    public static boolean isEmpty()
39    {
40       return interceptions.isEmpty();
41    }
42    
43    public static int size()
44    {
45       return interceptions.size();
46    }
47    
48    public static String JavaDoc get(int index)
49    {
50       return (String JavaDoc)interceptions.get(index);
51    }
52    
53    public static void addConstructorInterception(Class JavaDoc aspect, Constructor JavaDoc c)
54    {
55       interceptions.add(getConstructorName(getClassName(aspect), c));
56    }
57
58    public static void addConstructionInterception(Class JavaDoc aspect, Constructor JavaDoc c)
59    {
60       interceptions.add(getConstructionName(getClassName(aspect), c));
61    }
62    
63    public static void addMethodInterception(Class JavaDoc aspect, Method JavaDoc m)
64    {
65       interceptions.add(getMethodName(getClassName(aspect), m));
66    }
67    
68    public static void addFieldReadInterception(Class JavaDoc aspect, Field JavaDoc f)
69    {
70       interceptions.add(getFieldReadName(getClassName(aspect), f));
71    }
72    
73    public static void addFieldWriteInterception(Class JavaDoc aspect, Field JavaDoc f)
74    {
75       interceptions.add(getFieldWriteName(getClassName(aspect), f));
76    }
77
78    public static String JavaDoc getConstructorName(String JavaDoc aspect, String JavaDoc clazz)
79    {
80       return aspect + " : " + clazz + ".new";
81    }
82    
83    public static String JavaDoc getConstructionName(String JavaDoc aspect, String JavaDoc clazz)
84    {
85       return aspect + " : " + clazz + ".new...";
86    }
87    
88    public static String JavaDoc getMethodName(String JavaDoc aspect, String JavaDoc clazz, String JavaDoc m)
89    {
90       return aspect + " : " + clazz + "." + m;
91    }
92    
93    public static String JavaDoc getFieldReadName(String JavaDoc aspect, String JavaDoc clazz, String JavaDoc f)
94    {
95       return aspect + " : " + clazz + ".r_" + f;
96    }
97    
98    public static String JavaDoc getFieldWriteName(String JavaDoc aspect, String JavaDoc clazz, String JavaDoc f)
99    {
100       return aspect + " : " + clazz + ".w_" + f;
101    }
102    
103    private static String JavaDoc getConstructorName(String JavaDoc aspect, Constructor JavaDoc con)
104    {
105       return getConstructorName(aspect, getClassName(con));
106    }
107    
108    private static String JavaDoc getConstructionName(String JavaDoc aspect, Constructor JavaDoc con)
109    {
110       return getConstructionName(aspect, getClassName(con));
111    }
112    
113    private static String JavaDoc getMethodName(String JavaDoc aspect, Method JavaDoc m)
114    {
115       return getMethodName(aspect, getClassName(m), m.getName());
116    }
117    
118    private static String JavaDoc getFieldReadName(String JavaDoc aspect, Field JavaDoc f)
119    {
120       return getFieldReadName(aspect, getClassName(f), f.getName());
121    }
122    
123    private static String JavaDoc getFieldWriteName(String JavaDoc aspect, Field JavaDoc f)
124    {
125       return getFieldWriteName(aspect, getClassName(f), f.getName());
126    }
127
128    private static String JavaDoc getClassName(Constructor JavaDoc c)
129    {
130       return getClassName(c.getDeclaringClass().getName());
131    }
132    
133    private static String JavaDoc getClassName(Method JavaDoc m)
134    {
135       return getClassName(m.getDeclaringClass().getName());
136    }
137    
138    private static String JavaDoc getClassName(Field JavaDoc f)
139    {
140       return getClassName(f.getDeclaringClass().getName());
141    }
142    
143    private static String JavaDoc getClassName(Class JavaDoc clazz)
144    {
145       return getClassName(clazz.getName());
146    }
147    
148    private static String JavaDoc getClassName(String JavaDoc s)
149    {
150       return s.substring(s.lastIndexOf('.') + 1);
151    }
152 }
153
Popular Tags