- Revision
- 243
- Author
- mauro
- Date
- 2007-07-09 07:59:19 -0500 (Mon, 09 Jul 2007)
Log Message
Refactored PicoComponentRegistry to use registration keys of type Object, although only Class or String keys can be used to locate component class implementations specified in the servlet context.
Modified Paths
Diff
Modified: trunk/core/src/main/java/org/codehaus/waffle/context/pico/PicoComponentRegistry.java (242 => 243)
--- trunk/core/src/main/java/org/codehaus/waffle/context/pico/PicoComponentRegistry.java 2007-07-09 12:32:59 UTC (rev 242) +++ trunk/core/src/main/java/org/codehaus/waffle/context/pico/PicoComponentRegistry.java 2007-07-09 12:59:19 UTC (rev 243) @@ -133,13 +133,22 @@ * </context-param> * </code> * - * @param key represents the interface Class which the implementation should be registered under. + * @param key represents the component key which the implementation should be registered under. * @param defaultClass represents the Class to use by default (when not over-written). * @param servletContext required to obtain the InitParameter defined for the web application. * @throws WaffleException */ - protected static Class<?> locateComponentClass(Class<?> key, Class<?> defaultClass, ServletContext servletContext) throws WaffleException { - String className = servletContext.getInitParameter(key.getName()); + protected static Class<?> locateComponentClass(Object key, Class<?> defaultClass, ServletContext servletContext) throws WaffleException { + String parameterName = null; + if ( key instanceof Class ){ + parameterName = ((Class<?>)key).getName(); + } else if ( key instanceof String ){ + parameterName = (String) key; + } else { + return defaultClass; + } + + String className = servletContext.getInitParameter(parameterName); if (className == null || className.equals("")) { return defaultClass; @@ -165,7 +174,7 @@ /** * Register the correct class to the underlying container */ - private void register(Class<?> key, Class<?> defaultClass, ServletContext servletContext) throws WaffleException { + private void register(Object key, Class<?> defaultClass, ServletContext servletContext) throws WaffleException { Class<?> actualClass = locateComponentClass(key, defaultClass, servletContext); picoContainer.registerComponentImplementation(key, actualClass); }
To unsubscribe from this list please visit:
