use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.
the class FormattingConversionServiceTests method proxiedConverter.
@Test
public void proxiedConverter() {
Converter<?, ?> converter = new IntegerConverter();
formattingService.addConverter((Converter<?, ?>) new ProxyFactory(converter).getProxy());
assertEquals(Integer.valueOf(1), formattingService.convert("1", Integer.class));
}
use of org.springframework.aop.framework.ProxyFactory in project spring-framework by spring-projects.
the class MBeanExporterTests method testExportJdkProxy.
@Test
public void testExportJdkProxy() throws Exception {
JmxTestBean bean = new JmxTestBean();
bean.setName("Rob Harrop");
ProxyFactory factory = new ProxyFactory();
factory.setTarget(bean);
factory.addAdvice(new NopInterceptor());
factory.setInterfaces(IJmxTestBean.class);
IJmxTestBean proxy = (IJmxTestBean) factory.getProxy();
String name = "bean:mmm=whatever";
Map<String, Object> beans = new HashMap<>();
beans.put(name, proxy);
MBeanExporter exporter = new MBeanExporter();
exporter.setServer(server);
exporter.setBeans(beans);
exporter.registerBeans();
ObjectName oname = ObjectName.getInstance(name);
Object nameValue = server.getAttribute(oname, "Name");
assertEquals("Rob Harrop", nameValue);
}
use of org.springframework.aop.framework.ProxyFactory in project spring-data-mongodb by spring-projects.
the class DefaultDbRefResolver method createLazyLoadingProxy.
/**
* Creates a proxy for the given {@link MongoPersistentProperty} using the given {@link DbRefResolverCallback} to
* eventually resolve the value of the property.
*
* @param property must not be {@literal null}.
* @param dbref can be {@literal null}.
* @param callback must not be {@literal null}.
* @return
*/
private Object createLazyLoadingProxy(MongoPersistentProperty property, @Nullable DBRef dbref, DbRefResolverCallback callback, DbRefProxyHandler handler) {
Class<?> propertyType = property.getType();
LazyLoadingInterceptor interceptor = new LazyLoadingInterceptor(property, dbref, exceptionTranslator, callback);
if (!propertyType.isInterface()) {
Factory factory = (Factory) objenesis.newInstance(getEnhancedTypeFor(propertyType));
factory.setCallbacks(new Callback[] { interceptor });
return handler.populateId(property, dbref, factory);
}
ProxyFactory proxyFactory = new ProxyFactory();
for (Class<?> type : propertyType.getInterfaces()) {
proxyFactory.addInterface(type);
}
proxyFactory.addInterface(LazyLoadingProxy.class);
proxyFactory.addInterface(propertyType);
proxyFactory.addAdvice(interceptor);
return handler.populateId(property, dbref, proxyFactory.getProxy());
}
use of org.springframework.aop.framework.ProxyFactory in project spring-data-mongodb by spring-projects.
the class SessionAwareMethodInterceptorUnitTests method createProxyInstance.
private <T> T createProxyInstance(ClientSession session, T target, Class<T> targetType) {
ProxyFactory factory = new ProxyFactory();
factory.setTarget(target);
factory.setInterfaces(targetType);
factory.setOpaque(true);
factory.addAdvice(new SessionAwareMethodInterceptor<>(session, target, MongoDatabase.class, this::proxyDatabase, MongoCollection.class, this::proxyCollection));
return targetType.cast(factory.getProxy());
}
use of org.springframework.aop.framework.ProxyFactory in project uPortal by Jasig.
the class EventingLocalContainerEntityManagerFactoryBean method createNativeEntityManagerFactory.
@Override
protected EntityManagerFactory createNativeEntityManagerFactory() throws PersistenceException {
final String persistenceUnitName = this.getPersistenceUnitName();
// Create actual EMF
final EntityManagerFactory nativeEntityManagerFactory = super.createNativeEntityManagerFactory();
// Add a proxy to the EMF which results in events
final ProxyFactory proxyFactory = new ProxyFactory(nativeEntityManagerFactory);
proxyFactory.addAdvice(new EventingEntityMangerFactoryInterceptor(applicationEventPublisher, contextReady, persistenceUnitName));
return (EntityManagerFactory) proxyFactory.getProxy();
}
Aggregations