http://git-wip-us.apache.org/repos/asf/camel/blob/3eeb97ac/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/sqs/springboot/SqsComponentConfiguration.java ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/sqs/springboot/SqsComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/sqs/springboot/SqsComponentConfiguration.java index f5be5c0..654ffcf 100644 --- a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/sqs/springboot/SqsComponentConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/sqs/springboot/SqsComponentConfiguration.java @@ -16,6 +16,8 @@ */ package org.apache.camel.component.aws.sqs.springboot; +import javax.annotation.Generated; +import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon; import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -24,8 +26,11 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * * Generated by camel-package-maven-plugin - do not edit this file! */ +@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") @ConfigurationProperties(prefix = "camel.component.aws-sqs") -public class SqsComponentConfiguration { +public class SqsComponentConfiguration + extends + ComponentConfigurationPropertiesCommon { /** * Whether the component should resolve property placeholders on itself when
http://git-wip-us.apache.org/repos/asf/camel/blob/3eeb97ac/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/swf/springboot/SWFComponentAutoConfiguration.java ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/swf/springboot/SWFComponentAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/swf/springboot/SWFComponentAutoConfiguration.java index a2f24ce..aafe618 100644 --- a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/swf/springboot/SWFComponentAutoConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/swf/springboot/SWFComponentAutoConfiguration.java @@ -16,68 +16,114 @@ */ package org.apache.camel.component.aws.swf.springboot; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import javax.annotation.Generated; import org.apache.camel.CamelContext; import org.apache.camel.component.aws.swf.SWFComponent; +import org.apache.camel.spi.ComponentCustomizer; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.apache.camel.spring.boot.ComponentConfigurationProperties; +import org.apache.camel.spring.boot.util.GroupCondition; +import org.apache.camel.util.IntrospectionSupport; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionMessage; -import org.springframework.boot.autoconfigure.condition.ConditionOutcome; +import org.springframework.boot.autoconfigure.condition.AllNestedConditions; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.SpringBootCondition; -import org.springframework.boot.bind.RelaxedPropertyResolver; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Lazy; -import org.springframework.core.type.AnnotatedTypeMetadata; /** * Generated by camel-package-maven-plugin - do not edit this file! */ @Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") @Configuration -@ConditionalOnBean(type = "org.apache.camel.spring.boot.CamelAutoConfiguration") @Conditional(SWFComponentAutoConfiguration.Condition.class) -@AutoConfigureAfter(name = "org.apache.camel.spring.boot.CamelAutoConfiguration") -public class SWFComponentAutoConfiguration { +@AutoConfigureAfter(CamelAutoConfiguration.class) +@EnableConfigurationProperties({ComponentConfigurationProperties.class, + SWFComponentConfiguration.class}) +public class SWFComponentAutoConfiguration extends AllNestedConditions { + + private static final Logger LOGGER = LoggerFactory + .getLogger(SWFComponentAutoConfiguration.class); + @Autowired + private CamelContext camelContext; + @Autowired(required = false) + private List<ComponentCustomizer<SWFComponent>> customizers; + @Autowired + private ComponentConfigurationProperties globalConfiguration; + @Autowired + private SWFComponentConfiguration componentConfiguration; + + public SWFComponentAutoConfiguration() { + super(ConfigurationPhase.REGISTER_BEAN); + } + + @ConditionalOnBean(CamelContext.class) + public static class OnCamelContext { + } + + @ConditionalOnBean(CamelAutoConfiguration.class) + public static class OnCamelAutoConfiguration { + } + + public static class Condition extends GroupCondition { + public Condition() { + super("camel.component", "camel.component.aws-swf"); + } + } @Lazy @Bean(name = "aws-swf-component") @ConditionalOnClass(CamelContext.class) @ConditionalOnMissingBean(SWFComponent.class) - public SWFComponent configureSWFComponent(CamelContext camelContext) - throws Exception { + public SWFComponent configureSWFComponent() throws Exception { SWFComponent component = new SWFComponent(); component.setCamelContext(camelContext); - return component; - } - - @Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") - public static class Condition extends SpringBootCondition { - @Override - public ConditionOutcome getMatchOutcome( - ConditionContext conditionContext, - AnnotatedTypeMetadata annotatedTypeMetadata) { - boolean groupEnabled = isEnabled(conditionContext, - "camel.component.", true); - ConditionMessage.Builder message = ConditionMessage - .forCondition("camel.component.aws-swf"); - if (isEnabled(conditionContext, "camel.component.aws-swf.", - groupEnabled)) { - return ConditionOutcome.match(message.because("enabled")); + Map<String, Object> parameters = new HashMap<>(); + IntrospectionSupport.getProperties(componentConfiguration, 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) { + } } - return ConditionOutcome.noMatch(message.because("not enabled")); } - - private boolean isEnabled( - org.springframework.context.annotation.ConditionContext context, - java.lang.String prefix, boolean defaultValue) { - RelaxedPropertyResolver resolver = new RelaxedPropertyResolver( - context.getEnvironment(), prefix); - return resolver.getProperty("enabled", Boolean.class, defaultValue); + IntrospectionSupport.setProperties(camelContext, + camelContext.getTypeConverter(), component, parameters); + boolean useConfigurers = globalConfiguration.getConfigurer() + .isEnabled() + && componentConfiguration.getConfigurer().isEnabled(); + if (useConfigurers && ObjectHelper.isNotEmpty(customizers)) { + for (ComponentCustomizer<SWFComponent> configurer : customizers) { + LOGGER.debug("Configure component {}, with configurer {}", + component, configurer); + configurer.customize(component); + } } + return component; } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/3eeb97ac/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/swf/springboot/SWFComponentConfiguration.java ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/swf/springboot/SWFComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/swf/springboot/SWFComponentConfiguration.java index c824a9a..10623c9 100644 --- a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/swf/springboot/SWFComponentConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/swf/springboot/SWFComponentConfiguration.java @@ -16,6 +16,8 @@ */ package org.apache.camel.component.aws.swf.springboot; +import javax.annotation.Generated; +import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon; import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -24,8 +26,11 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * * Generated by camel-package-maven-plugin - do not edit this file! */ +@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") @ConfigurationProperties(prefix = "camel.component.aws-swf") -public class SWFComponentConfiguration { +public class SWFComponentConfiguration + extends + ComponentConfigurationPropertiesCommon { /** * Whether the component should resolve property placeholders on itself when http://git-wip-us.apache.org/repos/asf/camel/blob/3eeb97ac/platforms/spring-boot/components-starter/camel-azure-starter/src/main/java/org/apache/camel/component/azure/blob/springboot/BlobServiceComponentAutoConfiguration.java ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-azure-starter/src/main/java/org/apache/camel/component/azure/blob/springboot/BlobServiceComponentAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-azure-starter/src/main/java/org/apache/camel/component/azure/blob/springboot/BlobServiceComponentAutoConfiguration.java index 5e8ee71..7df562e 100644 --- a/platforms/spring-boot/components-starter/camel-azure-starter/src/main/java/org/apache/camel/component/azure/blob/springboot/BlobServiceComponentAutoConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-azure-starter/src/main/java/org/apache/camel/component/azure/blob/springboot/BlobServiceComponentAutoConfiguration.java @@ -16,68 +16,115 @@ */ package org.apache.camel.component.azure.blob.springboot; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import javax.annotation.Generated; import org.apache.camel.CamelContext; import org.apache.camel.component.azure.blob.BlobServiceComponent; +import org.apache.camel.spi.ComponentCustomizer; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.apache.camel.spring.boot.ComponentConfigurationProperties; +import org.apache.camel.spring.boot.util.GroupCondition; +import org.apache.camel.util.IntrospectionSupport; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionMessage; -import org.springframework.boot.autoconfigure.condition.ConditionOutcome; +import org.springframework.boot.autoconfigure.condition.AllNestedConditions; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.SpringBootCondition; -import org.springframework.boot.bind.RelaxedPropertyResolver; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Lazy; -import org.springframework.core.type.AnnotatedTypeMetadata; /** * Generated by camel-package-maven-plugin - do not edit this file! */ @Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") @Configuration -@ConditionalOnBean(type = "org.apache.camel.spring.boot.CamelAutoConfiguration") @Conditional(BlobServiceComponentAutoConfiguration.Condition.class) -@AutoConfigureAfter(name = "org.apache.camel.spring.boot.CamelAutoConfiguration") -public class BlobServiceComponentAutoConfiguration { +@AutoConfigureAfter(CamelAutoConfiguration.class) +@EnableConfigurationProperties({ComponentConfigurationProperties.class, + BlobServiceComponentConfiguration.class}) +public class BlobServiceComponentAutoConfiguration extends AllNestedConditions { + + private static final Logger LOGGER = LoggerFactory + .getLogger(BlobServiceComponentAutoConfiguration.class); + @Autowired + private CamelContext camelContext; + @Autowired(required = false) + private List<ComponentCustomizer<BlobServiceComponent>> customizers; + @Autowired + private ComponentConfigurationProperties globalConfiguration; + @Autowired + private BlobServiceComponentConfiguration componentConfiguration; + + public BlobServiceComponentAutoConfiguration() { + super(ConfigurationPhase.REGISTER_BEAN); + } + + @ConditionalOnBean(CamelContext.class) + public static class OnCamelContext { + } + + @ConditionalOnBean(CamelAutoConfiguration.class) + public static class OnCamelAutoConfiguration { + } + + public static class Condition extends GroupCondition { + public Condition() { + super("camel.component", "camel.component.azure-blob"); + } + } @Lazy @Bean(name = "azure-blob-component") @ConditionalOnClass(CamelContext.class) @ConditionalOnMissingBean(BlobServiceComponent.class) - public BlobServiceComponent configureBlobServiceComponent( - CamelContext camelContext) throws Exception { + public BlobServiceComponent configureBlobServiceComponent() + throws Exception { BlobServiceComponent component = new BlobServiceComponent(); component.setCamelContext(camelContext); - return component; - } - - @Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") - public static class Condition extends SpringBootCondition { - @Override - public ConditionOutcome getMatchOutcome( - ConditionContext conditionContext, - AnnotatedTypeMetadata annotatedTypeMetadata) { - boolean groupEnabled = isEnabled(conditionContext, - "camel.component.", true); - ConditionMessage.Builder message = ConditionMessage - .forCondition("camel.component.azure-blob"); - if (isEnabled(conditionContext, "camel.component.azure-blob.", - groupEnabled)) { - return ConditionOutcome.match(message.because("enabled")); + Map<String, Object> parameters = new HashMap<>(); + IntrospectionSupport.getProperties(componentConfiguration, 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) { + } } - return ConditionOutcome.noMatch(message.because("not enabled")); } - - private boolean isEnabled( - org.springframework.context.annotation.ConditionContext context, - java.lang.String prefix, boolean defaultValue) { - RelaxedPropertyResolver resolver = new RelaxedPropertyResolver( - context.getEnvironment(), prefix); - return resolver.getProperty("enabled", Boolean.class, defaultValue); + IntrospectionSupport.setProperties(camelContext, + camelContext.getTypeConverter(), component, parameters); + boolean useConfigurers = globalConfiguration.getConfigurer() + .isEnabled() + && componentConfiguration.getConfigurer().isEnabled(); + if (useConfigurers && ObjectHelper.isNotEmpty(customizers)) { + for (ComponentCustomizer<BlobServiceComponent> configurer : customizers) { + LOGGER.debug("Configure component {}, with configurer {}", + component, configurer); + configurer.customize(component); + } } + return component; } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/3eeb97ac/platforms/spring-boot/components-starter/camel-azure-starter/src/main/java/org/apache/camel/component/azure/blob/springboot/BlobServiceComponentConfiguration.java ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-azure-starter/src/main/java/org/apache/camel/component/azure/blob/springboot/BlobServiceComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-azure-starter/src/main/java/org/apache/camel/component/azure/blob/springboot/BlobServiceComponentConfiguration.java index baf8052..9d01362 100644 --- a/platforms/spring-boot/components-starter/camel-azure-starter/src/main/java/org/apache/camel/component/azure/blob/springboot/BlobServiceComponentConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-azure-starter/src/main/java/org/apache/camel/component/azure/blob/springboot/BlobServiceComponentConfiguration.java @@ -16,6 +16,8 @@ */ package org.apache.camel.component.azure.blob.springboot; +import javax.annotation.Generated; +import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon; import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -24,8 +26,11 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * * Generated by camel-package-maven-plugin - do not edit this file! */ +@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") @ConfigurationProperties(prefix = "camel.component.azure-blob") -public class BlobServiceComponentConfiguration { +public class BlobServiceComponentConfiguration + extends + ComponentConfigurationPropertiesCommon { /** * Whether the component should resolve property placeholders on itself when http://git-wip-us.apache.org/repos/asf/camel/blob/3eeb97ac/platforms/spring-boot/components-starter/camel-azure-starter/src/main/java/org/apache/camel/component/azure/queue/springboot/QueueServiceComponentAutoConfiguration.java ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-azure-starter/src/main/java/org/apache/camel/component/azure/queue/springboot/QueueServiceComponentAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-azure-starter/src/main/java/org/apache/camel/component/azure/queue/springboot/QueueServiceComponentAutoConfiguration.java index 691ab09..e2ec376 100644 --- a/platforms/spring-boot/components-starter/camel-azure-starter/src/main/java/org/apache/camel/component/azure/queue/springboot/QueueServiceComponentAutoConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-azure-starter/src/main/java/org/apache/camel/component/azure/queue/springboot/QueueServiceComponentAutoConfiguration.java @@ -16,68 +16,115 @@ */ package org.apache.camel.component.azure.queue.springboot; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import javax.annotation.Generated; import org.apache.camel.CamelContext; import org.apache.camel.component.azure.queue.QueueServiceComponent; +import org.apache.camel.spi.ComponentCustomizer; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.apache.camel.spring.boot.ComponentConfigurationProperties; +import org.apache.camel.spring.boot.util.GroupCondition; +import org.apache.camel.util.IntrospectionSupport; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionMessage; -import org.springframework.boot.autoconfigure.condition.ConditionOutcome; +import org.springframework.boot.autoconfigure.condition.AllNestedConditions; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.SpringBootCondition; -import org.springframework.boot.bind.RelaxedPropertyResolver; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Lazy; -import org.springframework.core.type.AnnotatedTypeMetadata; /** * Generated by camel-package-maven-plugin - do not edit this file! */ @Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") @Configuration -@ConditionalOnBean(type = "org.apache.camel.spring.boot.CamelAutoConfiguration") @Conditional(QueueServiceComponentAutoConfiguration.Condition.class) -@AutoConfigureAfter(name = "org.apache.camel.spring.boot.CamelAutoConfiguration") -public class QueueServiceComponentAutoConfiguration { +@AutoConfigureAfter(CamelAutoConfiguration.class) +@EnableConfigurationProperties({ComponentConfigurationProperties.class, + QueueServiceComponentConfiguration.class}) +public class QueueServiceComponentAutoConfiguration extends AllNestedConditions { + + private static final Logger LOGGER = LoggerFactory + .getLogger(QueueServiceComponentAutoConfiguration.class); + @Autowired + private CamelContext camelContext; + @Autowired(required = false) + private List<ComponentCustomizer<QueueServiceComponent>> customizers; + @Autowired + private ComponentConfigurationProperties globalConfiguration; + @Autowired + private QueueServiceComponentConfiguration componentConfiguration; + + public QueueServiceComponentAutoConfiguration() { + super(ConfigurationPhase.REGISTER_BEAN); + } + + @ConditionalOnBean(CamelContext.class) + public static class OnCamelContext { + } + + @ConditionalOnBean(CamelAutoConfiguration.class) + public static class OnCamelAutoConfiguration { + } + + public static class Condition extends GroupCondition { + public Condition() { + super("camel.component", "camel.component.azure-queue"); + } + } @Lazy @Bean(name = "azure-queue-component") @ConditionalOnClass(CamelContext.class) @ConditionalOnMissingBean(QueueServiceComponent.class) - public QueueServiceComponent configureQueueServiceComponent( - CamelContext camelContext) throws Exception { + public QueueServiceComponent configureQueueServiceComponent() + throws Exception { QueueServiceComponent component = new QueueServiceComponent(); component.setCamelContext(camelContext); - return component; - } - - @Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") - public static class Condition extends SpringBootCondition { - @Override - public ConditionOutcome getMatchOutcome( - ConditionContext conditionContext, - AnnotatedTypeMetadata annotatedTypeMetadata) { - boolean groupEnabled = isEnabled(conditionContext, - "camel.component.", true); - ConditionMessage.Builder message = ConditionMessage - .forCondition("camel.component.azure-queue"); - if (isEnabled(conditionContext, "camel.component.azure-queue.", - groupEnabled)) { - return ConditionOutcome.match(message.because("enabled")); + Map<String, Object> parameters = new HashMap<>(); + IntrospectionSupport.getProperties(componentConfiguration, 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) { + } } - return ConditionOutcome.noMatch(message.because("not enabled")); } - - private boolean isEnabled( - org.springframework.context.annotation.ConditionContext context, - java.lang.String prefix, boolean defaultValue) { - RelaxedPropertyResolver resolver = new RelaxedPropertyResolver( - context.getEnvironment(), prefix); - return resolver.getProperty("enabled", Boolean.class, defaultValue); + IntrospectionSupport.setProperties(camelContext, + camelContext.getTypeConverter(), component, parameters); + boolean useConfigurers = globalConfiguration.getConfigurer() + .isEnabled() + && componentConfiguration.getConfigurer().isEnabled(); + if (useConfigurers && ObjectHelper.isNotEmpty(customizers)) { + for (ComponentCustomizer<QueueServiceComponent> configurer : customizers) { + LOGGER.debug("Configure component {}, with configurer {}", + component, configurer); + configurer.customize(component); + } } + return component; } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/3eeb97ac/platforms/spring-boot/components-starter/camel-azure-starter/src/main/java/org/apache/camel/component/azure/queue/springboot/QueueServiceComponentConfiguration.java ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-azure-starter/src/main/java/org/apache/camel/component/azure/queue/springboot/QueueServiceComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-azure-starter/src/main/java/org/apache/camel/component/azure/queue/springboot/QueueServiceComponentConfiguration.java index 3810a4d..78c1d83 100644 --- a/platforms/spring-boot/components-starter/camel-azure-starter/src/main/java/org/apache/camel/component/azure/queue/springboot/QueueServiceComponentConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-azure-starter/src/main/java/org/apache/camel/component/azure/queue/springboot/QueueServiceComponentConfiguration.java @@ -16,6 +16,8 @@ */ package org.apache.camel.component.azure.queue.springboot; +import javax.annotation.Generated; +import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon; import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -24,8 +26,11 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * * Generated by camel-package-maven-plugin - do not edit this file! */ +@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") @ConfigurationProperties(prefix = "camel.component.azure-queue") -public class QueueServiceComponentConfiguration { +public class QueueServiceComponentConfiguration + extends + ComponentConfigurationPropertiesCommon { /** * Whether the component should resolve property placeholders on itself when http://git-wip-us.apache.org/repos/asf/camel/blob/3eeb97ac/platforms/spring-boot/components-starter/camel-barcode-starter/src/main/java/org/apache/camel/dataformat/barcode/springboot/BarcodeDataFormatAutoConfiguration.java ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-barcode-starter/src/main/java/org/apache/camel/dataformat/barcode/springboot/BarcodeDataFormatAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-barcode-starter/src/main/java/org/apache/camel/dataformat/barcode/springboot/BarcodeDataFormatAutoConfiguration.java index d7cafd9..0118a34 100644 --- a/platforms/spring-boot/components-starter/camel-barcode-starter/src/main/java/org/apache/camel/dataformat/barcode/springboot/BarcodeDataFormatAutoConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-barcode-starter/src/main/java/org/apache/camel/dataformat/barcode/springboot/BarcodeDataFormatAutoConfiguration.java @@ -17,6 +17,7 @@ package org.apache.camel.dataformat.barcode.springboot; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.annotation.Generated; import org.apache.camel.CamelContext; @@ -24,40 +25,72 @@ import org.apache.camel.CamelContextAware; import org.apache.camel.RuntimeCamelException; import org.apache.camel.dataformat.barcode.BarcodeDataFormat; import org.apache.camel.spi.DataFormat; +import org.apache.camel.spi.DataFormatCustomizer; import org.apache.camel.spi.DataFormatFactory; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.apache.camel.spring.boot.DataFormatConfigurationProperties; +import org.apache.camel.spring.boot.util.GroupCondition; import org.apache.camel.util.IntrospectionSupport; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionMessage; -import org.springframework.boot.autoconfigure.condition.ConditionOutcome; +import org.springframework.boot.autoconfigure.condition.AllNestedConditions; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.SpringBootCondition; -import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; -import org.springframework.core.type.AnnotatedTypeMetadata; /** * Generated by camel-package-maven-plugin - do not edit this file! */ @Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") @Configuration -@ConditionalOnBean(type = "org.apache.camel.spring.boot.CamelAutoConfiguration") @Conditional(BarcodeDataFormatAutoConfiguration.Condition.class) @AutoConfigureAfter(name = "org.apache.camel.spring.boot.CamelAutoConfiguration") -@EnableConfigurationProperties(BarcodeDataFormatConfiguration.class) -public class BarcodeDataFormatAutoConfiguration { +@EnableConfigurationProperties({DataFormatConfigurationProperties.class, + BarcodeDataFormatConfiguration.class}) +public class BarcodeDataFormatAutoConfiguration extends AllNestedConditions { + + private static final Logger LOGGER = LoggerFactory + .getLogger(BarcodeDataFormatAutoConfiguration.class); + @Autowired + private CamelContext camelContext; + @Autowired(required = false) + private List<DataFormatCustomizer<BarcodeDataFormat>> customizers; + @Autowired + private DataFormatConfigurationProperties globalConfiguration; + @Autowired + private BarcodeDataFormatConfiguration dataformatConfiguration; + + public BarcodeDataFormatAutoConfiguration() { + super(ConfigurationPhase.REGISTER_BEAN); + } + + @ConditionalOnBean(CamelContext.class) + public static class OnCamelContext { + } + + @ConditionalOnBean(CamelAutoConfiguration.class) + public static class OnCamelAutoConfiguration { + } + + @ConditionalOnBean(CamelAutoConfiguration.class) + public static class Condition extends GroupCondition { + public Condition() { + super("camel.dataformat", "camel.dataformat.barcode"); + } + } @Bean(name = "barcode-dataformat-factory") @ConditionalOnClass(CamelContext.class) @ConditionalOnMissingBean(BarcodeDataFormat.class) - public DataFormatFactory configureBarcodeDataFormatFactory( - final CamelContext camelContext, - final BarcodeDataFormatConfiguration configuration) { + public DataFormatFactory configureBarcodeDataFormatFactory() + throws Exception { return new DataFormatFactory() { public DataFormat newInstance() { BarcodeDataFormat dataformat = new BarcodeDataFormat(); @@ -71,7 +104,7 @@ public class BarcodeDataFormatAutoConfiguration { } try { Map<String, Object> parameters = new HashMap<>(); - IntrospectionSupport.getProperties(configuration, + IntrospectionSupport.getProperties(dataformatConfiguration, parameters, null, false); IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), dataformat, @@ -79,34 +112,19 @@ public class BarcodeDataFormatAutoConfiguration { } catch (Exception e) { throw new RuntimeCamelException(e); } + boolean useConfigurers = globalConfiguration.getConfigurer() + .isEnabled() + && dataformatConfiguration.getConfigurer().isEnabled(); + if (useConfigurers && ObjectHelper.isNotEmpty(customizers)) { + for (DataFormatCustomizer<BarcodeDataFormat> configurer : customizers) { + LOGGER.debug( + "Configure dataformat {}, with configurer {}", + dataformat, configurer); + configurer.customize(dataformat); + } + } return dataformat; } }; } - - @Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") - public static class Condition extends SpringBootCondition { - @Override - public ConditionOutcome getMatchOutcome( - ConditionContext conditionContext, - AnnotatedTypeMetadata annotatedTypeMetadata) { - boolean groupEnabled = isEnabled(conditionContext, - "camel.dataformat.", true); - ConditionMessage.Builder message = ConditionMessage - .forCondition("camel.dataformat.barcode"); - if (isEnabled(conditionContext, "camel.dataformat.barcode.", - groupEnabled)) { - return ConditionOutcome.match(message.because("enabled")); - } - return ConditionOutcome.noMatch(message.because("not enabled")); - } - - private boolean isEnabled( - org.springframework.context.annotation.ConditionContext context, - java.lang.String prefix, boolean defaultValue) { - RelaxedPropertyResolver resolver = new RelaxedPropertyResolver( - context.getEnvironment(), prefix); - return resolver.getProperty("enabled", Boolean.class, defaultValue); - } - } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/3eeb97ac/platforms/spring-boot/components-starter/camel-barcode-starter/src/main/java/org/apache/camel/dataformat/barcode/springboot/BarcodeDataFormatConfiguration.java ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-barcode-starter/src/main/java/org/apache/camel/dataformat/barcode/springboot/BarcodeDataFormatConfiguration.java b/platforms/spring-boot/components-starter/camel-barcode-starter/src/main/java/org/apache/camel/dataformat/barcode/springboot/BarcodeDataFormatConfiguration.java index d8539be..1f71cfe 100644 --- a/platforms/spring-boot/components-starter/camel-barcode-starter/src/main/java/org/apache/camel/dataformat/barcode/springboot/BarcodeDataFormatConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-barcode-starter/src/main/java/org/apache/camel/dataformat/barcode/springboot/BarcodeDataFormatConfiguration.java @@ -17,6 +17,7 @@ package org.apache.camel.dataformat.barcode.springboot; import javax.annotation.Generated; +import org.apache.camel.spring.boot.DataFormatConfigurationPropertiesCommon; import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -26,7 +27,9 @@ import org.springframework.boot.context.properties.ConfigurationProperties; */ @Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") @ConfigurationProperties(prefix = "camel.dataformat.barcode") -public class BarcodeDataFormatConfiguration { +public class BarcodeDataFormatConfiguration + extends + DataFormatConfigurationPropertiesCommon { /** * Width of the barcode http://git-wip-us.apache.org/repos/asf/camel/blob/3eeb97ac/platforms/spring-boot/components-starter/camel-base64-starter/src/main/java/org/apache/camel/dataformat/base64/springboot/Base64DataFormatAutoConfiguration.java ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-base64-starter/src/main/java/org/apache/camel/dataformat/base64/springboot/Base64DataFormatAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-base64-starter/src/main/java/org/apache/camel/dataformat/base64/springboot/Base64DataFormatAutoConfiguration.java index f0b1387..b782146 100644 --- a/platforms/spring-boot/components-starter/camel-base64-starter/src/main/java/org/apache/camel/dataformat/base64/springboot/Base64DataFormatAutoConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-base64-starter/src/main/java/org/apache/camel/dataformat/base64/springboot/Base64DataFormatAutoConfiguration.java @@ -17,6 +17,7 @@ package org.apache.camel.dataformat.base64.springboot; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.annotation.Generated; import org.apache.camel.CamelContext; @@ -24,40 +25,72 @@ import org.apache.camel.CamelContextAware; import org.apache.camel.RuntimeCamelException; import org.apache.camel.dataformat.base64.Base64DataFormat; import org.apache.camel.spi.DataFormat; +import org.apache.camel.spi.DataFormatCustomizer; import org.apache.camel.spi.DataFormatFactory; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.apache.camel.spring.boot.DataFormatConfigurationProperties; +import org.apache.camel.spring.boot.util.GroupCondition; import org.apache.camel.util.IntrospectionSupport; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionMessage; -import org.springframework.boot.autoconfigure.condition.ConditionOutcome; +import org.springframework.boot.autoconfigure.condition.AllNestedConditions; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.SpringBootCondition; -import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; -import org.springframework.core.type.AnnotatedTypeMetadata; /** * Generated by camel-package-maven-plugin - do not edit this file! */ @Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") @Configuration -@ConditionalOnBean(type = "org.apache.camel.spring.boot.CamelAutoConfiguration") @Conditional(Base64DataFormatAutoConfiguration.Condition.class) @AutoConfigureAfter(name = "org.apache.camel.spring.boot.CamelAutoConfiguration") -@EnableConfigurationProperties(Base64DataFormatConfiguration.class) -public class Base64DataFormatAutoConfiguration { +@EnableConfigurationProperties({DataFormatConfigurationProperties.class, + Base64DataFormatConfiguration.class}) +public class Base64DataFormatAutoConfiguration extends AllNestedConditions { + + private static final Logger LOGGER = LoggerFactory + .getLogger(Base64DataFormatAutoConfiguration.class); + @Autowired + private CamelContext camelContext; + @Autowired(required = false) + private List<DataFormatCustomizer<Base64DataFormat>> customizers; + @Autowired + private DataFormatConfigurationProperties globalConfiguration; + @Autowired + private Base64DataFormatConfiguration dataformatConfiguration; + + public Base64DataFormatAutoConfiguration() { + super(ConfigurationPhase.REGISTER_BEAN); + } + + @ConditionalOnBean(CamelContext.class) + public static class OnCamelContext { + } + + @ConditionalOnBean(CamelAutoConfiguration.class) + public static class OnCamelAutoConfiguration { + } + + @ConditionalOnBean(CamelAutoConfiguration.class) + public static class Condition extends GroupCondition { + public Condition() { + super("camel.dataformat", "camel.dataformat.base64"); + } + } @Bean(name = "base64-dataformat-factory") @ConditionalOnClass(CamelContext.class) @ConditionalOnMissingBean(Base64DataFormat.class) - public DataFormatFactory configureBase64DataFormatFactory( - final CamelContext camelContext, - final Base64DataFormatConfiguration configuration) { + public DataFormatFactory configureBase64DataFormatFactory() + throws Exception { return new DataFormatFactory() { public DataFormat newInstance() { Base64DataFormat dataformat = new Base64DataFormat(); @@ -71,7 +104,7 @@ public class Base64DataFormatAutoConfiguration { } try { Map<String, Object> parameters = new HashMap<>(); - IntrospectionSupport.getProperties(configuration, + IntrospectionSupport.getProperties(dataformatConfiguration, parameters, null, false); IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), dataformat, @@ -79,34 +112,19 @@ public class Base64DataFormatAutoConfiguration { } catch (Exception e) { throw new RuntimeCamelException(e); } + boolean useConfigurers = globalConfiguration.getConfigurer() + .isEnabled() + && dataformatConfiguration.getConfigurer().isEnabled(); + if (useConfigurers && ObjectHelper.isNotEmpty(customizers)) { + for (DataFormatCustomizer<Base64DataFormat> configurer : customizers) { + LOGGER.debug( + "Configure dataformat {}, with configurer {}", + dataformat, configurer); + configurer.customize(dataformat); + } + } return dataformat; } }; } - - @Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") - public static class Condition extends SpringBootCondition { - @Override - public ConditionOutcome getMatchOutcome( - ConditionContext conditionContext, - AnnotatedTypeMetadata annotatedTypeMetadata) { - boolean groupEnabled = isEnabled(conditionContext, - "camel.dataformat.", true); - ConditionMessage.Builder message = ConditionMessage - .forCondition("camel.dataformat.base64"); - if (isEnabled(conditionContext, "camel.dataformat.base64.", - groupEnabled)) { - return ConditionOutcome.match(message.because("enabled")); - } - return ConditionOutcome.noMatch(message.because("not enabled")); - } - - private boolean isEnabled( - org.springframework.context.annotation.ConditionContext context, - java.lang.String prefix, boolean defaultValue) { - RelaxedPropertyResolver resolver = new RelaxedPropertyResolver( - context.getEnvironment(), prefix); - return resolver.getProperty("enabled", Boolean.class, defaultValue); - } - } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/3eeb97ac/platforms/spring-boot/components-starter/camel-base64-starter/src/main/java/org/apache/camel/dataformat/base64/springboot/Base64DataFormatConfiguration.java ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-base64-starter/src/main/java/org/apache/camel/dataformat/base64/springboot/Base64DataFormatConfiguration.java b/platforms/spring-boot/components-starter/camel-base64-starter/src/main/java/org/apache/camel/dataformat/base64/springboot/Base64DataFormatConfiguration.java index e0d52d3..02c66a3 100644 --- a/platforms/spring-boot/components-starter/camel-base64-starter/src/main/java/org/apache/camel/dataformat/base64/springboot/Base64DataFormatConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-base64-starter/src/main/java/org/apache/camel/dataformat/base64/springboot/Base64DataFormatConfiguration.java @@ -17,6 +17,7 @@ package org.apache.camel.dataformat.base64.springboot; import javax.annotation.Generated; +import org.apache.camel.spring.boot.DataFormatConfigurationPropertiesCommon; import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -26,7 +27,9 @@ import org.springframework.boot.context.properties.ConfigurationProperties; */ @Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") @ConfigurationProperties(prefix = "camel.dataformat.base64") -public class Base64DataFormatConfiguration { +public class Base64DataFormatConfiguration + extends + DataFormatConfigurationPropertiesCommon { /** * To specific a maximum line length for the encoded data. By default 76 is http://git-wip-us.apache.org/repos/asf/camel/blob/3eeb97ac/platforms/spring-boot/components-starter/camel-bean-validator-starter/src/main/java/org/apache/camel/component/bean/validator/springboot/BeanValidatorComponentAutoConfiguration.java ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-bean-validator-starter/src/main/java/org/apache/camel/component/bean/validator/springboot/BeanValidatorComponentAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-bean-validator-starter/src/main/java/org/apache/camel/component/bean/validator/springboot/BeanValidatorComponentAutoConfiguration.java index 731fb15..40a83c4 100644 --- a/platforms/spring-boot/components-starter/camel-bean-validator-starter/src/main/java/org/apache/camel/component/bean/validator/springboot/BeanValidatorComponentAutoConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-bean-validator-starter/src/main/java/org/apache/camel/component/bean/validator/springboot/BeanValidatorComponentAutoConfiguration.java @@ -16,68 +16,117 @@ */ package org.apache.camel.component.bean.validator.springboot; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import javax.annotation.Generated; import org.apache.camel.CamelContext; import org.apache.camel.component.bean.validator.BeanValidatorComponent; +import org.apache.camel.spi.ComponentCustomizer; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.apache.camel.spring.boot.ComponentConfigurationProperties; +import org.apache.camel.spring.boot.util.GroupCondition; +import org.apache.camel.util.IntrospectionSupport; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionMessage; -import org.springframework.boot.autoconfigure.condition.ConditionOutcome; +import org.springframework.boot.autoconfigure.condition.AllNestedConditions; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.SpringBootCondition; -import org.springframework.boot.bind.RelaxedPropertyResolver; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Lazy; -import org.springframework.core.type.AnnotatedTypeMetadata; /** * Generated by camel-package-maven-plugin - do not edit this file! */ @Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") @Configuration -@ConditionalOnBean(type = "org.apache.camel.spring.boot.CamelAutoConfiguration") @Conditional(BeanValidatorComponentAutoConfiguration.Condition.class) -@AutoConfigureAfter(name = "org.apache.camel.spring.boot.CamelAutoConfiguration") -public class BeanValidatorComponentAutoConfiguration { +@AutoConfigureAfter(CamelAutoConfiguration.class) +@EnableConfigurationProperties({ComponentConfigurationProperties.class, + BeanValidatorComponentConfiguration.class}) +public class BeanValidatorComponentAutoConfiguration + extends + AllNestedConditions { + + private static final Logger LOGGER = LoggerFactory + .getLogger(BeanValidatorComponentAutoConfiguration.class); + @Autowired + private CamelContext camelContext; + @Autowired(required = false) + private List<ComponentCustomizer<BeanValidatorComponent>> customizers; + @Autowired + private ComponentConfigurationProperties globalConfiguration; + @Autowired + private BeanValidatorComponentConfiguration componentConfiguration; + + public BeanValidatorComponentAutoConfiguration() { + super(ConfigurationPhase.REGISTER_BEAN); + } + + @ConditionalOnBean(CamelContext.class) + public static class OnCamelContext { + } + + @ConditionalOnBean(CamelAutoConfiguration.class) + public static class OnCamelAutoConfiguration { + } + + public static class Condition extends GroupCondition { + public Condition() { + super("camel.component", "camel.component.bean-validator"); + } + } @Lazy @Bean(name = "bean-validator-component") @ConditionalOnClass(CamelContext.class) @ConditionalOnMissingBean(BeanValidatorComponent.class) - public BeanValidatorComponent configureBeanValidatorComponent( - CamelContext camelContext) throws Exception { + public BeanValidatorComponent configureBeanValidatorComponent() + throws Exception { BeanValidatorComponent component = new BeanValidatorComponent(); component.setCamelContext(camelContext); - return component; - } - - @Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") - public static class Condition extends SpringBootCondition { - @Override - public ConditionOutcome getMatchOutcome( - ConditionContext conditionContext, - AnnotatedTypeMetadata annotatedTypeMetadata) { - boolean groupEnabled = isEnabled(conditionContext, - "camel.component.", true); - ConditionMessage.Builder message = ConditionMessage - .forCondition("camel.component.bean-validator"); - if (isEnabled(conditionContext, "camel.component.bean-validator.", - groupEnabled)) { - return ConditionOutcome.match(message.because("enabled")); + Map<String, Object> parameters = new HashMap<>(); + IntrospectionSupport.getProperties(componentConfiguration, 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) { + } } - return ConditionOutcome.noMatch(message.because("not enabled")); } - - private boolean isEnabled( - org.springframework.context.annotation.ConditionContext context, - java.lang.String prefix, boolean defaultValue) { - RelaxedPropertyResolver resolver = new RelaxedPropertyResolver( - context.getEnvironment(), prefix); - return resolver.getProperty("enabled", Boolean.class, defaultValue); + IntrospectionSupport.setProperties(camelContext, + camelContext.getTypeConverter(), component, parameters); + boolean useConfigurers = globalConfiguration.getConfigurer() + .isEnabled() + && componentConfiguration.getConfigurer().isEnabled(); + if (useConfigurers && ObjectHelper.isNotEmpty(customizers)) { + for (ComponentCustomizer<BeanValidatorComponent> configurer : customizers) { + LOGGER.debug("Configure component {}, with configurer {}", + component, configurer); + configurer.customize(component); + } } + return component; } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/3eeb97ac/platforms/spring-boot/components-starter/camel-bean-validator-starter/src/main/java/org/apache/camel/component/bean/validator/springboot/BeanValidatorComponentConfiguration.java ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-bean-validator-starter/src/main/java/org/apache/camel/component/bean/validator/springboot/BeanValidatorComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-bean-validator-starter/src/main/java/org/apache/camel/component/bean/validator/springboot/BeanValidatorComponentConfiguration.java index f70737b..c91da96 100644 --- a/platforms/spring-boot/components-starter/camel-bean-validator-starter/src/main/java/org/apache/camel/component/bean/validator/springboot/BeanValidatorComponentConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-bean-validator-starter/src/main/java/org/apache/camel/component/bean/validator/springboot/BeanValidatorComponentConfiguration.java @@ -16,6 +16,8 @@ */ package org.apache.camel.component.bean.validator.springboot; +import javax.annotation.Generated; +import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon; import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -24,8 +26,11 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * * Generated by camel-package-maven-plugin - do not edit this file! */ +@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") @ConfigurationProperties(prefix = "camel.component.bean-validator") -public class BeanValidatorComponentConfiguration { +public class BeanValidatorComponentConfiguration + extends + ComponentConfigurationPropertiesCommon { /** * Whether the component should resolve property placeholders on itself when http://git-wip-us.apache.org/repos/asf/camel/blob/3eeb97ac/platforms/spring-boot/components-starter/camel-beanio-starter/src/main/java/org/apache/camel/dataformat/beanio/springboot/BeanIODataFormatAutoConfiguration.java ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-beanio-starter/src/main/java/org/apache/camel/dataformat/beanio/springboot/BeanIODataFormatAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-beanio-starter/src/main/java/org/apache/camel/dataformat/beanio/springboot/BeanIODataFormatAutoConfiguration.java index 04d3b3b..9d25941 100644 --- a/platforms/spring-boot/components-starter/camel-beanio-starter/src/main/java/org/apache/camel/dataformat/beanio/springboot/BeanIODataFormatAutoConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-beanio-starter/src/main/java/org/apache/camel/dataformat/beanio/springboot/BeanIODataFormatAutoConfiguration.java @@ -17,6 +17,7 @@ package org.apache.camel.dataformat.beanio.springboot; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.annotation.Generated; import org.apache.camel.CamelContext; @@ -24,40 +25,72 @@ import org.apache.camel.CamelContextAware; import org.apache.camel.RuntimeCamelException; import org.apache.camel.dataformat.beanio.BeanIODataFormat; import org.apache.camel.spi.DataFormat; +import org.apache.camel.spi.DataFormatCustomizer; import org.apache.camel.spi.DataFormatFactory; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.apache.camel.spring.boot.DataFormatConfigurationProperties; +import org.apache.camel.spring.boot.util.GroupCondition; import org.apache.camel.util.IntrospectionSupport; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionMessage; -import org.springframework.boot.autoconfigure.condition.ConditionOutcome; +import org.springframework.boot.autoconfigure.condition.AllNestedConditions; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.SpringBootCondition; -import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; -import org.springframework.core.type.AnnotatedTypeMetadata; /** * Generated by camel-package-maven-plugin - do not edit this file! */ @Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") @Configuration -@ConditionalOnBean(type = "org.apache.camel.spring.boot.CamelAutoConfiguration") @Conditional(BeanIODataFormatAutoConfiguration.Condition.class) @AutoConfigureAfter(name = "org.apache.camel.spring.boot.CamelAutoConfiguration") -@EnableConfigurationProperties(BeanIODataFormatConfiguration.class) -public class BeanIODataFormatAutoConfiguration { +@EnableConfigurationProperties({DataFormatConfigurationProperties.class, + BeanIODataFormatConfiguration.class}) +public class BeanIODataFormatAutoConfiguration extends AllNestedConditions { + + private static final Logger LOGGER = LoggerFactory + .getLogger(BeanIODataFormatAutoConfiguration.class); + @Autowired + private CamelContext camelContext; + @Autowired(required = false) + private List<DataFormatCustomizer<BeanIODataFormat>> customizers; + @Autowired + private DataFormatConfigurationProperties globalConfiguration; + @Autowired + private BeanIODataFormatConfiguration dataformatConfiguration; + + public BeanIODataFormatAutoConfiguration() { + super(ConfigurationPhase.REGISTER_BEAN); + } + + @ConditionalOnBean(CamelContext.class) + public static class OnCamelContext { + } + + @ConditionalOnBean(CamelAutoConfiguration.class) + public static class OnCamelAutoConfiguration { + } + + @ConditionalOnBean(CamelAutoConfiguration.class) + public static class Condition extends GroupCondition { + public Condition() { + super("camel.dataformat", "camel.dataformat.beanio"); + } + } @Bean(name = "beanio-dataformat-factory") @ConditionalOnClass(CamelContext.class) @ConditionalOnMissingBean(BeanIODataFormat.class) - public DataFormatFactory configureBeanIODataFormatFactory( - final CamelContext camelContext, - final BeanIODataFormatConfiguration configuration) { + public DataFormatFactory configureBeanIODataFormatFactory() + throws Exception { return new DataFormatFactory() { public DataFormat newInstance() { BeanIODataFormat dataformat = new BeanIODataFormat(); @@ -71,7 +104,7 @@ public class BeanIODataFormatAutoConfiguration { } try { Map<String, Object> parameters = new HashMap<>(); - IntrospectionSupport.getProperties(configuration, + IntrospectionSupport.getProperties(dataformatConfiguration, parameters, null, false); IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), dataformat, @@ -79,34 +112,19 @@ public class BeanIODataFormatAutoConfiguration { } catch (Exception e) { throw new RuntimeCamelException(e); } + boolean useConfigurers = globalConfiguration.getConfigurer() + .isEnabled() + && dataformatConfiguration.getConfigurer().isEnabled(); + if (useConfigurers && ObjectHelper.isNotEmpty(customizers)) { + for (DataFormatCustomizer<BeanIODataFormat> configurer : customizers) { + LOGGER.debug( + "Configure dataformat {}, with configurer {}", + dataformat, configurer); + configurer.customize(dataformat); + } + } return dataformat; } }; } - - @Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") - public static class Condition extends SpringBootCondition { - @Override - public ConditionOutcome getMatchOutcome( - ConditionContext conditionContext, - AnnotatedTypeMetadata annotatedTypeMetadata) { - boolean groupEnabled = isEnabled(conditionContext, - "camel.dataformat.", true); - ConditionMessage.Builder message = ConditionMessage - .forCondition("camel.dataformat.beanio"); - if (isEnabled(conditionContext, "camel.dataformat.beanio.", - groupEnabled)) { - return ConditionOutcome.match(message.because("enabled")); - } - return ConditionOutcome.noMatch(message.because("not enabled")); - } - - private boolean isEnabled( - org.springframework.context.annotation.ConditionContext context, - java.lang.String prefix, boolean defaultValue) { - RelaxedPropertyResolver resolver = new RelaxedPropertyResolver( - context.getEnvironment(), prefix); - return resolver.getProperty("enabled", Boolean.class, defaultValue); - } - } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/3eeb97ac/platforms/spring-boot/components-starter/camel-beanio-starter/src/main/java/org/apache/camel/dataformat/beanio/springboot/BeanIODataFormatConfiguration.java ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-beanio-starter/src/main/java/org/apache/camel/dataformat/beanio/springboot/BeanIODataFormatConfiguration.java b/platforms/spring-boot/components-starter/camel-beanio-starter/src/main/java/org/apache/camel/dataformat/beanio/springboot/BeanIODataFormatConfiguration.java index 2a32468..1b68ba5 100644 --- a/platforms/spring-boot/components-starter/camel-beanio-starter/src/main/java/org/apache/camel/dataformat/beanio/springboot/BeanIODataFormatConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-beanio-starter/src/main/java/org/apache/camel/dataformat/beanio/springboot/BeanIODataFormatConfiguration.java @@ -17,6 +17,7 @@ package org.apache.camel.dataformat.beanio.springboot; import javax.annotation.Generated; +import org.apache.camel.spring.boot.DataFormatConfigurationPropertiesCommon; import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -26,7 +27,9 @@ import org.springframework.boot.context.properties.ConfigurationProperties; */ @Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") @ConfigurationProperties(prefix = "camel.dataformat.beanio") -public class BeanIODataFormatConfiguration { +public class BeanIODataFormatConfiguration + extends + DataFormatConfigurationPropertiesCommon { /** * The BeanIO mapping file. Is by default loaded from the classpath. You can http://git-wip-us.apache.org/repos/asf/camel/blob/3eeb97ac/platforms/spring-boot/components-starter/camel-beanstalk-starter/src/main/java/org/apache/camel/component/beanstalk/springboot/BeanstalkComponentAutoConfiguration.java ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-beanstalk-starter/src/main/java/org/apache/camel/component/beanstalk/springboot/BeanstalkComponentAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-beanstalk-starter/src/main/java/org/apache/camel/component/beanstalk/springboot/BeanstalkComponentAutoConfiguration.java index ed4684b..990c46e 100644 --- a/platforms/spring-boot/components-starter/camel-beanstalk-starter/src/main/java/org/apache/camel/component/beanstalk/springboot/BeanstalkComponentAutoConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-beanstalk-starter/src/main/java/org/apache/camel/component/beanstalk/springboot/BeanstalkComponentAutoConfiguration.java @@ -17,50 +17,81 @@ package org.apache.camel.component.beanstalk.springboot; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.annotation.Generated; import org.apache.camel.CamelContext; import org.apache.camel.component.beanstalk.BeanstalkComponent; +import org.apache.camel.spi.ComponentCustomizer; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.apache.camel.spring.boot.ComponentConfigurationProperties; +import org.apache.camel.spring.boot.util.GroupCondition; import org.apache.camel.util.IntrospectionSupport; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionMessage; -import org.springframework.boot.autoconfigure.condition.ConditionOutcome; +import org.springframework.boot.autoconfigure.condition.AllNestedConditions; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.SpringBootCondition; -import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Lazy; -import org.springframework.core.type.AnnotatedTypeMetadata; /** * Generated by camel-package-maven-plugin - do not edit this file! */ @Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") @Configuration -@ConditionalOnBean(type = "org.apache.camel.spring.boot.CamelAutoConfiguration") @Conditional(BeanstalkComponentAutoConfiguration.Condition.class) -@AutoConfigureAfter(name = "org.apache.camel.spring.boot.CamelAutoConfiguration") -@EnableConfigurationProperties(BeanstalkComponentConfiguration.class) -public class BeanstalkComponentAutoConfiguration { +@AutoConfigureAfter(CamelAutoConfiguration.class) +@EnableConfigurationProperties({ComponentConfigurationProperties.class, + BeanstalkComponentConfiguration.class}) +public class BeanstalkComponentAutoConfiguration extends AllNestedConditions { + + private static final Logger LOGGER = LoggerFactory + .getLogger(BeanstalkComponentAutoConfiguration.class); + @Autowired + private CamelContext camelContext; + @Autowired(required = false) + private List<ComponentCustomizer<BeanstalkComponent>> customizers; + @Autowired + private ComponentConfigurationProperties globalConfiguration; + @Autowired + private BeanstalkComponentConfiguration componentConfiguration; + + public BeanstalkComponentAutoConfiguration() { + super(ConfigurationPhase.REGISTER_BEAN); + } + + @ConditionalOnBean(CamelContext.class) + public static class OnCamelContext { + } + + @ConditionalOnBean(CamelAutoConfiguration.class) + public static class OnCamelAutoConfiguration { + } + + public static class Condition extends GroupCondition { + public Condition() { + super("camel.component", "camel.component.beanstalk"); + } + } @Lazy @Bean(name = "beanstalk-component") @ConditionalOnClass(CamelContext.class) @ConditionalOnMissingBean(BeanstalkComponent.class) - public BeanstalkComponent configureBeanstalkComponent( - CamelContext camelContext, - BeanstalkComponentConfiguration configuration) throws Exception { + public BeanstalkComponent configureBeanstalkComponent() throws Exception { BeanstalkComponent component = new BeanstalkComponent(); component.setCamelContext(camelContext); Map<String, Object> parameters = new HashMap<>(); - IntrospectionSupport.getProperties(configuration, parameters, null, - false); + IntrospectionSupport.getProperties(componentConfiguration, parameters, + null, false); for (Map.Entry<String, Object> entry : parameters.entrySet()) { Object value = entry.getValue(); Class<?> paramClass = value.getClass(); @@ -83,32 +114,16 @@ public class BeanstalkComponentAutoConfiguration { } IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), component, parameters); - return component; - } - - @Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") - public static class Condition extends SpringBootCondition { - @Override - public ConditionOutcome getMatchOutcome( - ConditionContext conditionContext, - AnnotatedTypeMetadata annotatedTypeMetadata) { - boolean groupEnabled = isEnabled(conditionContext, - "camel.component.", true); - ConditionMessage.Builder message = ConditionMessage - .forCondition("camel.component.beanstalk"); - if (isEnabled(conditionContext, "camel.component.beanstalk.", - groupEnabled)) { - return ConditionOutcome.match(message.because("enabled")); + boolean useConfigurers = globalConfiguration.getConfigurer() + .isEnabled() + && componentConfiguration.getConfigurer().isEnabled(); + if (useConfigurers && ObjectHelper.isNotEmpty(customizers)) { + for (ComponentCustomizer<BeanstalkComponent> configurer : customizers) { + LOGGER.debug("Configure component {}, with configurer {}", + component, configurer); + configurer.customize(component); } - return ConditionOutcome.noMatch(message.because("not enabled")); - } - - private boolean isEnabled( - org.springframework.context.annotation.ConditionContext context, - java.lang.String prefix, boolean defaultValue) { - RelaxedPropertyResolver resolver = new RelaxedPropertyResolver( - context.getEnvironment(), prefix); - return resolver.getProperty("enabled", Boolean.class, defaultValue); } + return component; } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/3eeb97ac/platforms/spring-boot/components-starter/camel-beanstalk-starter/src/main/java/org/apache/camel/component/beanstalk/springboot/BeanstalkComponentConfiguration.java ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-beanstalk-starter/src/main/java/org/apache/camel/component/beanstalk/springboot/BeanstalkComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-beanstalk-starter/src/main/java/org/apache/camel/component/beanstalk/springboot/BeanstalkComponentConfiguration.java index 6aae498..e13f33e 100644 --- a/platforms/spring-boot/components-starter/camel-beanstalk-starter/src/main/java/org/apache/camel/component/beanstalk/springboot/BeanstalkComponentConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-beanstalk-starter/src/main/java/org/apache/camel/component/beanstalk/springboot/BeanstalkComponentConfiguration.java @@ -18,6 +18,7 @@ package org.apache.camel.component.beanstalk.springboot; import javax.annotation.Generated; import org.apache.camel.component.beanstalk.ConnectionSettingsFactory; +import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.NestedConfigurationProperty; @@ -29,7 +30,9 @@ import org.springframework.boot.context.properties.NestedConfigurationProperty; */ @Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") @ConfigurationProperties(prefix = "camel.component.beanstalk") -public class BeanstalkComponentConfiguration { +public class BeanstalkComponentConfiguration + extends + ComponentConfigurationPropertiesCommon { /** * Custom ConnectionSettingsFactory. Specify which ConnectionSettingsFactory http://git-wip-us.apache.org/repos/asf/camel/blob/3eeb97ac/platforms/spring-boot/components-starter/camel-bindy-starter/src/main/java/org/apache/camel/dataformat/bindy/csv/springboot/BindyCsvDataFormatAutoConfiguration.java ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-bindy-starter/src/main/java/org/apache/camel/dataformat/bindy/csv/springboot/BindyCsvDataFormatAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-bindy-starter/src/main/java/org/apache/camel/dataformat/bindy/csv/springboot/BindyCsvDataFormatAutoConfiguration.java index 4ed920a..dd85c10 100644 --- a/platforms/spring-boot/components-starter/camel-bindy-starter/src/main/java/org/apache/camel/dataformat/bindy/csv/springboot/BindyCsvDataFormatAutoConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-bindy-starter/src/main/java/org/apache/camel/dataformat/bindy/csv/springboot/BindyCsvDataFormatAutoConfiguration.java @@ -17,6 +17,7 @@ package org.apache.camel.dataformat.bindy.csv.springboot; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.annotation.Generated; import org.apache.camel.CamelContext; @@ -24,40 +25,72 @@ import org.apache.camel.CamelContextAware; import org.apache.camel.RuntimeCamelException; import org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat; import org.apache.camel.spi.DataFormat; +import org.apache.camel.spi.DataFormatCustomizer; import org.apache.camel.spi.DataFormatFactory; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.apache.camel.spring.boot.DataFormatConfigurationProperties; +import org.apache.camel.spring.boot.util.GroupCondition; import org.apache.camel.util.IntrospectionSupport; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionMessage; -import org.springframework.boot.autoconfigure.condition.ConditionOutcome; +import org.springframework.boot.autoconfigure.condition.AllNestedConditions; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.SpringBootCondition; -import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; -import org.springframework.core.type.AnnotatedTypeMetadata; /** * Generated by camel-package-maven-plugin - do not edit this file! */ @Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") @Configuration -@ConditionalOnBean(type = "org.apache.camel.spring.boot.CamelAutoConfiguration") @Conditional(BindyCsvDataFormatAutoConfiguration.Condition.class) @AutoConfigureAfter(name = "org.apache.camel.spring.boot.CamelAutoConfiguration") -@EnableConfigurationProperties(BindyCsvDataFormatConfiguration.class) -public class BindyCsvDataFormatAutoConfiguration { +@EnableConfigurationProperties({DataFormatConfigurationProperties.class, + BindyCsvDataFormatConfiguration.class}) +public class BindyCsvDataFormatAutoConfiguration extends AllNestedConditions { + + private static final Logger LOGGER = LoggerFactory + .getLogger(BindyCsvDataFormatAutoConfiguration.class); + @Autowired + private CamelContext camelContext; + @Autowired(required = false) + private List<DataFormatCustomizer<BindyCsvDataFormat>> customizers; + @Autowired + private DataFormatConfigurationProperties globalConfiguration; + @Autowired + private BindyCsvDataFormatConfiguration dataformatConfiguration; + + public BindyCsvDataFormatAutoConfiguration() { + super(ConfigurationPhase.REGISTER_BEAN); + } + + @ConditionalOnBean(CamelContext.class) + public static class OnCamelContext { + } + + @ConditionalOnBean(CamelAutoConfiguration.class) + public static class OnCamelAutoConfiguration { + } + + @ConditionalOnBean(CamelAutoConfiguration.class) + public static class Condition extends GroupCondition { + public Condition() { + super("camel.dataformat", "camel.dataformat.bindy-csv"); + } + } @Bean(name = "bindy-csv-dataformat-factory") @ConditionalOnClass(CamelContext.class) @ConditionalOnMissingBean(BindyCsvDataFormat.class) - public DataFormatFactory configureBindyCsvDataFormatFactory( - final CamelContext camelContext, - final BindyCsvDataFormatConfiguration configuration) { + public DataFormatFactory configureBindyCsvDataFormatFactory() + throws Exception { return new DataFormatFactory() { public DataFormat newInstance() { BindyCsvDataFormat dataformat = new BindyCsvDataFormat(); @@ -71,7 +104,7 @@ public class BindyCsvDataFormatAutoConfiguration { } try { Map<String, Object> parameters = new HashMap<>(); - IntrospectionSupport.getProperties(configuration, + IntrospectionSupport.getProperties(dataformatConfiguration, parameters, null, false); IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), dataformat, @@ -79,34 +112,19 @@ public class BindyCsvDataFormatAutoConfiguration { } catch (Exception e) { throw new RuntimeCamelException(e); } + boolean useConfigurers = globalConfiguration.getConfigurer() + .isEnabled() + && dataformatConfiguration.getConfigurer().isEnabled(); + if (useConfigurers && ObjectHelper.isNotEmpty(customizers)) { + for (DataFormatCustomizer<BindyCsvDataFormat> configurer : customizers) { + LOGGER.debug( + "Configure dataformat {}, with configurer {}", + dataformat, configurer); + configurer.customize(dataformat); + } + } return dataformat; } }; } - - @Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo") - public static class Condition extends SpringBootCondition { - @Override - public ConditionOutcome getMatchOutcome( - ConditionContext conditionContext, - AnnotatedTypeMetadata annotatedTypeMetadata) { - boolean groupEnabled = isEnabled(conditionContext, - "camel.dataformat.", true); - ConditionMessage.Builder message = ConditionMessage - .forCondition("camel.dataformat.bindy-csv"); - if (isEnabled(conditionContext, "camel.dataformat.bindy-csv.", - groupEnabled)) { - return ConditionOutcome.match(message.because("enabled")); - } - return ConditionOutcome.noMatch(message.because("not enabled")); - } - - private boolean isEnabled( - org.springframework.context.annotation.ConditionContext context, - java.lang.String prefix, boolean defaultValue) { - RelaxedPropertyResolver resolver = new RelaxedPropertyResolver( - context.getEnvironment(), prefix); - return resolver.getProperty("enabled", Boolean.class, defaultValue); - } - } } \ No newline at end of file