List of usage examples for org.springframework.aop.framework ProxyFactory getProxy
public Object getProxy()
From source file:fr.mby.utils.spring.beans.factory.support.BasicProxywiredFactory.java
protected IManageableProxywired proxywire(final TargetSource targetSource) { final Class<?>[] proxtyInterfaces = new Class[] { targetSource.getTargetClass(), IManageableProxywired.class }; final ProxyFactory proxyFactory = new ProxyFactory(proxtyInterfaces); proxyFactory.addAdvice(new InterfaceImplementationAdvice(IManageableProxywired.class, (IManageableProxywired) targetSource)); proxyFactory.setTargetSource(targetSource); return (IManageableProxywired) proxyFactory.getProxy(); }
From source file:net.shopxx.service.impl.ConfigServiceImpl.java
public void init() { try {/* www . j a v a 2s. co m*/ Setting setting = SystemUtils.getSetting(); setting.setSmtpPassword(null); setting.setKuaidi100Key(null); setting.setCnzzPassword(null); setting.setSmsKey(null); ProxyFactory proxyFactory = new ProxyFactory(setting); proxyFactory.setProxyTargetClass(true); proxyFactory.addAdvice(new MethodBeforeAdvice() { public void before(Method method, Object[] args, Object target) throws Throwable { if (StringUtils.startsWith(method.getName(), "set")) { throw new UnsupportedOperationException("Operation not supported"); } } }); Configuration configuration = freeMarkerConfigurer.getConfiguration(); configuration.setSharedVariable("setting", proxyFactory.getProxy()); configuration.setSharedVariable("locale", setting.getLocale()); configuration.setSharedVariable("theme", setting.getTheme()); if (setting.getIsDevelopmentEnabled()) { configuration.setSetting("template_update_delay", "0"); reloadableResourceBundleMessageSource.setCacheSeconds(0); } else { configuration.setSetting("template_update_delay", templateUpdateDelay); reloadableResourceBundleMessageSource.setCacheSeconds(messageCacheSeconds); } fixedLocaleResolver.setDefaultLocale(LocaleUtils.toLocale(setting.getLocale().toString())); } catch (TemplateModelException e) { throw new RuntimeException(e.getMessage(), e); } catch (TemplateException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:com.sinosoft.one.data.jpa.repository.support.OneRepositoryFactorySupport.java
/** * Returns a repository instance for the given interface backed by an instance providing implementation logic for * custom logic.//from w w w . ja v a2s .co m * * @param <T> * @param repositoryInterface * @param customImplementation * @return */ @SuppressWarnings({ "unchecked" }) public <T> T getRepository(Class<T> repositoryInterface, Object customImplementation) { RepositoryMetadata metadata = getRepositoryMetadata(repositoryInterface); Class<?> customImplementationClass = null == customImplementation ? null : customImplementation.getClass(); RepositoryInformation information = getRepositoryInformation(metadata, customImplementationClass); validate(information, customImplementation); Object target = getTargetRepository(information); // Create proxy ProxyFactory result = new ProxyFactory(); result.setTarget(target); result.setInterfaces(new Class[] { repositoryInterface, Repository.class }); for (RepositoryProxyPostProcessor processor : postProcessors) { processor.postProcess(result); } result.addAdvice(new OneQueryExecutorMethodInterceptor(information, customImplementation, target)); return (T) result.getProxy(); }
From source file:fr.pilato.spring.elasticsearch.ElasticsearchAbstractClientFactoryBean.java
@Override public void afterPropertiesSet() throws Exception { logger.info("Starting ElasticSearch client"); if (async) {/* w w w . jav a2 s. c o m*/ Assert.notNull(taskExecutor); Future<Client> future = taskExecutor.submit(new Callable<Client>() { @Override public Client call() throws Exception { return initialize(); } }); ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.setProxyTargetClass(true); proxyFactory.setTargetClass(Client.class); proxyFactory.addAdvice(new GenericInvocationHandler(future)); proxyfiedClient = (Client) proxyFactory.getProxy(); } else { client = initialize(); } }
From source file:org.synyx.hades.dao.orm.GenericDaoFactory.java
/** * Returns a DAO instance for the given interface backed by an instance * providing implementation logic for custom logic. * //from w w w. j ava 2 s . com * @param <T> * @param daoInterface * @param customDaoImplementation * @return */ @SuppressWarnings("unchecked") public <T extends GenericDao<?, ?>> T getDao(Class<T> daoInterface, Object customDaoImplementation) { validate(daoInterface, customDaoImplementation); try { // Instantiate generic dao @SuppressWarnings("rawtypes") GenericDaoSupport genericJpaDao = getDaoClass().newInstance(); genericJpaDao.setEntityManager(entityManager); genericJpaDao.setDomainClass(ClassUtils.getDomainClass(daoInterface)); genericJpaDao.validate(); // Create proxy ProxyFactory result = new ProxyFactory(); result.setTarget(genericJpaDao); result.setInterfaces(new Class[] { daoInterface }); for (DaoProxyPostProcessor processor : postProcessors) { processor.postProcess(result); } result.addAdvice( new QueryExecuterMethodInterceptor(daoInterface, customDaoImplementation, genericJpaDao)); return (T) result.getProxy(); } catch (InstantiationException e) { throw new IllegalStateException(e); } catch (IllegalAccessException e) { throw new IllegalStateException(e); } }
From source file:org.springmodules.cache.interceptor.proxy.CacheProxyFactoryBean.java
/** * Creates the proxy for target object. This method is invoked by a * BeanFactory after it has set all bean properties supplied. * /* ww w.ja va 2 s .c o m*/ * @throws IllegalStateException * if target is <code>null</code>. * @throws AopConfigException * if the proxy interfaces or proxyTargetClass are not set and the * target type is <code>org.springframework.aop.TargetSource</code>. */ public void afterPropertiesSet() throws IllegalStateException, AopConfigException { cachingInterceptor.afterPropertiesSet(); flushingInterceptor.afterPropertiesSet(); if (target == null) { throw new IllegalStateException("Property 'target' is required"); } ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.addAdvisor(new CachingModelSourceAdvisor(cachingInterceptor)); if (hasFlushingModels) { proxyFactory.addAdvisor(new FlushingModelSourceAdvisor(flushingInterceptor)); } proxyFactory.copyFrom(this); TargetSource targetSource = createTargetSource(target); proxyFactory.setTargetSource(targetSource); if (proxyInterfaces != null) { proxyFactory.setInterfaces(proxyInterfaces); } else if (!isProxyTargetClass()) { if (target instanceof TargetSource) { throw new AopConfigException("Either 'proxyInterfaces' or 'proxyTargetClass' is required " + "when using a TargetSource as 'target'"); } // rely on AOP infrastructure to tell us what interfaces to proxy proxyFactory.setInterfaces(ClassUtils.getAllInterfaces(target)); } proxy = proxyFactory.getProxy(); }
From source file:org.nabucco.alfresco.enhScriptEnv.common.script.converter.rhino.ScriptableFacadeMapConverter.java
/** * {@inheritDoc}//from w w w . j a v a 2s .c om */ @Override public Object convertValueForScript(final Object value, final ValueConverter globalDelegate, final Class<?> expectedClass) { if (!(value instanceof Map<?, ?>)) { throw new IllegalArgumentException("value must be a Map"); } final Object result; final ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.addAdvice(new AdapterObjectInterceptor()); proxyFactory.addAdvice(new ScriptableBaseAdapterInterceptor()); proxyFactory.addAdvice(new ScriptableListLikeMapAdapterInterceptor()); proxyFactory.addAdvice(new ScriptableMapListAdapterInterceptor()); proxyFactory.addAdvice(new MapLengthFacadeInterceptor(Undefined.instance, false)); // proxyFactory.addAdvice(new ListLikeMapAdapterInterceptor()); // some existing scripts in Alfresco expect Map-contained strings not to be converted proxyFactory.addAdvice(new ValueConvertingMapInterceptor(globalDelegate, true)); // this somehow worked in Java 8 Nashorn PoC, but return types of remove(Object) differ between Map and List // proxyFactory.setInterfaces(ClassUtils.collectInterfaces(value, Arrays.<Class<?>> asList(Scriptable.class, List.class, AdapterObject.class))); proxyFactory.setInterfaces(ClassUtils.collectInterfaces(value, Arrays.<Class<?>>asList(Scriptable.class, AdapterObject.class))); proxyFactory.setTarget(value); result = proxyFactory.getProxy(); return result; }
From source file:org.arrow.service.engine.execution.impl.MultipleEventAwareExecutionListener.java
/** * Initializes a catching multiple event. * //from ww w .j a v a2 s .c o m * @return BpmnNodeEntity */ private BpmnNodeEntity initializeCatchingEvent(BpmnNodeEntity entity, Set<EventDefinition> definitions) { ProxyFactory factory = new ProxyFactory(entity); for (EventDefinition definition : definitions) { // Signal event definition if (definition instanceof SignalEventDefinition) { SignalEventDefinition def = (SignalEventDefinition) definition; Advice advice = new SignalEventHandlerIntroduction(def); factory.addAdvice(advice); } // Message event definition else if (definition instanceof MessageEventDefinition) { MessageEventDefinition def = (MessageEventDefinition) definition; Advice advice = new MessageEventHandlerIntroduction(def); factory.addAdvice(advice); } // Timer event definition else if (definition instanceof TimerEventDefinition) { TimerEventDefinition def = (TimerEventDefinition) definition; Advice advice = new TimerEventHandlerIntroduction(def); factory.addAdvice(advice); } // Conditional event definition else if (definition instanceof ConditionalEventDefinition) { ConditionalEventDefinition def = (ConditionalEventDefinition) definition; Advice advice = new ConditionalEventHandlerIntroduction(def); factory.addAdvice(advice); } } return (BpmnNodeEntity) factory.getProxy(); }
From source file:org.arrow.service.engine.execution.impl.MultipleEventAwareExecutionListener.java
/** * Initializes a throwing multiple event. * /* w ww . j a v a 2s . c o m*/ * @return BpmnNodeEntity */ private BpmnNodeEntity initializeThrowingEvent(BpmnNodeEntity entity, Set<EventDefinition> definitions) { ProxyFactory factory = new ProxyFactory(entity); for (EventDefinition definition : definitions) { // Signal event definition if (definition instanceof SignalEventDefinition) { SignalEventDefinition def = (SignalEventDefinition) definition; Advice advice = new SignalEventPublisherIntroduction(def); factory.addAdvice(advice); } // Message event definition else if (definition instanceof MessageEventDefinition) { MessageEventDefinition def = (MessageEventDefinition) definition; Advice advice = new MessageEventPublisherIntroduction(def); factory.addAdvice(advice); } // Timer event definition else if (definition instanceof TimerEventDefinition) { TimerEventDefinition def = (TimerEventDefinition) definition; Advice advice = new TimerEventPublisherIntroduction(def); factory.addAdvice(advice); } // Conditional event definition else if (definition instanceof ConditionalEventDefinition) { ConditionalEventDefinition def = (ConditionalEventDefinition) definition; Advice advice = new ConditionalEventPublisherIntroduction(def); factory.addAdvice(advice); } } return (BpmnNodeEntity) factory.getProxy(); }
From source file:org.arrow.service.engine.execution.interceptor.impl.MultipleEventAwareInitializer.java
/** * Initializes a catching multiple event. * * @return BpmnNodeEntity/* ww w .j av a 2 s . c o m*/ */ private BpmnNodeEntity initializeCatchingEvent(BpmnNodeEntity entity, Set<EventDefinition> definitions) { ProxyFactory factory = new ProxyFactory(entity); for (EventDefinition definition : definitions) { // Signal event definition if (definition instanceof SignalEventDefinition) { SignalEventDefinition def = (SignalEventDefinition) definition; Advice advice = new SignalEventHandlerIntroduction(def); factory.addAdvice(advice); } // Message event definition else if (definition instanceof MessageEventDefinition) { MessageEventDefinition def = (MessageEventDefinition) definition; Advice advice = new MessageEventHandlerIntroduction(def); factory.addAdvice(advice); } // Timer event definition else if (definition instanceof TimerEventDefinition) { TimerEventDefinition def = (TimerEventDefinition) definition; Advice advice = new TimerEventHandlerIntroduction(def); factory.addAdvice(advice); } // Conditional event definition else if (definition instanceof ConditionalEventDefinition) { ConditionalEventDefinition def = (ConditionalEventDefinition) definition; Advice advice = new ConditionalEventHandlerIntroduction(def); factory.addAdvice(advice); } } factory.addInterface(BpmnNodeEntity.class); return (BpmnNodeEntity) factory.getProxy(); }