hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject cvs commit: jakarta-hivemind status.xml
Date Tue, 09 Nov 2004 17:26:11 GMT
hlship      2004/11/09 09:26:11

  Modified:    framework/src/java/org/apache/hivemind/methodmatch
                        MethodMatcher.java
               framework/src/test/org/apache/hivemind/methodmatch
                        TestMethodMatcher.java
               .        status.xml
  Log:
  HIVEMIND-75: Add ability to set default value for non-matches in MethodMatcher.
  
  Revision  Changes    Path
  1.5       +57 -35    jakarta-hivemind/framework/src/java/org/apache/hivemind/methodmatch/MethodMatcher.java
  
  Index: MethodMatcher.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/methodmatch/MethodMatcher.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MethodMatcher.java	29 Jul 2004 13:18:48 -0000	1.4
  +++ MethodMatcher.java	9 Nov 2004 17:26:11 -0000	1.5
  @@ -24,37 +24,34 @@
   import org.apache.hivemind.service.MethodSignature;
   
   /**
  - * A utility class used for matching a {@link org.apache.hivemind.service.MethodSignature}
against
  - * a method pattern (this is primarily used by {@link org.apache.hivemind.ServiceInterceptorFactory
  + * A utility class used for matching a {@link org.apache.hivemind.service.MethodSignature}against
a
  + * method pattern (this is primarily used by {@link org.apache.hivemind.ServiceInterceptorFactory
    * interceptor factories}). A method pattern consists of a <em>name pattern</em>
and an optional
    * <em>parameters pattern</em>.
  - * 
    * <p>
    * The name pattern matches against the method name, and can be one of the following:
    * <ul>
  - * <li>A single name - which requires an exact match.  Example: <code>perform</code>
  - * <li>A name suffix, indicated with a leading '*'.  Example: <code>*form</code>
  - * <li>A name prefix, indicated with a trailing '*'.  Example: <code>per*</code>
  - * <li>A name substring, indicated with leading and trailing '*'s.  Example: <code>*erfo*</code>.
  - * <li>A match any, indicated with a single '*'.  Example: <code>*</code>
  + * <li>A single name - which requires an exact match. Example: <code>perform</code>
  + * <li>A name suffix, indicated with a leading '*'. Example: <code>*form</code>
  + * <li>A name prefix, indicated with a trailing '*'. Example: <code>per*</code>
  + * <li>A name substring, indicated with leading and trailing '*'s. Example: <code>*erfo*</code>.
  + * <li>A match any, indicated with a single '*'. Example: <code>*</code>
    * </ul>
  - * 
    * <p>
    * The parameters pattern follows the name pattern and is optional. It is used to check
the number
    * of parameters, or their types. When the parameters pattern is omitted, then the number
and types
    * of parameters are not considred when matching methods.
  - * 
    * <p>
    * The parameters pattern, when present, is contained within open and closed parenthis
after the
  - * method pattern.  Inside the parenthesis may be a number, indicating the exact number
of
  - * method parameters to match against. Alternately, a comma-seperated list of Java types
is used,
  - * which matches against a method that takes the exact set of parameters.  Examples:
  + * method pattern. Inside the parenthesis may be a number, indicating the exact number
of method
  + * parameters to match against. Alternately, a comma-seperated list of Java types is used,
which
  + * matches against a method that takes the exact set of parameters. Examples:
    * <ul>
  - * <li><code>perform()</code> -- method with no parameters
  - * <li><code>perform(2)</code> -- method with two parameters
  - * <li><code>perform(java.util.List, int)</code> - method taking a List
and an int parameter
  - * </ul> 
  - *
  + * <li><code>perform()</code>-- method with no parameters
  + * <li><code>perform(2)</code>-- method with two parameters
  + * <li><code>perform(java.util.List, int)</code>- method taking a List
and an int parameter
  + * </ul>
  + * 
    * @author Howard Lewis Ship
    */
   public class MethodMatcher
  @@ -62,7 +59,9 @@
       private class StoredPattern
       {
           String _methodPattern;
  +
           MethodFilter _filter;
  +
           Object _patternValue;
   
           StoredPattern(String pattern, Object value)
  @@ -82,14 +81,15 @@
                   }
                   catch (RuntimeException ex)
                   {
  -                    Location l = HiveMind.findLocation(new Object[] { _patternValue, ex
});
  +                    Location l = HiveMind.findLocation(new Object[]
  +                    { _patternValue, ex });
   
                       if (l == null)
                           throw ex;
   
  -                    throw new ApplicationRuntimeException(
  -                        MethodMatchMessages.exceptionAtLocation(l, ex),
  -                        ex);
  +                    throw new ApplicationRuntimeException(MethodMatchMessages.exceptionAtLocation(
  +                            l,
  +                            ex), ex);
                   }
               }
   
  @@ -98,19 +98,40 @@
       }
   
       private MethodPatternParser _parser = new MethodPatternParser();
  +
       private List _methodInfos;
   
  +    private Object _defaultValue;
  +
  +    /**
  +     * Constructor that takes a default value returned when no stored method pattern matches
the
  +     * input to {@link #get(MethodSignature)}.
  +     * 
  +     * @since 1.1
  +     */
  +    public MethodMatcher(Object defaultValue)
  +    {
  +        _defaultValue = defaultValue;
  +    }
  +
  +    public MethodMatcher()
  +    {
  +        this(null);
  +    }
  +
       private MethodFilter parseMethodPattern(String pattern)
       {
           return _parser.parseMethodPattern(pattern);
       }
   
       /**
  -     * Stores a pattern and an associated value. Values can later be
  -     * accessed via {@link #get(Method)}.
  +     * Stores a pattern and an associated value. Values can later be accessed via
  +     * {@link #get(Method)}.
        * 
  -     * @param methodPattern a pattern that is used to recognize methods
  -     * @param patternValue a value associated with the pattern
  +     * @param methodPattern
  +     *            a pattern that is used to recognize methods
  +     * @param patternValue
  +     *            a value associated with the pattern
        */
       public synchronized void put(String methodPattern, Object patternValue)
       {
  @@ -123,17 +144,18 @@
       }
   
       /**
  -     * Returns a pattern value prevoiusly stored via {@link #put(String, Object)}.
  -     * Iterates over the patterns stored, in the order in which they were stored,
  -     * until a match is found.
  +     * Returns a pattern value prevoiusly stored via {@link #put(String, Object)}. Iterates
over
  +     * the patterns stored, in the order in which they were stored, until a match is found.
        * 
  -     * @param sig the MethodSignature to find a matching pattern for
  -     * @returns the pattern value for the matching pattern, or null if not found.
  +     * @param sig
  +     *            the MethodSignature to find a matching pattern for
  +     * @returns the pattern value for the matching pattern, or the default value if not
found (the
  +     *          default value may be set in the constructor)
        */
       public synchronized Object get(MethodSignature sig)
       {
           if (_methodInfos == null)
  -            return null;
  +            return _defaultValue;
   
           Iterator i = _methodInfos.iterator();
           while (i.hasNext())
  @@ -145,7 +167,7 @@
           }
   
           // Not found.
  -        
  -        return null;
  +
  +        return _defaultValue;
       }
  -}
  +}
  \ No newline at end of file
  
  
  
  1.5       +18 -8     jakarta-hivemind/framework/src/test/org/apache/hivemind/methodmatch/TestMethodMatcher.java
  
  Index: TestMethodMatcher.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/test/org/apache/hivemind/methodmatch/TestMethodMatcher.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestMethodMatcher.java	1 Aug 2004 17:40:36 -0000	1.4
  +++ TestMethodMatcher.java	9 Nov 2004 17:26:11 -0000	1.5
  @@ -21,8 +21,8 @@
   import org.apache.hivemind.service.MethodSignature;
   
   /**
  - * Tests for the {@link org.apache.hivemind.methodmatch.MethodMatcher} class.
  - *
  + * Tests for the {@link org.apache.hivemind.methodmatch.MethodMatcher}class.
  + * 
    * @author Howard Lewis Ship
    */
   public class TestMethodMatcher extends AbstractMethodTestCase
  @@ -43,6 +43,18 @@
           assertEquals(null, _m.get(getMethodSignature(this, "hashCode")));
       }
   
  +    /** @since 1.1 */
  +    public void testNoMatchReturnsDefault()
  +    {
  +        MethodMatcher m = new MethodMatcher("FRED");
  +
  +        assertEquals("FRED", m.get(getMethodSignature(this, "hashCode")));
  +
  +        m.put("zoop", "BARNEY");
  +
  +        assertEquals("FRED", m.get(getMethodSignature(this, "hashCode")));
  +    }
  +
       public void testMatch()
       {
           _m.put("equals(java.lang.Object)", "match");
  @@ -69,9 +81,8 @@
           }
           catch (ApplicationRuntimeException ex)
           {
  -            assertEquals(
  -                "Method pattern '*(' contains an invalid parameters pattern.",
  -                ex.getMessage());
  +            assertEquals("Method pattern '*(' contains an invalid parameters pattern.",
ex
  +                    .getMessage());
           }
       }
   
  @@ -94,12 +105,11 @@
           {
               String message = ex.getMessage();
   
  -            boolean matchesPattern =
  -                matches(
  +            boolean matchesPattern = matches(
                       message,
                       "Exception at .*?, line 3: Method pattern '\\*\\(' contains an invalid
parameters pattern\\.");
   
               assertEquals(true, matchesPattern);
           }
       }
  -}
  +}
  \ No newline at end of file
  
  
  
  1.79      +4 -2      jakarta-hivemind/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/status.xml,v
  retrieving revision 1.78
  retrieving revision 1.79
  diff -u -r1.78 -r1.79
  --- status.xml	9 Nov 2004 11:24:29 -0000	1.78
  +++ status.xml	9 Nov 2004 17:26:11 -0000	1.79
  @@ -89,11 +89,13 @@
           Add the hivemind.lib.AdapterRegistryFactory service implementation factory.
         </action>
         <action type="update" dev="HLS"> Removed the module parameter from ClassFactory.newClass()
and from 
  -        DefaultImplementationBuilder.buildDefaultImplementation().
  -      </action>
  +        DefaultImplementationBuilder.buildDefaultImplementation(). </action>
         <action type="update" dev="KW">
           BuilderFactory now supports autowiring through constructor based dependency injection.
         </action>
  +        <action type="fix" dev="HLS" fixes-bug="HIVEMIND-75">
  +          Add ability to set default value for non-matches in MethodMatcher.
  +        </action>
       </release>
   
      <release version="1.0" date="Sep 22 2004">
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org


Mime
View raw message