struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [1/3] git commit: Defines new interface to implement specialized internal converters
Date Thu, 14 Aug 2014 08:40:35 GMT
Repository: struts
Updated Branches:
  refs/heads/feature/locale-aware-converters [created] fe329f502


Defines new interface to implement specialized internal converters


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

Branch: refs/heads/feature/locale-aware-converters
Commit: dfb5203ea7010516ae7aa02889936392a982ab3a
Parents: d749bb8
Author: Lukasz Lenart <lukaszlenart@apache.org>
Authored: Thu Aug 14 10:39:13 2014 +0200
Committer: Lukasz Lenart <lukaszlenart@apache.org>
Committed: Thu Aug 14 10:39:13 2014 +0200

----------------------------------------------------------------------
 .../xwork2/conversion/InternalConverter.java    | 12 +++++++
 .../xwork2/conversion/InternalConverters.java   | 37 ++++++++++++++++++++
 2 files changed, 49 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/dfb5203e/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/InternalConverter.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/InternalConverter.java
b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/InternalConverter.java
new file mode 100644
index 0000000..50cf52b
--- /dev/null
+++ b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/InternalConverter.java
@@ -0,0 +1,12 @@
+package com.opensymphony.xwork2.conversion;
+
+/**
+ * Represents specialized converters which can convert value to given type T
+ */
+public interface InternalConverter<T> {
+
+    boolean canConvert(Object value);
+
+    T convert(Object value);
+
+}

http://git-wip-us.apache.org/repos/asf/struts/blob/dfb5203e/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/InternalConverters.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/InternalConverters.java
b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/InternalConverters.java
new file mode 100644
index 0000000..849e8af
--- /dev/null
+++ b/xwork-core/src/main/java/com/opensymphony/xwork2/conversion/InternalConverters.java
@@ -0,0 +1,37 @@
+package com.opensymphony.xwork2.conversion;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Holds reference to all internal converters to simplify lookup and registration
+ */
+public class InternalConverters<T> {
+
+    private final InternalConverter<T> NO_OP_CONVERTER = new InternalConverter<T>()
{
+
+        public boolean canConvert(Object value) {
+            return false;
+        }
+
+        public T convert(Object value) {
+            return null;
+        }
+    };
+
+    private List<InternalConverter<T>> converters = new ArrayList<InternalConverter<T>>();
+
+    public boolean register(InternalConverter<T> converter) {
+        return converters.add(converter);
+    }
+
+    public InternalConverter<T> lookup(Object value) {
+        for (InternalConverter<T> converter : converters) {
+            if (converter.canConvert(value)) {
+                return converter;
+            }
+        }
+        return NO_OP_CONVERTER;
+    }
+
+}


Mime
View raw message