You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/06/17 12:26:04 UTC
[camel] branch master updated: CAMEL-13652: Allow to plug a custom
DataFormatReifier
This is an automated email from the ASF dual-hosted git repository.
lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new bb15770 CAMEL-13652: Allow to plug a custom DataFormatReifier
bb15770 is described below
commit bb157702404e8066c10efb5e0e4e41b50a5ddf65
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Mon Jun 17 13:16:58 2019 +0200
CAMEL-13652: Allow to plug a custom DataFormatReifier
---
.../reifier/dataformat/DataFormatReifier.java | 8 +++--
.../apache/camel/refier/DataFormatReifierTest.java | 39 ++++++++++++++++++++++
2 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/core/camel-core/src/main/java/org/apache/camel/reifier/dataformat/DataFormatReifier.java b/core/camel-core/src/main/java/org/apache/camel/reifier/dataformat/DataFormatReifier.java
index b387e0e..4389ada 100644
--- a/core/camel-core/src/main/java/org/apache/camel/reifier/dataformat/DataFormatReifier.java
+++ b/core/camel-core/src/main/java/org/apache/camel/reifier/dataformat/DataFormatReifier.java
@@ -74,9 +74,9 @@ import static org.apache.camel.support.EndpointHelper.isReferenceParameter;
public abstract class DataFormatReifier<T extends DataFormatDefinition> {
- private static final Map<Class<?>, Function<DataFormatDefinition, DataFormatReifier<? extends DataFormatDefinition>>> DATAFORMATS;
+ private static final Map<Class<? extends DataFormatDefinition>, Function<DataFormatDefinition, DataFormatReifier<? extends DataFormatDefinition>>> DATAFORMATS;
static {
- Map<Class<?>, Function<DataFormatDefinition, DataFormatReifier<? extends DataFormatDefinition>>> map = new HashMap<>();
+ Map<Class<? extends DataFormatDefinition>, Function<DataFormatDefinition, DataFormatReifier<? extends DataFormatDefinition>>> map = new HashMap<>();
map.put(ASN1DataFormat.class, ASN1DataFormatReifier::new);
map.put(AvroDataFormat.class, AvroDataFormatReifier::new);
map.put(BarcodeDataFormat.class, BarcodeDataFormatReifier::new);
@@ -128,6 +128,10 @@ public abstract class DataFormatReifier<T extends DataFormatDefinition> {
this.definition = definition;
}
+ public static void registerReifier(Class<? extends DataFormatDefinition> dataFormatClass, Function<DataFormatDefinition, DataFormatReifier<? extends DataFormatDefinition>> creator) {
+ DATAFORMATS.put(dataFormatClass, creator);
+ }
+
/**
* Factory method to create the data format
*
diff --git a/core/camel-core/src/test/java/org/apache/camel/refier/DataFormatReifierTest.java b/core/camel-core/src/test/java/org/apache/camel/refier/DataFormatReifierTest.java
new file mode 100644
index 0000000..820e905
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/refier/DataFormatReifierTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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.refier;
+
+import org.apache.camel.model.dataformat.CustomDataFormat;
+import org.apache.camel.reifier.dataformat.CustomDataFormatReifier;
+import org.apache.camel.reifier.dataformat.DataFormatReifier;
+import org.junit.Test;
+
+public class DataFormatReifierTest {
+
+ @Test(expected = IllegalStateException.class)
+ public void shouldNotHandleCustomDataFormat() {
+ DataFormatReifier.reifier(new MyDataFormat());
+ }
+
+ @Test
+ public void shouldHandleCustomDataFormat() {
+ DataFormatReifier.registerReifier(MyDataFormat.class, CustomDataFormatReifier::new);
+ DataFormatReifier.reifier(new MyDataFormat());
+ }
+
+ public static class MyDataFormat extends CustomDataFormat {
+ }
+}