Search in sources :

Example 1 with CapService

use of org.jowidgets.cap.service.api.annotation.CapService in project jo-client-platform by jo-source.

the class ServicePostProcessor method postProcessAfterInitialization.

@Override
public Object postProcessAfterInitialization(final Object bean, final String beanName) {
    try {
        final CapService serviceAnnotation = beanFactory.findAnnotationOnBean(beanName, CapService.class);
        if (serviceAnnotation != null) {
            final Class<?> serviceType;
            if (serviceAnnotation.type() != void.class) {
                serviceType = serviceAnnotation.type();
            } else {
                if (bean.getClass().getInterfaces().length == 0) {
                    throw new RuntimeException(beanName + " must implement at least one interface or type must be set on @CapService annotation");
                }
                serviceType = bean.getClass().getInterfaces()[0];
            }
            String id = serviceAnnotation.id();
            if (id.isEmpty()) {
                id = serviceType.getName();
            }
            final IServiceId<Object> serviceId = new ServiceId<Object>(id, serviceType);
            SpringServiceProvider.getInstance().addService(serviceId, beanProxyFactory.createProxy(beanName, serviceType));
        }
    } catch (final NoSuchBeanDefinitionException e) {
    }
    return bean;
}
Also used : CapService(org.jowidgets.cap.service.api.annotation.CapService) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) IServiceId(org.jowidgets.service.api.IServiceId) ServiceId(org.jowidgets.service.tools.ServiceId)

Aggregations

CapService (org.jowidgets.cap.service.api.annotation.CapService)1 IServiceId (org.jowidgets.service.api.IServiceId)1 ServiceId (org.jowidgets.service.tools.ServiceId)1 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)1