Search in sources :

Example 6 with PropertyInject

use of org.apache.camel.PropertyInject in project camel by apache.

the class CdiCamelBeanPostProcessor method injectFields.

protected void injectFields(final Object bean, final String beanName) {
    ReflectionHelper.doWithFields(bean.getClass(), field -> {
        PropertyInject propertyInject = field.getAnnotation(PropertyInject.class);
        if (propertyInject != null) {
            try {
                injectFieldProperty(field, propertyInject.value(), propertyInject.defaultValue(), propertyInject.context(), bean, beanName);
            } catch (Exception cause) {
                throw new InjectionException("Injection of [" + propertyInject + "] for field [" + field + "] failed!", cause);
            }
        }
        BeanInject beanInject = field.getAnnotation(BeanInject.class);
        if (beanInject != null && getPostProcessorHelper().matchContext(beanInject.context())) {
            try {
                injectFieldBean(field, beanInject.value(), bean, beanName);
            } catch (Exception cause) {
                throw new InjectionException("Injection of [" + beanInject + "] for field [" + field + "] failed!", cause);
            }
        }
        EndpointInject endpointInject = field.getAnnotation(EndpointInject.class);
        if (endpointInject != null) {
            try {
                injectField(field, endpointInject.uri(), endpointInject.ref(), endpointInject.property(), endpointInject.context(), bean, beanName);
            } catch (Exception cause) {
                throw new InjectionException("Injection of [" + endpointInject + "] for field [" + field + "] failed!", cause);
            }
        }
        Produce produce = field.getAnnotation(Produce.class);
        if (produce != null) {
            try {
                injectField(field, produce.uri(), produce.ref(), produce.property(), produce.context(), bean, beanName);
            } catch (Exception cause) {
                throw new InjectionException("Injection of [" + produce + "] for field [" + field + "] failed!", cause);
            }
        }
    });
}
Also used : InjectionException(javax.enterprise.inject.InjectionException) EndpointInject(org.apache.camel.EndpointInject) BeanInject(org.apache.camel.BeanInject) Produce(org.apache.camel.Produce) PropertyInject(org.apache.camel.PropertyInject) UnsatisfiedResolutionException(javax.enterprise.inject.UnsatisfiedResolutionException) InjectionException(javax.enterprise.inject.InjectionException)

Aggregations

PropertyInject (org.apache.camel.PropertyInject)6 Field (java.lang.reflect.Field)2 BeanInject (org.apache.camel.BeanInject)2 EndpointInject (org.apache.camel.EndpointInject)2 Produce (org.apache.camel.Produce)2 Method (java.lang.reflect.Method)1 InjectionException (javax.enterprise.inject.InjectionException)1 UnsatisfiedResolutionException (javax.enterprise.inject.UnsatisfiedResolutionException)1 AttachmentObjects (org.apache.camel.AttachmentObjects)1 Attachments (org.apache.camel.Attachments)1 ExchangeException (org.apache.camel.ExchangeException)1 ExchangeProperties (org.apache.camel.ExchangeProperties)1 ExchangeProperty (org.apache.camel.ExchangeProperty)1 Expression (org.apache.camel.Expression)1 Header (org.apache.camel.Header)1 Headers (org.apache.camel.Headers)1 OutHeaders (org.apache.camel.OutHeaders)1 Properties (org.apache.camel.Properties)1 Property (org.apache.camel.Property)1 LanguageAnnotation (org.apache.camel.language.LanguageAnnotation)1