本文整理匯總了Java中org.springframework.aop.support.AopUtils.isJdkDynamicProxy方法的典型用法代碼示例。如果您正苦於以下問題:Java AopUtils.isJdkDynamicProxy方法的具體用法?Java AopUtils.isJdkDynamicProxy怎麽用?Java AopUtils.isJdkDynamicProxy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.aop.support.AopUtils
的用法示例。
在下文中一共展示了AopUtils.isJdkDynamicProxy方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getTargetObject
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
private static Object getTargetObject(Object proxy) {
try {
if (!AopUtils.isAopProxy(proxy)) {// 不是代理對象
return proxy;
}
if (AopUtils.isCglibProxy(proxy)) {// cglib代理對象
return getCglibProxyTargetObject(proxy);
}
if (AopUtils.isJdkDynamicProxy(proxy)) {// jdk動態代理
return getJdkDynamicProxyTargetObject(proxy);
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
return null;
}
示例2: isMultipleProxy
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
/**
* 是否代理了多次
* see http://jinnianshilongnian.iteye.com/blog/1894465
* @param proxy
* @return
*/
public static boolean isMultipleProxy(Object proxy) {
try {
ProxyFactory proxyFactory = null;
if(AopUtils.isJdkDynamicProxy(proxy)) {
proxyFactory = findJdkDynamicProxyFactory(proxy);
}
if(AopUtils.isCglibProxy(proxy)) {
proxyFactory = findCglibProxyFactory(proxy);
}
TargetSource targetSource = (TargetSource) ReflectionUtils.getField(ProxyFactory_targetSource_FIELD, proxyFactory);
return AopUtils.isAopProxy(targetSource.getTarget());
} catch (Exception e) {
throw new IllegalArgumentException("proxy args maybe not proxy with cglib or jdk dynamic proxy. this method not support", e);
}
}
示例3: removeAdvisor
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
private static void removeAdvisor(Object proxy, Class<? extends Advice> adviceClass) {
if(!AopUtils.isAopProxy(proxy)) {
return;
}
ProxyFactory proxyFactory = null;
if(AopUtils.isJdkDynamicProxy(proxy)) {
proxyFactory = findJdkDynamicProxyFactory(proxy);
}
if(AopUtils.isCglibProxy(proxy)) {
proxyFactory = findCglibProxyFactory(proxy);
}
Advisor[] advisors = proxyFactory.getAdvisors();
if(advisors == null || advisors.length == 0) {
return;
}
for(Advisor advisor : advisors) {
if(adviceClass.isAssignableFrom(advisor.getAdvice().getClass())) {
proxyFactory.removeAdvisor(advisor);
break;
}
}
}
示例4: hasAdvice
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
private static boolean hasAdvice(Object proxy, Class<? extends Advice> adviceClass) {
if(!AopUtils.isAopProxy(proxy)) {
return false;
}
ProxyFactory proxyFactory = null;
if(AopUtils.isJdkDynamicProxy(proxy)) {
proxyFactory = findJdkDynamicProxyFactory(proxy);
}
if(AopUtils.isCglibProxy(proxy)) {
proxyFactory = findCglibProxyFactory(proxy);
}
Advisor[] advisors = proxyFactory.getAdvisors();
if(advisors == null || advisors.length == 0) {
return false;
}
for(Advisor advisor : advisors) {
if(adviceClass.isAssignableFrom(advisor.getAdvice().getClass())) {
return true;
}
}
return false;
}
示例5: getTarget
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
private Object getTarget(Object proxy){
if(!AopUtils.isAopProxy(proxy)) {
return proxy;//不是代理對象
}
try {
if(AopUtils.isJdkDynamicProxy(proxy)) {
return getJdkDynamicProxyTargetObject(proxy);
} else { //cglib
return getCglibProxyTargetObject(proxy);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例6: checkManagedBean
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
/**
* Throws an IllegalArgumentException if it encounters a JDK dynamic proxy.
* Metadata can only be read from target classes and CGLIB proxies!
*/
@Override
protected void checkManagedBean(Object managedBean) throws IllegalArgumentException {
if (AopUtils.isJdkDynamicProxy(managedBean)) {
throw new IllegalArgumentException(
"MetadataMBeanInfoAssembler does not support JDK dynamic proxies - " +
"export the target beans directly or use CGLIB proxies instead");
}
}
示例7: getTarget
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
public static Object getTarget(Object proxy) throws Exception {
if (!isAopProxy(proxy)) {
return proxy;
} else {
if (AopUtils.isJdkDynamicProxy(proxy)) {
return getJdkDynamicProxyTargetObject(proxy);
} else {
return getCglibProxyTargetObject(proxy);
}
}
}
示例8: getTarget
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
/**
* 獲取 目標對象
* @param proxy 代理對象
* @return
* @throws Exception
*/
public static Object getTarget(Object proxy) throws Exception {
if(!AopUtils.isAopProxy(proxy)) {
return proxy;//不是代理對象
}
if(AopUtils.isJdkDynamicProxy(proxy)) {
return getJdkDynamicProxyTargetObject(proxy);
} else {
return getCglibProxyTargetObject(proxy);
}
}
示例9: getTargetObject
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
@SuppressWarnings({"unchecked"})
public static <T> T getTargetObject(Object proxy) throws Exception {
if (AopUtils.isJdkDynamicProxy(proxy)) {
return (T) getTargetObject(((Advised)proxy).getTargetSource().getTarget());
}
return (T) proxy; // expected to be cglib proxy then, which is simply a specialized class
}
示例10: getTarget
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
/**
* 獲取目標對象.
*
* @param proxy 代理對象
* @return 目標對象
*/
public static Object getTarget(final Object proxy) {
if (!AopUtils.isAopProxy(proxy)) {
return proxy;
}
if (AopUtils.isJdkDynamicProxy(proxy)) {
return getProxyTargetObject(proxy, "h");
} else {
return getProxyTargetObject(proxy, "CGLIB$CALLBACK_0");
}
}
示例11: getTarget
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
/**
* 獲取 目標對象
* @param proxy 代理對象
* @return
* @throws Exception
*/
public static Object getTarget(Object proxy) throws Exception {
if(!AopUtils.isAopProxy(proxy)) {
return proxy;//不是代理對象
}
if(AopUtils.isJdkDynamicProxy(proxy)) {
return getJdkDynamicProxyTargetObject(proxy);
} else { //cglib
return getCglibProxyTargetObject(proxy);
}
}
示例12: invoke
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
public Object invoke(final StroomBeanMethod stroomBeanMethod, final Object... args)
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
// Get the bean.
final Object bean = getBean(stroomBeanMethod.getBeanName());
final Method beanMethod = stroomBeanMethod.getBeanMethod();
if (bean != null) {
// Test to see if the bean is an instance of JdkDynamicProxy. If it
// is then only the interface will be available on the proxy. We
// ideally want to execute a method on the proxy as the proxy may be
// providing transactional behaviour or security interception etc.
// If we really can't get the method off the proxy then we will need
// to get the proxy target and invoke the method on that directly.
if (AopUtils.isJdkDynamicProxy(bean)) {
Method method = null;
// Try and get the method from the proxied interfaces.
for (final Method m : bean.getClass().getMethods()) {
if (m.getName().equals(beanMethod.getName())
&& Arrays.equals(m.getParameterTypes(), beanMethod.getParameterTypes())) {
method = m;
break;
}
}
if (method == null) {
// If we didn't manage to get the method from the proxied
// interfaces then invoke them method on the proxy target
// directly. This might result in errors as we will be
// bypassing transaction interception etc.
try {
final Object o = ((Advised) bean).getTargetSource().getTarget();
return beanMethod.invoke(o, args);
} catch (final Exception e) {
throw new RuntimeException(e);
}
} else {
return method.invoke(bean, args);
}
} else {
beanMethod.invoke(bean, args);
}
}
return null;
}
示例13: getClassForDescriptor
import org.springframework.aop.support.AopUtils; //導入方法依賴的package包/類
/**
* Return the class to be used for the JMX descriptor field "class".
* Only applied when the "exposeClassDescriptor" property is "true".
* <p>The default implementation returns the first implemented interface
* for a JDK proxy, and the target class else.
* @param managedBean the bean instance (might be an AOP proxy)
* @return the class to expose in the descriptor field "class"
* @see #setExposeClassDescriptor
* @see #getClassToExpose(Class)
* @see org.springframework.aop.framework.AopProxyUtils#proxiedUserInterfaces(Object)
*/
protected Class<?> getClassForDescriptor(Object managedBean) {
if (AopUtils.isJdkDynamicProxy(managedBean)) {
return AopProxyUtils.proxiedUserInterfaces(managedBean)[0];
}
return getClassToExpose(managedBean);
}