KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > aop > AopUtil


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.cache.aop;
8
9 import org.apache.commons.logging.Log;
10 import org.apache.commons.logging.LogFactory;
11 import org.jboss.aop.InstanceAdvisor;
12 import org.jboss.aop.Advised;
13 import org.jboss.aop.advice.Interceptor;
14 import org.jboss.aop.joinpoint.Invocation;
15 import org.jboss.aop.joinpoint.MethodInvocation;
16 import org.jboss.aop.proxy.ClassProxy;
17 import org.jboss.aop.proxy.ClassProxyFactory;
18 import org.jboss.aop.util.MethodHashing;
19 import org.jboss.util.NestedRuntimeException;
20 import org.jboss.cache.Fqn;
21
22 import java.lang.reflect.Method JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.Map JavaDoc;
25 import java.io.Serializable JavaDoc;
26
27 /**
28  * Unitlity methods for put, get and remove Collection classes object.
29  *
30  * @author Ben Wang
31  */

32 public class AopUtil
33 {
34    static Log log=LogFactory.getLog(AopUtil.class.getName());
35
36    /**
37     * Find cache interceptor with exact fqn.
38     * @param advisor
39     * @param fqn
40     * @return
41     */

42    static Interceptor findCacheInterceptor(InstanceAdvisor advisor, Fqn fqn)
43    {
44       org.jboss.aop.advice.Interceptor[] interceptors = advisor.getInterceptors();
45       // Step Check for cross references
46
for (int i = 0; i < interceptors.length; i++) {
47          Interceptor interceptor = interceptors[i];
48          if (interceptor instanceof CacheInterceptor) {
49             CacheInterceptor inter = (CacheInterceptor)interceptor;
50             if (inter != null && inter.getFqn().equals(fqn))
51             {
52                return interceptor;
53             }
54          }
55       }
56       return null;
57    }
58
59    /**
60     * Find existing cache interceptor. Since there is supposedly only one cache interceptor per
61     * pojo, this call should suffice. In addition, in cases of cross or circular reference,
62     * fqn can be different anyway.
63     * @param advisor
64     * @return
65     */

66    static Interceptor findCacheInterceptor(InstanceAdvisor advisor)
67    {
68       // TODO we assume there is only one interceptor now.
69
Interceptor[] interceptors = advisor.getInterceptors();
70       // Step Check for cross references
71
for (int i = 0; i < interceptors.length; i++) {
72          Interceptor interceptor = interceptors[i];
73          if (interceptor instanceof CacheInterceptor) {
74                return interceptor;
75          }
76       }
77       return null;
78    }
79
80    /**
81     * Check whether the object type is valid. An object type is valid if it is either: aspectized,
82     * Serializable, or primitive type. Otherwise a runtime exception is thrown.
83     *
84     * @param obj
85     */

86    static void checkObjectType(Object JavaDoc obj) {
87       if(obj == null) return;
88       if( ! (obj instanceof Advised) ) {
89           if( !(obj instanceof Serializable JavaDoc ) ) {
90                throw new IllegalArgumentException JavaDoc("TreeCacheAop.putObject(): Object type is neither " +
91                   " aspectized nor Serializable. Object class name is " +obj.getClass().getName());
92           }
93       }
94    }
95
96 }
97
Popular Tags