use of org.jowidgets.cap.service.api.annotation.ExecutorBean in project jo-client-platform by jo-source.
the class ExecutorAnnotationPostProcessor method postProcessAfterInitialization.
@SuppressWarnings("unchecked")
@Override
public Object postProcessAfterInitialization(final Object bean, final String beanName) {
try {
final ExecutorBean beanAnnotation = beanFactory.findAnnotationOnBean(beanName, ExecutorBean.class);
if (beanAnnotation != null) {
final IBeanAccess<? extends IBean> beanAccess = beanAccessProvider.getBeanAccess(beanAnnotation.value());
final List<String> propertyNames = new BeanTypeUtil(beanAccess.getBeanType()).getPropertyNames();
final Set<Method> methods = getExecutorMethods(bean);
for (final Method method : methods) {
final Object proxy = createExecutorProxy(beanFactory, beanName, method);
final IExecutorServiceBuilder<IBean, Object> builder = CapServiceToolkit.executorServiceBuilder(beanAccess);
if (proxy instanceof IBeanExecutor) {
builder.setExecutor((IBeanExecutor<IBean, Object>) proxy);
} else {
builder.setExecutor((IBeanListExecutor<IBean, Object>) proxy);
}
builder.setBeanDtoFactory(propertyNames);
final Executor executorAnnotation = method.getAnnotation(Executor.class);
builder.setAllowDeletedBeans(executorAnnotation.allowDeletedBeans());
builder.setAllowStaleBeans(executorAnnotation.allowStaleBeans());
if (executorAnnotation.checker() != DefaultExecutableChecker.class) {
try {
builder.setExecutableChecker(executorAnnotation.checker().newInstance());
} catch (final InstantiationException e) {
throw new RuntimeException(e);
} catch (final IllegalAccessException e) {
throw new RuntimeException(e);
}
}
IExecutorService<Object> executorService = builder.build();
if (transactionManager != null) {
executorService = new TransactionProxyFactory(transactionManager).createProxy(executorService, "execute");
}
final IServiceId<IExecutorService<Object>> serviceId = new ServiceId<IExecutorService<Object>>(executorAnnotation.id(), IExecutorService.class);
if (isLocal()) {
final DefaultCapServiceToolkit defaultCapServiceToolkit = new DefaultCapServiceToolkit();
final IServicesDecoratorProvider asyncDecoratorProvider = defaultCapServiceToolkit.serviceDecoratorProvider().asyncDecoratorProvider();
final IDecorator<IExecutorService<Object>> decorator = asyncDecoratorProvider.getDecorator(serviceId);
executorService = decorator.decorate(executorService);
}
SpringServiceProvider.getInstance().addService(serviceId, executorService);
}
}
} catch (final NoSuchBeanDefinitionException e) {
}
return bean;
}
Aggregations