- Revision
- 353
- Author
- mauro
- Date
- 2007-11-12 13:40:19 -0600 (Mon, 12 Nov 2007)
Log Message
Renamed default impl of interceptor chain.
Modified Paths
Added Paths
- trunk/core/src/main/java/org/codehaus/waffle/action/intercept/DefaultInterceptorChain.java
- trunk/core/src/test/java/org/codehaus/waffle/action/intercept/DefaultInterceptorChainTest.java
Removed Paths
Diff
Modified: trunk/core/src/main/java/org/codehaus/waffle/action/InterceptingActionMethodExecutor.java (352 => 353)
--- trunk/core/src/main/java/org/codehaus/waffle/action/InterceptingActionMethodExecutor.java 2007-11-12 19:38:05 UTC (rev 352) +++ trunk/core/src/main/java/org/codehaus/waffle/action/InterceptingActionMethodExecutor.java 2007-11-12 19:40:19 UTC (rev 353) @@ -11,7 +11,7 @@ package org.codehaus.waffle.action; import org.codehaus.waffle.action.intercept.InterceptorChain; -import org.codehaus.waffle.action.intercept.InterceptorChainImpl; +import org.codehaus.waffle.action.intercept.DefaultInterceptorChain; import org.codehaus.waffle.action.intercept.MethodInterceptor; import org.codehaus.waffle.action.intercept.MethodInterceptorComparator; import org.codehaus.waffle.context.ContextContainer; @@ -61,13 +61,13 @@ private Object handleInvocation(ControllerDefinition controllerDefinition) throws IllegalAccessException, InvocationTargetException { ContextContainer container = RequestLevelContainer.get(); - List<MethodInterceptor> methodInterceptors = new ArrayList<MethodInterceptor>(); - methodInterceptors.addAll(container.getAllComponentInstancesOfType(MethodInterceptor.class)); - Collections.sort(methodInterceptors, comparator); + List<MethodInterceptor> interceptors = new ArrayList<MethodInterceptor>(); + interceptors.addAll(container.getAllComponentInstancesOfType(MethodInterceptor.class)); + Collections.sort(interceptors, comparator); - methodInterceptors.add(new MethodInvokingMethodInterceptor()); + interceptors.add(new MethodInvokingMethodInterceptor()); - InterceptorChain chain = new InterceptorChainImpl(methodInterceptors); + InterceptorChain chain = new DefaultInterceptorChain(interceptors); MethodDefinition methodDefinition = controllerDefinition.getMethodDefinition(); Method method = methodDefinition.getMethod(); List<Object> methodArguments = methodDefinition.getMethodArguments();
Copied: trunk/core/src/main/java/org/codehaus/waffle/action/intercept/DefaultInterceptorChain.java (from rev 343, trunk/core/src/main/java/org/codehaus/waffle/action/intercept/InterceptorChainImpl.java) (0 => 353)
--- trunk/core/src/main/java/org/codehaus/waffle/action/intercept/DefaultInterceptorChain.java (rev 0) +++ trunk/core/src/main/java/org/codehaus/waffle/action/intercept/DefaultInterceptorChain.java 2007-11-12 19:40:19 UTC (rev 353) @@ -0,0 +1,42 @@ +/***************************************************************************** + * Copyright (C) 2005,2006 Michael Ward * + * All rights reserved. * + * ------------------------------------------------------------------------- * + * The software in this package is published under the terms of the BSD * + * style license a copy of which has been included with this distribution in * + * the LICENSE.txt file. * + * * + * Original code by: Michael Ward * + *****************************************************************************/ +package org.codehaus.waffle.action.intercept; + +import org.codehaus.waffle.controller.ControllerDefinition; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Iterator; +import java.util.List; + +public class DefaultInterceptorChain implements InterceptorChain { + private final Iterator<MethodInterceptor> iterator; + private Object returnValue; + + public DefaultInterceptorChain(List<MethodInterceptor> interceptors) { + this.iterator = interceptors.iterator(); + } + + public Object proceed(ControllerDefinition controllerDefinition, + Method method, + Object... arguments) throws IllegalAccessException, InvocationTargetException { + if (iterator.hasNext()) { + MethodInterceptor methodInterceptor = iterator.next(); + if (methodInterceptor.accept(method)) { + returnValue = methodInterceptor.intercept(controllerDefinition, method, this, arguments); + } else { + return proceed(controllerDefinition, method, arguments); // recursive + } + } + + return returnValue; + } +}
Deleted: trunk/core/src/main/java/org/codehaus/waffle/action/intercept/InterceptorChainImpl.java (352 => 353)
--- trunk/core/src/main/java/org/codehaus/waffle/action/intercept/InterceptorChainImpl.java 2007-11-12 19:38:05 UTC (rev 352) +++ trunk/core/src/main/java/org/codehaus/waffle/action/intercept/InterceptorChainImpl.java 2007-11-12 19:40:19 UTC (rev 353) @@ -1,42 +0,0 @@ -/***************************************************************************** - * Copyright (C) 2005,2006 Michael Ward * - * All rights reserved. * - * ------------------------------------------------------------------------- * - * The software in this package is published under the terms of the BSD * - * style license a copy of which has been included with this distribution in * - * the LICENSE.txt file. * - * * - * Original code by: Michael Ward * - *****************************************************************************/ -package org.codehaus.waffle.action.intercept; - -import org.codehaus.waffle.controller.ControllerDefinition; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Iterator; -import java.util.List; - -public class InterceptorChainImpl implements InterceptorChain { - private final Iterator<MethodInterceptor> iterator; - private Object returnValue; - - public InterceptorChainImpl(List<MethodInterceptor> interceptors) { - this.iterator = interceptors.iterator(); - } - - public Object proceed(ControllerDefinition controllerDefinition, - Method method, - Object... arguments) throws IllegalAccessException, InvocationTargetException { - if (iterator.hasNext()) { - MethodInterceptor methodInterceptor = iterator.next(); - if (methodInterceptor.accept(method)) { - returnValue = methodInterceptor.intercept(controllerDefinition, method, this, arguments); - } else { - return proceed(controllerDefinition, method, arguments); // recursive - } - } - - return returnValue; - } -}
Copied: trunk/core/src/test/java/org/codehaus/waffle/action/intercept/DefaultInterceptorChainTest.java (from rev 352, trunk/core/src/test/java/org/codehaus/waffle/action/intercept/InterceptorChainImplTest.java) (0 => 353)
--- trunk/core/src/test/java/org/codehaus/waffle/action/intercept/DefaultInterceptorChainTest.java (rev 0) +++ trunk/core/src/test/java/org/codehaus/waffle/action/intercept/DefaultInterceptorChainTest.java 2007-11-12 19:40:19 UTC (rev 353) @@ -0,0 +1,66 @@ +package org.codehaus.waffle.action.intercept; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +import org.codehaus.waffle.controller.ControllerDefinition; +import org.jmock.Expectations; +import org.jmock.Mockery; +import org.jmock.integration.junit4.JMock; +import org.junit.Test; +import org.junit.runner.RunWith; + [EMAIL PROTECTED](JMock.class) +public class DefaultInterceptorChainTest { + private final Mockery mockery = new Mockery(); + + @Test + public void canAcceptMethod() throws Exception { + final ControllerDefinition controllerDefinition = new ControllerDefinition(null, null, null); + final Method method = this.getClass().getMethods()[0]; + final Object argument = "foobar"; + + // Mock MethodInterceptor + final MethodInterceptor methodInterceptor = mockery.mock(MethodInterceptor.class); + mockery.checking(new Expectations() {{ + one (methodInterceptor).accept(method); + will(returnValue(true)); + one(methodInterceptor).intercept(with(same(controllerDefinition)), + with(same(method)), + with(any(InterceptorChain.class)), + with(equal(new Object[] {argument}))); + will(returnValue("hello")); + }}); + + List<MethodInterceptor> interceptors = new ArrayList<MethodInterceptor>(); + interceptors.add(methodInterceptor); + + InterceptorChain interceptorChain = new DefaultInterceptorChain(interceptors); + assertEquals("hello", interceptorChain.proceed(controllerDefinition, method, argument)); + } + + @Test + public void canRefuseMethod() throws Exception { + ControllerDefinition controllerDefinition = new ControllerDefinition(null, null, null); + final Method method = this.getClass().getMethods()[0]; + Object argument = "foobar"; + + // Mock MethodInterceptor + final MethodInterceptor methodInterceptor = mockery.mock(MethodInterceptor.class); + mockery.checking(new Expectations() {{ + one (methodInterceptor).accept(method); + will(returnValue(false)); + }}); + + List<MethodInterceptor> interceptors = new ArrayList<MethodInterceptor>(); + interceptors.add(methodInterceptor); + + DefaultInterceptorChain interceptorChain = new DefaultInterceptorChain(interceptors); + assertNull(interceptorChain.proceed(controllerDefinition, method, argument)); + } + +}
Deleted: trunk/core/src/test/java/org/codehaus/waffle/action/intercept/InterceptorChainImplTest.java (352 => 353)
--- trunk/core/src/test/java/org/codehaus/waffle/action/intercept/InterceptorChainImplTest.java 2007-11-12 19:38:05 UTC (rev 352) +++ trunk/core/src/test/java/org/codehaus/waffle/action/intercept/InterceptorChainImplTest.java 2007-11-12 19:40:19 UTC (rev 353) @@ -1,66 +0,0 @@ -package org.codehaus.waffle.action.intercept; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; - -import org.codehaus.waffle.controller.ControllerDefinition; -import org.jmock.Expectations; -import org.jmock.Mockery; -import org.jmock.integration.junit4.JMock; -import org.junit.Test; -import org.junit.runner.RunWith; - [EMAIL PROTECTED](JMock.class) -public class InterceptorChainImplTest { - private final Mockery mockery = new Mockery(); - - @Test - public void canAcceptMethod() throws Exception { - final ControllerDefinition controllerDefinition = new ControllerDefinition(null, null, null); - final Method method = this.getClass().getMethods()[0]; - final Object argument = "foobar"; - - // Mock MethodInterceptor - final MethodInterceptor methodInterceptor = mockery.mock(MethodInterceptor.class); - mockery.checking(new Expectations() {{ - one (methodInterceptor).accept(method); - will(returnValue(true)); - one(methodInterceptor).intercept(with(same(controllerDefinition)), - with(same(method)), - with(any(InterceptorChain.class)), - with(equal(new Object[] {argument}))); - will(returnValue("hello")); - }}); - - List<MethodInterceptor> interceptors = new ArrayList<MethodInterceptor>(); - interceptors.add(methodInterceptor); - - InterceptorChain interceptorChain = new InterceptorChainImpl(interceptors); - assertEquals("hello", interceptorChain.proceed(controllerDefinition, method, argument)); - } - - @Test - public void canRefuseMethod() throws Exception { - ControllerDefinition controllerDefinition = new ControllerDefinition(null, null, null); - final Method method = this.getClass().getMethods()[0]; - Object argument = "foobar"; - - // Mock MethodInterceptor - final MethodInterceptor methodInterceptor = mockery.mock(MethodInterceptor.class); - mockery.checking(new Expectations() {{ - one (methodInterceptor).accept(method); - will(returnValue(false)); - }}); - - List<MethodInterceptor> interceptors = new ArrayList<MethodInterceptor>(); - interceptors.add(methodInterceptor); - - InterceptorChainImpl interceptorChain = new InterceptorChainImpl(interceptors); - assertNull(interceptorChain.proceed(controllerDefinition, method, argument)); - } - -}
To unsubscribe from this list please visit:
