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 ta...@apache.org on 2003/11/20 05:49:06 UTC
cvs commit: jakarta-jetspeed-2/cps/test/rewriter test-001-output.html
taylor 2003/11/19 20:49:06
Modified: cps/src/java/org/apache/jetspeed/cps BaseCommonService.java
CommonService.java
cps/test/rewriter test-001-output.html
Log:
added helper function to load a model class from a configuration
Revision Changes Path
1.3 +66 -1 jakarta-jetspeed-2/cps/src/java/org/apache/jetspeed/cps/BaseCommonService.java
Index: BaseCommonService.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/cps/src/java/org/apache/jetspeed/cps/BaseCommonService.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BaseCommonService.java 18 Oct 2003 19:51:11 -0000 1.2
+++ BaseCommonService.java 20 Nov 2003 04:49:06 -0000 1.3
@@ -53,6 +53,11 @@
*/
package org.apache.jetspeed.cps;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.fulcrum.BaseService;
/**
@@ -66,4 +71,64 @@
*/
public abstract class BaseCommonService extends BaseService implements CommonService
{
+ private static Map modelClasses = new HashMap();
+ protected final static Log log = LogFactory.getLog(BaseCommonService.class);
+
+ /**
+ * Load an implementation class from the configuration.
+ *
+ * @param configurationName
+ * @return
+ * @throws CPSInitializationException
+ */
+ public Class loadModelClass(String configurationName)
+ throws CPSInitializationException
+ {
+ String className = getConfiguration().getString(configurationName, null);
+ if (null == className)
+ {
+ throw new CPSInitializationException(configurationName + " implementation configuration not found.");
+ }
+
+ try
+ {
+ Class classe = (Class)modelClasses.get(className);
+ if (null == classe)
+ {
+ classe = Class.forName(className);
+ modelClasses.put(className, classe);
+ }
+ return classe;
+
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new CPSInitializationException("Could not preload " + className + " implementation class.", e);
+ }
+ }
+
+ /**
+ * Creates objects given the class.
+ * Throws exceptions if the class is not found in the default class path,
+ * or the class is not an instance of CmsObject.
+ *
+ * @param classe the class of object
+ * @return the newly created object
+ * @throws ContentManagementException
+ */
+ public Object createObject(Class classe)
+ {
+ Object object = null;
+ try
+ {
+ object = classe.newInstance();
+ }
+ catch (Exception e)
+ {
+ log.error("Factory failed to create object: " + classe.getName(), e);
+ }
+
+ return object;
+ }
+
}
1.2 +22 -1 jakarta-jetspeed-2/cps/src/java/org/apache/jetspeed/cps/CommonService.java
Index: CommonService.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/cps/src/java/org/apache/jetspeed/cps/CommonService.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CommonService.java 28 Jul 2003 23:46:42 -0000 1.1
+++ CommonService.java 20 Nov 2003 04:49:06 -0000 1.2
@@ -66,4 +66,25 @@
*/
public interface CommonService extends Service
{
+ /**
+ * Load an implementation class from the configuration.
+ *
+ * @param configurationName
+ * @return
+ * @throws CPSInitializationException
+ */
+ public Class loadModelClass(String configurationName)
+ throws CPSInitializationException;
+
+ /**
+ * Creates objects given the class.
+ * Throws exceptions if the class is not found in the default class path,
+ * or the class is not an instance of CmsObject.
+ *
+ * @param classe the class of object
+ * @return the newly created object
+ * @throws ContentManagementException
+ */
+ public Object createObject(Class classe);
+
}
1.8 +3 -3 jakarta-jetspeed-2/cps/test/rewriter/test-001-output.html
Index: test-001-output.html
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/cps/test/rewriter/test-001-output.html,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- test-001-output.html 14 Oct 2003 06:37:56 -0000 1.7
+++ test-001-output.html 20 Nov 2003 04:49:06 -0000 1.8
@@ -1,8 +1,8 @@
<p>
This is a test</p>
-<a href="http://www.bluesunrise.com/suffix" target="_BLANK" name="1">keep this</a>
- <a href="http://www.rewriter.com/stuff/junk/stuffedjunk.html/suffix" target="_BLANK" name="2">junk</a>
- <a href="http://www.rewriter.com/stuff/junk/stuffedjunk.html/suffix" target="_BLANK" name="3">junk2</a>
+<a href="http://www.bluesunrise.com/suffix" name="1" target="_BLANK">keep this</a>
+ <a href="http://www.rewriter.com/stuff/junk/stuffedjunk.html/suffix" name="2" target="_BLANK">junk</a>
+ <a href="http://www.rewriter.com/stuff/junk/stuffedjunk.html/suffix" name="3" target="_BLANK">junk2</a>
<a href="javascript:whatever()" name="4">script</a>
<a href="mailto:david@bluesunrise.com" name="5">script</a>
<a href="#INTERNAL" name="6">internal</a>
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org