Search in sources :

Example 6 with ConditionalOnClass

use of org.springframework.boot.autoconfigure.condition.ConditionalOnClass in project camel by apache.

the class BindyFixedLengthDataFormatAutoConfiguration method configureBindyFixedLengthDataFormatFactory.

@Bean(name = "bindy-fixed-dataformat-factory")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(BindyFixedLengthDataFormat.class)
public DataFormatFactory configureBindyFixedLengthDataFormatFactory(final CamelContext camelContext, final BindyFixedLengthDataFormatConfiguration configuration) {
    return new DataFormatFactory() {

        public DataFormat newInstance() {
            BindyFixedLengthDataFormat dataformat = new BindyFixedLengthDataFormat();
            if (CamelContextAware.class.isAssignableFrom(BindyFixedLengthDataFormat.class)) {
                CamelContextAware contextAware = CamelContextAware.class.cast(dataformat);
                if (contextAware != null) {
                    contextAware.setCamelContext(camelContext);
                }
            }
            try {
                Map<String, Object> parameters = new HashMap<>();
                IntrospectionSupport.getProperties(configuration, parameters, null, false);
                IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), dataformat, parameters);
            } catch (Exception e) {
                throw new RuntimeCamelException(e);
            }
            return dataformat;
        }
    };
}
Also used : DataFormatFactory(org.apache.camel.spi.DataFormatFactory) CamelContextAware(org.apache.camel.CamelContextAware) HashMap(java.util.HashMap) BindyFixedLengthDataFormat(org.apache.camel.dataformat.bindy.fixed.BindyFixedLengthDataFormat) RuntimeCamelException(org.apache.camel.RuntimeCamelException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 7 with ConditionalOnClass

use of org.springframework.boot.autoconfigure.condition.ConditionalOnClass in project camel by apache.

the class BindyKeyValuePairDataFormatAutoConfiguration method configureBindyKeyValuePairDataFormatFactory.

@Bean(name = "bindy-kvp-dataformat-factory")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(BindyKeyValuePairDataFormat.class)
public DataFormatFactory configureBindyKeyValuePairDataFormatFactory(final CamelContext camelContext, final BindyKeyValuePairDataFormatConfiguration configuration) {
    return new DataFormatFactory() {

        public DataFormat newInstance() {
            BindyKeyValuePairDataFormat dataformat = new BindyKeyValuePairDataFormat();
            if (CamelContextAware.class.isAssignableFrom(BindyKeyValuePairDataFormat.class)) {
                CamelContextAware contextAware = CamelContextAware.class.cast(dataformat);
                if (contextAware != null) {
                    contextAware.setCamelContext(camelContext);
                }
            }
            try {
                Map<String, Object> parameters = new HashMap<>();
                IntrospectionSupport.getProperties(configuration, parameters, null, false);
                IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), dataformat, parameters);
            } catch (Exception e) {
                throw new RuntimeCamelException(e);
            }
            return dataformat;
        }
    };
}
Also used : DataFormatFactory(org.apache.camel.spi.DataFormatFactory) CamelContextAware(org.apache.camel.CamelContextAware) HashMap(java.util.HashMap) RuntimeCamelException(org.apache.camel.RuntimeCamelException) BindyKeyValuePairDataFormat(org.apache.camel.dataformat.bindy.kvp.BindyKeyValuePairDataFormat) RuntimeCamelException(org.apache.camel.RuntimeCamelException) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 8 with ConditionalOnClass

use of org.springframework.boot.autoconfigure.condition.ConditionalOnClass in project camel by apache.

the class BoonDataFormatAutoConfiguration method configureBoonDataFormatFactory.

@Bean(name = "boon-dataformat-factory")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(BoonDataFormat.class)
public DataFormatFactory configureBoonDataFormatFactory(final CamelContext camelContext, final BoonDataFormatConfiguration configuration) {
    return new DataFormatFactory() {

        public DataFormat newInstance() {
            BoonDataFormat dataformat = new BoonDataFormat();
            if (CamelContextAware.class.isAssignableFrom(BoonDataFormat.class)) {
                CamelContextAware contextAware = CamelContextAware.class.cast(dataformat);
                if (contextAware != null) {
                    contextAware.setCamelContext(camelContext);
                }
            }
            try {
                Map<String, Object> parameters = new HashMap<>();
                IntrospectionSupport.getProperties(configuration, parameters, null, false);
                IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), dataformat, parameters);
            } catch (Exception e) {
                throw new RuntimeCamelException(e);
            }
            return dataformat;
        }
    };
}
Also used : DataFormatFactory(org.apache.camel.spi.DataFormatFactory) CamelContextAware(org.apache.camel.CamelContextAware) HashMap(java.util.HashMap) RuntimeCamelException(org.apache.camel.RuntimeCamelException) BoonDataFormat(org.apache.camel.component.boon.BoonDataFormat) RuntimeCamelException(org.apache.camel.RuntimeCamelException) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 9 with ConditionalOnClass

use of org.springframework.boot.autoconfigure.condition.ConditionalOnClass in project camel by apache.

the class BoxComponentAutoConfiguration method configureBoxComponent.

@Lazy
@Bean(name = "box-component")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(BoxComponent.class)
public BoxComponent configureBoxComponent(CamelContext camelContext, BoxComponentConfiguration configuration) throws Exception {
    BoxComponent component = new BoxComponent();
    component.setCamelContext(camelContext);
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null, false);
    for (Map.Entry<String, Object> entry : parameters.entrySet()) {
        Object value = entry.getValue();
        Class<?> paramClass = value.getClass();
        if (paramClass.getName().endsWith("NestedConfiguration")) {
            Class nestedClass = null;
            try {
                nestedClass = (Class) paramClass.getDeclaredField("CAMEL_NESTED_CLASS").get(null);
                HashMap<String, Object> nestedParameters = new HashMap<>();
                IntrospectionSupport.getProperties(value, nestedParameters, null, false);
                Object nestedProperty = nestedClass.newInstance();
                IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), nestedProperty, nestedParameters);
                entry.setValue(nestedProperty);
            } catch (NoSuchFieldException e) {
            }
        }
    }
    IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), component, parameters);
    return component;
}
Also used : HashMap(java.util.HashMap) BoxComponent(org.apache.camel.component.box.BoxComponent) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) HashMap(java.util.HashMap) Map(java.util.Map) Lazy(org.springframework.context.annotation.Lazy) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 10 with ConditionalOnClass

use of org.springframework.boot.autoconfigure.condition.ConditionalOnClass in project camel by apache.

the class AvroComponentAutoConfiguration method configureAvroComponent.

@Lazy
@Bean(name = "avro-component")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(AvroComponent.class)
public AvroComponent configureAvroComponent(CamelContext camelContext, AvroComponentConfiguration configuration) throws Exception {
    AvroComponent component = new AvroComponent();
    component.setCamelContext(camelContext);
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null, false);
    for (Map.Entry<String, Object> entry : parameters.entrySet()) {
        Object value = entry.getValue();
        Class<?> paramClass = value.getClass();
        if (paramClass.getName().endsWith("NestedConfiguration")) {
            Class nestedClass = null;
            try {
                nestedClass = (Class) paramClass.getDeclaredField("CAMEL_NESTED_CLASS").get(null);
                HashMap<String, Object> nestedParameters = new HashMap<>();
                IntrospectionSupport.getProperties(value, nestedParameters, null, false);
                Object nestedProperty = nestedClass.newInstance();
                IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), nestedProperty, nestedParameters);
                entry.setValue(nestedProperty);
            } catch (NoSuchFieldException e) {
            }
        }
    }
    IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), component, parameters);
    return component;
}
Also used : HashMap(java.util.HashMap) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) AvroComponent(org.apache.camel.component.avro.AvroComponent) HashMap(java.util.HashMap) Map(java.util.Map) Lazy(org.springframework.context.annotation.Lazy) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

ConditionalOnClass (org.springframework.boot.autoconfigure.condition.ConditionalOnClass)296 Bean (org.springframework.context.annotation.Bean)296 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)295 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)290 Lazy (org.springframework.context.annotation.Lazy)223 HashMap (java.util.HashMap)183 Map (java.util.Map)106 CamelContextAware (org.apache.camel.CamelContextAware)69 RuntimeCamelException (org.apache.camel.RuntimeCamelException)45 DataFormatFactory (org.apache.camel.spi.DataFormatFactory)45 Scope (org.springframework.context.annotation.Scope)24 JavaScriptLanguage (org.apache.camel.builder.script.JavaScriptLanguage)1 PhpLanguage (org.apache.camel.builder.script.PhpLanguage)1 PythonLanguage (org.apache.camel.builder.script.PythonLanguage)1 RubyLanguage (org.apache.camel.builder.script.RubyLanguage)1 CoAPComponent (org.apache.camel.coap.CoAPComponent)1 AhcComponent (org.apache.camel.component.ahc.AhcComponent)1 WsComponent (org.apache.camel.component.ahc.ws.WsComponent)1 AMQPComponent (org.apache.camel.component.amqp.AMQPComponent)1 ApnsComponent (org.apache.camel.component.apns.ApnsComponent)1