當前位置: 首頁>>代碼示例>>Java>>正文


Java MethodInterceptor.invoke方法代碼示例

本文整理匯總了Java中org.aopalliance.intercept.MethodInterceptor.invoke方法的典型用法代碼示例。如果您正苦於以下問題:Java MethodInterceptor.invoke方法的具體用法?Java MethodInterceptor.invoke怎麽用?Java MethodInterceptor.invoke使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.aopalliance.intercept.MethodInterceptor的用法示例。


在下文中一共展示了MethodInterceptor.invoke方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: invoke

import org.aopalliance.intercept.MethodInterceptor; //導入方法依賴的package包/類
/**
 * InvocationHandler 接口中的 invoke 方法具體實現,封裝了具體的代理邏輯
 *
 * @param proxy
 * @param method
 * @param args
 * @return 代理方法或原方法的返回值
 * @throws Throwable
 */
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    MethodMatcher methodMatcher = advised.getMethodMatcher();

    // 使用方法匹配器 methodMatcher 測試 bean 中原始方法 method 是否符合匹配規則
    if (methodMatcher != null && methodMatcher.matchers(method, advised.getTargetSource().getTargetClass())) {

        // 獲取 Advice。MethodInterceptor 的父接口繼承了 Advice
        MethodInterceptor methodInterceptor = advised.getMethodInterceptor();

        // 將 bean 的原始 method 封裝成 MethodInvocation 實現類對象,
        // 將生成的對象傳給 Adivce 實現類對象,執行通知邏輯
        return methodInterceptor.invoke(
                new ReflectiveMethodInvocation(advised.getTargetSource().getTarget(), method, args));
    } else {
        // 當前 method 不符合匹配規則,直接調用 bean 中的原始 method
        return method.invoke(advised.getTargetSource().getTarget(), args);
    }
}
 
開發者ID:code4wt,項目名稱:toy-spring,代碼行數:29,代碼來源:JdkDynamicAopProxy.java

示例2: invoke

import org.aopalliance.intercept.MethodInterceptor; //導入方法依賴的package包/類
public Object invoke(MethodInvocation invocation) throws Throwable
{
    Injector inj = injector; // volatile read
    MethodInterceptor interceptor = inj != null ? inj.getInstance(key) : null;
    if (interceptor == null)
    {
        return invocation.proceed();
    }
    else
    {
        return interceptor.invoke(invocation);
    }
}
 
開發者ID:directwebremoting,項目名稱:dwr,代碼行數:14,代碼來源:InjectingMethodInterceptor.java

示例3: invoke

import org.aopalliance.intercept.MethodInterceptor; //導入方法依賴的package包/類
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
	//提取攔截method方法
	MethodInterceptor methodInterceptor = advised.getMethodInterceptor();
	//比較傳入的方法和原始對象的方法是否一致,如果一致則調用傳入的方法,那攔截的方法什麽時候調用?
	if (advised.getMethodMatcher() != null
			&& advised.getMethodMatcher().matches(method, advised.getTargetSource().getTarget().getClass())) {
		//這裏應該是先調用攔截的方法,然後調用原始對象的方法。但是一般括號裏的東西不是優先嗎?括號裏麵好像就隻有賦值操作而已。
		return methodInterceptor.invoke(new ReflectiveMethodInvocation(advised.getTargetSource().getTarget(),method, args));
	} else {
		return method.invoke(advised.getTargetSource().getTarget(), args);
	}
}
 
開發者ID:greyireland,項目名稱:tiny-spring,代碼行數:14,代碼來源:JdkDynamicAopProxy.java

示例4: invoke

import org.aopalliance.intercept.MethodInterceptor; //導入方法依賴的package包/類
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    MethodInterceptor methodInterceptor = advised.getMethodInterceptor();
    if(advised.getMethodMatcher() != null && advised.getMethodMatcher().matches(method, advised.getTargetSource().getTargetClass())){
        return methodInterceptor.invoke(new ReflectiveMethodInvocation(advised.getTargetSource().getTarget(), method, args));
    }
    return method.invoke(advised.getTargetSource().getTarget(), args);
}
 
開發者ID:cadeeper,項目名稱:my-spring,代碼行數:9,代碼來源:JdkDynamicAopProxy.java

示例5: invoke

import org.aopalliance.intercept.MethodInterceptor; //導入方法依賴的package包/類
@Override
public Object invoke(final MethodInvocation invocation)
    throws Throwable {
    MethodInvocation nextInvocation = invocation;

    // chain the method invocation of interceptors in reverse order
    for (int i = interceptors.length - 1; i >= 0; i--) {
        final MethodInterceptor interceptor = interceptors[i];
        final MethodInvocation previousInvocation = nextInvocation;
        nextInvocation = new MethodInvocation() {

            @Override
            public Object proceed()
                throws Throwable {
                return interceptor.invoke(previousInvocation);
            }

            @Override
            public Object getThis() {
                return invocation.getThis();
            }

            @Override
            public AccessibleObject getStaticPart() {
                return invocation.getStaticPart();
            }

            @Override
            public Object[] getArguments() {
                return invocation.getArguments();
            }

            @Override
            public Method getMethod() {
                return invocation.getMethod();
            }
        };
    }
    return nextInvocation.proceed();
}
 
開發者ID:RMBLWorx,項目名稱:timey,代碼行數:41,代碼來源:Interceptors.java

示例6: newTransactionalDynamicFinderInterceptor

import org.aopalliance.intercept.MethodInterceptor; //導入方法依賴的package包/類
/**
 * Combines the given finder and transaction interceptors into a single transactional finder interceptor.
 * 
 * @param finderInterceptor the finder interceptor to use
 * @param txInterceptor the transaction interceptor to use
 * @param txMatchers the transaction matchers, used to decide which methods to transact
 * @return the transactional method interceptor
 */
public static MethodInterceptor newTransactionalDynamicFinderInterceptor(final MethodInterceptor finderInterceptor,
                                                                  final MethodInterceptor txInterceptor,
                                                                  final Iterable<ClassAndMethodMatcher> txMatchers) {
    return new MethodInterceptor() {
        private ConcurrentMap<Method, Boolean> matcherCache = new ConcurrentHashMap<Method, Boolean>();
        public Object invoke(final MethodInvocation methodInvocation) throws Throwable {
            // Don't care about a theoretical extra run through this, so we don't lock
            if (!matcherCache.containsKey(methodInvocation.getMethod())) {
                boolean matches = false;
                for (ClassAndMethodMatcher matcher : txMatchers) {
                    matches |= matcher.getMethodMatcher().matches(methodInvocation.getMethod());
                }
                matcherCache.putIfAbsent(methodInvocation.getMethod(), matches);
            }

            if (matcherCache.get(methodInvocation.getMethod())) {
                return txInterceptor.invoke(new MethodInvocation() {
                    public Object[] getArguments() {
                        return methodInvocation.getArguments();
                    }
                    public Method getMethod() {
                        return methodInvocation.getMethod();
                    }
                    public Object proceed() throws Throwable {
                        return finderInterceptor.invoke(methodInvocation);
                    }
                    public Object getThis() {
                        return methodInvocation.getThis();
                    }
                    public AccessibleObject getStaticPart() {
                        return methodInvocation.getStaticPart();
                    }
                });
            } else {
                return finderInterceptor.invoke(methodInvocation);
            }
        }
    };
}
 
開發者ID:xuzhikethinker,項目名稱:t4f-data,代碼行數:48,代碼來源:DynamicFinders.java


注:本文中的org.aopalliance.intercept.MethodInterceptor.invoke方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。