Revision: 1000
          http://stripes.svn.sourceforge.net/stripes/?rev=1000&view=rev
Author:   bengunter
Date:     2008-11-07 01:03:49 +0000 (Fri, 07 Nov 2008)

Log Message:
-----------
More work on STS-614. ObjectFactory is now an interface in the .controller 
package with a DefaultObjectFactory implementation. It is a first-class 
configurable object with a getter in the Configuration interface. Most of the 
spots where we were calling Class.newInstance() have been replaced with a call 
to ObjectFactory.newInstance(Class).

Modified Paths:
--------------
    trunk/stripes/src/net/sourceforge/stripes/config/Configuration.java
    trunk/stripes/src/net/sourceforge/stripes/config/DefaultConfiguration.java
    trunk/stripes/src/net/sourceforge/stripes/config/RuntimeConfiguration.java
    
trunk/stripes/src/net/sourceforge/stripes/controller/AnnotatedClassActionResolver.java
    
trunk/stripes/src/net/sourceforge/stripes/controller/DefaultActionBeanContextFactory.java
    
trunk/stripes/src/net/sourceforge/stripes/controller/DefaultActionBeanPropertyBinder.java
    
trunk/stripes/src/net/sourceforge/stripes/controller/multipart/DefaultMultipartWrapperFactory.java
    
trunk/stripes/src/net/sourceforge/stripes/exception/DefaultExceptionHandler.java
    
trunk/stripes/src/net/sourceforge/stripes/format/DefaultFormatterFactory.java
    
trunk/stripes/src/net/sourceforge/stripes/tag/DefaultTagErrorRendererFactory.java
    trunk/stripes/src/net/sourceforge/stripes/tag/FieldMetadataTag.java
    trunk/stripes/src/net/sourceforge/stripes/util/ReflectUtil.java
    
trunk/stripes/src/net/sourceforge/stripes/util/bean/PropertyExpressionEvaluation.java
    
trunk/stripes/src/net/sourceforge/stripes/validation/DefaultTypeConverterFactory.java
    trunk/tests/src/net/sourceforge/stripes/StripesTestFixture.java
    
trunk/tests/src/net/sourceforge/stripes/format/DefaultFormatterFactoryTest.java
    
trunk/tests/src/net/sourceforge/stripes/validation/DefaultTypeConverterFactoryTest.java

Added Paths:
-----------
    
trunk/stripes/src/net/sourceforge/stripes/controller/DefaultObjectFactory.java
    trunk/stripes/src/net/sourceforge/stripes/controller/ObjectFactory.java

Removed Paths:
-------------
    trunk/stripes/src/net/sourceforge/stripes/util/ObjectFactory.java

Modified: trunk/stripes/src/net/sourceforge/stripes/config/Configuration.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/config/Configuration.java 
2008-11-06 00:39:33 UTC (rev 999)
+++ trunk/stripes/src/net/sourceforge/stripes/config/Configuration.java 
2008-11-07 01:03:49 UTC (rev 1000)
@@ -17,6 +17,7 @@
 import net.sourceforge.stripes.controller.ActionBeanPropertyBinder;
 import net.sourceforge.stripes.controller.ActionResolver;
 import net.sourceforge.stripes.controller.ActionBeanContextFactory;
+import net.sourceforge.stripes.controller.ObjectFactory;
 import net.sourceforge.stripes.localization.LocalizationBundleFactory;
 import net.sourceforge.stripes.localization.LocalePicker;
 import net.sourceforge.stripes.validation.TypeConverterFactory;
@@ -86,6 +87,14 @@
     boolean isDebugMode();
 
     /**
+     * Returns an instance of [EMAIL PROTECTED] ObjectFactory} that is used 
throughout Stripes to instantiate
+     * classes.
+     * 
+     * @return an instance of [EMAIL PROTECTED] ObjectFactory}.
+     */
+    ObjectFactory getObjectFactory();
+
+    /**
      * Returns an instance of ActionResolver that will be used by Stripes to 
lookup and resolve
      * ActionBeans.  The instance should be cached by the Configuration since 
multiple entities
      * in the system may access the ActionResolver throughout the lifetime of 
the application.

Modified: 
trunk/stripes/src/net/sourceforge/stripes/config/DefaultConfiguration.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/config/DefaultConfiguration.java  
2008-11-06 00:39:33 UTC (rev 999)
+++ trunk/stripes/src/net/sourceforge/stripes/config/DefaultConfiguration.java  
2008-11-07 01:03:49 UTC (rev 1000)
@@ -30,11 +30,13 @@
 import net.sourceforge.stripes.controller.BeforeAfterMethodInterceptor;
 import net.sourceforge.stripes.controller.DefaultActionBeanContextFactory;
 import net.sourceforge.stripes.controller.DefaultActionBeanPropertyBinder;
+import net.sourceforge.stripes.controller.DefaultObjectFactory;
 import net.sourceforge.stripes.controller.HttpCacheInterceptor;
 import net.sourceforge.stripes.controller.Interceptor;
 import net.sourceforge.stripes.controller.Intercepts;
 import net.sourceforge.stripes.controller.LifecycleStage;
 import net.sourceforge.stripes.controller.NameBasedActionResolver;
+import net.sourceforge.stripes.controller.ObjectFactory;
 import 
net.sourceforge.stripes.controller.multipart.DefaultMultipartWrapperFactory;
 import net.sourceforge.stripes.controller.multipart.MultipartWrapperFactory;
 import net.sourceforge.stripes.exception.DefaultExceptionHandler;
@@ -82,6 +84,7 @@
 
     private boolean debugMode;
     private BootstrapPropertyResolver resolver;
+    private ObjectFactory objectFactory;
     private ActionResolver actionResolver;
     private ActionBeanPropertyBinder actionBeanPropertyBinder;
     private ActionBeanContextFactory actionBeanContextFactory;
@@ -115,6 +118,12 @@
                 this.debugMode = false;
             }
 
+            this.objectFactory = initObjectFactory();
+            if (this.objectFactory == null) {
+                this.objectFactory = new DefaultObjectFactory();
+                this.objectFactory.init(this);
+            }
+
             this.actionResolver = initActionResolver();
             if (this.actionResolver == null) {
                 this.actionResolver = new NameBasedActionResolver();
@@ -253,6 +262,19 @@
        }
 
     /**
+     * Returns an instance of [EMAIL PROTECTED] ObjectFactory} that is used 
throughout Stripes to instantiate
+     * classes.
+     * 
+     * @return an instance of [EMAIL PROTECTED] ObjectFactory}.
+     */
+    public ObjectFactory getObjectFactory() {
+        return this.objectFactory;
+    }
+
+    /** Allows subclasses to initialize a non-default [EMAIL PROTECTED] 
ObjectFactory}. */
+    protected ObjectFactory initObjectFactory() { return null; }
+
+    /**
      * Returns an instance of [EMAIL PROTECTED] NameBasedActionResolver} 
unless a subclass has
      * overridden the default.
      * @return ActionResolver an instance of the configured resolver

Modified: 
trunk/stripes/src/net/sourceforge/stripes/config/RuntimeConfiguration.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/config/RuntimeConfiguration.java  
2008-11-06 00:39:33 UTC (rev 999)
+++ trunk/stripes/src/net/sourceforge/stripes/config/RuntimeConfiguration.java  
2008-11-07 01:03:49 UTC (rev 1000)
@@ -25,6 +25,7 @@
 import net.sourceforge.stripes.controller.ActionResolver;
 import net.sourceforge.stripes.controller.Interceptor;
 import net.sourceforge.stripes.controller.LifecycleStage;
+import net.sourceforge.stripes.controller.ObjectFactory;
 import net.sourceforge.stripes.controller.multipart.MultipartWrapperFactory;
 import net.sourceforge.stripes.exception.ExceptionHandler;
 import net.sourceforge.stripes.exception.StripesRuntimeException;
@@ -62,6 +63,9 @@
     /** The Configuration Key for enabling debug mode. */
     public static final String DEBUG_MODE = "Stripes.DebugMode";
 
+    /** The Configuration Key for looking up the name of the ObjectFactory 
class */
+    public static final String OBJECT_FACTORY = "ObjectFactory.Class";
+
     /** The Configuration Key for looking up the name of the ActionResolver 
class. */
     public static final String ACTION_RESOLVER = "ActionResolver.Class";
 
@@ -116,6 +120,11 @@
     }
 
     /** Looks for a class name in config and uses that to create the 
component. */
+    @Override protected ObjectFactory initObjectFactory() {
+        return initializeComponent(ObjectFactory.class, OBJECT_FACTORY);
+    }
+
+    /** Looks for a class name in config and uses that to create the 
component. */
     @Override protected ActionResolver initActionResolver() {
         return initializeComponent(ActionResolver.class, ACTION_RESOLVER);
     }
@@ -219,7 +228,8 @@
 
         for (Object type : classes) {
             try {
-                Interceptor interceptor = (Interceptor) ((Class) 
type).newInstance();
+                Interceptor interceptor = getObjectFactory().newInstance(
+                        (Class<? extends Interceptor>) type);
                 addInterceptor(map, interceptor);
             }
             catch (Exception e) {
@@ -245,7 +255,16 @@
         Class clazz = 
getBootstrapPropertyResolver().getClassProperty(propertyName, componentType);
         if (clazz != null) {
             try {
-                T component = (T) clazz.newInstance();
+                T component;
+
+                ObjectFactory objectFactory = getObjectFactory();
+                if (objectFactory != null) {
+                    component = objectFactory.newInstance((Class<T>) clazz);
+                }
+                else {
+                    component = (T) clazz.newInstance();
+                }
+
                 component.init(this);
                 return component;
             }

Modified: 
trunk/stripes/src/net/sourceforge/stripes/controller/AnnotatedClassActionResolver.java
===================================================================
--- 
trunk/stripes/src/net/sourceforge/stripes/controller/AnnotatedClassActionResolver.java
      2008-11-06 00:39:33 UTC (rev 999)
+++ 
trunk/stripes/src/net/sourceforge/stripes/controller/AnnotatedClassActionResolver.java
      2008-11-07 01:03:49 UTC (rev 1000)
@@ -415,7 +415,7 @@
     protected ActionBean makeNewActionBean(Class<? extends ActionBean> type, 
ActionBeanContext context)
         throws Exception {
 
-        return type.newInstance();
+        return getConfiguration().getObjectFactory().newInstance(type);
     }
 
 

Modified: 
trunk/stripes/src/net/sourceforge/stripes/controller/DefaultActionBeanContextFactory.java
===================================================================
--- 
trunk/stripes/src/net/sourceforge/stripes/controller/DefaultActionBeanContextFactory.java
   2008-11-06 00:39:33 UTC (rev 999)
+++ 
trunk/stripes/src/net/sourceforge/stripes/controller/DefaultActionBeanContextFactory.java
   2008-11-07 01:03:49 UTC (rev 1000)
@@ -64,7 +64,8 @@
     public ActionBeanContext getContextInstance(HttpServletRequest request,
                                                 HttpServletResponse response) 
throws ServletException {
         try {
-            ActionBeanContext context = this.contextClass.newInstance();
+            ActionBeanContext context = 
getConfiguration().getObjectFactory().newInstance(
+                    this.contextClass);
             context.setRequest(request);
             context.setResponse(response);
             return context;

Modified: 
trunk/stripes/src/net/sourceforge/stripes/controller/DefaultActionBeanPropertyBinder.java
===================================================================
--- 
trunk/stripes/src/net/sourceforge/stripes/controller/DefaultActionBeanPropertyBinder.java
   2008-11-06 00:39:33 UTC (rev 999)
+++ 
trunk/stripes/src/net/sourceforge/stripes/controller/DefaultActionBeanPropertyBinder.java
   2008-11-07 01:03:49 UTC (rev 1000)
@@ -380,7 +380,8 @@
                 collection = (Collection) 
ReflectUtil.getInterfaceInstance(targetType);
             }
             else {
-                collection = (Collection) targetType.newInstance();
+                collection = getConfiguration().getObjectFactory().newInstance(
+                        (Class<? extends Collection>) targetType);
             }
 
             collection.addAll(valueOrValues);

Copied: 
trunk/stripes/src/net/sourceforge/stripes/controller/DefaultObjectFactory.java 
(from rev 997, 
trunk/stripes/src/net/sourceforge/stripes/util/ObjectFactory.java)
===================================================================
--- 
trunk/stripes/src/net/sourceforge/stripes/controller/DefaultObjectFactory.java  
                            (rev 0)
+++ 
trunk/stripes/src/net/sourceforge/stripes/controller/DefaultObjectFactory.java  
    2008-11-07 01:03:49 UTC (rev 1000)
@@ -0,0 +1,59 @@
+/* Copyright 2008 Ben Gunter
+ *
+ * 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 net.sourceforge.stripes.controller;
+
+import net.sourceforge.stripes.config.Configuration;
+import net.sourceforge.stripes.exception.StripesRuntimeException;
+
+/**
+ * <p>
+ * An implementation of [EMAIL PROTECTED] ObjectFactory} that simply calls 
[EMAIL PROTECTED] Class#newInstance()} to
+ * obtain a new instance.
+ * </p>
+ * 
+ * @author Ben Gunter
+ * @since Stripes 1.5.1
+ */
+public class DefaultObjectFactory implements ObjectFactory {
+    private Configuration configuration;
+
+    /** Does nothing. */
+    public void init(Configuration configuration) throws Exception {
+        this.configuration = configuration;
+    }
+
+    /** Get the [EMAIL PROTECTED] Configuration} that was passed into [EMAIL 
PROTECTED] #init(Configuration)}. */
+    protected Configuration getConfiguration() {
+        return configuration;
+    }
+
+    /**
+     * Calls [EMAIL PROTECTED] Class#newInstance()} and returns the newly 
created object.
+     * 
+     * @param clazz The class to instantiate.
+     * @return The new object
+     */
+    public <T> T newInstance(Class<T> clazz) {
+        try {
+            return clazz.newInstance();
+        }
+        catch (InstantiationException e) {
+            throw new StripesRuntimeException("Could not instantiate " + 
clazz, e);
+        }
+        catch (IllegalAccessException e) {
+            throw new StripesRuntimeException("Could not instantiate " + 
clazz, e);
+        }
+    }
+}


Property changes on: 
trunk/stripes/src/net/sourceforge/stripes/controller/DefaultObjectFactory.java
___________________________________________________________________
Added: svn:mergeinfo
   + 

Copied: trunk/stripes/src/net/sourceforge/stripes/controller/ObjectFactory.java 
(from rev 997, 
trunk/stripes/src/net/sourceforge/stripes/util/ObjectFactory.java)
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/controller/ObjectFactory.java     
                        (rev 0)
+++ trunk/stripes/src/net/sourceforge/stripes/controller/ObjectFactory.java     
2008-11-07 01:03:49 UTC (rev 1000)
@@ -0,0 +1,43 @@
+/* Copyright 2008 Ben Gunter
+ *
+ * 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 net.sourceforge.stripes.controller;
+
+import net.sourceforge.stripes.config.ConfigurableComponent;
+
+/**
+ * Used throughout Stripes to instantiate classes. The default implementation 
is
+ * [EMAIL PROTECTED] DefaultObjectFactory}. You can specify an alternate 
implementation to use by setting the
+ * [EMAIL PROTECTED] ObjectFactory.Class} initialization parameter for [EMAIL 
PROTECTED] StripesFilter} or by placing your
+ * implementation in one of the packages named in [EMAIL PROTECTED] 
Extension.Packages}.
+ * 
+ * <pre>
+ * &lt;init-param&gt;
+ *  &lt;param-name&gt;ObjectFactory.Class&lt;/param-name&gt;
+ *  
&lt;param-value&gt;com.mycompany.stripes.ext.MyObjectFactory&lt;/param-value&gt;
+ * &lt;/init-param&gt;
+ * </pre>
+ * 
+ * @author Ben Gunter
+ * @since Stripes 1.5.1
+ */
+public interface ObjectFactory extends ConfigurableComponent {
+    /**
+     * Create a new instance of [EMAIL PROTECTED] clazz} and return it.
+     * 
+     * @param clazz The class to instantiate.
+     * @return A new instances of the class.
+     */
+    <T> T newInstance(Class<T> clazz);
+}
\ No newline at end of file


Property changes on: 
trunk/stripes/src/net/sourceforge/stripes/controller/ObjectFactory.java
___________________________________________________________________
Added: svn:mergeinfo
   + 

Modified: 
trunk/stripes/src/net/sourceforge/stripes/controller/multipart/DefaultMultipartWrapperFactory.java
===================================================================
--- 
trunk/stripes/src/net/sourceforge/stripes/controller/multipart/DefaultMultipartWrapperFactory.java
  2008-11-06 00:39:33 UTC (rev 999)
+++ 
trunk/stripes/src/net/sourceforge/stripes/controller/multipart/DefaultMultipartWrapperFactory.java
  2008-11-07 01:03:49 UTC (rev 1000)
@@ -49,10 +49,16 @@
     private static final Log log = 
Log.getInstance(DefaultMultipartWrapperFactory.class);
 
     // Instance level fields
+    private Configuration configuration;
     private Class<? extends MultipartWrapper> multipartClass;
     private long maxPostSizeInBytes = 1024 * 1024 * 10; // Defaults to 10MB
     private File temporaryDirectory;
 
+    /** Get the configuration object that was passed into [EMAIL PROTECTED] 
#init(Configuration)}. */
+    protected Configuration getConfiguration() {
+        return configuration;
+    }
+
     /**
      * Invoked directly after instantiation to allow the configured component 
to perform one time
      * initialization.  Components are expected to fail loudly if they are not 
going to be in a
@@ -63,6 +69,8 @@
      */
     @SuppressWarnings("unchecked")
        public void init(Configuration config) throws Exception {
+        this.configuration = config;
+
         // Determine which class we're using
         this.multipartClass = 
config.getBootstrapPropertyResolver().getClassProperty(WRAPPER_CLASS_NAME, 
MultipartWrapper.class);
         
@@ -139,7 +147,8 @@
      */
     public MultipartWrapper wrap(HttpServletRequest request) throws 
IOException, FileUploadLimitExceededException {
         try {
-            MultipartWrapper wrapper = this.multipartClass.newInstance();
+            MultipartWrapper wrapper = 
getConfiguration().getObjectFactory().newInstance(
+                    this.multipartClass);
             wrapper.build(request, this.temporaryDirectory, 
this.maxPostSizeInBytes);
             return wrapper;
         }

Modified: 
trunk/stripes/src/net/sourceforge/stripes/exception/DefaultExceptionHandler.java
===================================================================
--- 
trunk/stripes/src/net/sourceforge/stripes/exception/DefaultExceptionHandler.java
    2008-11-06 00:39:33 UTC (rev 999)
+++ 
trunk/stripes/src/net/sourceforge/stripes/exception/DefaultExceptionHandler.java
    2008-11-07 01:03:49 UTC (rev 1000)
@@ -335,7 +335,7 @@
      * @throws Exception if the handler class cannot be instantiated
      */
     protected void addHandler(Class<?> handlerClass) throws Exception {
-        addHandler(handlerClass.newInstance());
+        
addHandler(getConfiguration().getObjectFactory().newInstance(handlerClass));
     }
 
     /**

Modified: 
trunk/stripes/src/net/sourceforge/stripes/format/DefaultFormatterFactory.java
===================================================================
--- 
trunk/stripes/src/net/sourceforge/stripes/format/DefaultFormatterFactory.java   
    2008-11-06 00:39:33 UTC (rev 999)
+++ 
trunk/stripes/src/net/sourceforge/stripes/format/DefaultFormatterFactory.java   
    2008-11-07 01:03:49 UTC (rev 1000)
@@ -231,7 +231,7 @@
             String formatType, String formatPattern, Locale locale)
             throws Exception {
 
-        Formatter<?> formatter = clazz.newInstance();
+        Formatter<?> formatter = 
getConfiguration().getObjectFactory().newInstance(clazz);
         formatter.setFormatType(formatType);
         formatter.setFormatPattern(formatPattern);
         formatter.setLocale(locale);

Modified: 
trunk/stripes/src/net/sourceforge/stripes/tag/DefaultTagErrorRendererFactory.java
===================================================================
--- 
trunk/stripes/src/net/sourceforge/stripes/tag/DefaultTagErrorRendererFactory.java
   2008-11-06 00:39:33 UTC (rev 999)
+++ 
trunk/stripes/src/net/sourceforge/stripes/tag/DefaultTagErrorRendererFactory.java
   2008-11-07 01:03:49 UTC (rev 1000)
@@ -65,7 +65,8 @@
      */
     public TagErrorRenderer getTagErrorRenderer(InputTagSupport tag) {
         try {
-            TagErrorRenderer renderer = this.rendererClass.newInstance();
+            TagErrorRenderer renderer = 
getConfiguration().getObjectFactory().newInstance(
+                    this.rendererClass);
             renderer.init(tag);
             return renderer;
         }

Modified: trunk/stripes/src/net/sourceforge/stripes/tag/FieldMetadataTag.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/tag/FieldMetadataTag.java 
2008-11-06 00:39:33 UTC (rev 999)
+++ trunk/stripes/src/net/sourceforge/stripes/tag/FieldMetadataTag.java 
2008-11-07 01:03:49 UTC (rev 1000)
@@ -80,7 +80,7 @@
             beanClass = 
StripesFilter.getConfiguration().getActionResolver().getActionBeanType(action);
 
             try {
-                bean = beanClass.newInstance();
+                bean = 
StripesFilter.getConfiguration().getObjectFactory().newInstance(beanClass);
             }
             catch (Exception e) {
                 log.error(e);

Deleted: trunk/stripes/src/net/sourceforge/stripes/util/ObjectFactory.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/util/ObjectFactory.java   
2008-11-06 00:39:33 UTC (rev 999)
+++ trunk/stripes/src/net/sourceforge/stripes/util/ObjectFactory.java   
2008-11-07 01:03:49 UTC (rev 1000)
@@ -1,108 +0,0 @@
-/* Copyright 2008 Ben Gunter
- *
- * 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 net.sourceforge.stripes.util;
-
-import net.sourceforge.stripes.controller.StripesFilter;
-import net.sourceforge.stripes.exception.StripesRuntimeException;
-
-/**
- * <p>
- * This class is responsible for creating new objects during the binding stage 
of the request cycle.
- * This implementation simply calls [EMAIL PROTECTED] Class#newInstance()} to 
obtain a new instance.
- * </p>
- * <p>
- * You can use an alternate implementation by specifying the class name in the 
[EMAIL PROTECTED] StripesFilter}
- * init-param [EMAIL PROTECTED] ObjectFactory.Class} or by placing your 
implementation in one of the packages
- * named in [EMAIL PROTECTED] Extension.Packages}. The specified class must, 
of course, be a subclass of
- * [EMAIL PROTECTED] ObjectFactory}.
- * </p>
- * 
- * <pre>
- * &lt;init-param&gt;
- *  &lt;param-name&gt;ObjectFactory.Class&lt;/param-name&gt;
- *  
&lt;param-value&gt;com.mycompany.stripes.ext.MyObjectFactory&lt;/param-value&gt;
- * &lt;/init-param&gt;
- * </pre>
- * 
- * @author Ben Gunter
- * @since Stripes 1.5.1
- */
-public class ObjectFactory {
-    private static final Log log = Log.getInstance(ObjectFactory.class);
-
-    /**
-     * Name of the [EMAIL PROTECTED] StripesFilter} init-param that can be 
used to indicate the class name of
-     * the preferred subclass of [EMAIL PROTECTED] ObjectFactory} to use.
-     */
-    public static final String CONFIGURATION_PARAMETER = "ObjectFactory.Class";
-
-    /** Singleton instance */
-    private static ObjectFactory instance;
-
-    /**
-     * Get the singleton object factory. By default, this method returns an 
instance of
-     * [EMAIL PROTECTED] ObjectFactory}. The [EMAIL PROTECTED] StripesFilter} 
init-param named [EMAIL PROTECTED] ObjectFactory.Class}
-     * can be used to provide an alternate implementation.
-     */
-    public static ObjectFactory getInstance() {
-        if (instance == null) {
-            Class<? extends ObjectFactory> type = 
StripesFilter.getConfiguration()
-                    
.getBootstrapPropertyResolver().getClassProperty(CONFIGURATION_PARAMETER,
-                            ObjectFactory.class);
-
-            if (type == null) {
-                instance = new ObjectFactory();
-            }
-            else {
-                try {
-                    instance = type.newInstance();
-                }
-                catch (InstantiationException e) {
-                    throw new StripesRuntimeException(e);
-                }
-                catch (IllegalAccessException e) {
-                    throw new StripesRuntimeException(e);
-                }
-            }
-
-            log.info("ObjectFactory implementation is " + 
instance.getClass().getName());
-        }
-
-        return instance;
-    }
-
-    /** Set the singleton instance. */
-    public static void setInstance(ObjectFactory instance) {
-        ObjectFactory.instance = instance;
-    }
-
-    /**
-     * Calls [EMAIL PROTECTED] Class#newInstance()} and returns the newly 
created object.
-     * 
-     * @param clazz The class to instantiate.
-     * @return The new object
-     */
-    public <T> T newInstance(Class<T> clazz) {
-        try {
-            return clazz.newInstance();
-        }
-        catch (InstantiationException e) {
-            throw new StripesRuntimeException("Could not instantiate " + 
clazz, e);
-        }
-        catch (IllegalAccessException e) {
-            throw new StripesRuntimeException("Could not instantiate " + 
clazz, e);
-        }
-    }
-}

Modified: trunk/stripes/src/net/sourceforge/stripes/util/ReflectUtil.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/util/ReflectUtil.java     
2008-11-06 00:39:33 UTC (rev 999)
+++ trunk/stripes/src/net/sourceforge/stripes/util/ReflectUtil.java     
2008-11-07 01:03:49 UTC (rev 1000)
@@ -14,6 +14,7 @@
  */
 package net.sourceforge.stripes.util;
 
+import net.sourceforge.stripes.controller.StripesFilter;
 import net.sourceforge.stripes.exception.StripesRuntimeException;
 
 import java.util.Map;
@@ -135,7 +136,7 @@
                     "might get implemented.");
         }
         else {
-            return ObjectFactory.getInstance().<T>newInstance((Class<T>) impl);
+            return 
StripesFilter.getConfiguration().getObjectFactory().newInstance((Class<T>) 
impl);
         }
     }
 

Modified: 
trunk/stripes/src/net/sourceforge/stripes/util/bean/PropertyExpressionEvaluation.java
===================================================================
--- 
trunk/stripes/src/net/sourceforge/stripes/util/bean/PropertyExpressionEvaluation.java
       2008-11-06 00:39:33 UTC (rev 999)
+++ 
trunk/stripes/src/net/sourceforge/stripes/util/bean/PropertyExpressionEvaluation.java
       2008-11-07 01:03:49 UTC (rev 1000)
@@ -14,7 +14,7 @@
  */
 package net.sourceforge.stripes.util.bean;
 
-import net.sourceforge.stripes.util.ObjectFactory;
+import net.sourceforge.stripes.controller.StripesFilter;
 import net.sourceforge.stripes.util.ReflectUtil;
 
 import java.beans.PropertyDescriptor;
@@ -646,7 +646,7 @@
                 return ReflectUtil.getInterfaceInstance(clazz);
             }
             else {
-                return ObjectFactory.getInstance().newInstance(clazz);
+                return 
StripesFilter.getConfiguration().getObjectFactory().newInstance(clazz);
             }
         }
         catch (Exception e) {

Modified: 
trunk/stripes/src/net/sourceforge/stripes/validation/DefaultTypeConverterFactory.java
===================================================================
--- 
trunk/stripes/src/net/sourceforge/stripes/validation/DefaultTypeConverterFactory.java
       2008-11-06 00:39:33 UTC (rev 999)
+++ 
trunk/stripes/src/net/sourceforge/stripes/validation/DefaultTypeConverterFactory.java
       2008-11-07 01:03:49 UTC (rev 1000)
@@ -190,7 +190,7 @@
      */
     @SuppressWarnings("unchecked")
     public TypeConverter getInstance(Class<? extends TypeConverter> clazz, 
Locale locale) throws Exception {
-        TypeConverter converter = clazz.newInstance();
+        TypeConverter converter = 
getConfiguration().getObjectFactory().newInstance(clazz);
         converter.setLocale(locale);
         return converter;
     }

Modified: trunk/tests/src/net/sourceforge/stripes/StripesTestFixture.java
===================================================================
--- trunk/tests/src/net/sourceforge/stripes/StripesTestFixture.java     
2008-11-06 00:39:33 UTC (rev 999)
+++ trunk/tests/src/net/sourceforge/stripes/StripesTestFixture.java     
2008-11-07 01:03:49 UTC (rev 1000)
@@ -1,12 +1,16 @@
 package net.sourceforge.stripes;
 
+import java.util.Collections;
+import java.util.Map;
+
+import net.sourceforge.stripes.config.BootstrapPropertyResolver;
+import net.sourceforge.stripes.config.Configuration;
+import net.sourceforge.stripes.config.DefaultConfiguration;
+import net.sourceforge.stripes.controller.DispatcherServlet;
+import net.sourceforge.stripes.controller.StripesFilter;
+import net.sourceforge.stripes.mock.MockFilterConfig;
 import net.sourceforge.stripes.mock.MockServletContext;
-import net.sourceforge.stripes.controller.StripesFilter;
-import net.sourceforge.stripes.controller.DispatcherServlet;
 
-import java.util.Map;
-import java.util.HashMap;
-
 /**
  * Test fixture that sets up a MockServletContext in a way that it can then be
  * used be any test in Stripes.
@@ -15,6 +19,7 @@
  */
 public class StripesTestFixture {
     private static MockServletContext context;
+    private static Configuration configuration;
 
     /**
      * Gets a reference to the test MockServletContext. If the context is not 
already
@@ -25,16 +30,32 @@
     public static synchronized MockServletContext getServletContext() {
         if (context == null) {
             context = new MockServletContext("test");
+            context.addFilter(StripesFilter.class, "StripesFilter", 
getDefaultFilterParams());
 
-            // Add the Stripes Filter
-            Map<String,String> filterParams = new HashMap<String,String>();
-            filterParams.put("ActionResolver.Packages", 
"net.sourceforge.stripes");
-            context.addFilter(StripesFilter.class, "StripesFilter", 
filterParams);
-
             // Add the Stripes Dispatcher
             context.setServlet(DispatcherServlet.class, "StripesDispatcher", 
null);
         }
 
         return context;
     }
+
+    /** Gets a reference to the default configuration, which can be used for 
simple testing. */
+    public static synchronized Configuration getDefaultConfiguration() {
+        if (configuration == null) {
+            Configuration configuration = new DefaultConfiguration();
+            MockFilterConfig filterConfig = new MockFilterConfig();
+            filterConfig.addAllInitParameters(getDefaultFilterParams());
+            filterConfig.setServletContext(getServletContext());
+            configuration.setBootstrapPropertyResolver(new 
BootstrapPropertyResolver(filterConfig));
+            configuration.init();
+            StripesTestFixture.configuration = configuration;
+        }
+
+        return configuration;
+    }
+
+    /** Gets a map containing the default initialization parameters for 
StripesFilter */
+    public static Map<String, String> getDefaultFilterParams() {
+        return Collections.singletonMap("ActionResolver.Packages", 
"net.sourceforge.stripes");
+    }
 }

Modified: 
trunk/tests/src/net/sourceforge/stripes/format/DefaultFormatterFactoryTest.java
===================================================================
--- 
trunk/tests/src/net/sourceforge/stripes/format/DefaultFormatterFactoryTest.java 
    2008-11-06 00:39:33 UTC (rev 999)
+++ 
trunk/tests/src/net/sourceforge/stripes/format/DefaultFormatterFactoryTest.java 
    2008-11-07 01:03:49 UTC (rev 1000)
@@ -2,7 +2,7 @@
 
 import java.util.Locale;
 
-import net.sourceforge.stripes.config.DefaultConfiguration;
+import net.sourceforge.stripes.StripesTestFixture;
 
 import org.testng.Assert;
 import org.testng.annotations.Test;
@@ -11,7 +11,7 @@
     @Test(groups = "fast")
     public void testFormatterSuperclass() throws Exception {
         DefaultFormatterFactory factory = new DefaultFormatterFactory();
-        factory.init(new DefaultConfiguration());
+        factory.init(StripesTestFixture.getDefaultConfiguration());
 
         Locale locale = Locale.getDefault();
         Formatter<?> formatter;
@@ -47,7 +47,7 @@
     @Test(groups = "fast")
     public void testFormatterInterface() throws Exception {
         DefaultFormatterFactory factory = new DefaultFormatterFactory();
-        factory.init(new DefaultConfiguration());
+        factory.init(StripesTestFixture.getDefaultConfiguration());
 
         Locale locale = Locale.getDefault();
         Formatter<?> formatter;
@@ -95,7 +95,7 @@
     @Test(groups = "fast")
     public void testNullFormatterIsNeverBestMatch() throws Exception {
         DefaultFormatterFactory factory = new DefaultFormatterFactory();
-        factory.init(new DefaultConfiguration());
+        factory.init(StripesTestFixture.getDefaultConfiguration());
 
         Locale locale = Locale.getDefault();
         Formatter<?> formatter;
@@ -113,7 +113,7 @@
     @Test(groups = "fast")
     public void testFormatterSuperclassImplementsInterface() throws Exception {
         DefaultFormatterFactory factory = new DefaultFormatterFactory();
-        factory.init(new DefaultConfiguration());
+        factory.init(StripesTestFixture.getDefaultConfiguration());
 
         Locale locale = Locale.getDefault();
         Formatter<?> formatter;
@@ -135,7 +135,7 @@
          * both X and I then the formatter returned for Y and Z is the I 
formatter
          */
         factory = new DefaultFormatterFactory();
-        factory.init(new DefaultConfiguration());
+        factory.init(StripesTestFixture.getDefaultConfiguration());
 
         factory.add(SuperclassImplementsX.class, XFormatter.class); // mapping 
for base class
         factory.add(Y.class, YFormatter.class); // mapping for interface in 
the middle
@@ -150,7 +150,7 @@
 
     public void testFormatterForInterfaceSuperclass() throws Exception {
         DefaultFormatterFactory factory = new DefaultFormatterFactory();
-        factory.init(new DefaultConfiguration());
+        factory.init(StripesTestFixture.getDefaultConfiguration());
 
         Locale locale = Locale.getDefault();
         Formatter<?> formatter;

Modified: 
trunk/tests/src/net/sourceforge/stripes/validation/DefaultTypeConverterFactoryTest.java
===================================================================
--- 
trunk/tests/src/net/sourceforge/stripes/validation/DefaultTypeConverterFactoryTest.java
     2008-11-06 00:39:33 UTC (rev 999)
+++ 
trunk/tests/src/net/sourceforge/stripes/validation/DefaultTypeConverterFactoryTest.java
     2008-11-07 01:03:49 UTC (rev 1000)
@@ -2,7 +2,7 @@
 
 import java.util.Locale;
 
-import net.sourceforge.stripes.config.DefaultConfiguration;
+import net.sourceforge.stripes.StripesTestFixture;
 
 import org.testng.Assert;
 import org.testng.annotations.Test;
@@ -13,7 +13,7 @@
        @Test(groups="fast")
     public void testCharTypeConverter() throws Exception{
        DefaultTypeConverterFactory factory = new DefaultTypeConverterFactory();
-       factory.init(new DefaultConfiguration());
+       factory.init(StripesTestFixture.getDefaultConfiguration());
        
        TypeConverter typeConverter = factory.getTypeConverter(Character.class, 
Locale.getDefault());
         Assert.assertEquals(CharacterTypeConverter.class, 
typeConverter.getClass());


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to