james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [15/17] james-project git commit: JAMES-2578 Rename ArbitrarySerializable.Factory to Deserializer
Date Thu, 01 Nov 2018 04:07:50 GMT
JAMES-2578 Rename ArbitrarySerializable.Factory to Deserializer


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/cb91f992
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/cb91f992
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/cb91f992

Branch: refs/heads/master
Commit: cb91f992ee1a22607b6fcfbbf99846d4c4566f22
Parents: 1ccae90
Author: Gautier DI FOLCO <gdifolco@linagora.com>
Authored: Tue Oct 30 17:55:10 2018 +0100
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Thu Nov 1 11:03:43 2018 +0700

----------------------------------------------------------------------
 .../java/org/apache/mailet/ArbitrarySerializable.java   |  8 ++++----
 .../api/src/main/java/org/apache/mailet/Serializer.java | 12 ++++++------
 .../test/java/org/apache/mailet/AttributeValueTest.java |  4 ++--
 3 files changed, 12 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/cb91f992/mailet/api/src/main/java/org/apache/mailet/ArbitrarySerializable.java
----------------------------------------------------------------------
diff --git a/mailet/api/src/main/java/org/apache/mailet/ArbitrarySerializable.java b/mailet/api/src/main/java/org/apache/mailet/ArbitrarySerializable.java
index d4ab5ad..2462f32 100644
--- a/mailet/api/src/main/java/org/apache/mailet/ArbitrarySerializable.java
+++ b/mailet/api/src/main/java/org/apache/mailet/ArbitrarySerializable.java
@@ -24,14 +24,14 @@ import java.util.Optional;
 public interface ArbitrarySerializable<T> {
     public class Serializable<U> {
         private final AttributeValue<?> value;
-        private final Class<? extends Factory<U>> factory;
+        private final Class<? extends Deserializer<U>> factory;
 
-        public Serializable(AttributeValue<?> value, Class<? extends Factory<U>>
factory) {
+        public Serializable(AttributeValue<?> value, Class<? extends Deserializer<U>>
factory) {
             this.value = value;
             this.factory = factory;
         }
 
-        public Class<? extends Factory<U>> getFactory() {
+        public Class<? extends Deserializer<U>> getDeserializer() {
             return factory;
         }
 
@@ -40,7 +40,7 @@ public interface ArbitrarySerializable<T> {
         }
     }
 
-    public interface Factory<U> {
+    public interface Deserializer<U> {
         Optional<U> deserialize(Serializable<U> serializable);
     }
     

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb91f992/mailet/api/src/main/java/org/apache/mailet/Serializer.java
----------------------------------------------------------------------
diff --git a/mailet/api/src/main/java/org/apache/mailet/Serializer.java b/mailet/api/src/main/java/org/apache/mailet/Serializer.java
index 192d132..016472a 100644
--- a/mailet/api/src/main/java/org/apache/mailet/Serializer.java
+++ b/mailet/api/src/main/java/org/apache/mailet/Serializer.java
@@ -271,7 +271,7 @@ public interface Serializer<T> {
         public JsonNode serialize(T serializable) {
             ArbitrarySerializable.Serializable<T> serialized = serializable.serialize();
             ObjectNode serializedJson = JsonNodeFactory.instance.objectNode();
-            serializedJson.put("factory", serialized.getFactory().getName());
+            serializedJson.put("deserializer", serialized.getDeserializer().getName());
             serializedJson.replace("value", serialized.getValue().toJson());
             return serializedJson;
         }
@@ -285,7 +285,7 @@ public interface Serializer<T> {
         }
 
         public Optional<T> instantiate(ObjectNode fields) {
-            return Optional.ofNullable(fields.get("factory"))
+            return Optional.ofNullable(fields.get("deserializer"))
                 .flatMap(serializer ->
                     Optional.ofNullable(fields.get("value"))
                         .flatMap(value -> deserialize(serializer.asText(), AttributeValue.fromJson(value))));
@@ -294,10 +294,10 @@ public interface Serializer<T> {
         @SuppressWarnings("unchecked")
         private Optional<T> deserialize(String serializer, AttributeValue<?>
value) {
             try {
-                Class<?> factoryClass = Class.forName(serializer);
-                if (ArbitrarySerializable.Factory.class.isAssignableFrom(factoryClass)) {
-                    ArbitrarySerializable.Factory<T> factory = (ArbitrarySerializable.Factory<T>)
factoryClass.newInstance();
-                    return factory.deserialize(new ArbitrarySerializable.Serializable<>(value,
(Class<ArbitrarySerializable.Factory<T>>) factoryClass));
+                Class<?> deserializerClass = Class.forName(serializer);
+                if (ArbitrarySerializable.Deserializer.class.isAssignableFrom(deserializerClass))
{
+                    ArbitrarySerializable.Deserializer<T> deserializer = (ArbitrarySerializable.Deserializer<T>)
deserializerClass.newInstance();
+                    return deserializer.deserialize(new ArbitrarySerializable.Serializable<>(value,
(Class<ArbitrarySerializable.Deserializer<T>>) deserializerClass));
                 }
             } catch (Exception e) {
                 LOGGER.error("Error while deserializing using serializer {} and value {}",
serializer, value, e);

http://git-wip-us.apache.org/repos/asf/james-project/blob/cb91f992/mailet/api/src/test/java/org/apache/mailet/AttributeValueTest.java
----------------------------------------------------------------------
diff --git a/mailet/api/src/test/java/org/apache/mailet/AttributeValueTest.java b/mailet/api/src/test/java/org/apache/mailet/AttributeValueTest.java
index d1189d1..ef92c6b 100644
--- a/mailet/api/src/test/java/org/apache/mailet/AttributeValueTest.java
+++ b/mailet/api/src/test/java/org/apache/mailet/AttributeValueTest.java
@@ -342,7 +342,7 @@ class AttributeValueTest {
         void fromJsonStringShouldReturnQueueSerializableAttributeValueWhenQueueSerializable()
throws Exception {
             AttributeValue<TestArbitrarySerializable> expected = AttributeValue.of(new
TestArbitrarySerializable(42));
 
-            AttributeValue<?> actual = AttributeValue.fromJsonString("{\"serializer\":\"ArbitrarySerializableSerializer\",\"value\":{\"factory\":\"org.apache.mailet.AttributeValueTest$TestArbitrarySerializable$Factory\",\"value\":{\"serializer\":\"IntSerializer\",\"value\":42}}}");
+            AttributeValue<?> actual = AttributeValue.fromJsonString("{\"serializer\":\"ArbitrarySerializableSerializer\",\"value\":{\"deserializer\":\"org.apache.mailet.AttributeValueTest$TestArbitrarySerializable$Factory\",\"value\":{\"serializer\":\"IntSerializer\",\"value\":42}}}");
 
             assertThat(actual).isEqualTo(expected);
         }
@@ -572,7 +572,7 @@ class AttributeValueTest {
     }
 
     private static class TestArbitrarySerializable implements ArbitrarySerializable<TestArbitrarySerializable>
{
-        public static class Factory implements ArbitrarySerializable.Factory<TestArbitrarySerializable>
{
+        public static class Factory implements ArbitrarySerializable.Deserializer<TestArbitrarySerializable>
{
             @Override
             public Optional<TestArbitrarySerializable> deserialize(Serializable<TestArbitrarySerializable>
serializable) {
                 return Optional.of(serializable.getValue().value())


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message