You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by we...@apache.org on 2004/06/10 22:02:58 UTC
cvs commit: jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/factory JetspeedPortletFactory.java
weaver 2004/06/10 13:02:58
Modified: commons/src/java/org/apache/jetspeed/factory
JetspeedPortletFactory.java
Log:
Expanded JetspeedPortletFactory's ability to locate portlet classes by providing for alternate
ClassLoaders in addition to the Thread's context CL.
Revision Changes Path
1.4 +74 -2 jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/factory/JetspeedPortletFactory.java
Index: JetspeedPortletFactory.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/factory/JetspeedPortletFactory.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JetspeedPortletFactory.java 4 Jun 2004 02:37:15 -0000 1.3
+++ JetspeedPortletFactory.java 10 Jun 2004 20:02:58 -0000 1.4
@@ -15,6 +15,10 @@
*/
package org.apache.jetspeed.factory;
+import java.io.FileNotFoundException;
+import java.util.ArrayList;
+import java.util.Iterator;
+
import javax.portlet.Portlet;
import javax.portlet.PortletConfig;
import javax.portlet.PortletContext;
@@ -40,6 +44,8 @@
private static final Log log = LogFactory.getLog(JetspeedPortletFactory.class);
+ private static final ArrayList classLoaders = new ArrayList();
+
/**
* Gets a portlet by either creating it or returning a handle to it from the portlet 'cache'
*
@@ -65,7 +71,13 @@
return portlet;
}
- portlet = (Portlet)Thread.currentThread().getContextClassLoader().loadClass(className).newInstance();
+ portlet = loadPortletClass(className);
+
+ if(portlet == null)
+ {
+ throw new FileNotFoundException("Could not located portlet "+className+" in any classloader.");
+ }
+
ServletContext servletContext = servletConfig.getServletContext();
PortletContext portletContext =
PortalAccessor.createPortletContext(servletContext,
@@ -84,6 +96,66 @@
}
return portlet;
+ }
+
+ /**
+ * <p>
+ * loadPortletClass
+ * </p>
+ * Loads a Portlet class by first checking Thread.currentThread().getContextClassLoader()
+ * then by checking all of the ClassLoaders in <code>classLoaders</code> until the
+ * class is located or returns <code>null</code> if the Portlet class could not be found.
+ *
+ * @param className
+ * @return
+ * @throws InstantiationException
+ * @throws IllegalAccessException
+ */
+ public static Portlet loadPortletClass( String className ) throws InstantiationException, IllegalAccessException
+ {
+ Portlet portlet = null;
+ try
+ {
+ portlet = (Portlet)Thread.currentThread().getContextClassLoader().loadClass(className).newInstance();
+ }
+ catch (ClassNotFoundException e)
+ {
+ synchronized(classLoaders)
+ {
+ Iterator itr = classLoaders.iterator();
+ while(itr.hasNext() && portlet == null)
+ {
+ ClassLoader cl = (ClassLoader) itr.next();
+ try
+ {
+ portlet = (Portlet) cl.loadClass(className).newInstance();
+ }
+ catch (ClassNotFoundException e1)
+ {
+ // move along
+ }
+ }
+ }
+ }
+ return portlet;
+ }
+
+ /**
+ *
+ * <p>
+ * addClassLoader
+ * </p>
+ *
+ * Adds a ClassLoader to the search path, <code>classLoaders</code>, of the JetspeedPortletFactory.
+ *
+ * @param cl
+ */
+ public static void addClassLoader(ClassLoader cl)
+ {
+ synchronized(classLoaders)
+ {
+ classLoaders.add(cl);
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org