You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2015/09/28 20:53:08 UTC

[19/33] struts git commit: Uses factory method pattern

Uses factory method pattern


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

Branch: refs/heads/master
Commit: cb06d7d2580e37ab8aba2170c433c1674932c4de
Parents: e38d465
Author: Lukasz Lenart <lu...@gmail.com>
Authored: Fri Sep 4 09:08:32 2015 +0200
Committer: Lukasz Lenart <lu...@gmail.com>
Committed: Fri Sep 4 09:08:32 2015 +0200

----------------------------------------------------------------------
 .../xwork2/config/entities/ActionConfig.java    |  6 +--
 .../xwork2/config/entities/AllowedMethods.java  | 54 ++++++++++----------
 2 files changed, 31 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/cb06d7d2/core/src/main/java/com/opensymphony/xwork2/config/entities/ActionConfig.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/config/entities/ActionConfig.java b/core/src/main/java/com/opensymphony/xwork2/config/entities/ActionConfig.java
index 7c10c90..a821c93 100644
--- a/core/src/main/java/com/opensymphony/xwork2/config/entities/ActionConfig.java
+++ b/core/src/main/java/com/opensymphony/xwork2/config/entities/ActionConfig.java
@@ -63,7 +63,7 @@ public class ActionConfig extends Located implements Serializable {
         results = new LinkedHashMap<>();
         interceptors = new ArrayList<>();
         exceptionMappings = new ArrayList<>();
-        allowedMethods = new AllowedMethods(new HashSet<>(Collections.singletonList(DEFAULT_METHOD)));
+        allowedMethods = AllowedMethods.build(new HashSet<>(Collections.singletonList(DEFAULT_METHOD)));
     }
 
     /**
@@ -80,7 +80,7 @@ public class ActionConfig extends Located implements Serializable {
         this.interceptors = new ArrayList<>(orig.interceptors);
         this.results = new LinkedHashMap<>(orig.results);
         this.exceptionMappings = new ArrayList<>(orig.exceptionMappings);
-        this.allowedMethods = new AllowedMethods(orig.allowedMethods.list());
+        this.allowedMethods = AllowedMethods.build(orig.allowedMethods.list());
         this.location = orig.location;
     }
 
@@ -332,7 +332,7 @@ public class ActionConfig extends Located implements Serializable {
             target.results = Collections.unmodifiableMap(target.results);
             target.interceptors = Collections.unmodifiableList(target.interceptors);
             target.exceptionMappings = Collections.unmodifiableList(target.exceptionMappings);
-            target.allowedMethods = new AllowedMethods(allowedMethods);
+            target.allowedMethods = AllowedMethods.build(allowedMethods);
 
             ActionConfig result = target;
             target = new ActionConfig(target);

http://git-wip-us.apache.org/repos/asf/struts/blob/cb06d7d2/core/src/main/java/com/opensymphony/xwork2/config/entities/AllowedMethods.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/config/entities/AllowedMethods.java b/core/src/main/java/com/opensymphony/xwork2/config/entities/AllowedMethods.java
index f619d89..7582696 100644
--- a/core/src/main/java/com/opensymphony/xwork2/config/entities/AllowedMethods.java
+++ b/core/src/main/java/com/opensymphony/xwork2/config/entities/AllowedMethods.java
@@ -9,37 +9,39 @@ public class AllowedMethods {
 
     private Set<AllowedMethod> allowedMethods;
 
-    public AllowedMethods(Set<String> methods) {
+    public static AllowedMethods build(Set<String> methods) {
+
         Set<AllowedMethod> allowedMethods = new HashSet<>();
         for (String method : methods) {
-            allowedMethods.add(build(method));
-        }
-        this.allowedMethods = Collections.unmodifiableSet(allowedMethods);
-    }
-
-    private AllowedMethod build(String method) {
-        boolean isPattern = false;
-        int len = method.length();
-        StringBuilder ret = new StringBuilder();
-        char c;
-        for (int x = 0; x < len; x++) {
-            c = method.charAt(x);
-            if (x < len - 2 && c == '{' && '}' == method.charAt(x + 2)) {
-                ret.append("(.*)");
-                isPattern = true;
-                x += 2;
+            boolean isPattern = false;
+            int len = method.length();
+            StringBuilder ret = new StringBuilder();
+            char c;
+            for (int x = 0; x < len; x++) {
+                c = method.charAt(x);
+                if (x < len - 2 && c == '{' && '}' == method.charAt(x + 2)) {
+                    ret.append("(.*)");
+                    isPattern = true;
+                    x += 2;
+                } else {
+                    ret.append(c);
+                }
+            }
+            if (isPattern && !method.startsWith("regex:")) {
+                allowedMethods.add(new PatternAllowedMethod(ret.toString(), method));
+            } else if (method.startsWith("regex:")) {
+                String pattern = method.substring(method.indexOf(":") + 1);
+                allowedMethods.add(new PatternAllowedMethod(pattern, method));
             } else {
-                ret.append(c);
+                allowedMethods.add(new LiteralAllowedMethod(ret.toString()));
             }
         }
-        if (isPattern && !method.startsWith("regex:")) {
-            return new PatternAllowedMethod(ret.toString(), method);
-        } else if (method.startsWith("regex:")) {
-            String pattern = method.substring(method.indexOf(":") + 1);
-            return new PatternAllowedMethod(pattern, method);
-        } else {
-            return new LiteralAllowedMethod(ret.toString());
-        }
+
+        return new AllowedMethods(allowedMethods);
+    }
+
+    private AllowedMethods(Set<AllowedMethod> methods) {
+        this.allowedMethods = Collections.unmodifiableSet(methods);
     }
 
     public boolean isAllowed(String method) {