Return-Path: Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 41977 invoked by uid 500); 20 Aug 2003 07:34:36 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 41762 invoked by uid 500); 20 Aug 2003 07:34:26 -0000 Delivered-To: apmail-cocoon-2.1-cvs@apache.org Received: (qmail 41568 invoked from network); 20 Aug 2003 07:34:20 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 20 Aug 2003 07:34:19 -0000 Received: (qmail 94201 invoked by uid 1260); 20 Aug 2003 07:34:37 -0000 Date: 20 Aug 2003 07:34:37 -0000 Message-ID: <20030820073437.94200.qmail@minotaur.apache.org> From: cziegeler@apache.org To: cocoon-2.1-cvs@apache.org Subject: cvs commit: cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/components/persistance RequestDataStoreImpl.java RequestDataStore.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N cziegeler 2003/08/20 00:34:37 Modified: src/blocks/portal/java/org/apache/cocoon/portal/impl PortalServiceImpl.java src/blocks/portal/conf portal.xconf Added: src/blocks/portal/java/org/apache/cocoon/portal/impl PortalServiceInfo.java src/blocks/portal/java/org/apache/cocoon/components/persistance RequestDataStoreImpl.java RequestDataStore.java Log: Removing use of RequestLifecycleComponent Adding new request data store instead Revision Changes Path 1.7 +38 -85 cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortalServiceImpl.java Index: PortalServiceImpl.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortalServiceImpl.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- PortalServiceImpl.java 18 Jul 2003 14:41:46 -0000 1.6 +++ PortalServiceImpl.java 20 Aug 2003 07:34:36 -0000 1.7 @@ -50,11 +50,12 @@ */ package org.apache.cocoon.portal.impl; -import java.io.IOException; -import java.util.*; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; -import org.apache.avalon.excalibur.pool.Recyclable; import org.apache.avalon.framework.activity.Disposable; +import org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.component.Composable; @@ -66,22 +67,16 @@ import org.apache.avalon.framework.context.ContextException; import org.apache.avalon.framework.context.Contextualizable; import org.apache.avalon.framework.logger.AbstractLogEnabled; -import org.apache.cocoon.ProcessingException; -import org.apache.cocoon.components.RequestLifecycleComponent; -import org.apache.cocoon.environment.ObjectModelHelper; -import org.apache.cocoon.environment.Session; -import org.apache.cocoon.environment.SourceResolver; -import org.apache.cocoon.portal.Constants; +import org.apache.avalon.framework.thread.ThreadSafe; +import org.apache.cocoon.components.ContextHelper; +import org.apache.cocoon.components.persistance.RequestDataStore; import org.apache.cocoon.portal.PortalComponentManager; import org.apache.cocoon.portal.PortalService; -import org.xml.sax.SAXException; /** * Default implementation of a portal service using a session to store * custom information. * - * TODO: Make this ThreadSafe - * * @author Carsten Ziegeler * @author Volker Schmitt * @@ -90,129 +85,82 @@ public class PortalServiceImpl extends AbstractLogEnabled implements Composable, - RequestLifecycleComponent, + ThreadSafe, PortalService, Contextualizable, - Recyclable, Disposable, Configurable { protected Context context; - protected Map objectModel; - - protected Map temporaryAttributes = new HashMap(); - protected ComponentManager manager; - protected String portalName; - - protected String attributePrefix; + protected Map portalComponentManagers = new HashMap(); - protected PortalComponentManager portalComponentManager; + protected RequestDataStore dataStore; - protected Map portalComponentManagers = new HashMap(); + final protected String key = this.getClass().getName(); public void compose(ComponentManager componentManager) throws ComponentException { this.manager = componentManager; + this.dataStore = (RequestDataStore) this.manager.lookup(RequestDataStore.ROLE); } - - public void setup(SourceResolver resolver, Map objectModel) throws ProcessingException, SAXException, IOException { - this.objectModel = objectModel; - - Map context = (Map)objectModel.get(ObjectModelHelper.PARENT_CONTEXT); - if (context != null) { - String portalName = (String)context.get(Constants.PORTAL_NAME_KEY); - if (portalName != null) { - this.setPortalName(portalName); - } - } + protected PortalServiceInfo getInfo() { + PortalServiceInfo info = (PortalServiceInfo) this.dataStore.getRequestData(this.key); + if ( info == null ) { + info = new PortalServiceInfo(); + info.setup(ContextHelper.getObjectModel(this.context), this.portalComponentManagers); + this.dataStore.setRequestData(this.key, info); + } + return info; } - + public String getPortalName() { - return this.portalName; + return this.getInfo().getPortalName(); } public void setPortalName(String value) { - this.portalName = value; - this.attributePrefix = this.getClass().getName() + '/' + this.portalName + '/'; - this.portalComponentManager = (PortalComponentManager) this.portalComponentManagers.get(this.portalName); - if ( this.portalComponentManager == null ) { - throw new RuntimeException("Portal '"+this.portalName+"' is not configured."); - } - } - - /* (non-Javadoc) - * @see org.apache.avalon.excalibur.pool.Recyclable#recycle() - */ - public void recycle() { - this.portalName = null; - this.temporaryAttributes.clear(); - this.portalComponentManager = null; + this.getInfo().setPortalName(value); } public Object getAttribute(String key) { - final Session session = ObjectModelHelper.getRequest(this.objectModel).getSession(false); - if (session == null) { - return null; - } - return session.getAttribute( this.attributePrefix + key); + return this.getInfo().getAttribute(key); } public void setAttribute(String key, Object value) { - final Session session = ObjectModelHelper.getRequest(this.objectModel).getSession(); - session.setAttribute( this.attributePrefix + key, value); + this.getInfo().setAttribute(key, value); } public void removeAttribute(String key) { - final Session session = ObjectModelHelper.getRequest(this.objectModel).getSession(false); - if ( session != null ) { - session.removeAttribute( this.attributePrefix + key); - } + this.getInfo().removeAttribute(key); } public Iterator getAttributeNames() { - final Session session = ObjectModelHelper.getRequest(this.objectModel).getSession(false); - if ( session != null ) { - List names = new ArrayList(); - Enumeration e = session.getAttributeNames(); - final int pos = this.attributePrefix.length() + 1; - if ( e != null ) { - while ( e.hasMoreElements() ) { - final String name = (String)e.nextElement(); - if ( name.startsWith( this.attributePrefix )) { - names.add( name.substring( pos ) ); - } - } - } - return names.iterator(); - } - return Collections.EMPTY_MAP.keySet().iterator(); + return this.getInfo().getAttributeNames(); } public Object getTemporaryAttribute(String key) { - return this.temporaryAttributes.get( key ); + return this.getInfo().getTemporaryAttribute(key); } public void setTemporaryAttribute(String key, Object value) { - this.temporaryAttributes.put( key, value ); + this.getInfo().setTemporaryAttribute(key, value); } public void removeTemporaryAttribute(String key) { - this.temporaryAttributes.remove( key ); + this.getInfo().removeTemporaryAttribute(key); } public Iterator getTemporaryAttributeNames() { - return this.temporaryAttributes.keySet().iterator(); + return this.getInfo().getTemporaryAttributeNames(); } - /** * Return the component manager for the current portal */ public PortalComponentManager getComponentManager() { - return this.portalComponentManager; + return this.getInfo().getComponentManager(); } /* (non-Javadoc) @@ -226,6 +174,11 @@ * @see org.apache.avalon.framework.activity.Disposable#dispose() */ public void dispose() { + if ( this.manager != null ) { + this.manager.release( (Component)this.dataStore ); + this.manager = null; + this.dataStore = null; + } final Iterator i = this.portalComponentManagers.values().iterator(); while ( i.hasNext() ) { ContainerUtil.dispose( i.next() ); 1.1 cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortalServiceInfo.java Index: PortalServiceInfo.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, 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 Cocoon" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact apache@apache.org. 5. Products derived from this software may not be called "Apache", 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 (INCLU- DING, 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 and was originally created by Stefano Mazzocchi . For more information on the Apache Software Foundation, please see . */ package org.apache.cocoon.portal.impl; import java.util.*; import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; import java.util.Iterator; import java.util.List; import java.util.Map; import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.Session; import org.apache.cocoon.portal.Constants; import org.apache.cocoon.portal.PortalComponentManager; /** * The portal information for the current request * * @author Carsten Ziegeler * * @version CVS $Id: PortalServiceInfo.java,v 1.1 2003/08/20 07:34:36 cziegeler Exp $ */ public class PortalServiceInfo { private Map portalComponentManagers; private Map objectModel; protected Map temporaryAttributes = new HashMap(); protected String portalName; protected String attributePrefix; protected PortalComponentManager portalComponentManager; public void setup(Map objectModel, Map managers) { this.objectModel = objectModel; this.portalComponentManagers = managers; Map context = (Map)objectModel.get(ObjectModelHelper.PARENT_CONTEXT); if (context != null) { String portalName = (String)context.get(Constants.PORTAL_NAME_KEY); if (portalName != null) { this.setPortalName(portalName); } } } public String getPortalName() { return this.portalName; } public void setPortalName(String value) { this.portalName = value; this.attributePrefix = this.getClass().getName() + '/' + this.portalName + '/'; this.portalComponentManager = (PortalComponentManager) this.portalComponentManagers.get(this.portalName); if ( this.portalComponentManager == null ) { throw new RuntimeException("Portal '"+this.portalName+"' is not configured."); } } public Object getAttribute(String key) { final Session session = ObjectModelHelper.getRequest(this.objectModel).getSession(false); if (session == null) { return null; } return session.getAttribute( this.attributePrefix + key); } public void setAttribute(String key, Object value) { final Session session = ObjectModelHelper.getRequest(this.objectModel).getSession(); session.setAttribute( this.attributePrefix + key, value); } public void removeAttribute(String key) { final Session session = ObjectModelHelper.getRequest(this.objectModel).getSession(false); if ( session != null ) { session.removeAttribute( this.attributePrefix + key); } } public Iterator getAttributeNames() { final Session session = ObjectModelHelper.getRequest(this.objectModel).getSession(false); if ( session != null ) { List names = new ArrayList(); Enumeration e = session.getAttributeNames(); final int pos = this.attributePrefix.length() + 1; if ( e != null ) { while ( e.hasMoreElements() ) { final String name = (String)e.nextElement(); if ( name.startsWith( this.attributePrefix )) { names.add( name.substring( pos ) ); } } } return names.iterator(); } return Collections.EMPTY_MAP.keySet().iterator(); } public Object getTemporaryAttribute(String key) { return this.temporaryAttributes.get( key ); } public void setTemporaryAttribute(String key, Object value) { this.temporaryAttributes.put( key, value ); } public void removeTemporaryAttribute(String key) { this.temporaryAttributes.remove( key ); } public Iterator getTemporaryAttributeNames() { return this.temporaryAttributes.keySet().iterator(); } /** * Return the component manager for the current portal */ public PortalComponentManager getComponentManager() { return this.portalComponentManager; } } 1.23 +1 -0 cocoon-2.1/src/blocks/portal/conf/portal.xconf Index: portal.xconf =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/conf/portal.xconf,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- portal.xconf 29 Jul 2003 06:52:15 -0000 1.22 +++ portal.xconf 20 Aug 2003 07:34:36 -0000 1.23 @@ -82,4 +82,5 @@ + 1.1 cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/components/persistance/RequestDataStoreImpl.java Index: RequestDataStoreImpl.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, 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 Cocoon" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact apache@apache.org. 5. Products derived from this software may not be called "Apache", 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 (INCLU- DING, 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 and was originally created by Stefano Mazzocchi . For more information on the Apache Software Foundation, please see . */ package org.apache.cocoon.components.persistance; import java.util.HashMap; import java.util.Map; import org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.context.Context; import org.apache.avalon.framework.context.ContextException; import org.apache.avalon.framework.context.Contextualizable; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.cocoon.components.ContextHelper; import org.apache.cocoon.environment.ObjectModelHelper; /** * * @author Carsten Ziegeler * * @version CVS $Id: RequestDataStoreImpl.java,v 1.1 2003/08/20 07:34:36 cziegeler Exp $ */ public class RequestDataStoreImpl extends AbstractLogEnabled implements Component, ThreadSafe, RequestDataStore, Contextualizable { protected Context context; protected String requestDataKey; protected String globalRequestDataKey; /* (non-Javadoc) * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context) */ public void contextualize(Context context) throws ContextException { this.context = context; this.requestDataKey = this.getClass().getName() + "/RD"; this.globalRequestDataKey = this.getClass().getName() + "/GRD"; } /* (non-Javadoc) * @see org.apache.cocoon.components.persistance.RequestDataStore#getGlobalRequestData(java.lang.String) */ public Object getGlobalRequestData(String key) { Object value = null; final Map objectModel = (Map)ContextHelper.getObjectModel(this.context); Map m = (Map)objectModel.get(this.globalRequestDataKey); if ( m != null ) { value = m.get( key ); } return value; } /* (non-Javadoc) * @see org.apache.cocoon.components.persistance.RequestDataStore#getRequestData(java.lang.String) */ public Object getRequestData(String key) { Object value = null; final Map objectModel = (Map)ContextHelper.getObjectModel(this.context); Map m = (Map)objectModel.get(this.requestDataKey + ObjectModelHelper.getRequest(objectModel).hashCode()); if ( m != null ) { value = m.get( key ); } return value; } /* (non-Javadoc) * @see org.apache.cocoon.components.persistance.RequestDataStore#removeGlobalRequestData(java.lang.String) */ public void removeGlobalRequestData(String key) { final Map objectModel = (Map)ContextHelper.getObjectModel(this.context); Map m = (Map)objectModel.get(this.globalRequestDataKey); if ( m != null ) { objectModel.remove( key ); } } /* (non-Javadoc) * @see org.apache.cocoon.components.persistance.RequestDataStore#removeRequestData(java.lang.String) */ public void removeRequestData(String key) { final Map objectModel = (Map)ContextHelper.getObjectModel(this.context); Map m = (Map)objectModel.get(this.requestDataKey + ObjectModelHelper.getRequest(objectModel).hashCode()); if ( m != null ) { objectModel.remove( key ); } } /* (non-Javadoc) * @see org.apache.cocoon.components.persistance.RequestDataStore#setGlobalRequestData(java.lang.String, java.lang.Object) */ public void setGlobalRequestData(String key, Object value) { final Map objectModel = (Map)ContextHelper.getObjectModel(this.context); Map m = (Map)objectModel.get(this.globalRequestDataKey); if ( m == null ) { m = new HashMap(); objectModel.put(this.globalRequestDataKey, m); } m.put(key, value); } /* (non-Javadoc) * @see org.apache.cocoon.components.persistance.RequestDataStore#setRequestData(java.lang.String, java.lang.Object) */ public void setRequestData(String key, Object value) { final Map objectModel = (Map)ContextHelper.getObjectModel(this.context); Map m = (Map)objectModel.get(this.requestDataKey + ObjectModelHelper.getRequest(objectModel).hashCode()); if ( m == null ) { m = new HashMap(); objectModel.put(this.requestDataKey + ObjectModelHelper.getRequest(objectModel).hashCode(), m); } m.put(key, value); } } 1.1 cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/components/persistance/RequestDataStore.java Index: RequestDataStore.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, 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 Cocoon" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact apache@apache.org. 5. Products derived from this software may not be called "Apache", 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 (INCLU- DING, 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 and was originally created by Stefano Mazzocchi . For more information on the Apache Software Foundation, please see . */ package org.apache.cocoon.components.persistance; /** * * @author Carsten Ziegeler * * @version CVS $Id: RequestDataStore.java,v 1.1 2003/08/20 07:34:36 cziegeler Exp $ */ public interface RequestDataStore { String ROLE = RequestDataStore.class.getName(); Object getRequestData(String key); void removeRequestData(String key); void setRequestData(String key, Object value); Object getGlobalRequestData(String key); void removeGlobalRequestData(String key); void setGlobalRequestData(String key, Object value); }