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 2015/07/09 18:00:15 UTC
[2/2] camel git commit: CAMEL-7463: Routes should support prop:
property placeholder for any attributes for expression/predicates/dataformats
as well.
CAMEL-7463: Routes should support prop: property placeholder for any attributes for expression/predicates/dataformats as well.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9f319029
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9f319029
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9f319029
Branch: refs/heads/master
Commit: 9f319029ecc031cf8bf1756ab8a0e9e4e52c2902
Parents: 678c294
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jul 9 16:19:25 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jul 9 18:06:37 2015 +0200
----------------------------------------------------------------------
.../camel/model/DataFormatDefinition.java | 18 ++++++++-
.../camel/model/OtherAttributesAware.java | 40 ++++++++++++++++++++
.../apache/camel/model/ProcessorDefinition.java | 4 +-
.../camel/model/ProcessorDefinitionHelper.java | 16 ++++----
.../model/language/ExpressionDefinition.java | 19 +++++++++-
5 files changed, 85 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/9f319029/camel-core/src/main/java/org/apache/camel/model/DataFormatDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/DataFormatDefinition.java b/camel-core/src/main/java/org/apache/camel/model/DataFormatDefinition.java
index 75fe121..38f3d93 100644
--- a/camel-core/src/main/java/org/apache/camel/model/DataFormatDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/DataFormatDefinition.java
@@ -16,10 +16,13 @@
*/
package org.apache.camel.model;
+import java.util.Map;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAnyAttribute;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;
+import javax.xml.namespace.QName;
import org.apache.camel.CamelContext;
import org.apache.camel.spi.DataFormat;
@@ -36,11 +39,14 @@ import static org.apache.camel.util.EndpointHelper.isReferenceParameter;
@Metadata(label = "dataformat,transformation")
@XmlType(name = "dataFormat")
@XmlAccessorType(XmlAccessType.FIELD)
-public class DataFormatDefinition extends IdentifiedType {
+public class DataFormatDefinition extends IdentifiedType implements OtherAttributesAware {
@XmlTransient
private DataFormat dataFormat;
@XmlTransient
private String dataFormatName;
+ // use xs:any to support optional property placeholders
+ @XmlAnyAttribute
+ private Map<QName, Object> otherAttributes;
public DataFormatDefinition() {
}
@@ -66,7 +72,7 @@ public class DataFormatDefinition extends IdentifiedType {
ObjectHelper.notNull(ref, "ref or type");
// try to let resolver see if it can resolve it, its not always possible
- type = ((ModelCamelContext) routeContext.getCamelContext()).resolveDataFormatDefinition(ref);
+ type = routeContext.getCamelContext().resolveDataFormatDefinition(ref);
if (type != null) {
return type.getDataFormat(routeContext);
@@ -177,6 +183,14 @@ public class DataFormatDefinition extends IdentifiedType {
this.dataFormat = dataFormat;
}
+ public Map<QName, Object> getOtherAttributes() {
+ return otherAttributes;
+ }
+
+ public void setOtherAttributes(Map<QName, Object> otherAttributes) {
+ this.otherAttributes = otherAttributes;
+ }
+
public String getShortName() {
String name = getClass().getSimpleName();
if (name.endsWith("DataFormat")) {
http://git-wip-us.apache.org/repos/asf/camel/blob/9f319029/camel-core/src/main/java/org/apache/camel/model/OtherAttributesAware.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/OtherAttributesAware.java b/camel-core/src/main/java/org/apache/camel/model/OtherAttributesAware.java
new file mode 100644
index 0000000..0251287
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/OtherAttributesAware.java
@@ -0,0 +1,40 @@
+/**
+ * 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
+ *
+ * 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;
+
+import java.util.Map;
+import javax.xml.namespace.QName;
+
+/**
+ * Models can support being configured with any other attributes to shadow existing options to be used for property placeholders.
+ * <p/>
+ * For example to override attributes that are configured as a boolean or integer type. Then the any attributes can be used to
+ * override those existing attributes and supporting property placeholders.
+ */
+public interface OtherAttributesAware {
+
+ /**
+ * Adds optional attribute to use as property placeholder
+ */
+ Map<QName, Object> getOtherAttributes();
+
+ /**
+ * Adds optional attribute to use as property placeholder
+ */
+ void setOtherAttributes(Map<QName, Object> otherAttributes);
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/9f319029/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index 214057e..b7789f7 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -78,7 +78,7 @@ import org.slf4j.LoggerFactory;
* @version
*/
@XmlAccessorType(XmlAccessType.FIELD)
-public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>> extends OptionalIdentifiedDefinition<Type> implements Block {
+public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>> extends OptionalIdentifiedDefinition<Type> implements Block, OtherAttributesAware {
@XmlTransient
private static final AtomicInteger COUNTER = new AtomicInteger();
@XmlTransient
@@ -3551,10 +3551,12 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
this.inheritErrorHandler = inheritErrorHandler;
}
+ @Override
public Map<QName, Object> getOtherAttributes() {
return otherAttributes;
}
+ @Override
public void setOtherAttributes(Map<QName, Object> otherAttributes) {
this.otherAttributes = otherAttributes;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/9f319029/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
index 63d0131..9eea4a8 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
@@ -665,10 +665,10 @@ public final class ProcessorDefinitionHelper {
* Inspects the given definition and resolves any property placeholders from its properties.
* <p/>
* This implementation will check all the getter/setter pairs on this instance and for all the values
- * (which is a String type) will be property placeholder resolved.
+ * (which is a String type) will be property placeholder resolved. The definition should implement {@link OtherAttributesAware}
*
* @param camelContext the Camel context
- * @param definition the definition
+ * @param definition the definition which should implement {@link OtherAttributesAware}
* @throws Exception is thrown if property placeholders was used and there was an error resolving them
* @see org.apache.camel.CamelContext#resolvePropertyPlaceholders(String)
* @see org.apache.camel.component.properties.PropertiesComponent
@@ -680,17 +680,17 @@ public final class ProcessorDefinitionHelper {
Map<String, Object> properties = new HashMap<String, Object>();
IntrospectionSupport.getProperties(definition, properties, null);
- ProcessorDefinition<?> processorDefinition = null;
- if (definition instanceof ProcessorDefinition) {
- processorDefinition = (ProcessorDefinition<?>) definition;
+ OtherAttributesAware other = null;
+ if (definition instanceof OtherAttributesAware) {
+ other = (OtherAttributesAware) definition;
}
// include additional properties which have the Camel placeholder QName
// and when the definition parameter is this (otherAttributes belong to this)
- if (processorDefinition != null && processorDefinition.getOtherAttributes() != null) {
- for (QName key : processorDefinition.getOtherAttributes().keySet()) {
+ if (other != null && other.getOtherAttributes() != null) {
+ for (QName key : other.getOtherAttributes().keySet()) {
if (Constants.PLACEHOLDER_QNAME.equals(key.getNamespaceURI())) {
String local = key.getLocalPart();
- Object value = processorDefinition.getOtherAttributes().get(key);
+ Object value = other.getOtherAttributes().get(key);
if (value != null && value instanceof String) {
// enforce a properties component to be created if none existed
CamelContextHelper.lookupPropertiesComponent(camelContext, true);
http://git-wip-us.apache.org/repos/asf/camel/blob/9f319029/camel-core/src/main/java/org/apache/camel/model/language/ExpressionDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/language/ExpressionDefinition.java b/camel-core/src/main/java/org/apache/camel/model/language/ExpressionDefinition.java
index 86ea52e..c7917a5 100644
--- a/camel-core/src/main/java/org/apache/camel/model/language/ExpressionDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/language/ExpressionDefinition.java
@@ -17,8 +17,10 @@
package org.apache.camel.model.language;
import java.util.List;
+import java.util.Map;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAnyAttribute;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlID;
import javax.xml.bind.annotation.XmlRootElement;
@@ -27,12 +29,14 @@ import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlValue;
import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+import javax.xml.namespace.QName;
import org.apache.camel.AfterPropertiesConfigured;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Expression;
import org.apache.camel.Predicate;
+import org.apache.camel.model.OtherAttributesAware;
import org.apache.camel.spi.Language;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.Required;
@@ -49,7 +53,7 @@ import org.apache.camel.util.ObjectHelper;
@XmlRootElement
@XmlType(name = "expression") // must be named expression
@XmlAccessorType(XmlAccessType.FIELD)
-public class ExpressionDefinition implements Expression, Predicate {
+public class ExpressionDefinition implements Expression, Predicate, OtherAttributesAware {
@XmlAttribute
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@XmlID
@@ -64,6 +68,9 @@ public class ExpressionDefinition implements Expression, Predicate {
private Expression expressionValue;
@XmlTransient
private ExpressionDefinition expressionType;
+ // use xs:any to support optional property placeholders
+ @XmlAnyAttribute
+ private Map<QName, Object> otherAttributes;
public ExpressionDefinition() {
}
@@ -241,6 +248,16 @@ public class ExpressionDefinition implements Expression, Predicate {
this.trim = trim;
}
+ @Override
+ public Map<QName, Object> getOtherAttributes() {
+ return otherAttributes;
+ }
+
+ @Override
+ public void setOtherAttributes(Map<QName, Object> otherAttributes) {
+ this.otherAttributes = otherAttributes;
+ }
+
/**
* Returns some descriptive text to describe this node
*/