Title: [waffle-scm] [383] trunk/core/src/main/java/org/codehaus/waffle: Added ControllerMonitor.

Diff

Modified: trunk/core/src/main/java/org/codehaus/waffle/ComponentRegistry.java (382 => 383)

--- trunk/core/src/main/java/org/codehaus/waffle/ComponentRegistry.java	2007-11-15 17:07:11 UTC (rev 382)
+++ trunk/core/src/main/java/org/codehaus/waffle/ComponentRegistry.java	2007-11-15 17:27:08 UTC (rev 383)
@@ -27,6 +27,7 @@
 import org.codehaus.waffle.monitor.ActionMonitor;
 import org.codehaus.waffle.monitor.BindMonitor;
 import org.codehaus.waffle.monitor.ContextMonitor;
+import org.codehaus.waffle.monitor.ControllerMonitor;
 import org.codehaus.waffle.monitor.RegistrarMonitor;
 import org.codehaus.waffle.monitor.ServletMonitor;
 import org.codehaus.waffle.validation.Validator;
@@ -62,6 +63,8 @@
     
     ControllerDefinitionFactory getControllerDefinitionFactory();
 
+    ControllerMonitor getControllerMonitor();
+
     ControllerNameResolver getControllerNameResolver();
 
     DataBinder getDataBinder();

Modified: trunk/core/src/main/java/org/codehaus/waffle/context/pico/PicoComponentRegistry.java (382 => 383)

--- trunk/core/src/main/java/org/codehaus/waffle/context/pico/PicoComponentRegistry.java	2007-11-15 17:07:11 UTC (rev 382)
+++ trunk/core/src/main/java/org/codehaus/waffle/context/pico/PicoComponentRegistry.java	2007-11-15 17:27:08 UTC (rev 383)
@@ -45,6 +45,7 @@
 import org.codehaus.waffle.monitor.ActionMonitor;
 import org.codehaus.waffle.monitor.BindMonitor;
 import org.codehaus.waffle.monitor.ContextMonitor;
+import org.codehaus.waffle.monitor.ControllerMonitor;
 import org.codehaus.waffle.monitor.RegistrarMonitor;
 import org.codehaus.waffle.monitor.ServletMonitor;
 import org.codehaus.waffle.monitor.SilentMonitor;
@@ -87,6 +88,7 @@
         register(ContextContainerFactory.class, PicoContextContainerFactory.class, servletContext);
         register(ContextMonitor.class, SilentMonitor.class, servletContext);
         register(ControllerDefinitionFactory.class, ContextControllerDefinitionFactory.class, servletContext);
+        register(ControllerMonitor.class, SilentMonitor.class, servletContext);
         register(ControllerNameResolver.class, ContextPathControllerNameResolver.class, servletContext);
         register(MessageResources.class, DefaultMessageResources.class, servletContext);
         register(MethodDefinitionFinder.class, AnnotatedMethodDefinitionFinder.class, servletContext);
@@ -225,6 +227,10 @@
         return locateByType(ContextMonitor.class);
     }
 
+    public ControllerMonitor getControllerMonitor() {
+        return locateByType(ControllerMonitor.class);
+    }
+
     public ControllerNameResolver getControllerNameResolver() {
         return locateByType(ControllerNameResolver.class);
     }

Modified: trunk/core/src/main/java/org/codehaus/waffle/controller/ContextControllerDefinitionFactory.java (382 => 383)

--- trunk/core/src/main/java/org/codehaus/waffle/controller/ContextControllerDefinitionFactory.java	2007-11-15 17:07:11 UTC (rev 382)
+++ trunk/core/src/main/java/org/codehaus/waffle/controller/ContextControllerDefinitionFactory.java	2007-11-15 17:27:08 UTC (rev 383)
@@ -21,6 +21,7 @@
 import org.codehaus.waffle.action.MissingActionMethodException;
 import org.codehaus.waffle.context.ContextContainer;
 import org.codehaus.waffle.context.RequestLevelContainer;
+import org.codehaus.waffle.monitor.ControllerMonitor;
 
 /**
  * Implementation of the controller definition factory which uses the context container to look up the
@@ -32,10 +33,13 @@
 public class ContextControllerDefinitionFactory implements ControllerDefinitionFactory {
     private final MethodDefinitionFinder methodDefinitionFinder;
     private final ControllerNameResolver controllerNameResolver;
+    private final ControllerMonitor controllerMonitor;
 
-    public ContextControllerDefinitionFactory(MethodDefinitionFinder methodDefinitionFinder, ControllerNameResolver controllerNameResolver) {
+    public ContextControllerDefinitionFactory(MethodDefinitionFinder methodDefinitionFinder,
+            ControllerNameResolver controllerNameResolver, ControllerMonitor controllerMonitor) {
         this.methodDefinitionFinder = methodDefinitionFinder;
         this.controllerNameResolver = controllerNameResolver;
+        this.controllerMonitor = controllerMonitor;
     }
 
     /**
@@ -51,6 +55,7 @@
         try {
             methodDefinition = findMethodDefinition(controller, request, response);
         } catch ( MissingActionMethodException e) {
+            controllerMonitor.methodDefinitionNotFound(name);
             // default to null 
             // TODO introduce a NullMethodDefinition?
         }        
@@ -63,6 +68,7 @@
         ContextContainer requestLevelContainer = RequestLevelContainer.get();
 
         if (requestLevelContainer == null) {
+            controllerMonitor.requestContextContainerNotFound();
             String error = "No context container found at request level. "
                     + "Please ensure that a WaffleRequestFilter was registered in the web.xml";
             throw new WaffleException(error);
@@ -70,6 +76,7 @@
 
         Object controller = requestLevelContainer.getComponentInstance(name);
         if (controller == null) {
+            controllerMonitor.controllerNotFound(name);
             String error = "No controller configured for the specified path: '"
                     + request.getRequestURI() + "' (controller name='" + name + "') "
                     + "Please ensure that controller '" + name + "' was registered in the Registrar.";

Modified: trunk/core/src/main/java/org/codehaus/waffle/controller/ContextPathControllerNameResolver.java (382 => 383)

--- trunk/core/src/main/java/org/codehaus/waffle/controller/ContextPathControllerNameResolver.java	2007-11-15 17:07:11 UTC (rev 382)
+++ trunk/core/src/main/java/org/codehaus/waffle/controller/ContextPathControllerNameResolver.java	2007-11-15 17:27:08 UTC (rev 383)
@@ -12,6 +12,8 @@
 
 import javax.servlet.http.HttpServletRequest;
 
+import org.codehaus.waffle.monitor.ControllerMonitor;
+
 /**
  * Default implementations of name resolver which return the name of the last portion of the context path before the dot.
  * 
@@ -19,19 +21,23 @@
  */
 public class ContextPathControllerNameResolver implements ControllerNameResolver {
     private static final String DOT_REGEX = "\\.";
+    private final ControllerMonitor controllerMonitor;
 
-    public ContextPathControllerNameResolver() {
+    public ContextPathControllerNameResolver(ControllerMonitor controllerMonitor) {
+        this.controllerMonitor = controllerMonitor;
     }
 
     public String findControllerName(HttpServletRequest request) {
         String path = request.getPathInfo();
 
         if (path == null) {
-            path = request.getRequestURI().replaceFirst(request.getContextPath(), "");
+            path = request.getRequestURI().replaceFirst(request.getContextPath(), "");            
         }
 
         path = path.substring(1); // remove '/'
-        return path.split(DOT_REGEX)[0];
+        String name = path.split(DOT_REGEX)[0];
+        controllerMonitor.controllerNameResolved(name, path);
+        return name;
     }
 
 }

Modified: trunk/core/src/main/java/org/codehaus/waffle/controller/RubyControllerDefinitionFactory.java (382 => 383)

--- trunk/core/src/main/java/org/codehaus/waffle/controller/RubyControllerDefinitionFactory.java	2007-11-15 17:07:11 UTC (rev 382)
+++ trunk/core/src/main/java/org/codehaus/waffle/controller/RubyControllerDefinitionFactory.java	2007-11-15 17:27:08 UTC (rev 383)
@@ -1,15 +1,17 @@
 package org.codehaus.waffle.controller;
 
+import java.lang.reflect.Method;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
 import org.codehaus.waffle.WaffleException;
 import org.codehaus.waffle.action.MethodDefinition;
 import org.codehaus.waffle.action.MethodDefinitionFinder;
 import org.codehaus.waffle.action.MethodNameResolver;
+import org.codehaus.waffle.monitor.ControllerMonitor;
 import org.jruby.runtime.builtin.IRubyObject;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.lang.reflect.Method;
-
 public class RubyControllerDefinitionFactory extends ContextControllerDefinitionFactory {
     private final MethodNameResolver methodNameResolver;
     private static final Method executeMethod;
@@ -24,8 +26,8 @@
 
     public RubyControllerDefinitionFactory(MethodDefinitionFinder methodDefinitionFinder,
                                            ControllerNameResolver controllerNameResolver,
-                                           MethodNameResolver methodNameResolver) {
-        super(methodDefinitionFinder, controllerNameResolver);
+                                           MethodNameResolver methodNameResolver, ControllerMonitor controllerMonitor) {
+        super(methodDefinitionFinder, controllerNameResolver, controllerMonitor);
         this.methodNameResolver = methodNameResolver;
     }
 

Modified: trunk/core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java (382 => 383)

--- trunk/core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java	2007-11-15 17:07:11 UTC (rev 382)
+++ trunk/core/src/main/java/org/codehaus/waffle/monitor/AbstractWritingMonitor.java	2007-11-15 17:27:08 UTC (rev 383)
@@ -39,7 +39,7 @@
  * 
  * @author Mauro Talevi
  */
-public abstract class AbstractWritingMonitor implements ActionMonitor, BindMonitor, ContextMonitor, RegistrarMonitor, ServletMonitor {
+public abstract class AbstractWritingMonitor implements ActionMonitor, BindMonitor, ContextMonitor, ControllerMonitor, RegistrarMonitor, ServletMonitor {
 
     private Map<String, Level> levels;
     private Map<String, String> templates;
@@ -72,6 +72,10 @@
         levels.put("applicationContextContainerDestroyed", DEBUG);
         levels.put("sessionContextContainerCreated", DEBUG);
         levels.put("requestContextContainerCreated", DEBUG);
+        levels.put("controllerNameResolved", DEBUG);
+        levels.put("controllerNotFound", WARN);
+        levels.put("methodDefinitionNotFound", WARN);
+        levels.put("requestContextContainerNotFound", WARN);
         levels.put("componentRegistered", DEBUG);
         levels.put("instanceRegistered", DEBUG);
         levels.put("nonCachingComponentRegistered", DEBUG);
@@ -102,6 +106,10 @@
         templates.put("applicationContextContainerDestroyed", "Application context container destroyed");
         templates.put("sessionContextContainerCreated", "Session context container created with parent application container {0}");
         templates.put("requestContextContainerCreated", "Request context container created with parent session container {0}");
+        templates.put("controllerNameResolved", "Controller name resolved to {0} from path {1}");        
+        templates.put("controllerNotFound", "Controller not found for name {0}");
+        templates.put("methodDefinitionNotFound", "Method definition not found for controller name {0}");
+        templates.put("requestContextContainerNotFound", "Request level context container not found");
         templates.put("componentRegistered", "Registered component of type {1} with key {0} and parameters {2}");
         templates.put("instanceRegistered", "Registered instance {1} with key {0}");
         templates.put("nonCachingComponentRegistered", "Registered non-caching component of type {1} with key {0} and parameters {2}");
@@ -225,6 +233,22 @@
         write("requestContextContainerCreated", sessionContextContainer);                                
     }
 
+    public void controllerNameResolved(String name, String path) {
+        write("controllerNameResolved", name, path);        
+    }
+    
+    public void controllerNotFound(String name){
+        write("controllerNotFound", name);                
+    }
+
+    public void methodDefinitionNotFound(String controllerName){
+        write("methodDefinitionNotFound", controllerName);                
+    }
+
+    public void requestContextContainerNotFound(){
+        write("requestContextContainerNotFound");                        
+    }
+
     public void componentRegistered(Object key, Class<?> type, Object[] parameters) {
         write("componentRegistered", key, type, asList(parameters));
     }

Added: trunk/core/src/main/java/org/codehaus/waffle/monitor/ControllerMonitor.java (0 => 383)

--- trunk/core/src/main/java/org/codehaus/waffle/monitor/ControllerMonitor.java	                        (rev 0)
+++ trunk/core/src/main/java/org/codehaus/waffle/monitor/ControllerMonitor.java	2007-11-15 17:27:08 UTC (rev 383)
@@ -0,0 +1,29 @@
+/*****************************************************************************
+ * 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: Mauro Talevi                                            *
+ *****************************************************************************/
+package org.codehaus.waffle.monitor;
+
+
+/**
+ * A monitor for controller-related events
+ * 
+ * @author Mauro Talevi
+ */
+public interface ControllerMonitor extends Monitor {
+
+    void controllerNameResolved(String name, String path);
+
+    void controllerNotFound(String name);
+
+    void methodDefinitionNotFound(String controllerName);
+
+    void requestContextContainerNotFound();
+
+}

Modified: trunk/core/src/test/java/org/codehaus/waffle/context/pico/PicoComponentRegistryTest.java (382 => 383)

--- trunk/core/src/test/java/org/codehaus/waffle/context/pico/PicoComponentRegistryTest.java	2007-11-15 17:07:11 UTC (rev 382)
+++ trunk/core/src/test/java/org/codehaus/waffle/context/pico/PicoComponentRegistryTest.java	2007-11-15 17:27:08 UTC (rev 383)
@@ -46,6 +46,7 @@
 import org.codehaus.waffle.monitor.ActionMonitor;
 import org.codehaus.waffle.monitor.BindMonitor;
 import org.codehaus.waffle.monitor.ContextMonitor;
+import org.codehaus.waffle.monitor.ControllerMonitor;
 import org.codehaus.waffle.monitor.RegistrarMonitor;
 import org.codehaus.waffle.monitor.ServletMonitor;
 import org.codehaus.waffle.testmodel.StubActionMethodExecutor;
@@ -130,7 +131,7 @@
             {
                 one(servletContext).getInitParameterNames();
                 will(returnValue(EMPTY_ENUMERATION));
-                exactly(21).of(servletContext).getInitParameter(with(any(String.class)));
+                exactly(22).of(servletContext).getInitParameter(with(any(String.class)));
             }
         });
 
@@ -143,6 +144,7 @@
         assertTrue(componentRegistry.getBindMonitor() instanceof AbstractWritingMonitor);
         assertTrue(componentRegistry.getContextContainerFactory() instanceof AbstractContextContainerFactory);
         assertTrue(componentRegistry.getContextMonitor() instanceof AbstractWritingMonitor);
+        assertTrue(componentRegistry.getControllerMonitor() instanceof AbstractWritingMonitor);
         assertTrue(componentRegistry.getControllerNameResolver() instanceof ContextPathControllerNameResolver);
         assertTrue(componentRegistry.getControllerDefinitionFactory() instanceof ContextControllerDefinitionFactory);
         assertTrue(componentRegistry.getDataBinder() instanceof OgnlDataBinder);
@@ -190,6 +192,8 @@
                 will(returnValue(StubMonitor.class.getName()));
                 one(servletContext).getInitParameter(ControllerDefinitionFactory.class.getName());
                 will(returnValue(StubControllerDefinitionFactory.class.getName()));
+                one(servletContext).getInitParameter(ControllerMonitor.class.getName());
+                will(returnValue(StubMonitor.class.getName()));
                 one(servletContext).getInitParameter(ControllerNameResolver.class.getName());
                 will(returnValue(StubControllerNameResolver.class.getName()));
                 one(servletContext).getInitParameter(DataBinder.class.getName());

Modified: trunk/core/src/test/java/org/codehaus/waffle/controller/ContextControllerDefinitionFactoryTest.java (382 => 383)

--- trunk/core/src/test/java/org/codehaus/waffle/controller/ContextControllerDefinitionFactoryTest.java	2007-11-15 17:07:11 UTC (rev 382)
+++ trunk/core/src/test/java/org/codehaus/waffle/controller/ContextControllerDefinitionFactoryTest.java	2007-11-15 17:27:08 UTC (rev 383)
@@ -12,6 +12,7 @@
 import org.codehaus.waffle.action.MethodDefinitionFinder;
 import org.codehaus.waffle.context.RequestLevelContainer;
 import org.codehaus.waffle.context.pico.PicoContextContainer;
+import org.codehaus.waffle.monitor.SilentMonitor;
 import org.codehaus.waffle.testmodel.FakeController;
 import org.jmock.Expectations;
 import org.jmock.Mockery;
@@ -62,7 +63,7 @@
         });
 
         ControllerDefinitionFactory controllerDefinitionFactory = new ContextControllerDefinitionFactory(finder,
-                new ContextPathControllerNameResolver());
+                new ContextPathControllerNameResolver(new SilentMonitor()), new SilentMonitor());
         ControllerDefinition controllerDefinition = controllerDefinitionFactory.getControllerDefinition(request,
                 response);
 
@@ -93,7 +94,7 @@
         final MethodDefinitionFinder finder = mockery.mock(MethodDefinitionFinder.class);
 
         ControllerDefinitionFactory controllerDefinitionFactory = new ContextControllerDefinitionFactory(finder,
-                new ContextPathControllerNameResolver());
+                new ContextPathControllerNameResolver(new SilentMonitor()), new SilentMonitor());
 
         controllerDefinitionFactory.getControllerDefinition(request, response);
     }
@@ -107,7 +108,7 @@
         final HttpServletRequest request = mockery.mock(HttpServletRequest.class);
 
         ContextControllerDefinitionFactory controllerDefinitionFactory = new ContextControllerDefinitionFactory(null,
-                null);
+                null, new SilentMonitor());
 
         controllerDefinitionFactory.findController("foobar", request);
     }

Modified: trunk/core/src/test/java/org/codehaus/waffle/controller/ContextPathControllerNameResolverTest.java (382 => 383)

--- trunk/core/src/test/java/org/codehaus/waffle/controller/ContextPathControllerNameResolverTest.java	2007-11-15 17:07:11 UTC (rev 382)
+++ trunk/core/src/test/java/org/codehaus/waffle/controller/ContextPathControllerNameResolverTest.java	2007-11-15 17:27:08 UTC (rev 383)
@@ -4,6 +4,7 @@
 
 import javax.servlet.http.HttpServletRequest;
 
+import org.codehaus.waffle.monitor.SilentMonitor;
 import org.jmock.Expectations;
 import org.jmock.Mockery;
 import org.jmock.integration.junit4.JMock;
@@ -31,7 +32,7 @@
             }
         });
 
-        ControllerNameResolver controllerNameResolver = new ContextPathControllerNameResolver();
+        ControllerNameResolver controllerNameResolver = new ContextPathControllerNameResolver(new SilentMonitor());
         assertEquals("foo/bar", controllerNameResolver.findControllerName(request));
     }
 
@@ -46,7 +47,7 @@
             }
         });
 
-        ControllerNameResolver controllerNameResolver = new ContextPathControllerNameResolver();
+        ControllerNameResolver controllerNameResolver = new ContextPathControllerNameResolver(new SilentMonitor());
         assertEquals("foobar", controllerNameResolver.findControllerName(request));
     }
 
@@ -65,7 +66,7 @@
             }
         });
 
-        ControllerNameResolver controllerNameResolver = new ContextPathControllerNameResolver();
+        ControllerNameResolver controllerNameResolver = new ContextPathControllerNameResolver(new SilentMonitor());
         assertEquals("foobar", controllerNameResolver.findControllerName(request));
     }
 }

Modified: trunk/core/src/test/java/org/codehaus/waffle/controller/RubyControllerDefinitionFactoryTest.java (382 => 383)

--- trunk/core/src/test/java/org/codehaus/waffle/controller/RubyControllerDefinitionFactoryTest.java	2007-11-15 17:07:11 UTC (rev 382)
+++ trunk/core/src/test/java/org/codehaus/waffle/controller/RubyControllerDefinitionFactoryTest.java	2007-11-15 17:27:08 UTC (rev 383)
@@ -6,6 +6,7 @@
 
 import org.codehaus.waffle.context.ContextContainer;
 import org.codehaus.waffle.context.RequestLevelContainer;
+import org.codehaus.waffle.monitor.SilentMonitor;
 import org.jmock.Expectations;
 import org.jmock.Mockery;
 import org.jmock.integration.junit4.JMock;
@@ -28,7 +29,7 @@
 
     @Test
     public void canHandleIRubyObject() {
-        RubyControllerDefinitionFactory factory = new RubyControllerDefinitionFactory(null, null, null);
+        RubyControllerDefinitionFactory factory = new RubyControllerDefinitionFactory(null, null, null, new SilentMonitor());
 
         final ContextContainer contextContainer = mockery.mock(ContextContainer.class);
         mockery.checking(new Expectations() {
@@ -46,7 +47,7 @@
 
     @Test
     public void canHandleNonRubyObjects() {
-        RubyControllerDefinitionFactory factory = new RubyControllerDefinitionFactory(null, null, null);
+        RubyControllerDefinitionFactory factory = new RubyControllerDefinitionFactory(null, null, null, new SilentMonitor());
 
         final ContextContainer contextContainer = mockery.mock(ContextContainer.class);
         mockery.checking(new Expectations() {

Modified: trunk/core/src/test/java/org/codehaus/waffle/testmodel/StubMonitor.java (382 => 383)

--- trunk/core/src/test/java/org/codehaus/waffle/testmodel/StubMonitor.java	2007-11-15 17:07:11 UTC (rev 382)
+++ trunk/core/src/test/java/org/codehaus/waffle/testmodel/StubMonitor.java	2007-11-15 17:27:08 UTC (rev 383)
@@ -12,13 +12,14 @@
 import org.codehaus.waffle.monitor.ActionMonitor;
 import org.codehaus.waffle.monitor.BindMonitor;
 import org.codehaus.waffle.monitor.ContextMonitor;
+import org.codehaus.waffle.monitor.ControllerMonitor;
 import org.codehaus.waffle.monitor.RegistrarMonitor;
 import org.codehaus.waffle.monitor.ServletMonitor;
 import org.codehaus.waffle.registrar.Registrar;
 import org.codehaus.waffle.validation.BindErrorMessage;
 import org.codehaus.waffle.view.View;
 
-public class StubMonitor implements ActionMonitor, BindMonitor, ContextMonitor, RegistrarMonitor, ServletMonitor {
+public class StubMonitor implements ActionMonitor, BindMonitor, ContextMonitor, ControllerMonitor, RegistrarMonitor, ServletMonitor {
 
     public void defaultActionMethodFound(MethodDefinition methodDefinition) {
     }
@@ -83,6 +84,18 @@
     public void sessionContextContainerCreated(ContextContainer applicationContextContainer) {
     }
 
+    public void controllerNameResolved(String name, String path) {        
+    }
+
+    public void controllerNotFound(String name) {
+    }
+
+    public void methodDefinitionNotFound(String controllerName) {
+    }
+
+    public void requestContextContainerNotFound() {
+    }
+
     public void componentRegistered(Object key, Class<?> clazz, Object[] parameters) {
     }
 
@@ -95,4 +108,5 @@
     public void servletServiceFailed(Exception cause) {
     }
 
+
 }


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to