taylor 2004/02/18 01:14:15 Modified: . .classpath cps maven.xml project.xml cps/src/java/org/apache/jetspeed/cps CommonPortletServices.java Added: cps/src/java/META-INF js-components.properties cps/src/java/org/apache/jetspeed/components ComponentManagement.java ComponentManager.java ContainerManagement.java InterceptorAdapter.java InterceptorAdapterFactory.java cps/src/test/org/apache/jetspeed/components TestComponentManager.java cps/test/WEB-INF/conf components.properties components.xml Log: Start of Component Manager based upon Pico Container. Revision Changes Path 1.17 +1 -1 jakarta-jetspeed-2/.classpath Index: .classpath =================================================================== RCS file: /home/cvs/jakarta-jetspeed-2/.classpath,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- .classpath 17 Feb 2004 18:35:00 -0000 1.16 +++ .classpath 18 Feb 2004 09:14:14 -0000 1.17 @@ -19,7 +19,6 @@ <classpathentry exported="true" kind="var" path="MAVEN_REPO/commons-betwixt/jars/commons-betwixt-1.0-beta-1.jar"/> <classpathentry exported="true" kind="var" path="MAVEN_REPO/commons-beanutils/jars/commons-beanutils-1.6.jar"/> <classpathentry exported="true" kind="var" path="MAVEN_REPO/castor/jars/castor-0.9.4.3.jar"/> - <classpathentry exported="true" kind="var" path="MAVEN_REPO/commons-configuration/jars/commons-configuration-1.0-dev.jar"/> <classpathentry exported="true" kind="var" path="MAVEN_REPO/commons-digester/jars/commons-digester-1.3.jar"/> <classpathentry exported="true" kind="var" path="MAVEN_REPO/commons-io/jars/commons-io-0.1.jar"/> <classpathentry exported="true" kind="var" path="MAVEN_REPO/commons-lang/jars/commons-lang-1.0.1.jar"/> @@ -47,5 +46,6 @@ <classpathentry kind="var" path="MAVEN_REPO/velocity-tools/jars/velocity-tools-view-1.1-beta1.jar"/> <classpathentry kind="var" path="MAVEN_REPO/picocontainer/jars/picocontainer-1.0-beta-5-SNAPSHOT.jar"/> <classpathentry kind="var" path="MAVEN_REPO/commons-dbcp/jars/commons-dbcp-1.1.jar"/> + <classpathentry kind="var" path="MAVEN_REPO/commons-configuration/jars/commons-configuration-SNAPSHOT.jar"/> <classpathentry kind="output" path="bin"/> </classpath> 1.7 +12 -1 jakarta-jetspeed-2/cps/maven.xml Index: maven.xml =================================================================== RCS file: /home/cvs/jakarta-jetspeed-2/cps/maven.xml,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- maven.xml 17 Feb 2004 04:02:39 -0000 1.6 +++ maven.xml 18 Feb 2004 09:14:14 -0000 1.7 @@ -4,12 +4,23 @@ xmlns:reactor="reactor"> <!-- Target of maven test:single test --> - <property name='testcase' value='org.apache.jetspeed.cps.components.TestHSQL'/> + <property name='testcase' value='org.apache.jetspeed.components.TestComponentManager'/> <goal name="deployJar"> <attainGoal name="jar:install"/> <copy file="${basedir}/target/${maven.final.name}.jar" todir="${deploy.war.dir}/jetspeed/WEB-INF/lib"/> </goal> + + <!-- ================================================================ --> + <!-- Set System properties for junit --> + <!-- ================================================================ --> + <preGoal name="test:single"> + <copy file="./src/java/META-INF/js-components.properties" tofile="./target/classes/META-INF/js-components.properties"/> + </preGoal> + + <preGoal name="test:test"> + <copy file="./src/java/META-INF/js-components.properties" tofile="./target/classes/META-INF/js-components.properties"/> + </preGoal> </project> 1.11 +8 -1 jakarta-jetspeed-2/cps/project.xml Index: project.xml =================================================================== RCS file: /home/cvs/jakarta-jetspeed-2/cps/project.xml,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- project.xml 17 Feb 2004 04:02:39 -0000 1.10 +++ project.xml 18 Feb 2004 09:14:14 -0000 1.11 @@ -64,7 +64,14 @@ </dependency> <dependency> <id>commons-configuration</id> - <version>1.0-dev</version> + <version>SNAPSHOT</version> + <properties> + <war.bundle.jar>true</war.bundle.jar> + </properties> + </dependency> + <dependency> + <id>dom4j</id> + <version>1.4</version> <properties> <war.bundle.jar>true</war.bundle.jar> </properties> 1.1 jakarta-jetspeed-2/cps/src/java/META-INF/js-components.properties Index: js-components.properties =================================================================== components = locator, locator2 locator.classname = org.apache.jetspeed.cps.template.TemplateLocatorComponentImpl # locator.adapter = not defined locator2.classname = org.apache.jetspeed.cps.template.TemplateLocatorComponentImpl locator2.container = persistence locator.roots = WEB-INF/templates locator.templatelocator.classname = org.apache.jetspeed.cps.template.TemplateLocatorImpl locator.template.class = org.apache.jetspeed.cps.template.TemplateImpl locator.default.type = layout locator.default.template.name = columns.vm locator.default.extension = vm locator2.roots = WEB-INF/templates locator2.templatelocator.classname = org.apache.jetspeed.cps.template.TemplateLocatorImpl locator2.template.class = org.apache.jetspeed.cps.template.TemplateImpl locator2.default.type = layout locator2.default.template.name = columns.vm locator2.default.extension = vm 1.1 jakarta-jetspeed-2/cps/src/java/org/apache/jetspeed/components/ComponentManagement.java Index: ComponentManagement.java =================================================================== /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2000-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Jetspeed" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * "Apache Jetspeed", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.jetspeed.components; /** * ComponentManagement * * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a> * @version $Id: ComponentManagement.java,v 1.1 2004/02/18 09:14:14 taylor Exp $ */ public interface ComponentManagement { Object getComponent(String componentName); Object getComponent(String containerName, String componentName); // I am thinking that there should be categories and discovery of components // Try to find the best component given params "database, psml" // Object getComponent(UniveralDescription description); } 1.1 jakarta-jetspeed-2/cps/src/java/org/apache/jetspeed/components/ComponentManager.java Index: ComponentManager.java =================================================================== /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2000-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Jetspeed" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * "Apache Jetspeed", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.jetspeed.components; import java.io.IOException; import java.net.URL; import java.util.Collection; import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Properties; import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.picocontainer.MutablePicoContainer; import org.picocontainer.Parameter; import org.picocontainer.Startable; import org.picocontainer.defaults.ComponentAdapterFactory; import org.picocontainer.defaults.ConstantParameter; import org.picocontainer.defaults.DefaultPicoContainer; /** * ComponentManager manages Jetspeed components. * * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a> * @version $Id: ComponentManager.java,v 1.1 2004/02/18 09:14:14 taylor Exp $ */ public class ComponentManager implements Startable, ContainerManagement, ComponentManagement { private static final Log log = LogFactory.getLog(ComponentManager.class); private Configuration config = null; private Map containers = new HashMap(); private MutablePicoContainer defaultContainer = null; private ComponentManager() { // requires a components configuration } public ComponentManager(Configuration config) { this.config = config; } public void start() { createContainers(); loadComponents(); // start containers // with container hierachies, will starting the root container start its children? // defaultContainer.start(); Iterator all = containers.values().iterator(); while (all.hasNext()) { MutablePicoContainer container = (MutablePicoContainer)all.next(); container.start(); } } public void stop() { } public Object getComponent(String componentName) { // TODO: might be better to use a container hierarchy, with parent containers return this.defaultContainer.getComponentInstance(componentName); } public Object getComponent(String containerName, String componentName) { Object component = null; MutablePicoContainer container = getContainer(containerName); if (container != null) { component = container.getComponentInstance(componentName); } return component; } public MutablePicoContainer getContainer(String containerName) { return (MutablePicoContainer)this.containers.get(containerName); } public MutablePicoContainer getDefaultContainer() { return this.defaultContainer; } public Collection getContainers() { return this.containers.values(); } private void loadComponents() { ClassLoader classLoader = Thread.currentThread().getContextClassLoader() ; Enumeration resources = null; try { resources = classLoader.getResources("META-INF/js-components.properties") ; } catch (IOException e) { log.error("failed to load js components", e); return; } while(resources.hasMoreElements()) { URL url = (URL)resources.nextElement(); System.out.println("Loading URL " + url); this.loadComponent(url); } } private void createContainers() { // for now this is kinda hard-coded to the simple properties file format String defaultContainer = config.getString("default.container"); String [] containerNames = config.getStringArray("containers"); MutablePicoContainer container = null; for (int ix = 0; ix < containerNames.length; ix++) { String className = config.getString("container." + containerNames[ix] + ".classname"); String adapter = config.getString("container." + containerNames[ix] + ".adapter"); try { Class containerClass = Class.forName(className); container = (MutablePicoContainer)containerClass.newInstance(); if (containerNames.equals(defaultContainer)) { this.defaultContainer = container; } containers.put(containerNames[ix], container); System.out.println("Created container for container " + containerNames[ix] + " and class " + className); } catch (Exception e) { log.error("failed to create container " + containerNames[ix] + " and class " + className, e); } } if (this.defaultContainer == null) { if (container != null) { this.defaultContainer = container; } else { this.defaultContainer = new DefaultPicoContainer(); containers.put("default", this.defaultContainer); } } } private void loadComponent(URL url) { PropertiesConfiguration configuration = new PropertiesConfiguration(); configuration.setFileName(url.getFile().toString()); try { System.out.println("loading configuration: " + configuration); configuration.load(); } catch (IOException e) { log.error("Failed to load js component configuration for " + url, e); return; } String [] componentNames = configuration.getStringArray("components"); for (int ix = 0; ix < componentNames.length; ix++) { System.out.println("loading component: [" + componentNames[ix] + "]"); String className = configuration.getString(componentNames[ix] + ".classname"); String containerName = configuration.getString(componentNames[ix] + ".container"); // String adapter = config.getString("container." + componentNames[ix] + ".adapter"); try { Configuration componentConfig = configuration.subset(componentNames[ix]); // debugConfig(componentConfig); Class componentClass = Class.forName(className); Parameter [] parameters = {new ConstantParameter(componentConfig)}; MutablePicoContainer container = this.getContainer(containerName); if (null == container) { container = this.defaultContainer; } container.registerComponentImplementation(componentNames[ix], componentClass, parameters); System.out.println("Created component " + componentNames[ix] + " and class " + className); } catch (Exception e) { log.error("failed to create component " + componentNames[ix] + " and class " + className, e); } } } private void debugConfig(Configuration config) { Iterator it = config.getKeys(); while (it.hasNext()) { String key = (String)it.next(); System.out.println("key = " + key + ", value = " + config.getProperty(key)); } System.out.println("*** roots = " + config.getString("roots")); } } 1.1 jakarta-jetspeed-2/cps/src/java/org/apache/jetspeed/components/ContainerManagement.java Index: ContainerManagement.java =================================================================== /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2000-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Jetspeed" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * "Apache Jetspeed", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.jetspeed.components; import java.util.Collection; import org.picocontainer.MutablePicoContainer; /** * ContainerManagement * * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a> * @version $Id: ContainerManagement.java,v 1.1 2004/02/18 09:14:14 taylor Exp $ */ public interface ContainerManagement { // TODO: GENERAL: build in hierachies (parents) of containers // TODO: RESOLVE: NanoContainer doesn't share the same base class or any common interfaces with PicoContainer MutablePicoContainer getContainer(String containerName); MutablePicoContainer getDefaultContainer(); Collection getContainers(); // void addContainer(String containerName, MutablePicoContainer container); // void removeContainer(String containerName); } 1.1 jakarta-jetspeed-2/cps/src/java/org/apache/jetspeed/components/InterceptorAdapter.java Index: InterceptorAdapter.java =================================================================== /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2000-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Jetspeed" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * "Apache Jetspeed", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.jetspeed.components; import org.picocontainer.ComponentAdapter; import org.picocontainer.PicoInitializationException; import org.picocontainer.PicoIntrospectionException; import org.picocontainer.defaults.AssignabilityRegistrationException; import org.picocontainer.defaults.DecoratingComponentAdapterFactory; import org.picocontainer.defaults.ImplementationHidingComponentAdapter; import org.picocontainer.defaults.InterfaceFinder; import org.picocontainer.defaults.NotConcreteRegistrationException; import org.picocontainer.defaults.Swappable; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; /** * InterceptorAdaptor * * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a> * @version $Id: InterceptorAdapter.java,v 1.1 2004/02/18 09:14:14 taylor Exp $ */ public class InterceptorAdapter extends ImplementationHidingComponentAdapter // DecoratingComponentAdapterFactory { public InterceptorAdapter(ComponentAdapter delegate) { super(delegate); } private final InterfaceFinder interfaceFinder = new InterfaceFinder(); public Object getComponentInstance() throws PicoInitializationException, PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException { Class[] interfaces; if (getDelegate().getComponentKey() instanceof Class && ((Class) getDelegate().getComponentKey()).isInterface()) { // If the compo interfaces = new Class[] {(Class) getDelegate().getComponentKey()}; } else { interfaces = interfaceFinder.getInterfaces( getDelegate().getComponentImplementation()); } Class[] swappableAugmentedInterfaces = new Class[interfaces.length + 1]; swappableAugmentedInterfaces[interfaces.length] = Swappable.class; System.arraycopy( interfaces, 0, swappableAugmentedInterfaces, 0, interfaces.length); if (interfaces.length == 0) { throw new PicoIntrospectionException( "Can't hide implementation for " + getDelegate().getComponentImplementation().getName() + ". It doesn't implement any interfaces."); } final DelegatingInvocationHandler delegatingInvocationHandler = new DelegatingInvocationHandler(this); return Proxy.newProxyInstance( getClass().getClassLoader(), swappableAugmentedInterfaces, delegatingInvocationHandler); } private Object getDelegatedComponentInstance() { return super.getComponentInstance(); } private class DelegatingInvocationHandler implements InvocationHandler, Swappable { private final InterceptorAdapter adapter; private Object delegatedInstance; public DelegatingInvocationHandler(InterceptorAdapter adapter) { this.adapter = adapter; } public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { System.out.println("Invoking method: " + method); Class declaringClass = method.getDeclaringClass(); if (declaringClass.equals(Object.class)) { if (method.equals(InterfaceFinder.hashCode)) { // Return the hashCode of ourself, as Proxy.newProxyInstance() may // return cached proxies. We want a unique hashCode for each created proxy! return new Integer( System.identityHashCode( DelegatingInvocationHandler.this)); } if (method.equals(InterfaceFinder.equals)) { return new Boolean(proxy == args[0]); } // If it's any other method defined by Object, call on ourself. return method.invoke(DelegatingInvocationHandler.this, args); } else if (declaringClass.equals(Swappable.class)) { return method.invoke(this, args); } else { if (delegatedInstance == null) { delegatedInstance = adapter.getDelegatedComponentInstance(); } return method.invoke(delegatedInstance, args); } } public Object __hotSwap(Object newSubject) { Object result = delegatedInstance; delegatedInstance = newSubject; return result; } } } 1.1 jakarta-jetspeed-2/cps/src/java/org/apache/jetspeed/components/InterceptorAdapterFactory.java Index: InterceptorAdapterFactory.java =================================================================== /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2000-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Jetspeed" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * "Apache Jetspeed", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.jetspeed.components; import org.picocontainer.defaults.DecoratingComponentAdapterFactory; import org.picocontainer.defaults.DefaultComponentAdapterFactory; import org.picocontainer.ComponentAdapter; import org.picocontainer.Parameter; import org.picocontainer.PicoIntrospectionException; import org.picocontainer.defaults.*; /** * InterceptorAdapterFactory * * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a> * @version $Id: InterceptorAdapterFactory.java,v 1.1 2004/02/18 09:14:14 taylor Exp $ */ public class InterceptorAdapterFactory extends DecoratingComponentAdapterFactory { public InterceptorAdapterFactory() { this(new DefaultComponentAdapterFactory()); } public InterceptorAdapterFactory(ComponentAdapterFactory delegate) { super(delegate); } public ComponentAdapter createComponentAdapter(Object componentKey, Class componentImplementation, Parameter[] parameters) throws PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException { return new InterceptorAdapter(super.createComponentAdapter(componentKey, componentImplementation, parameters)); } } 1.6 +1 -25 jakarta-jetspeed-2/cps/src/java/org/apache/jetspeed/cps/CommonPortletServices.java Index: CommonPortletServices.java =================================================================== RCS file: /home/cvs/jakarta-jetspeed-2/cps/src/java/org/apache/jetspeed/cps/CommonPortletServices.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- CommonPortletServices.java 13 Feb 2004 03:48:27 -0000 1.5 +++ CommonPortletServices.java 18 Feb 2004 09:14:14 -0000 1.6 @@ -53,16 +53,8 @@ */ package org.apache.jetspeed.cps; -import java.util.Enumeration; -import java.util.Hashtable; import java.util.Properties; import java.io.FileInputStream; -import java.io.IOException; -import java.net.URL; - -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -235,20 +227,4 @@ return initialized; } - /** - * Load all CPS component descriptors from the class path - * - * @throws IOException - */ - public static void loadServiceDescriptors() - throws IOException - { - ClassLoader cl = Thread.currentThread().getContextClassLoader() ; - Enumeration e = cl.getResources("META-INF/component.properties") ; - while(e.hasMoreElements()) - { - URL url = (URL)e.nextElement(); - System.out.println("url = " + url); - } - } } 1.1 jakarta-jetspeed-2/cps/src/test/org/apache/jetspeed/components/TestComponentManager.java Index: TestComponentManager.java =================================================================== /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2000-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache Jetspeed" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", * "Apache Jetspeed", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.jetspeed.components; import java.io.File; import java.util.Iterator; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.commons.configuration.DOM4JConfiguration; import org.apache.jetspeed.cps.template.TemplateLocatorComponent; import org.picocontainer.MutablePicoContainer; import org.picocontainer.defaults.CachingComponentAdapter; import org.picocontainer.defaults.CachingComponentAdapterFactory; import org.picocontainer.defaults.ComponentAdapterFactory; import org.picocontainer.defaults.DefaultComponentAdapterFactory; import org.picocontainer.defaults.DefaultPicoContainer; /** * TestComponentManager * * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a> * @version $Id: TestComponentManager.java,v 1.1 2004/02/18 09:14:14 taylor Exp $ */ public class TestComponentManager extends TestCase { public TestComponentManager(String name) { super( name ); } /** * Start the tests. * * @param args the arguments. Not used */ public static void main(String args[]) { junit.awtui.TestRunner.main( new String[] { TestComponentManager.class.getName() } ); } public void setup() { System.out.println("Setup: Testing Email"); } public static Test suite() { // All methods starting with "test" will be executed in the test suite. return new TestSuite(TestComponentManager.class); } public void testManager() throws Exception { Configuration config = getConfiguration(); ComponentManager cm = new ComponentManager(config); cm.start(); int count = 0; Iterator containers = cm.getContainers().iterator(); while (containers.hasNext()) { MutablePicoContainer container = (MutablePicoContainer)containers.next(); System.out.println("container = " + container); count++; } assertTrue("count = 2 " + count, count == 2); MutablePicoContainer container = cm.getContainer("default"); assertNotNull("default container is null", container); container = cm.getContainer("persistence"); assertNotNull("persistence container is null", container); TemplateLocatorComponent locator1 = (TemplateLocatorComponent)cm.getComponent("locator"); assertNotNull("locator1 is null", locator1); TemplateLocatorComponent locator2 = (TemplateLocatorComponent)cm.getComponent("persistence", "locator2"); assertNotNull("locator2 is null", locator2); cm.stop(); System.out.println("Component Manager Test completed"); } public Configuration getConfiguration() throws Exception { String filename = getConfigurationFile(); // DOM4JConfiguration configuration = new DOM4JConfiguration(); PropertiesConfiguration configuration = new PropertiesConfiguration(); configuration.setFileName(filename); configuration.load(); return configuration; } public String getConfigurationFile() { // return getApplicationRoot() + "/WEB-INF/conf/components.xml"; return getApplicationRoot() + "/WEB-INF/conf/components.properties"; } public String getApplicationRoot() { String applicationRoot = "test"; File testPath = new File(applicationRoot); if (!testPath.exists()) { testPath = new File( "cps" + File.separator + applicationRoot); if (testPath.exists()) { applicationRoot = testPath.getAbsolutePath(); } } return applicationRoot; } public void testInterceptorAdapter() throws Exception { InterceptorAdapterFactory adapterFactory = new InterceptorAdapterFactory(new DefaultComponentAdapterFactory()); CachingComponentAdapterFactory cachingComponentAdapterFactory = new CachingComponentAdapterFactory(adapterFactory); ComponentAdapterFactory caf = cachingComponentAdapterFactory; DefaultPicoContainer pico = new DefaultPicoContainer(caf); CachingComponentAdapter dumbAdapter = (CachingComponentAdapter) caf.createComponentAdapter("dumb", DumbImpl.class, null); pico.registerComponent(dumbAdapter); Dumb dumb = (Dumb) dumbAdapter.getComponentInstance(); System.out.println("dumb = " + dumb); dumb.test(); Dumb dumb2 = (Dumb) dumbAdapter.getComponentInstance(); 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/test/WEB-INF/conf/components.properties Index: components.properties =================================================================== # this should be implemented in XML containers = default, persistence default.container = default container.default.classname = org.picocontainer.defaults.DefaultPicoContainer container.default.adapter = unknown container.persistence.classname = org.picocontainer.defaults.DefaultPicoContainer container.persistence.adapter = unknown 1.1 jakarta-jetspeed-2/cps/test/WEB-INF/conf/components.xml Index: components.xml =================================================================== <config> <version>2.0</version> <container> <name>default</name> <class>org.picocontainer.defaults.DefaultPicoContainer</class> <type>pico</type> <default>true</default> <component> <name>template-locator</name> <class>org.apache.jetspeed.cps.template.TemplateLocatorComponentImpl</class> </component> <component> <name>template-locator2</name> <class>org.apache.jetspeed.cps.template.TemplateLocatorComponentImpl</class> </component> </container> <container> <name>persistence</name> <class>org.picocontainer.defaults.DefaultPicoContainer</class> <type>pico</type> <default>true</default> <component> <name>whatever</name> <class>org.apache.jetspeed.cps.template.TemplateLocatorComponentImpl</class> </component> </container> </config>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]