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/02/18 20:37:19 UTC
cvs commit: jakarta-jetspeed-2/cps/src/test/org/apache/jetspeed/components SmartImpl.java SmartImpl.bsh DumbImpl.java Dumb.java Smart.java TestComponentManager.java
weaver 2004/02/18 11:37:19
Modified: cps/src/java/org/apache/jetspeed/components
ComponentManager.java
cps/src/test/org/apache/jetspeed/components
TestComponentManager.java
Added: cps/src/java/org/apache/jetspeed/components
ConfigurableBeanShellComponentAdapter.java
cps/src/test/org/apache/jetspeed/components SmartImpl.java
SmartImpl.bsh DumbImpl.java Dumb.java Smart.java
Log:
add scriptable component configuration to the ComponentManager
Revision Changes Path
1.2 +25 -4 jakarta-jetspeed-2/cps/src/java/org/apache/jetspeed/components/ComponentManager.java
Index: ComponentManager.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/cps/src/java/org/apache/jetspeed/components/ComponentManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ComponentManager.java 18 Feb 2004 09:14:14 -0000 1.1
+++ ComponentManager.java 18 Feb 2004 19:37:19 -0000 1.2
@@ -66,9 +66,11 @@
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nanocontainer.script.bsh.BeanShellComponentAdapter;
import org.picocontainer.MutablePicoContainer;
import org.picocontainer.Parameter;
import org.picocontainer.Startable;
+import org.picocontainer.defaults.BeanComponentAdapter;
import org.picocontainer.defaults.ComponentAdapterFactory;
import org.picocontainer.defaults.ConstantParameter;
import org.picocontainer.defaults.DefaultPicoContainer;
@@ -214,9 +216,11 @@
}
private void loadComponent(URL url)
- {
+ {
+ //TODO We should be looking for a persistent configuration then use the one found in the CL to fill any dafults
PropertiesConfiguration configuration = new PropertiesConfiguration();
configuration.setFileName(url.getFile().toString());
+
try
{
System.out.println("loading configuration: " + configuration);
@@ -241,8 +245,9 @@
{
Configuration componentConfig = configuration.subset(componentNames[ix]);
// debugConfig(componentConfig);
- Class componentClass = Class.forName(className);
+ Class componentClass = Class.forName(className);
Parameter [] parameters = {new ConstantParameter(componentConfig)};
+
MutablePicoContainer container = this.getContainer(containerName);
if (null == container)
@@ -250,7 +255,15 @@
container = this.defaultContainer;
}
- container.registerComponentImplementation(componentNames[ix], componentClass, parameters);
+ if(hasBeanshellConfig(componentClass))
+ {
+ container.registerComponent(new ConfigurableBeanShellComponentAdapter(componentNames[ix], componentClass, null, componentConfig));
+ }
+ else
+ {
+ container.registerComponentImplementation(componentNames[ix], componentClass, parameters);
+ }
+
System.out.println("Created component " + componentNames[ix] + " and class " + className);
}
@@ -270,5 +283,13 @@
System.out.println("key = " + key + ", value = " + config.getProperty(key));
}
System.out.println("*** roots = " + config.getString("roots"));
+ }
+
+ private boolean hasBeanshellConfig(Class componentClass)
+ {
+ String scriptName = componentClass.getName().replace('.','/')+".bsh";
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader() ;
+ URL scriptUrl = classLoader.getResource(scriptName);
+ return scriptUrl != null;
}
}
1.1 jakarta-jetspeed-2/cps/src/java/org/apache/jetspeed/components/ConfigurableBeanShellComponentAdapter.java
Index: ConfigurableBeanShellComponentAdapter.java
===================================================================
package org.apache.jetspeed.components;
import org.apache.commons.configuration.Configuration;
import org.nanocontainer.script.bsh.BeanShellComponentAdapter;
import org.picocontainer.ComponentAdapter;
import org.picocontainer.Parameter;
/**
* <p>
* ConfigurableBeanShellComponentAdapter
* </p>
*
* @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
* @version $Id: ConfigurableBeanShellComponentAdapter.java,v 1.1 2004/02/18 19:37:19 weaver Exp $
*
*/
public class ConfigurableBeanShellComponentAdapter extends BeanShellComponentAdapter implements ComponentAdapter
{
private Configuration conf;
/**
* @param arg0
* @param arg1
* @param arg2
*/
public ConfigurableBeanShellComponentAdapter(Object arg0, Class arg1, Parameter[] arg2, Configuration conf)
{
super(arg0, arg1, arg2);
this.conf = conf;
}
public Configuration getConfiguration()
{
return conf;
}
}
1.2 +7 -21 jakarta-jetspeed-2/cps/src/test/org/apache/jetspeed/components/TestComponentManager.java
Index: TestComponentManager.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/cps/src/test/org/apache/jetspeed/components/TestComponentManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestComponentManager.java 18 Feb 2004 09:14:14 -0000 1.1
+++ TestComponentManager.java 18 Feb 2004 19:37:19 -0000 1.2
@@ -121,7 +121,7 @@
System.out.println("container = " + container);
count++;
}
- assertTrue("count = 2 " + count, count == 2);
+ assertTrue("count = 2" + count, count == 2);
MutablePicoContainer container = cm.getContainer("default");
assertNotNull("default container is null", container);
@@ -134,6 +134,11 @@
TemplateLocatorComponent locator2 = (TemplateLocatorComponent)cm.getComponent("persistence", "locator2");
assertNotNull("locator2 is null", locator2);
+
+ Smart smart = (Smart) cm.getComponent(Smart.class.getName());
+ assertNotNull("Smart is null", smart);
+ smart.test();
+
cm.stop();
@@ -194,24 +199,5 @@
System.out.println("dumb2 = " + dumb2);
}
-
- public static interface Dumb
- {
- void test();
- }
-
- public static class DumbImpl implements Dumb
- {
- public DumbImpl()
- {
- System.out.println("Constructing Dumb");
- }
-
- public void test()
- {
- System.out.println("calling test");
- }
- }
-
}
1.1 jakarta-jetspeed-2/cps/src/test/org/apache/jetspeed/components/SmartImpl.java
Index: SmartImpl.java
===================================================================
/**
* Created on Feb 18, 2004
*
*
* @author
*/
package org.apache.jetspeed.components;
public class SmartImpl implements Smart
{
private String string;
private int integer;
public SmartImpl(String string, int integer)
{
System.out.println("Constructing Smart");
this.string = string;
this.integer = integer;
}
public void test()
{
System.out.println("SmartImpl.test() was called. String is: "+string+" Integer is: "+integer);
}
}
1.1 jakarta-jetspeed-2/cps/src/test/org/apache/jetspeed/components/SmartImpl.bsh
Index: SmartImpl.bsh
===================================================================
import org.apache.commons.configuration.Configuration;
// We use a special ConfigurableBeasnShellComponentAdapter to pass
// in soft coded configuration values
Configuration conf = adapter.getConfiguration();
// Extract the values
String string = conf.getString("string");
int integer = conf.getInt("integer");
// and create a instance. The adapter will search the BeanShell
// for a vairable named instance and return it.
instance = new SmartImpl(string, integer);
1.1 jakarta-jetspeed-2/cps/src/test/org/apache/jetspeed/components/DumbImpl.java
Index: DumbImpl.java
===================================================================
/**
* Created on Feb 18, 2004
*
*
* @author
*/
package org.apache.jetspeed.components;
public class DumbImpl implements Dumb
{
public DumbImpl()
{
System.out.println("Constructing Dumb");
}
public void test()
{
System.out.println("DumbImpl.test() was called");
}
}
1.1 jakarta-jetspeed-2/cps/src/test/org/apache/jetspeed/components/Dumb.java
Index: Dumb.java
===================================================================
/**
* Created on Feb 18, 2004
*
*
* @author
*/
package org.apache.jetspeed.components;
public interface Dumb
{
void test();
}
1.1 jakarta-jetspeed-2/cps/src/test/org/apache/jetspeed/components/Smart.java
Index: Smart.java
===================================================================
/**
* Created on Feb 18, 2004
*
*
* @author
*/
package org.apache.jetspeed.components;
public interface Smart
{
void test();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org