List of usage examples for org.springframework.aop.framework AdvisedSupport getTargetSource
@Override
public TargetSource getTargetSource()
From source file:com.liferay.portal.remote.json.web.service.extender.internal.ServiceJSONWebServiceScannerStrategy.java
/** * @see com.liferay.portal.jsonwebservice.SpringJSONWebServiceScannerStrategy#getTargetClass( * Object)/*from w w w .j a v a 2 s. c om*/ */ protected Class<?> getTargetClass(Object service) throws Exception { while (ProxyUtil.isProxyClass(service.getClass())) { InvocationHandler invocationHandler = ProxyUtil.getInvocationHandler(service); if (invocationHandler instanceof AdvisedSupportProxy) { AdvisedSupport advisedSupport = ServiceBeanAopProxy.getAdvisedSupport(service); TargetSource targetSource = advisedSupport.getTargetSource(); service = targetSource.getTarget(); } else if (invocationHandler instanceof ClassLoaderBeanHandler) { ClassLoaderBeanHandler classLoaderBeanHandler = (ClassLoaderBeanHandler) invocationHandler; Object bean = classLoaderBeanHandler.getBean(); if (bean instanceof ServiceWrapper) { ServiceWrapper<?> serviceWrapper = (ServiceWrapper<?>) bean; service = serviceWrapper.getWrappedService(); } else { service = bean; } } } return service.getClass(); }
From source file:com.liferay.portal.spring.extender.internal.bean.ApplicationContextServicePublisher.java
protected Class<?> getTargetClass(Object service) throws Exception { Class<?> clazz = service.getClass(); if (ProxyUtil.isProxyClass(clazz)) { AdvisedSupport advisedSupport = ServiceBeanAopProxy.getAdvisedSupport(service); TargetSource targetSource = advisedSupport.getTargetSource(); Object target = targetSource.getTarget(); clazz = target.getClass();// w ww . j a v a 2s . c o m } return clazz; }
From source file:org.springframework.aop.framework.asm.DefaultCodeGenerationStrategySelector.java
public CodeGenerationStrategy select(AdvisedSupport advised, Method method, Class targetClass) { if (Advised.class == method.getDeclaringClass()) { return new AdvisedMixinCodeGenerationStrategy(); }/*www.j a v a 2 s .c o m*/ // need the advice chain to do perform anymore selections List chain = advised.getAdvisorChainFactory().getInterceptorsAndDynamicInterceptionAdvice(advised, method, targetClass); CodeGenerationStrategy strategy = null; if (isHashCodeMethod(method)) { strategy = new HashCodeCodeGenerationStrategy(); } // TODO: consider adding explicit expose proxy support to certain strategies // TODO: consider factoring out certain calls such as release for the target source if (chain.isEmpty() && (!advised.isExposeProxy())) { if (advised.getTargetSource().isStatic()) { strategy = new StraightToTargetCodeGenerationStrategy(); } else { strategy = new NonStaticTargetSourceCodeGenerationStrategy(); } // TODO: add explicit support for empty target source } else { // TODO: add explicit support for static target sources // TODO: add explicit support for an empty target source // TODO: add agressive inlining for before/after advice strategy = new AdvisedCodeGenerationStrategy(); } if (logger.isInfoEnabled()) { logger.info("Selected strategy [" + strategy.getClass().getName() + "] for method [" + method + "]."); } return strategy; }
From source file:org.springframework.aop.framework.Cglib2AopProxy.java
/** * Create a new Cglib2AopProxy for the given AOP configuration. * @throws AopConfigException if the config is invalid. We try to throw an informative * exception in this case, rather than let a mysterious failure happen later. *///w w w . j ava 2 s .co m protected Cglib2AopProxy(AdvisedSupport config) throws AopConfigException { if (config == null) { throw new AopConfigException("Cannot create AopProxy with null ProxyConfig"); } if (config.getAdvisors().length == 0 && config.getTargetSource() == AdvisedSupport.EMPTY_TARGET_SOURCE) { throw new AopConfigException("Cannot create AopProxy with no advisors and no target source"); } //DK - is this check really necessary? //should this 'config.getTargetSource() == AdvisedSupport.EMPTY_TARGET_SOURCE' be enough? if (config.getTargetSource().getTargetClass() == null) { throw new AopConfigException("Either an interface or a target is required for proxy creation"); } this.advised = config; }
From source file:org.springframework.aop.framework.CglibAopProxy.java
/** * Create a new CglibAopProxy for the given AOP configuration. * @param config the AOP configuration as AdvisedSupport object * @throws AopConfigException if the config is invalid. We try to throw an informative * exception in this case, rather than let a mysterious failure happen later. *///from w w w. ja v a 2 s .co m public CglibAopProxy(AdvisedSupport config) throws AopConfigException { Assert.notNull(config, "AdvisedSupport must not be null"); if (config.getAdvisors().length == 0 && config.getTargetSource() == AdvisedSupport.EMPTY_TARGET_SOURCE) { throw new AopConfigException("No advisors and no TargetSource specified"); } this.advised = config; this.advisedDispatcher = new AdvisedDispatcher(this.advised); }
From source file:org.springframework.aop.framework.JdkDynamicAopProxy.java
/** * Construct a new JdkDynamicAopProxy for the given AOP configuration. * @param config the AOP configuration as AdvisedSupport object * @throws AopConfigException if the config is invalid. We try to throw an informative * exception in this case, rather than let a mysterious failure happen later. *///w ww .j a v a 2 s.c om public JdkDynamicAopProxy(AdvisedSupport config) throws AopConfigException { Assert.notNull(config, "AdvisedSupport must not be null"); if (config.getAdvisors().length == 0 && config.getTargetSource() == AdvisedSupport.EMPTY_TARGET_SOURCE) { throw new AopConfigException("No advisors and no TargetSource specified"); } this.advised = config; }
From source file:org.springframework.aop.framework.OptimizedJdkDynamicAopProxy.java
/** * Construct a new JDK proxy.//from w ww . ja v a2 s .c o m * @throws AopConfigException if the config is invalid. We try * to throw an informative exception in this case, rather than let * a mysterious failure happen later. */ protected OptimizedJdkDynamicAopProxy(AdvisedSupport config) throws AopConfigException { if (config == null) throw new AopConfigException("Cannot create AopProxy with null ProxyConfig"); if (config.getAdvisors().length == 0 && config.getTargetSource() == AdvisedSupport.EMPTY_TARGET_SOURCE) throw new AopConfigException("Cannot create AopProxy with no advisors and no target source"); this.advised = config; this.advisors = config.getAdvisors(); if (!config.targetSource.isStatic()) { throw new AopConfigException("Can't use Optimized JDK proxy with non-static target source"); } if (config.exposeProxy) { throw new AopConfigException("Can't use Optimized JDK proxy if proxy needs to be exposed"); } try { // TODO must be frozen System.err.println("Caching lockable target"); this.target = config.targetSource.getTarget(); this.targetClass = target.getClass(); } catch (Exception ex) { throw new AopConfigException("Can't obtain target from static TargetSource", ex); } }