Author: mrdon
Date: Sat Jun 18 21:57:26 2005
New Revision: 191320
URL: http://svn.apache.org/viewcvs?rev=191320&view=rev
Log:
* Adding the ability to load classes with a desired classloader
* Config factories now use the Digester classloader
PR: 18227
Modified:
struts/core/trunk/src/share/org/apache/struts/config/ConfigRuleSet.java
struts/core/trunk/src/share/org/apache/struts/util/RequestUtils.java
Modified:
struts/core/trunk/src/share/org/apache/struts/config/ConfigRuleSet.java
URL:
http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/config/ConfigRuleSet.java?rev=191320&r1=191319&r2=191320&view=diff
==============================================================================
--- struts/core/trunk/src/share/org/apache/struts/config/ConfigRuleSet.java
(original)
+++ struts/core/trunk/src/share/org/apache/struts/config/ConfigRuleSet.java Sat
Jun 18 21:57:26 2005
@@ -56,13 +56,15 @@
*/
public void addRuleInstances(Digester digester) {
+ ClassLoader cl = digester.getClassLoader();
+
digester.addRule
("struts-config/action-mappings",
new SetActionMappingClassRule());
digester.addFactoryCreate
("struts-config/action-mappings/action",
- new ActionMappingFactory());
+ new ActionMappingFactory(cl));
digester.addSetProperties
("struts-config/action-mappings/action");
digester.addSetNext
@@ -91,7 +93,7 @@
digester.addFactoryCreate
("struts-config/action-mappings/action/forward",
- new ActionForwardFactory());
+ new ActionForwardFactory(cl));
digester.addSetProperties
("struts-config/action-mappings/action/forward");
digester.addSetNext
@@ -124,7 +126,7 @@
digester.addFactoryCreate
("struts-config/form-beans/form-bean",
- new ActionFormBeanFactory());
+ new ActionFormBeanFactory(cl));
digester.addSetProperties
("struts-config/form-beans/form-bean");
digester.addSetNext
@@ -173,7 +175,7 @@
digester.addFactoryCreate
("struts-config/global-forwards/forward",
- new GlobalForwardFactory());
+ new GlobalForwardFactory(cl));
digester.addSetProperties
("struts-config/global-forwards/forward");
digester.addSetNext
@@ -318,6 +320,13 @@
*/
final class ActionFormBeanFactory extends AbstractObjectCreationFactory {
+ private ClassLoader cl;
+
+ public ActionFormBeanFactory(ClassLoader cl) {
+ super();
+ this.cl = cl;
+ }
+
public Object createObject(Attributes attributes) {
// Identify the name of the class to instantiate
@@ -331,7 +340,7 @@
Object actionFormBean = null;
try {
actionFormBean =
- RequestUtils.applicationInstance(className);
+ RequestUtils.applicationInstance(className, cl);
} catch (Exception e) {
digester.getLogger().error(
"ActionFormBeanFactory.createObject: ", e);
@@ -374,6 +383,14 @@
*/
final class ActionMappingFactory extends AbstractObjectCreationFactory {
+ private ClassLoader cl;
+
+ public ActionMappingFactory(ClassLoader cl) {
+ super();
+ this.cl = cl;
+ }
+
+
public Object createObject(Attributes attributes) {
// Identify the name of the class to instantiate
@@ -387,7 +404,7 @@
Object actionMapping = null;
try {
actionMapping =
- RequestUtils.applicationInstance(className);
+ RequestUtils.applicationInstance(className, cl);
} catch (Exception e) {
digester.getLogger().error(
"ActionMappingFactory.createObject: ", e);
@@ -430,6 +447,14 @@
*/
final class GlobalForwardFactory extends AbstractObjectCreationFactory {
+ private ClassLoader cl;
+
+ public GlobalForwardFactory(ClassLoader cl) {
+ super();
+ this.cl = cl;
+ }
+
+
public Object createObject(Attributes attributes) {
// Identify the name of the class to instantiate
@@ -443,7 +468,7 @@
Object globalForward = null;
try {
globalForward =
- RequestUtils.applicationInstance(className);
+ RequestUtils.applicationInstance(className, cl);
} catch (Exception e) {
digester.getLogger().error(
"GlobalForwardFactory.createObject: ", e);
@@ -464,6 +489,14 @@
*/
final class ActionForwardFactory extends AbstractObjectCreationFactory {
+ private ClassLoader cl;
+
+ public ActionForwardFactory(ClassLoader cl) {
+ super();
+ this.cl = cl;
+ }
+
+
public Object createObject(Attributes attributes) {
// Identify the name of the class to instantiate
@@ -477,7 +510,7 @@
Object actionForward = null;
try {
actionForward =
- RequestUtils.applicationInstance(className);
+ RequestUtils.applicationInstance(className, cl);
} catch (Exception e) {
digester.getLogger().error(
"ActionForwardFactory.createObject: ", e);
Modified: struts/core/trunk/src/share/org/apache/struts/util/RequestUtils.java
URL:
http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/util/RequestUtils.java?rev=191320&r1=191319&r2=191320&view=diff
==============================================================================
--- struts/core/trunk/src/share/org/apache/struts/util/RequestUtils.java
(original)
+++ struts/core/trunk/src/share/org/apache/struts/util/RequestUtils.java Sat
Jun 18 21:57:26 2005
@@ -98,12 +98,29 @@
* @exception ClassNotFoundException if the class cannot be found
*/
public static Class applicationClass(String className) throws
ClassNotFoundException {
+ return applicationClass(className, null);
+ }
+
+ /**
+ * <p>Return the <code>Class</code> object for the specified fully
qualified
+ * class name, from this web application's class loader.</p>
+ *
+ * @param className Fully qualified class name to be loaded
+ * @param classLoader The desired classloader to use
+ * @return Class object
+ *
+ * @exception ClassNotFoundException if the class cannot be found
+ */
+ public static Class applicationClass(String className, ClassLoader
classLoader)
+ throws ClassNotFoundException {
- // Look up the class loader to be used
- ClassLoader classLoader =
Thread.currentThread().getContextClassLoader();
if (classLoader == null) {
- classLoader = RequestUtils.class.getClassLoader();
- }
+ // Look up the class loader to be used
+ classLoader = Thread.currentThread().getContextClassLoader();
+ if (classLoader == null) {
+ classLoader = RequestUtils.class.getClassLoader();
+ }
+ }
// Attempt to load the specified class
return (classLoader.loadClass(className));
@@ -132,7 +149,32 @@
public static Object applicationInstance(String className)
throws ClassNotFoundException, IllegalAccessException,
InstantiationException {
- return (applicationClass(className).newInstance());
+ return applicationInstance(className, null);
+ }
+
+ /**
+ * <p>Return a new instance of the specified fully qualified class name,
+ * after loading the class from this web application's class loader.
+ * The specified class <strong>MUST</strong> have a public zero-arguments
+ * constructor.</p>
+ *
+ * @param className Fully qualified class name to use
+ * @param classLoader The desired classloader to use
+ *
+ * @return new instance of class
+ * @exception ClassNotFoundException if the class cannot be found
+ * @exception IllegalAccessException if the class or its constructor
+ * is not accessible
+ * @exception InstantiationException if this class represents an
+ * abstract class, an interface, an array class, a primitive type,
+ * or void
+ * @exception InstantiationException if this class has no
+ * zero-arguments constructor
+ */
+ public static Object applicationInstance(String className, ClassLoader
classLoader)
+ throws ClassNotFoundException, IllegalAccessException,
InstantiationException {
+
+ return (applicationClass(className, classLoader).newInstance());
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]