This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit e59cf7a415deccc2031343c9fca04fae34a226c9 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Tue Aug 13 08:54:11 2019 +0200 CAMEL-13850: Optimize model classes to provide changeable properties that support property placeholders to avoid reflection. Work in progress. --- .../camel/spi/PropertyPlaceholderConfigurer.java} | 28 +++++++--------------- .../apache/camel/model/DataFormatDefinition.java | 2 +- ...> DefinitionPropertyPlaceholderConfigurer.java} | 9 +++---- .../camel/model/OptionalIdentifiedDefinition.java | 2 +- .../camel/model/ProcessorDefinitionHelper.java | 7 +++--- .../camel/model/language/ExpressionDefinition.java | 4 ++-- .../apt/CoreEipAnnotationProcessorHelper.java | 16 ++++++------- 7 files changed, 29 insertions(+), 39 deletions(-) diff --git a/core/camel-core/src/main/java/org/apache/camel/model/DefinitionPropertyPlaceholderConfigurable.java b/core/camel-api/src/main/java/org/apache/camel/spi/PropertyPlaceholderConfigurer.java similarity index 51% copy from core/camel-core/src/main/java/org/apache/camel/model/DefinitionPropertyPlaceholderConfigurable.java copy to core/camel-api/src/main/java/org/apache/camel/spi/PropertyPlaceholderConfigurer.java index 1209972..34b7693 100644 --- a/core/camel-core/src/main/java/org/apache/camel/model/DefinitionPropertyPlaceholderConfigurable.java +++ b/core/camel-api/src/main/java/org/apache/camel/spi/PropertyPlaceholderConfigurer.java @@ -1,51 +1,41 @@ -/* +/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.model; +package org.apache.camel.spi; import java.util.Map; import java.util.function.Consumer; import java.util.function.Supplier; import org.apache.camel.CamelContext; -import org.apache.camel.model.placeholder.DefinitionPropertiesPlaceholderProviderHelper; -/** - * To be used for configuring property placeholder options on the EIP models. - */ -public interface DefinitionPropertyPlaceholderConfigurable { +public interface PropertyPlaceholderConfigurer { /** - * Gets the options on the model definition which supports property placeholders and can be resolved. + * Gets the options which supports property placeholders and can be resolved. * This will be all the string based options. * * @return key/values of options */ - default Map<String, Supplier<String>> getReadPropertyPlaceholderOptions(CamelContext camelContext) { - DefinitionPropertyPlaceholderConfigurable aware = DefinitionPropertiesPlaceholderProviderHelper.provider(this).orElse(null); - return aware != null ? aware.getReadPropertyPlaceholderOptions(camelContext) : null; - } + Map<String, Supplier<String>> getReadPropertyPlaceholderOptions(CamelContext camelContext); /** * To update an existing property using the function with the key/value and returning the changed value * This will be all the string based options. */ - default Map<String, Consumer<String>> getWritePropertyPlaceholderOptions(CamelContext camelContext) { - DefinitionPropertyPlaceholderConfigurable aware = DefinitionPropertiesPlaceholderProviderHelper.provider(this).orElse(null); - return aware != null ? aware.getWritePropertyPlaceholderOptions(camelContext) : null; - } + Map<String, Consumer<String>> getWritePropertyPlaceholderOptions(CamelContext camelContext); } diff --git a/core/camel-core/src/main/java/org/apache/camel/model/DataFormatDefinition.java b/core/camel-core/src/main/java/org/apache/camel/model/DataFormatDefinition.java index f36fb68..6e14717 100644 --- a/core/camel-core/src/main/java/org/apache/camel/model/DataFormatDefinition.java +++ b/core/camel-core/src/main/java/org/apache/camel/model/DataFormatDefinition.java @@ -35,7 +35,7 @@ import org.apache.camel.spi.Metadata; @Metadata(label = "dataformat,transformation") @XmlType(name = "dataFormat") @XmlAccessorType(XmlAccessType.FIELD) -public class DataFormatDefinition extends IdentifiedType implements OtherAttributesAware, DefinitionPropertyPlaceholderConfigurable { +public class DataFormatDefinition extends IdentifiedType implements OtherAttributesAware, DefinitionPropertyPlaceholderConfigurer { @XmlTransient private DataFormat dataFormat; @XmlTransient diff --git a/core/camel-core/src/main/java/org/apache/camel/model/DefinitionPropertyPlaceholderConfigurable.java b/core/camel-core/src/main/java/org/apache/camel/model/DefinitionPropertyPlaceholderConfigurer.java similarity index 78% rename from core/camel-core/src/main/java/org/apache/camel/model/DefinitionPropertyPlaceholderConfigurable.java rename to core/camel-core/src/main/java/org/apache/camel/model/DefinitionPropertyPlaceholderConfigurer.java index 1209972..65ec401 100644 --- a/core/camel-core/src/main/java/org/apache/camel/model/DefinitionPropertyPlaceholderConfigurable.java +++ b/core/camel-core/src/main/java/org/apache/camel/model/DefinitionPropertyPlaceholderConfigurer.java @@ -22,11 +22,12 @@ import java.util.function.Supplier; import org.apache.camel.CamelContext; import org.apache.camel.model.placeholder.DefinitionPropertiesPlaceholderProviderHelper; +import org.apache.camel.spi.PropertyPlaceholderConfigurer; /** * To be used for configuring property placeholder options on the EIP models. */ -public interface DefinitionPropertyPlaceholderConfigurable { +public interface DefinitionPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer { /** * Gets the options on the model definition which supports property placeholders and can be resolved. @@ -35,8 +36,8 @@ public interface DefinitionPropertyPlaceholderConfigurable { * @return key/values of options */ default Map<String, Supplier<String>> getReadPropertyPlaceholderOptions(CamelContext camelContext) { - DefinitionPropertyPlaceholderConfigurable aware = DefinitionPropertiesPlaceholderProviderHelper.provider(this).orElse(null); - return aware != null ? aware.getReadPropertyPlaceholderOptions(camelContext) : null; + PropertyPlaceholderConfigurer configurer = DefinitionPropertiesPlaceholderProviderHelper.provider(this).orElse(null); + return configurer != null ? configurer.getReadPropertyPlaceholderOptions(camelContext) : null; } /** @@ -44,7 +45,7 @@ public interface DefinitionPropertyPlaceholderConfigurable { * This will be all the string based options. */ default Map<String, Consumer<String>> getWritePropertyPlaceholderOptions(CamelContext camelContext) { - DefinitionPropertyPlaceholderConfigurable aware = DefinitionPropertiesPlaceholderProviderHelper.provider(this).orElse(null); + PropertyPlaceholderConfigurer aware = DefinitionPropertiesPlaceholderProviderHelper.provider(this).orElse(null); return aware != null ? aware.getWritePropertyPlaceholderOptions(camelContext) : null; } diff --git a/core/camel-core/src/main/java/org/apache/camel/model/OptionalIdentifiedDefinition.java b/core/camel-core/src/main/java/org/apache/camel/model/OptionalIdentifiedDefinition.java index 9ca6bff..1fb350f 100644 --- a/core/camel-core/src/main/java/org/apache/camel/model/OptionalIdentifiedDefinition.java +++ b/core/camel-core/src/main/java/org/apache/camel/model/OptionalIdentifiedDefinition.java @@ -31,7 +31,7 @@ import org.apache.camel.spi.NodeIdFactory; @XmlType(name = "optionalIdentifiedDefinition") @XmlAccessorType(XmlAccessType.PROPERTY) // must use XmlAccessType.PROPERTY which is required by camel-spring / camel-blueprint for their namespace parsers -public abstract class OptionalIdentifiedDefinition<T extends OptionalIdentifiedDefinition<T>> implements NamedNode, DefinitionPropertyPlaceholderConfigurable { +public abstract class OptionalIdentifiedDefinition<T extends OptionalIdentifiedDefinition<T>> implements NamedNode, DefinitionPropertyPlaceholderConfigurer { private String id; private Boolean customId; diff --git a/core/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java b/core/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java index 69e06b3..947ee37 100644 --- a/core/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java +++ b/core/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java @@ -28,7 +28,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.ScheduledExecutorService; import java.util.function.Consumer; import java.util.function.Supplier; - import javax.xml.namespace.QName; import org.apache.camel.CamelContext; @@ -37,8 +36,8 @@ import org.apache.camel.NamedNode; import org.apache.camel.RuntimeCamelException; import org.apache.camel.spi.ExecutorServiceManager; import org.apache.camel.spi.PropertiesComponent; +import org.apache.camel.spi.PropertyPlaceholderConfigurer; import org.apache.camel.spi.RouteContext; -import org.apache.camel.support.IntrospectionSupport; import org.apache.camel.support.PropertyBindingSupport; import org.apache.camel.util.ObjectHelper; import org.apache.camel.util.StringHelper; @@ -686,11 +685,11 @@ public final class ProcessorDefinitionHelper { LOG.trace("Resolving property placeholders for: {}", definition); // only do this for models that supports property placeholders - if (!(definition instanceof DefinitionPropertyPlaceholderConfigurable)) { + if (!(definition instanceof PropertyPlaceholderConfigurer)) { return; } - DefinitionPropertyPlaceholderConfigurable ppa = (DefinitionPropertyPlaceholderConfigurable) definition; + PropertyPlaceholderConfigurer ppa = (PropertyPlaceholderConfigurer) definition; // find all getter/setter which we can use for property placeholders Map<String, String> changedProperties = new HashMap<>(); diff --git a/core/camel-core/src/main/java/org/apache/camel/model/language/ExpressionDefinition.java b/core/camel-core/src/main/java/org/apache/camel/model/language/ExpressionDefinition.java index 4e8fb41..4f59766f 100644 --- a/core/camel-core/src/main/java/org/apache/camel/model/language/ExpressionDefinition.java +++ b/core/camel-core/src/main/java/org/apache/camel/model/language/ExpressionDefinition.java @@ -38,7 +38,7 @@ import org.apache.camel.Expression; import org.apache.camel.ExpressionFactory; import org.apache.camel.NoSuchLanguageException; import org.apache.camel.Predicate; -import org.apache.camel.model.DefinitionPropertyPlaceholderConfigurable; +import org.apache.camel.model.DefinitionPropertyPlaceholderConfigurer; import org.apache.camel.model.OtherAttributesAware; import org.apache.camel.spi.Language; import org.apache.camel.spi.Metadata; @@ -56,7 +56,7 @@ import org.apache.camel.util.ObjectHelper; @XmlRootElement @XmlType(name = "expression") // must be named expression @XmlAccessorType(XmlAccessType.FIELD) -public class ExpressionDefinition implements Expression, Predicate, OtherAttributesAware, ExpressionFactory, DefinitionPropertyPlaceholderConfigurable { +public class ExpressionDefinition implements Expression, Predicate, OtherAttributesAware, ExpressionFactory, DefinitionPropertyPlaceholderConfigurer { @XmlAttribute @XmlID private String id; diff --git a/tooling/apt/src/main/java/org/apache/camel/tools/apt/CoreEipAnnotationProcessorHelper.java b/tooling/apt/src/main/java/org/apache/camel/tools/apt/CoreEipAnnotationProcessorHelper.java index 6b49614..93f57a0 100644 --- a/tooling/apt/src/main/java/org/apache/camel/tools/apt/CoreEipAnnotationProcessorHelper.java +++ b/tooling/apt/src/main/java/org/apache/camel/tools/apt/CoreEipAnnotationProcessorHelper.java @@ -176,7 +176,7 @@ public class CoreEipAnnotationProcessorHelper { return; } - TypeElement parent = findTypeElement(processingEnv, roundEnv, "org.apache.camel.model.DefinitionPropertyPlaceholderConfigurable"); + TypeElement parent = findTypeElement(processingEnv, roundEnv, "org.apache.camel.spi.PropertyPlaceholderConfigurer"); String def = classElement.getSimpleName().toString(); String fqnDef = classElement.getQualifiedName().toString(); String cn = def + "PropertyPlaceholderProvider"; @@ -220,9 +220,9 @@ public class CoreEipAnnotationProcessorHelper { w.write("\n"); w.write("import org.apache.camel.CamelContext;\n"); w.write("import " + fqnDef + ";\n"); - w.write("import org.apache.camel.model.DefinitionPropertyPlaceholderConfigurable;\n"); + w.write("import org.apache.camel.spi.PropertyPlaceholderConfigurer;\n"); w.write("\n"); - w.write("public class " + cn + " implements DefinitionPropertyPlaceholderConfigurable {\n"); + w.write("public class " + cn + " implements PropertyPlaceholderConfigurer {\n"); w.write("\n"); w.write(" private final Map<String, Supplier<String>> readPlaceholders = new HashMap<>();\n"); w.write(" private final Map<String, Consumer<String>> writePlaceholders = new HashMap<>();\n"); @@ -330,16 +330,16 @@ public class CoreEipAnnotationProcessorHelper { w.write("import java.util.function.Function;\n"); w.write("import java.util.function.Supplier;\n"); w.write("\n"); - w.write("import org.apache.camel.model.DefinitionPropertyPlaceholderConfigurable;\n"); + w.write("import org.apache.camel.spi.PropertyPlaceholderConfigurer;\n"); for (String def : propertyPlaceholderDefinitions) { w.write("import " + def + ";\n"); } w.write("\n"); w.write("public class DefinitionPropertiesPlaceholderProviderHelper {\n"); w.write("\n"); - w.write(" private static final Map<Class, Function<Object, DefinitionPropertyPlaceholderConfigurable>> MAP;\n"); + w.write(" private static final Map<Class, Function<Object, PropertyPlaceholderConfigurer>> MAP;\n"); w.write(" static {\n"); - w.write(" Map<Class, Function<Object, DefinitionPropertyPlaceholderConfigurable>> map = new HashMap<>(" + propertyPlaceholderDefinitions.size() + ");\n"); + w.write(" Map<Class, Function<Object, PropertyPlaceholderConfigurer>> map = new HashMap<>(" + propertyPlaceholderDefinitions.size() + ");\n"); for (String def : propertyPlaceholderDefinitions) { String cn = def.substring(def.lastIndexOf('.') + 1); w.write(" map.put(" + cn + ".class, " + cn + "PropertyPlaceholderProvider::new);\n"); @@ -347,8 +347,8 @@ public class CoreEipAnnotationProcessorHelper { w.write(" MAP = map;\n"); w.write(" }\n"); w.write("\n"); - w.write(" public static Optional<DefinitionPropertyPlaceholderConfigurable> provider(Object definition) {\n"); - w.write(" Function<Object, DefinitionPropertyPlaceholderConfigurable> func = MAP.get(definition.getClass());\n"); + w.write(" public static Optional<PropertyPlaceholderConfigurer> provider(Object definition) {\n"); + w.write(" Function<Object, PropertyPlaceholderConfigurer> func = MAP.get(definition.getClass());\n"); w.write(" if (func != null) {\n"); w.write(" return Optional.of(func.apply(definition));\n"); w.write(" }\n");