当前位置: 首页>>代码示例>>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;未经允许,请勿转载。