You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/08/13 06:25:07 UTC
[camel] 05/09: CAMEL-13850: Optimize model classes to provide
changeable properties that support property placeholders to avoid
reflection. Work in progress.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch CAMEL-13850
in repository https://gitbox.apache.org/repos/asf/camel.git
commit dd6f55404c9a92e0157bfde363dde2f93ea24ff5
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Aug 12 22:31:52 2019 +0200
CAMEL-13850: Optimize model classes to provide changeable properties that support property placeholders to avoid reflection. Work in progress.
---
.../apache/camel/model/DataFormatDefinition.java | 2 +-
.../camel/model/ProcessorDefinitionHelper.java | 6 ++-
.../java/org/apache/camel/model/ToDefinition.java | 51 +---------------------
.../camel/model/language/ExpressionDefinition.java | 3 +-
4 files changed, 8 insertions(+), 54 deletions(-)
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 c7f3452..f36fb68 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 {
+public class DataFormatDefinition extends IdentifiedType implements OtherAttributesAware, DefinitionPropertyPlaceholderConfigurable {
@XmlTransient
private DataFormat dataFormat;
@XmlTransient
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 b57f51a..169dc3d 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
@@ -626,7 +626,7 @@ public final class ProcessorDefinitionHelper {
}
private static void addRestoreAction(Map<String, Consumer<String>> writeProperties, final Map<String, String> properties) {
- if (properties.isEmpty()) {
+ if (properties == null || properties.isEmpty()) {
return;
}
@@ -685,7 +685,7 @@ public final class ProcessorDefinitionHelper {
Map<String, Supplier<String>> readProperties = ppa.getReadPropertyPlaceholderOptions(camelContext);
Map<String, Consumer<String>> writeProperties = ppa.getWritePropertyPlaceholderOptions(camelContext);
- if (!readProperties.isEmpty()) {
+ if (readProperties != null && !readProperties.isEmpty()) {
if (LOG.isTraceEnabled()) {
LOG.trace("There are {} properties on: {}", readProperties.size(), definition);
}
@@ -718,6 +718,8 @@ public final class ProcessorDefinitionHelper {
*/
public static void resolveKnownConstantFields(CamelContext camelContext, Object definition) throws Exception {
LOG.trace("Resolving known fields for: {}", definition);
+
+ // TODO: implement this
/*
// find all String getter/setter
Map<String, Object> properties = new HashMap<>();
diff --git a/core/camel-core/src/main/java/org/apache/camel/model/ToDefinition.java b/core/camel-core/src/main/java/org/apache/camel/model/ToDefinition.java
index 10b61d8..4204727 100644
--- a/core/camel-core/src/main/java/org/apache/camel/model/ToDefinition.java
+++ b/core/camel-core/src/main/java/org/apache/camel/model/ToDefinition.java
@@ -16,21 +16,15 @@
*/
package org.apache.camel.model;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.function.Consumer;
-import java.util.function.Supplier;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
-import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.ExchangePattern;
import org.apache.camel.builder.EndpointProducerBuilder;
import org.apache.camel.spi.Metadata;
-import org.apache.camel.spi.PropertiesComponent;
/**
* Sends the message to a static endpoint
@@ -38,18 +32,11 @@ import org.apache.camel.spi.PropertiesComponent;
@Metadata(label = "eip,endpoint,routing")
@XmlRootElement(name = "to")
@XmlAccessorType(XmlAccessType.FIELD)
-public class ToDefinition extends SendDefinition<ToDefinition> implements DefinitionPropertyPlaceholderConfigurable {
+public class ToDefinition extends SendDefinition<ToDefinition> {
@XmlAttribute
private ExchangePattern pattern;
- private final Map<String, Supplier<String>> readPlaceholders = new HashMap<>();
- private final Map<String, Consumer<String>> writePlaceholders = new HashMap<>();
-
public ToDefinition() {
- readPlaceholders.put("id", this::getId);
- readPlaceholders.put("uri", this::getUri);
- writePlaceholders.put("id", this::setId);
- writePlaceholders.put("uri", this::setUri);
}
public ToDefinition(String uri) {
@@ -104,41 +91,5 @@ public class ToDefinition extends SendDefinition<ToDefinition> implements Defini
this.pattern = pattern;
}
- @Override
- public Map<String, Supplier<String>> getReadPropertyPlaceholderOptions(final CamelContext camelContext) {
- if (getOtherAttributes() != null && !getOtherAttributes().isEmpty()) {
- final Map<String, Supplier<String>> answer = new HashMap<>(readPlaceholders);
- getOtherAttributes().forEach((k, v) -> {
- if (Constants.PLACEHOLDER_QNAME.equals(k.getNamespaceURI())) {
- if (v instanceof String) {
- // enforce a properties component to be created if none existed
- camelContext.getPropertiesComponent(true);
-
- // value must be enclosed with placeholder tokens
- String s = (String) v;
- String prefixToken = PropertiesComponent.PREFIX_TOKEN;
- String suffixToken = PropertiesComponent.SUFFIX_TOKEN;
-
- if (!s.startsWith(prefixToken)) {
- s = prefixToken + s;
- }
- if (!s.endsWith(suffixToken)) {
- s = s + suffixToken;
- }
- final String value = s;
- answer.put(k.getLocalPart(), () -> value);
- }
- }
- });
- return answer;
- } else {
- return readPlaceholders;
- }
- }
-
- @Override
- public Map<String, Consumer<String>> getWritePropertyPlaceholderOptions(CamelContext camelContext) {
- return writePlaceholders;
- }
}
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 66fda0a..4e8fb41 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,6 +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.OtherAttributesAware;
import org.apache.camel.spi.Language;
import org.apache.camel.spi.Metadata;
@@ -55,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 {
+public class ExpressionDefinition implements Expression, Predicate, OtherAttributesAware, ExpressionFactory, DefinitionPropertyPlaceholderConfigurable {
@XmlAttribute
@XmlID
private String id;