本文整理汇总了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);
}
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
示例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());
}
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
}
示例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);
}
示例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);
}
示例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);
}