KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jdon > bussinessproxy > dyncproxy > DynamicProxyWeaving


1 /**
2  * Copyright 2003-2006 the original author or authors.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6
7        http://www.apache.org/licenses/LICENSE-2.0
8
9   * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */

15
16 package com.jdon.bussinessproxy.dyncproxy;
17
18 import java.lang.reflect.InvocationHandler JavaDoc;
19 import java.lang.reflect.Method JavaDoc;
20
21 import com.jdon.aop.AopClient;
22 import com.jdon.container.access.TargetMetaRequest;
23 import com.jdon.util.Debug;
24
25
26 /**
27   * Dynamic Proxy Weaving mode
28   * Weaving implemention is dynamic proxy
29   * Every target service object has its DynamicProxyWeaving object
30   *
31  * 动æ€?代ç?†ç±» å?¯å®žçŽ°AOP拦截
32  * @author banq
33  */

34
35 public class DynamicProxyWeaving implements InvocationHandler JavaDoc, java.io.Serializable JavaDoc {
36
37   private final static String JavaDoc module = DynamicProxyWeaving.class.getName();
38
39   private AopClient aopClient;
40   private TargetMetaRequest targetMetaRequest;
41
42   public DynamicProxyWeaving(TargetMetaRequest targetMetaRequest, AopClient aopClient) {
43     this.targetMetaRequest = targetMetaRequest;
44     this.aopClient = aopClient;
45   }
46   
47   /**
48    * 方法调用
49    * 需è¦?拦截方法在这里实现。目å‰?实现arround intercept
50    * @param p_proxy Object
51    * @param m Method
52    * @param args Object[]
53    * @throws Throwable
54    * @return Object
55    */

56   public Object JavaDoc invoke(Object JavaDoc p_proxy, Method JavaDoc m, Object JavaDoc[] args) throws
57       Throwable JavaDoc {
58     Debug.logVerbose("<################################>Action: JdonFramework core entrance", module);
59     Debug.logVerbose("[JdonFramework]<################>execute method=" + m.getDeclaringClass().getName() + "." + m.getName() , module);
60     Object JavaDoc result = null;
61     try {
62       result = aopClient.invoke(targetMetaRequest, m, args);
63       Debug.logVerbose("[JdonFramework]<################>finish executing method=" + m.getDeclaringClass().getName() + "." + m.getName() + " successfully!", module);
64       Debug.logVerbose("<################################><end:", module);
65     } catch (Exception JavaDoc ex) {
66       Debug.logError(ex, module);
67     } catch (Throwable JavaDoc ex) {
68       throw new Throwable JavaDoc(ex);
69     }
70
71     return result;
72
73   }
74     
75
76 }
77
Popular Tags