List of usage examples for org.springframework.aop.target SingletonTargetSource SingletonTargetSource
public SingletonTargetSource(Object target)
From source file:im.tym.wraop.impl.ProxyCreatorBasedWrapperFactorySpi.java
protected AdvisedSupport getAdvisedSupportFor(final I object) { return new AdvisedSupport() { {/*from w w w . j a v a 2 s .co m*/ copyConfigurationFrom(proxyCreator, new SingletonTargetSource(object), Arrays.asList(proxyCreator.getAdvisors())); } }; }
From source file:org.LexGrid.LexBIG.caCore.client.proxy.LexEVSProxyHelperImpl.java
@Override protected Object convertObjectToProxy(ApplicationService as, Object obj) { if (null == obj) return null; //Check to see if the returned object is an EVSRemoteExecutionResults. //If so, unwrap it and update the proxy target if (obj instanceof RemoteExecutionResults) { RemoteExecutionResults results = (RemoteExecutionResults) obj; //if the returned results are null, return null if (results.getReturnValue() == null) return null; //Get the current proxy target and update it with the retuned value //from the server Advised advised = (Advised) AopContext.currentProxy(); advised.setTargetSource(new SingletonTargetSource(results.getObj())); obj = results.getReturnValue();/* w w w.ja v a 2s. c om*/ } if (obj instanceof RemoteShell) { Class<?>[] targetInterfaces = ((RemoteShell) obj).getTargetInterfaces(); Class<?> targetClass = ((RemoteShell) obj).getTargetClass(); ProxyFactory pf = new ProxyFactory(targetInterfaces); pf.addAdvice(new LexEVSBeanProxy(as, this)); pf.setProxyTargetClass(true); pf.setTargetClass(targetClass); pf.setTarget(obj); return pf.getProxy(); } if (obj instanceof Integer || obj instanceof Float || obj instanceof Double || obj instanceof Character || obj instanceof Long || obj instanceof Boolean || obj instanceof String || obj instanceof Date || obj instanceof LexEVSBeanProxy || obj instanceof BeanProxy) return obj; if (!LexEVSCaCoreUtils.isLexBigClass(obj.getClass())) { return obj; } // Don't proxy client-safe LexBig objects if (isClientSafe(obj.getClass())) { return obj; } else { return LexEVSCaCoreUtils.createProxy(obj, as, this); } }
From source file:org.joyrest.oauth2.initializer.OAuth2Initializer.java
private DefaultTokenServices txProxiedTokenServices(DefaultTokenServices tokenServices, DataSource dataSource) { AnnotationTransactionAttributeSource attrSource = new AnnotationTransactionAttributeSource(); DataSourceTransactionManager txManager = new DataSourceTransactionManager(dataSource); TransactionInterceptor txInterceptor = transactionInterceptor(attrSource, txManager); BeanFactoryTransactionAttributeSourceAdvisor txAdvisor = transactionAdvisor(attrSource, txInterceptor); ClassLoader classLoader = ClassUtils.getDefaultClassLoader(); ProxyFactory proxyFactory = new ProxyFactory(tokenServices); proxyFactory.addAdvice(txInterceptor); proxyFactory.addAdvisor(txAdvisor);// www .ja va 2 s . c o m proxyFactory.setInterfaces(ClassUtils .getAllInterfacesForClass(new SingletonTargetSource(tokenServices).getTargetClass(), classLoader)); return (DefaultTokenServices) proxyFactory.getProxy(classLoader); }
From source file:org.springmodules.cache.interceptor.proxy.CacheProxyFactoryBean.java
/** * Set the target or <code>TargetSource</code>. * /*from www .jav a 2 s. co m*/ * @param targetObject * target. If this is an implementation of <code>TargetSource</code> * it is used as our <code>TargetSource</code>; otherwise it is * wrapped in a <code>SingletonTargetSource</code>. * @return a <code>TargetSource</code> for this object. */ protected TargetSource createTargetSource(Object targetObject) { TargetSource targetSource = null; if (targetObject instanceof TargetSource) { targetSource = (TargetSource) targetObject; } else { targetSource = new SingletonTargetSource(targetObject); } return targetSource; }
From source file:org.springframework.aop.framework.AdvisedSupport.java
/** * Set the given object as target.//from w w w . j a v a 2 s .co m * Will create a SingletonTargetSource for the object. * @see #setTargetSource * @see org.springframework.aop.target.SingletonTargetSource */ public void setTarget(Object target) { setTargetSource(new SingletonTargetSource(target)); }
From source file:org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.java
/** * Wrap the given bean if necessary, i.e. if it is eligible for being proxied. * @param bean the raw bean instance/*w w w. j a v a 2 s. c om*/ * @param beanName the name of the bean * @param cacheKey the cache key for metadata access * @return a proxy wrapping the bean, or the raw bean instance as-is */ protected Object wrapIfNecessary(Object bean, String beanName, Object cacheKey) { if (StringUtils.hasLength(beanName) && this.targetSourcedBeans.contains(beanName)) { return bean; } if (Boolean.FALSE.equals(this.advisedBeans.get(cacheKey))) { return bean; } if (isInfrastructureClass(bean.getClass()) || shouldSkip(bean.getClass(), beanName)) { this.advisedBeans.put(cacheKey, Boolean.FALSE); return bean; } // Create proxy if we have advice. Object[] specificInterceptors = getAdvicesAndAdvisorsForBean(bean.getClass(), beanName, null); if (specificInterceptors != DO_NOT_PROXY) { this.advisedBeans.put(cacheKey, Boolean.TRUE); Object proxy = createProxy(bean.getClass(), beanName, specificInterceptors, new SingletonTargetSource(bean)); this.proxyTypes.put(cacheKey, proxy.getClass()); return proxy; } this.advisedBeans.put(cacheKey, Boolean.FALSE); return bean; }
From source file:org.springframework.aop.framework.ProxyFactoryBean.java
/** * Return a TargetSource to use when creating a proxy. If the target was not * specified at the end of the interceptorNames list, the TargetSource will be * this class's TargetSource member. Otherwise, we get the target bean and wrap * it in a TargetSource if necessary.//from w ww . j a va2 s .com */ private TargetSource freshTargetSource() { if (this.targetName == null) { if (logger.isTraceEnabled()) { logger.trace("Not refreshing target: Bean name not specified in 'interceptorNames'."); } return this.targetSource; } else { if (this.beanFactory == null) { throw new IllegalStateException("No BeanFactory available anymore (probably due to serialization) " + "- cannot resolve target with name '" + this.targetName + "'"); } if (logger.isDebugEnabled()) { logger.debug("Refreshing target with name '" + this.targetName + "'"); } Object target = this.beanFactory.getBean(this.targetName); return (target instanceof TargetSource ? (TargetSource) target : new SingletonTargetSource(target)); } }
From source file:org.springframework.aop.target.AbstractPrototypeBasedTargetSource.java
/** * Replaces this object with a SingletonTargetSource on serialization. * Protected as otherwise it won't be invoked for subclasses. * (The writeReplace() method must be visible to the class being serialized.) * <p>With this implementation of this method, there is no need to mark * non-serializable fields in this class or subclasses as transient. */// w w w . jav a2 s . c o m protected Object writeReplace() throws ObjectStreamException { if (logger.isDebugEnabled()) { logger.debug("Disconnecting TargetSource [" + this + "]"); } try { TargetSource disconnectedTargetSource = new SingletonTargetSource(getTarget()); return disconnectedTargetSource; } catch (Exception ex) { throw new AspectException("Can't get target", ex); } }