You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by zr...@apache.org on 2019/08/22 19:25:52 UTC
[camel] 02/04: CAMEL-13893: reintroduce configuration options ...
This is an automated email from the ASF dual-hosted git repository.
zregvart pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit fa0a21a6610a88025f16ac9cc1e3d6ac5111daf8
Author: Zoran Regvart <zr...@apache.org>
AuthorDate: Thu Aug 22 20:01:54 2019 +0200
CAMEL-13893: reintroduce configuration options ...
...for Any23 XML configuration
This reintroduces configuration options for Any23 XML configuration by
adding `ConfigurationOptions` class that's mapped within Camel's XML
namespace.
Also adds a unit test to the REST DSL XML generator to check if the
generated XML DSL root element is declared with default namespace.
Also excludes *Helper classes from being declared in Spring and OSGi
Blueprint schemas.
---
.../any23/spring/SpringAny23DataFormatTest.xml | 3 ++
components/camel-blueprint/pom.xml | 7 +++
components/camel-spring/pom.xml | 7 +++
.../apache/camel/model/ConfigurationOption.java | 53 ++++++++++++++++++++++
.../apache/camel/model/ConfigurationOptions.java | 51 +++++++++++++++++++++
.../camel/model/dataformat/Any23DataFormat.java | 18 ++++----
.../reifier/dataformat/Any23DataFormatReifier.java | 4 +-
7 files changed, 132 insertions(+), 11 deletions(-)
diff --git a/components/camel-any23/src/test/resources/org/apache/camel/dataformat/any23/spring/SpringAny23DataFormatTest.xml b/components/camel-any23/src/test/resources/org/apache/camel/dataformat/any23/spring/SpringAny23DataFormatTest.xml
index 213f5ff..2820541 100644
--- a/components/camel-any23/src/test/resources/org/apache/camel/dataformat/any23/spring/SpringAny23DataFormatTest.xml
+++ b/components/camel-any23/src/test/resources/org/apache/camel/dataformat/any23/spring/SpringAny23DataFormatTest.xml
@@ -29,6 +29,9 @@
<dataFormats>
<any23 id="any23" baseURI ="http://mock.foo/bar" outputFormat="TURTLE" >
+ <configuration>
+ <option name="any23.extraction.metadata.nesting" value="off" />
+ </configuration>
<extractors>html-head-title</extractors>
</any23>
</dataFormats>
diff --git a/components/camel-blueprint/pom.xml b/components/camel-blueprint/pom.xml
index 8fa489b..567e9ed 100644
--- a/components/camel-blueprint/pom.xml
+++ b/components/camel-blueprint/pom.xml
@@ -266,6 +266,13 @@
<source>${project.build.directory}/schema-src</source>
</sources>
<createJavaDocAnnotations>false</createJavaDocAnnotations>
+ <schemaSourceExcludeFilters>
+ <filter implementation="org.codehaus.mojo.jaxb2.shared.filters.pattern.PatternFileFilter">
+ <patterns>
+ <pattern>Helper.java</pattern>
+ </patterns>
+ </filter>
+ </schemaSourceExcludeFilters>
</configuration>
</plugin>
</plugins>
diff --git a/components/camel-spring/pom.xml b/components/camel-spring/pom.xml
index ee2f176..2849484 100644
--- a/components/camel-spring/pom.xml
+++ b/components/camel-spring/pom.xml
@@ -297,6 +297,13 @@
<source>${project.build.directory}/schema-src</source>
</sources>
<createJavaDocAnnotations>false</createJavaDocAnnotations>
+ <schemaSourceExcludeFilters>
+ <filter implementation="org.codehaus.mojo.jaxb2.shared.filters.pattern.PatternFileFilter">
+ <patterns>
+ <pattern>Helper.java</pattern>
+ </patterns>
+ </filter>
+ </schemaSourceExcludeFilters>
</configuration>
</plugin>
<plugin>
diff --git a/core/camel-core/src/main/java/org/apache/camel/model/ConfigurationOption.java b/core/camel-core/src/main/java/org/apache/camel/model/ConfigurationOption.java
new file mode 100644
index 0000000..f34897d
--- /dev/null
+++ b/core/camel-core/src/main/java/org/apache/camel/model/ConfigurationOption.java
@@ -0,0 +1,53 @@
+/*
+ * 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 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.spi.Metadata;
+
+@Metadata(label = "configuration")
+@XmlRootElement(name = "option")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class ConfigurationOption {
+
+ @XmlAttribute(required = true)
+ public String name;
+
+ @XmlAttribute(required = true)
+ public String value;
+
+ public ConfigurationOption() {
+ }
+
+ public ConfigurationOption(final String name, final String value) {
+ this.name = name;
+ this.value = value;
+ }
+
+ String name() {
+ return name;
+ }
+
+ String value() {
+ return value;
+ }
+
+}
diff --git a/core/camel-core/src/main/java/org/apache/camel/model/ConfigurationOptions.java b/core/camel-core/src/main/java/org/apache/camel/model/ConfigurationOptions.java
new file mode 100644
index 0000000..129e747
--- /dev/null
+++ b/core/camel-core/src/main/java/org/apache/camel/model/ConfigurationOptions.java
@@ -0,0 +1,51 @@
+/*
+ * 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.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.spi.Metadata;
+
+@Metadata(label = "configuration")
+@XmlRootElement(name = "configuration")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class ConfigurationOptions {
+ @XmlElement(name = "option")
+ public List<ConfigurationOption> globalOptions = new ArrayList<>();
+
+ public Map<String, String> asMap() {
+ return globalOptions.stream()
+ .collect(Collectors.toMap(ConfigurationOption::name, ConfigurationOption::value));
+ }
+
+ public static ConfigurationOptions from(Map<String, String> map) {
+ final ConfigurationOptions ret = new ConfigurationOptions();
+
+ map.forEach((k, v) -> ret.globalOptions.add(new ConfigurationOption(k, v)));
+
+ return ret;
+ }
+
+}
diff --git a/core/camel-core/src/main/java/org/apache/camel/model/dataformat/Any23DataFormat.java b/core/camel-core/src/main/java/org/apache/camel/model/dataformat/Any23DataFormat.java
index ec795dd..f0f8110 100644
--- a/core/camel-core/src/main/java/org/apache/camel/model/dataformat/Any23DataFormat.java
+++ b/core/camel-core/src/main/java/org/apache/camel/model/dataformat/Any23DataFormat.java
@@ -18,13 +18,14 @@ package org.apache.camel.model.dataformat;
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.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlTransient;
+import org.apache.camel.model.ConfigurationOptions;
import org.apache.camel.model.DataFormatDefinition;
import org.apache.camel.spi.Metadata;
@@ -39,8 +40,7 @@ public class Any23DataFormat extends DataFormatDefinition {
@XmlAttribute
@Metadata(defaultValue = "RDF4JMODEL")
private Any23Type outputFormat;
- @XmlTransient
- private Map<String, String> configurations;
+ private ConfigurationOptions configuration = new ConfigurationOptions();
@XmlElement
private List<String> extractors;
@XmlAttribute
@@ -63,13 +63,13 @@ public class Any23DataFormat extends DataFormatDefinition {
public Any23DataFormat(String baseuri, Any23Type outputFormat, Map<String, String> configurations) {
this(baseuri, outputFormat);
this.outputFormat = outputFormat;
- this.configurations = configurations;
+ this.configuration = ConfigurationOptions.from(configurations);
}
public Any23DataFormat(String baseuri, Any23Type outputFormat, Map<String, String> configurations, List<String> extractors) {
this(baseuri, outputFormat, configurations);
this.outputFormat = outputFormat;
- this.configurations = configurations;
+ this.configuration = ConfigurationOptions.from(configurations);
this.extractors = extractors;
}
@@ -85,8 +85,8 @@ public class Any23DataFormat extends DataFormatDefinition {
this.outputFormat = outputFormat;
}
- public Map<String, String> getConfigurations() {
- return configurations;
+ public Map<String, String> getConfiguration() {
+ return configuration.asMap();
}
/**
@@ -96,8 +96,8 @@ public class Any23DataFormat extends DataFormatDefinition {
* "https://github.com/apache/any23/blob/master/api/src/main/resources/default-configuration.properties">here</a>.
* If not provided, a default configuration is used.
*/
- public void setConfigurations(Map<String, String> configurations) {
- this.configurations = configurations;
+ public void setConfiguration(Map<String, String> configurations) {
+ this.configuration = ConfigurationOptions.from(configurations);
}
public List<String> getExtractors() {
diff --git a/core/camel-core/src/main/java/org/apache/camel/reifier/dataformat/Any23DataFormatReifier.java b/core/camel-core/src/main/java/org/apache/camel/reifier/dataformat/Any23DataFormatReifier.java
index 3979217..12885f0 100644
--- a/core/camel-core/src/main/java/org/apache/camel/reifier/dataformat/Any23DataFormatReifier.java
+++ b/core/camel-core/src/main/java/org/apache/camel/reifier/dataformat/Any23DataFormatReifier.java
@@ -37,8 +37,8 @@ public class Any23DataFormatReifier extends DataFormatReifier<Any23DataFormat> {
if (definition.getOutputFormat() != null) {
setProperty(camelContext, dataFormat, "outputFormat", definition.getOutputFormat());
}
- if (definition.getConfigurations() != null) {
- setProperty(camelContext, dataFormat, "configurations", definition.getConfigurations());
+ if (definition.getConfiguration() != null) {
+ setProperty(camelContext, dataFormat, "configurations", definition.getConfiguration());
}
if (definition.getExtractors() != null) {
setProperty(camelContext, dataFormat, "extractors", definition.getExtractors());