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


Java MethodProxy.invoke方法代碼示例

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


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

示例1: intercept

import net.sf.cglib.proxy.MethodProxy; //導入方法依賴的package包/類
@Override
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
    if(isDecorated(method)) {
        // Decorated method
        return proxy.invokeSuper(obj, args);
    } else {
        final T t = ((Decorator<T>) obj).delegate();
        if(method.getDeclaringClass().isInstance(t)) {
            // Forwarded method
            return proxy.invoke(t, args);
        } else {
            // Forwarded method shadowed by an interface method in the decorator.
            //
            // This can happen if the decorator implements an interface that the
            // base class doesn't, and that interface contains a method that shadows
            // one on the base class. Java would allow the method to be called on the
            // base anyway, but MethodProxy refuses to invoke it on something that
            // is not assignable to the method's declaring type. So, unfortunately,
            // we have to fall back to the JDK to handle this case.
            return methodHandles.get(method, () ->
                resolver.virtualHandle(t.getClass(), method).bindTo(t)
            ).invokeWithArguments(args);
        }
    }
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:26,代碼來源:LibCGDecoratorGenerator.java

示例2: intercept

import net.sf.cglib.proxy.MethodProxy; //導入方法依賴的package包/類
public Object intercept(
	final Object obj, 
	final Method method, 
	final Object[] args, 
	final MethodProxy proxy) 
throws Throwable {
	if (constructed) {
		Object result = invoke(method, args, obj);
		if (result==INVOKE_IMPLEMENTATION) {
			return proxy.invoke( getImplementation(), args );
		}
		else {
			return result;
		}
	}
	else {
		//while constructor is running
		return proxy.invokeSuper(obj, args);
	}
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:21,代碼來源:CGLIBLazyInitializer.java

示例3: intercept

import net.sf.cglib.proxy.MethodProxy; //導入方法依賴的package包/類
@Override
public Object intercept(final Object proxy, final Method method, final Object[] args, final MethodProxy methodProxy) throws Throwable {
    final FeatureResolver resolver = FeatureResolver.newFeatureResolver(delegate.getClass()).withTestMethod(method)
            .withDefaultCleanupPhase(CleanupPhase.NONE).build();

    Object result = null;
    final TestMethodInvocationImpl invocation = new TestMethodInvocationImpl(delegate, method, resolver);
    executor.processBefore(invocation);
    try {
        result = methodProxy.invoke(delegate, args);
    } catch (final Exception e) {
        invocation.setTestException(e);
        executor.processAfter(invocation);
        throw e;
    }
    executor.processAfter(invocation);

    return result;
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:20,代碼來源:CucumberInterceptor.java

示例4: intercept

import net.sf.cglib.proxy.MethodProxy; //導入方法依賴的package包/類
@Override
public Object intercept(final Object proxy, final Method method, final Object[] args, final MethodProxy methodProxy) throws Throwable {
    if (isObjectMethod(method) || hasConcordionAnnotations(method)) {
        return methodProxy.invoke(delegate, args);
    }

    final FeatureResolver resolver = FeatureResolver.newFeatureResolver(delegate.getClass()).withTestMethod(method)
            .withDefaultCleanupPhase(CleanupPhase.NONE).build();

    Object result = null;
    final TestInvocationImpl invocation = new TestInvocationImpl(delegate, method, resolver);
    executor.processBefore(invocation);
    try {
        result = methodProxy.invoke(delegate, args);
    } catch (final Exception e) {
        invocation.setTestException(e);
        executor.processAfter(invocation);
        throw e;
    }
    executor.processAfter(invocation);

    return result;
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:24,代碼來源:ConcordionInterceptor.java

示例5: intercept

import net.sf.cglib.proxy.MethodProxy; //導入方法依賴的package包/類
/**
 * @see net.sf.cglib.proxy.MethodInterceptor#intercept(Object,
 * Method, Object[], net.sf.cglib.proxy.MethodProxy)
 */
@Override
public Object intercept(final Object object, final Method method, final Object[] args,
                        final MethodProxy proxy) throws Throwable {
    if (isFinalizeMethod(method)) {
        // swallow finalize call
        return null;
    } else if (isEqualsMethod(method)) {
        return (equals(args[0])) ? Boolean.TRUE : Boolean.FALSE;
    } else if (isHashCodeMethod(method)) {
        return hashCode();
    } else if (isToStringMethod(method)) {
        return toString();
    } else if (isWriteReplaceMethod(method)) {
        return writeReplace();
    } else if (method.getDeclaringClass().equals(ILazyInitProxy.class)) {
        return getObjectLocator();
    }

    if (target == null) {
        target = locator.locateProxyTarget();
    }
    return proxy.invoke(target, args);
}
 
開發者ID:sabomichal,項目名稱:spring-injector,代碼行數:28,代碼來源:LazyInitProxyFactory.java

示例6: intercept

import net.sf.cglib.proxy.MethodProxy; //導入方法依賴的package包/類
@Override
public Object intercept(Object o, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
    String methodName = method.getName();

    if (args.length == 1 && methodName.startsWith("set") && methodName.length() >= 4 && method.getReturnType() == void.class) {
        String property = methodName.substring(3);
        Object newValue = args[0];
        Object prevValue = ReflectionUtils.callGetter(object, (newValue instanceof Boolean ? "is" : "get") + property);

        ValueChange change = values.get(property);
        if (change != null) {
            change.newValue = newValue;
        } else {
            if (prevValue == null && newValue != null || prevValue != null && newValue == null || prevValue != null && !prevValue.equals(newValue)) {
                change = new ValueChange(ReflectionUtils.callGetter(object, (newValue instanceof Boolean ? "is" : "get") + property), newValue);
                values.put(property, change);
            }
        }
        methodProxy.invoke(object, args);
        return null;
    } else if (args.length == 0 && (methodName.startsWith("get") || methodName.startsWith("is"))) {
        return methodProxy.invoke(object, args);
    } else {
        throw new RuntimeException("Can't intercept bean change due to unknown method call: " + method.getName() + " on " + o.getClass().getName());
    }
}
 
開發者ID:sk89q,項目名稱:quest-pages,代碼行數:27,代碼來源:BeanChange.java

示例7: intercept

import net.sf.cglib.proxy.MethodProxy; //導入方法依賴的package包/類
@Override
public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
    if (method.isAnnotationPresent(Step.class)) {
        String value = method.getAnnotation(Step.class).value();
        if (value.isEmpty()) {
            value = new ReadableMethodName(method.getName()).toString();
        }
        new Report(value).testNG();
    }
    Object result = methodProxy.invoke(original, objects);
    if (result == original) {
        return o;
    }
    return result;
}
 
開發者ID:WileyLabs,項目名稱:teasy,代碼行數:16,代碼來源:AllureStep2TestNG.java

示例8: intercept

import net.sf.cglib.proxy.MethodProxy; //導入方法依賴的package包/類
@Override
public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {

    LOGGER.info("before");

    Object invoke = methodProxy.invoke(o, objects);
    LOGGER.info("after");
    return invoke;
}
 
開發者ID:crossoverJie,項目名稱:Java-Interview,代碼行數:10,代碼來源:RealSubjectIntercept.java

示例9: intercept

import net.sf.cglib.proxy.MethodProxy; //導入方法依賴的package包/類
@Override
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {

    if (method.getName().equals("toString") && args.length == 0) {
        String sql = toString((String) proxy.invoke(realInsert, args));
        return sql;
    }
    return proxy.invoke(realInsert, args);
}
 
開發者ID:kkmike999,項目名稱:YuiHatano,代碼行數:10,代碼來源:InsertOrReplaceProxy.java

示例10: invokeRaw

import net.sf.cglib.proxy.MethodProxy; //導入方法依賴的package包/類
@Override @SneakyThrows
protected Object invokeRaw(Object obj,
                           Object[] args,
                           MethodProxy methodProxy) {
    return target != null
            ? methodProxy.invoke(target, args)
            : methodProxy.invokeSuper(obj, args);
}
 
開發者ID:bingoohuang,項目名稱:westcache,代碼行數:9,代碼來源:CglibCacheMethodInterceptor.java

示例11: intercept

import net.sf.cglib.proxy.MethodProxy; //導入方法依賴的package包/類
public Object intercept(Object obj, Method method, Object[] args,
                        MethodProxy proxy) throws Throwable {
    System.out.println("Before Advice");

    // 注意此處的參數是注入的target 而不是obj  
    Object result = proxy.invoke(target, args);
    System.out.println("After Advice");
    return result;
}
 
開發者ID:ansafari,項目名稱:melon,代碼行數:10,代碼來源:BookClass.java

示例12: intercept

import net.sf.cglib.proxy.MethodProxy; //導入方法依賴的package包/類
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Object intercept(Object object, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
	
	if(parent != null) {
		parent.methods.add(method);
	} else {
		this.methods.add(method);
	}
	
	if(execute) {
		Object result = methodProxy.invoke(target, args);
		
		if(result == null && !TypeUtils.isValueType(method.getReturnType())) {
			try {
				Object o = method.getReturnType().newInstance();
				MethodRecordProxy proxyTmp = 
					new MethodRecordProxy(o, parent != null ? parent : this);
				result = proxyTmp.getProxy();
			} catch(Exception e) {
				result = null;
			}
		}
		
		return result;
	} else {
		return null;
	}
}
 
開發者ID:naskarlab,項目名稱:fluent-query,代碼行數:30,代碼來源:MethodRecordProxy.java

示例13: intercept

import net.sf.cglib.proxy.MethodProxy; //導入方法依賴的package包/類
@Override
public Object intercept(Object delegate, Method method, Object[] args, MethodProxy proxy) throws Throwable {
    if (today.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.ENGLISH).startsWith("S")) {
        throw new IllegalStateException(method.getName() + " not allowed on weekends!");
    }
    return proxy.invoke(delegate, args);
}
 
開發者ID:ruediste,項目名稱:salta,代碼行數:8,代碼來源:AopTest.java

示例14: intercept

import net.sf.cglib.proxy.MethodProxy; //導入方法依賴的package包/類
@Override
public Object intercept(final Object object,
                        final Method method,
                        final Object[] args,
                        final MethodProxy proxy)
                                // CHECKSTYLE:OFF
                                throws Throwable {
                                // CHECKSTYLE:ON

    if(isMethod(method, void.class, "finalize")) {
        // swallow finalize call
        return null;
    } else if(isMethod(method, boolean.class, "equals", Object.class)) {
        return (equals(args[0])) ? Boolean.TRUE : Boolean.FALSE;
    } else if(isMethod(method, int.class, "hashCode")) {
        return hashCode();
    } else if(isMethod(method, String.class, "toString")) {
        return toString();
    } else if(isMethod(method, Object.class, "writeReplace")) {
        return writeReplace();
    }

    if(entityManager == null || !entityManager.isOpen()) {
        entityManager = factory.createEntityManager();
    }

    return proxy.invoke(entityManager, args);
}
 
開發者ID:Metrink,項目名稱:croquet,代碼行數:29,代碼來源:EntityManagerProxyFactory.java

示例15: intercept

import net.sf.cglib.proxy.MethodProxy; //導入方法依賴的package包/類
@Override
public Object intercept(final Object object,
                        final Method method,
                        final Object[] args,
                        final MethodProxy proxy)
                                // CHECKSTYLE:OFF
                                throws Throwable {
                                // CHECKSTYLE:ON

    if(isMethod(method, void.class, "finalize")) {
        // swallow finalize call
        return null;
    } else if(isMethod(method, boolean.class, "equals", Object.class)) {
        return (equals(args[0])) ? Boolean.TRUE : Boolean.FALSE;
    } else if(isMethod(method, int.class, "hashCode")) {
        return hashCode();
    } else if(isMethod(method, String.class, "toString")) {
        return toString();
    } else if(isMethod(method, Object.class, "writeReplace")) {
        return writeReplace();
    }

    if(queryRunner == null) {
        queryRunner = new QueryRunner(dataSourceFactory.getDataSource());
    }

    return proxy.invoke(queryRunner, args);
}
 
開發者ID:Metrink,項目名稱:croquet,代碼行數:29,代碼來源:QueryRunnerProxyFactory.java


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