You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by mr...@apache.org on 2006/11/16 09:31:13 UTC

svn commit: r475636 - /struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java

Author: mrdon
Date: Thu Nov 16 00:31:12 2006
New Revision: 475636

URL: http://svn.apache.org/viewvc?view=rev&rev=475636
Log:
Added better handling of unloaded 'struts' classes (treat as optional),
added better logging of loading problems
WW-1506

Modified:
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java?view=diff&rev=475636&r1=475635&r2=475636
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java Thu Nov 16 00:31:12 2006
@@ -180,17 +180,23 @@
                 try {
                     Class cls = ClassLoaderUtil.loadClass(foundName, this.getClass());
                     if (LOG.isDebugEnabled()) {
-                        LOG.info("Choosing bean ("+cls+") for "+type);
+                        LOG.debug("Choosing bean ("+cls+") for "+type);
                     }
                     builder.factory(type, cls, scope);
                 } catch (ClassNotFoundException ex) {
                     // Perhaps a spring bean id, so we'll delegate to the object factory at runtime
                     if (LOG.isDebugEnabled()) {
-                        LOG.info("Choosing bean ("+foundName+") for "+type+" to be loaded from the ObjectFactory");
+                        LOG.debug("Choosing bean ("+foundName+") for "+type+" to be loaded from the ObjectFactory");
+                    }
+                    if (DEFAULT_BEAN_NAME.equals(foundName)) {
+                        // Probably an optional bean, will ignore
+                    } else {
+                        if (ObjectFactory.class != type) {
+                            builder.factory(type, new ObjectFactoryDelegateFactory(foundName, type), scope);
+                        } else {
+                            throw new ConfigurationException("Cannot locate the chosen ObjectFactory implementation: "+foundName);
+                        }
                     }
-                    if (ObjectFactory.class != type) {
-                        builder.factory(type, new ObjectFactoryDelegateFactory(foundName), scope);
-                    }    
                 }
             }
         } else {
@@ -200,13 +206,19 @@
     
     class ObjectFactoryDelegateFactory implements Factory {
         String name;
-        ObjectFactoryDelegateFactory(String name) {
+        Class type;
+        ObjectFactoryDelegateFactory(String name, Class type) {
             this.name = name;
+            this.type = type;
         }
         
         public Object create(Context context) throws Exception {
             ObjectFactory objFactory = context.getContainer().getInstance(ObjectFactory.class);
-            return objFactory.buildBean(name, null, false);
+            try {
+                return objFactory.buildBean(name, null, false);
+            } catch (ClassNotFoundException ex) {
+                throw new ConfigurationException("Unable to load bean "+type.getName()+" ("+name+")");
+            }
         }
     }
 }