You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by jc...@apache.org on 2005/08/23 05:10:34 UTC

svn commit: r239308 - in /jakarta/commons/sandbox/proxy/trunk/src: java/org/apache/commons/proxy/interceptor/filter/PatternMethodFilter.java test/org/apache/commons/proxy/interceptor/filter/TestPatternMethodFilter.java

Author: jcarman
Date: Mon Aug 22 20:10:30 2005
New Revision: 239308

URL: http://svn.apache.org/viewcvs?rev=239308&view=rev
Log:
Adding PatternMethodFilter

Added:
    jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/interceptor/filter/PatternMethodFilter.java
    jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/interceptor/filter/TestPatternMethodFilter.java

Added: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/interceptor/filter/PatternMethodFilter.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/interceptor/filter/PatternMethodFilter.java?rev=239308&view=auto
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/interceptor/filter/PatternMethodFilter.java (added)
+++ jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/interceptor/filter/PatternMethodFilter.java Mon Aug 22 20:10:30 2005
@@ -0,0 +1,42 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation
+ *
+ *  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 org.apache.commons.proxy.interceptor.filter;
+
+import org.apache.commons.proxy.interceptor.MethodFilter;
+
+import java.lang.reflect.Method;
+
+/**
+ * A method filter implementation that returns true if the method's name
+ * matches a supplied regular expression (JDK regex) pattern string.
+ *
+ * @author James Carman
+ * @version 1.0
+ */
+public class PatternMethodFilter implements MethodFilter
+{
+    private final String pattern;
+
+    public PatternMethodFilter( String pattern )
+    {
+        this.pattern = pattern;
+    }
+
+    public boolean accepts( Method method )
+    {
+        return method.getName().matches( pattern );
+    }
+}

Added: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/interceptor/filter/TestPatternMethodFilter.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/interceptor/filter/TestPatternMethodFilter.java?rev=239308&view=auto
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/interceptor/filter/TestPatternMethodFilter.java (added)
+++ jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/interceptor/filter/TestPatternMethodFilter.java Mon Aug 22 20:10:30 2005
@@ -0,0 +1,35 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation
+ *
+ *  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 org.apache.commons.proxy.interceptor.filter;
+
+import junit.framework.TestCase;
+
+import java.util.Date;
+
+/**
+ * @author James Carman
+ * @version 1.0
+ */
+public class TestPatternMethodFilter extends TestCase
+{
+    public void testAccepts() throws Exception
+    {
+        final PatternMethodFilter filter = new PatternMethodFilter( "set\\w+|get\\w+" );
+        assertTrue( filter.accepts( Date.class.getMethod( "getSeconds" ) ) );
+        assertTrue( filter.accepts( Date.class.getMethod( "setSeconds", Integer.TYPE ) ) );
+        assertFalse( filter.accepts( Date.class.getMethod( "toString" ) ) );
+    }
+}



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