Revision: 1370
Author: sberlin
Date: Sat Nov 13 06:28:14 2010
Log: issue 570 & issue 569 -- share a hierarchy for servlet module bindings, expose a method to see if the binding will match against a URI.
http://code.google.com/p/google-guice/source/detail?r=1370

Added:
/trunk/extensions/servlet/src/com/google/inject/servlet/ServletModuleBinding.java
Modified:
/trunk/extensions/servlet/src/com/google/inject/servlet/AbstractServletModuleBinding.java /trunk/extensions/servlet/src/com/google/inject/servlet/FilterDefinition.java /trunk/extensions/servlet/src/com/google/inject/servlet/InstanceFilterBinding.java /trunk/extensions/servlet/src/com/google/inject/servlet/InstanceFilterBindingImpl.java /trunk/extensions/servlet/src/com/google/inject/servlet/InstanceServletBinding.java /trunk/extensions/servlet/src/com/google/inject/servlet/InstanceServletBindingImpl.java /trunk/extensions/servlet/src/com/google/inject/servlet/LinkedFilterBinding.java /trunk/extensions/servlet/src/com/google/inject/servlet/LinkedFilterBindingImpl.java /trunk/extensions/servlet/src/com/google/inject/servlet/LinkedServletBinding.java /trunk/extensions/servlet/src/com/google/inject/servlet/LinkedServletBindingImpl.java /trunk/extensions/servlet/src/com/google/inject/servlet/ServletDefinition.java

=======================================
--- /dev/null
+++ /trunk/extensions/servlet/src/com/google/inject/servlet/ServletModuleBinding.java Sat Nov 13 06:28:14 2010
@@ -0,0 +1,39 @@
+/**
+ * Copyright (C) 2010 Google Inc.
+ *
+ * Licensed 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 com.google.inject.servlet;
+
+import java.util.Map;
+
+/**
+ * A binding created by {...@link ServletModule}.
+ *
+ * @author [email protected] (Sam Berlin)
+ */
+public interface ServletModuleBinding {
+
+  /** Returns the pattern type that this binding was created with. */
+  UriPatternType getUriPatternType();
+
+  /** Returns the pattern used to match against the binding. */
+  String getPattern();
+
+  /** Returns any context params supplied when creating the binding. */
+  Map<String, String> getInitParams();
+
+  /** Returns true if the given URI will match this binding. */
+  boolean matchesUri(String uri);
+}
=======================================
--- /trunk/extensions/servlet/src/com/google/inject/servlet/AbstractServletModuleBinding.java Sun Aug 22 11:48:23 2010 +++ /trunk/extensions/servlet/src/com/google/inject/servlet/AbstractServletModuleBinding.java Sat Nov 13 06:28:14 2010
@@ -23,19 +23,19 @@
  *
  * @author [email protected] (Sam Berlin)
  */
-class AbstractServletModuleBinding<T> {
+class AbstractServletModuleBinding<T> implements ServletModuleBinding {

   private final Map<String, String> initParams;
   private final String pattern;
   private final T target;
-  private final UriPatternType patternType;
+  private final UriPatternMatcher patternMatcher;

AbstractServletModuleBinding(Map<String, String> initParams, String pattern, T target,
-      UriPatternType patternType) {
+      UriPatternMatcher patternMatcher) {
     this.initParams = initParams;
     this.pattern = pattern;
     this.target = target;
-    this.patternType = patternType;
+    this.patternMatcher = patternMatcher;
   }

   public Map<String, String> getInitParams() {
@@ -51,7 +51,11 @@
   }

   public UriPatternType getUriPatternType() {
-    return patternType;
+    return patternMatcher.getPatternType();
+  }
+
+  public boolean matchesUri(String uri) {
+    return patternMatcher.matches(uri);
   }

 }
=======================================
--- /trunk/extensions/servlet/src/com/google/inject/servlet/FilterDefinition.java Sat Oct 16 18:31:25 2010 +++ /trunk/extensions/servlet/src/com/google/inject/servlet/FilterDefinition.java Sat Nov 13 06:28:14 2010
@@ -75,13 +75,13 @@
             new InstanceFilterBindingImpl(initParams,
                 pattern,
                 filterInstance,
-                patternMatcher.getPatternType()));
+                patternMatcher));
       } else {
         return ((ServletModuleTargetVisitor<B, V>)visitor).visit(
             new LinkedFilterBindingImpl(initParams,
                 pattern,
                 filterKey,
-                patternMatcher.getPatternType()));
+                patternMatcher));
       }
     } else {
       return visitor.visit(binding);
=======================================
--- /trunk/extensions/servlet/src/com/google/inject/servlet/InstanceFilterBinding.java Sun Aug 22 11:48:23 2010 +++ /trunk/extensions/servlet/src/com/google/inject/servlet/InstanceFilterBinding.java Sat Nov 13 06:28:14 2010
@@ -16,8 +16,6 @@

 package com.google.inject.servlet;

-import java.util.Map;
-
 import javax.servlet.Filter;

 /**
@@ -26,22 +24,7 @@
  * @author [email protected]
  * @since 3.0
  */
-public interface InstanceFilterBinding {
-
-  /**
-   * Returns the pattern type that this filter binding was created with.
- * This will be {...@link UriPatternType#REGEX} if the binding was created with
-   * {...@link ServletModule#filterRegex(String, String...)}, and
-   * {...@link UriPatternType#SERVLET} if it was created with
-   * {...@link ServletModule#filter(String, String...)}.
-   */
-  UriPatternType getUriPatternType();
-
-  /** Returns the pattern used to match against the filter. */
-  String getPattern();
-
-  /** Returns any context params supplied when creating the binding. */
-  Map<String, String> getInitParams();
+public interface InstanceFilterBinding extends ServletModuleBinding {

   /** Returns the filter instance that will be used. */
   Filter getFilterInstance();
=======================================
--- /trunk/extensions/servlet/src/com/google/inject/servlet/InstanceFilterBindingImpl.java Sun Sep 26 15:02:00 2010 +++ /trunk/extensions/servlet/src/com/google/inject/servlet/InstanceFilterBindingImpl.java Sat Nov 13 06:28:14 2010
@@ -31,8 +31,8 @@
     InstanceFilterBinding {

   InstanceFilterBindingImpl(Map<String, String> initParams, String pattern,
-      Filter target, UriPatternType patternType) {
-    super(initParams, pattern, target, patternType);
+      Filter target, UriPatternMatcher patternMatcher) {
+    super(initParams, pattern, target, patternMatcher);
   }

   public Filter getFilterInstance() {
=======================================
--- /trunk/extensions/servlet/src/com/google/inject/servlet/InstanceServletBinding.java Sun Aug 22 11:48:23 2010 +++ /trunk/extensions/servlet/src/com/google/inject/servlet/InstanceServletBinding.java Sat Nov 13 06:28:14 2010
@@ -16,8 +16,6 @@

 package com.google.inject.servlet;

-import java.util.Map;
-
 import javax.servlet.http.HttpServlet;

 /**
@@ -26,22 +24,7 @@
  * @author [email protected]
  * @since 3.0
  */
-public interface InstanceServletBinding {
-
-  /**
-   * Returns the pattern type that this servlet binding was created with.
- * This will be {...@link UriPatternType#REGEX} if the binding was created with
-   * {...@link ServletModule#serveRegex(String, String...)}, and
-   * {...@link UriPatternType#SERVLET} if it was created with
-   * {...@link ServletModule#serve(String, String...)}.
-   */
-  UriPatternType getUriPatternType();
-
-  /** Returns the pattern used to match against the servlet. */
-  String getPattern();
-
-  /** Returns any init params supplied when creating the binding. */
-  Map<String, String> getInitParams();
+public interface InstanceServletBinding extends ServletModuleBinding {

   /** Returns the servlet instance that will be used. */
   HttpServlet getServletInstance();
=======================================
--- /trunk/extensions/servlet/src/com/google/inject/servlet/InstanceServletBindingImpl.java Sun Sep 26 15:02:00 2010 +++ /trunk/extensions/servlet/src/com/google/inject/servlet/InstanceServletBindingImpl.java Sat Nov 13 06:28:14 2010
@@ -31,8 +31,8 @@
     InstanceServletBinding {

InstanceServletBindingImpl(Map<String, String> initParams, String pattern,
-      HttpServlet target, UriPatternType patternType) {
-    super(initParams, pattern, target, patternType);
+      HttpServlet target, UriPatternMatcher patternMatcher) {
+    super(initParams, pattern, target, patternMatcher);
   }

   public HttpServlet getServletInstance() {
=======================================
--- /trunk/extensions/servlet/src/com/google/inject/servlet/LinkedFilterBinding.java Sun Aug 22 11:48:23 2010 +++ /trunk/extensions/servlet/src/com/google/inject/servlet/LinkedFilterBinding.java Sat Nov 13 06:28:14 2010
@@ -16,8 +16,6 @@

 package com.google.inject.servlet;

-import java.util.Map;
-
 import javax.servlet.Filter;

 import com.google.inject.Key;
@@ -28,22 +26,7 @@
  * @author [email protected]
  * @since 3.0
  */
-public interface LinkedFilterBinding {
-
-  /**
-   * Returns the pattern type that this filter binding was created with.
- * This will be {...@link UriPatternType#REGEX} if the binding was created with
-   * {...@link ServletModule#filterRegex(String, String...)}, and
-   * {...@link UriPatternType#SERVLET} if it was created with
-   * {...@link ServletModule#filter(String, String...)}.
-   */
-  UriPatternType getUriPatternType();
-
-  /** Returns the pattern used to match against the filter. */
-  String getPattern();
-
-  /** Returns any init params supplied when creating the binding. */
-  Map<String, String> getInitParams();
+public interface LinkedFilterBinding extends ServletModuleBinding {

   /** Returns the key used to lookup the filter instance. */
   Key<? extends Filter> getLinkedKey();
=======================================
--- /trunk/extensions/servlet/src/com/google/inject/servlet/LinkedFilterBindingImpl.java Sun Sep 26 15:02:00 2010 +++ /trunk/extensions/servlet/src/com/google/inject/servlet/LinkedFilterBindingImpl.java Sat Nov 13 06:28:14 2010
@@ -32,8 +32,8 @@
     implements LinkedFilterBinding {

   LinkedFilterBindingImpl(Map<String, String> initParams, String pattern,
-      Key<? extends Filter> target, UriPatternType patternType) {
-    super(initParams, pattern, target, patternType);
+      Key<? extends Filter> target, UriPatternMatcher patternMatcher) {
+    super(initParams, pattern, target, patternMatcher);
   }

   public Key<? extends Filter> getLinkedKey() {
=======================================
--- /trunk/extensions/servlet/src/com/google/inject/servlet/LinkedServletBinding.java Sun Aug 22 11:48:23 2010 +++ /trunk/extensions/servlet/src/com/google/inject/servlet/LinkedServletBinding.java Sat Nov 13 06:28:14 2010
@@ -16,8 +16,6 @@

 package com.google.inject.servlet;

-import java.util.Map;
-
 import javax.servlet.http.HttpServlet;

 import com.google.inject.Key;
@@ -28,22 +26,7 @@
  * @author [email protected]
  * @since 3.0
  */
-public interface LinkedServletBinding {
-
-  /**
-   * Returns the pattern type that this servlet binding was created with.
- * This will be {...@link UriPatternType#REGEX} if the binding was created with
-   * {...@link ServletModule#serveRegex(String, String...)}, and
-   * {...@link UriPatternType#SERVLET} if it was created with
-   * {...@link ServletModule#serve(String, String...)}.
-   */
-  UriPatternType getUriPatternType();
-
-  /** Returns the pattern used to match against the servlet. */
-  String getPattern();
-
-  /** Returns any init params supplied when creating the binding. */
-  Map<String, String> getInitParams();
+public interface LinkedServletBinding extends ServletModuleBinding {

   /** Returns the key used to lookup the servlet instance. */
   Key<? extends HttpServlet> getLinkedKey();
=======================================
--- /trunk/extensions/servlet/src/com/google/inject/servlet/LinkedServletBindingImpl.java Sun Sep 26 15:02:00 2010 +++ /trunk/extensions/servlet/src/com/google/inject/servlet/LinkedServletBindingImpl.java Sat Nov 13 06:28:14 2010
@@ -32,8 +32,8 @@
     implements LinkedServletBinding {

   LinkedServletBindingImpl(Map<String, String> initParams, String pattern,
-      Key<? extends HttpServlet> target, UriPatternType patternType) {
-    super(initParams, pattern, target, patternType);
+ Key<? extends HttpServlet> target, UriPatternMatcher patternMatcher) {
+    super(initParams, pattern, target, patternMatcher);
   }

   public Key<? extends HttpServlet> getLinkedKey() {
=======================================
--- /trunk/extensions/servlet/src/com/google/inject/servlet/ServletDefinition.java Thu Oct 21 05:35:46 2010 +++ /trunk/extensions/servlet/src/com/google/inject/servlet/ServletDefinition.java Sat Nov 13 06:28:14 2010
@@ -79,13 +79,13 @@
             new InstanceServletBindingImpl(initParams,
                 pattern,
                 servletInstance,
-                patternMatcher.getPatternType()));
+                patternMatcher));
       } else {
         return ((ServletModuleTargetVisitor<B, V>)visitor).visit(
             new LinkedServletBindingImpl(initParams,
                 pattern,
                 servletKey,
-                patternMatcher.getPatternType()));
+                patternMatcher));
       }
     } else {
       return visitor.visit(binding);

--
You received this message because you are subscribed to the Google Groups 
"google-guice-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice-dev?hl=en.

Reply via email to