1 /* $Id: RemoteInterceptor.java 22 2010-05-18 10:20:25Z lavans $ */
\r
2 package com.lavans.luz2.lremote.intercetor;
\r
4 import java.lang.reflect.Method;
\r
6 import net.sf.cglib.proxy.MethodInterceptor;
\r
7 import net.sf.cglib.proxy.MethodProxy;
\r
9 import org.apache.commons.logging.Log;
\r
10 import org.apache.commons.logging.LogFactory;
\r
12 import com.lavans.luz2.lremote.annotation.LRemote;
\r
13 import com.lavans.luz2.lremote.connector.ConnectManager;
\r
14 import com.lavans.luz2.lremote.connector.Connector;
\r
16 public class RemoteInterceptor implements MethodInterceptor{
\r
18 private static Log logger = LogFactory.getLog(ConnectManager.class.getName());
\r
21 public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
\r
22 // Check the method is local
\r
23 LRemote lremote = method.getAnnotation(LRemote.class);
\r
24 if((lremote==null) || lremote.group().equals(LRemote.LOCAL)){
\r
25 return proxy.invokeSuper(obj, args);
\r
29 ConnectManager connectManager = ConnectManager.getInstance();
\r
30 Connector connector = connectManager.getConnector(lremote);
\r
31 if(connector == null){
\r
32 logger.error("No connector is valid");
\r
36 return connector.execute(method.getDeclaringClass().getName(), method.getName(), method.getParameterTypes(), args);
\r