cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/aspect/impl MapItem.java AspectDataFieldHandler.java
Date Mon, 26 May 2003 14:29:53 GMT
cziegeler    2003/05/26 07:29:53

  Modified:    src/blocks/portal/java/org/apache/cocoon/portal/profile/impl
                        MapSourceAdapter.java
                        CopletInstanceDataManager.java
                        SimpleProfileManager.java
  Added:       src/blocks/portal/java/org/apache/cocoon/portal/util
                        AspectDataFieldHandler.java
                        ConfigurationFieldHandler.java
                        CopletBaseDataFieldHandler.java
                        CopletDataReferenceFieldHandler.java MapItem.java
                        ParameterFieldHandler.java
                        CopletInstanceDataFieldHandler.java
                        AttributesFieldHandler.java
                        CopletBaseDataReferenceFieldHandler.java
                        CopletDataFieldHandler.java
                        CopletInstanceDataReferenceFieldHandler.java
                        ReferenceFieldHandler.java
  Removed:     src/blocks/portal/java/org/apache/cocoon/portal/profile/impl
                        CopletInstanceDataReferenceFieldHandler.java
                        CopletBaseDataReferenceFieldHandler.java
                        CopletDataFieldHandler.java
                        ReferenceFieldHandler.java
                        CopletDataReferenceFieldHandler.java
                        CopletInstanceDataFieldHandler.java
                        CopletBaseDataFieldHandler.java
                        ConfigurationFieldHandler.java
                        AttributesFieldHandler.java
               src/blocks/portal/java/org/apache/cocoon/portal/layout/impl
                        ParameterFieldHandler.java
               src/blocks/portal/java/org/apache/cocoon/portal/aspect/impl
                        MapItem.java AspectDataFieldHandler.java
  Log:
  Refactoring, improving performance
  
  Revision  Changes    Path
  1.1                  cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/util/AspectDataFieldHandler.java
  
  Index: AspectDataFieldHandler.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  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.portal.util;
  
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  
  import org.apache.cocoon.portal.aspect.Aspectalizable;
  import org.exolab.castor.mapping.FieldHandler;
  
  /**
   * Field handler for aspects of an Aspectizable object.
   *
   * @author <a href="mailto:bluetkemeier@s-und-n.de">Björn Lütkemeier</a>
   * 
   * @version CVS $Id: AspectDataFieldHandler.java,v 1.1 2003/05/26 14:29:52 cziegeler Exp $
   */
  public class AspectDataFieldHandler
  implements FieldHandler
  {
  	public void checkValidity(Object object)
  	{
  	}
  
  	public Object getValue(Object object) 
  	{
  		HashMap map = new HashMap();
  		Iterator iterator;
  
  		Map data = ((Aspectalizable) object).getPersistentAspectData();
  		if (data == null)
  			return map;
  
  		iterator = data.entrySet().iterator();
  		Map.Entry entry;
  		Object key;
  		while (iterator.hasNext()) {
  			entry = (Map.Entry)iterator.next();
  			key = entry.getKey();
  			map.put(key, new MapItem(key, entry.getValue()));
  		}
  		return map;
  	}
  
  	public Object newInstance(Object parent)
  	{
  		return new MapItem();
  	}
  
  	public void resetValue(Object object)
  	{
  		// impossible
  	}
  
  	public void setValue(Object object, Object value)
  	{
  		MapItem item = (MapItem)value;
  		((Aspectalizable)object).addPersistentAspectData((String)item.getKey(), item.getValue());
  	}
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/util/ConfigurationFieldHandler.java
  
  Index: ConfigurationFieldHandler.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  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.portal.util;
  
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  
  import org.apache.cocoon.portal.coplet.CopletBaseData;
  import org.exolab.castor.mapping.FieldHandler;
  import org.exolab.castor.mapping.MapItem;
  
  /**
   * Field handler for attributes of a CopletBaseData object.
   *
   * @author <a href="mailto:bluetkemeier@s-und-n.de">Björn Lütkemeier</a>
   * 
   * @version CVS $Id: ConfigurationFieldHandler.java,v 1.1 2003/05/26 14:29:52 cziegeler Exp $
   */
  public class ConfigurationFieldHandler
  implements FieldHandler
  {
  	public void checkValidity(Object object)
  	{
  	}
  
  	public Object getValue(Object object) 
  	{
  		HashMap map = new HashMap();
  		Iterator iterator = ((CopletBaseData)object).getCopletConfig().entrySet().iterator();
  		Map.Entry entry;
  		Object key;
  		while (iterator.hasNext()) {
  			entry = (Map.Entry)iterator.next();
  			key = entry.getKey();
  			map.put(key, new MapItem(key, entry.getValue()));
  		}
  		return map;
  	}
  
  	public Object newInstance(Object parent)
  	{
  		return new MapItem();
  	}
  
  	public void resetValue(Object object)
  	{
  		((CopletBaseData)object).getCopletConfig().clear();
  	}
  
  	public void setValue(Object object, Object value)
  	{
  		MapItem item = (MapItem)value;
  		((CopletBaseData)object).setCopletConfig((String)item.getKey(), item.getValue());
  	}
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/util/CopletBaseDataFieldHandler.java
  
  Index: CopletBaseDataFieldHandler.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  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.portal.util;
  
  import java.util.Iterator;
  import java.util.Map;
  import java.util.Vector;
  
  import org.apache.cocoon.portal.coplet.CopletBaseData;
  import org.apache.cocoon.portal.profile.impl.CopletBaseDataManager;
  import org.exolab.castor.mapping.FieldHandler;
  
  
  /**
   * Field handler for CopletBaseData instances.
   *
   * @author <a href="mailto:bluetkemeier@s-und-n.de">Björn Lütkemeier</a>
   * 
   * @version CVS $Id: CopletBaseDataFieldHandler.java,v 1.1 2003/05/26 14:29:52 cziegeler Exp $
   */
  public class CopletBaseDataFieldHandler 
  implements FieldHandler {
  
  	public void checkValidity(Object object)
  	{
  	}
  
  	public Object getValue(Object object) 
  	{
  		Map map = ((CopletBaseDataManager)object).getCopletBaseData();
  		Vector result = new Vector(map.size());
  		
  		Iterator iterator = map.values().iterator();
  		while (iterator.hasNext())
  			result.addElement(iterator.next());
  		
  		return result;
  	}
  
  	public Object newInstance(Object parent)
  	{
  		return new CopletBaseData();
  	}
  
  	public void resetValue(Object object)
  	{
  		((CopletBaseDataManager)object).getCopletBaseData().clear();
  	}
  
  	public void setValue(Object object, Object value)
  	{
  		CopletBaseData data = (CopletBaseData)value;
  		((CopletBaseDataManager)object).getCopletBaseData().put(data.getId(), data);
  	}
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/util/CopletDataReferenceFieldHandler.java
  
  Index: CopletDataReferenceFieldHandler.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  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.portal.util;
  
  import org.apache.cocoon.portal.coplet.CopletData;
  import org.apache.cocoon.portal.coplet.CopletInstanceData;
  
  /**
   * Field handler for external CopletData references.
   *
   * @author <a href="mailto:bluetkemeier@s-und-n.de">Björn Lütkemeier</a>
   * 
   * @version CVS $Id: CopletDataReferenceFieldHandler.java,v 1.1 2003/05/26 14:29:52 cziegeler Exp $
   */
  public class CopletDataReferenceFieldHandler 
  extends ReferenceFieldHandler {
  
  	public void checkValidity(Object object)
  	{
  	}
  
  	public Object getValue(Object object) 
  	{
  		CopletData copletData = ((CopletInstanceData)object).getCopletData();
  		if (copletData != null) {
  			return copletData.getId();
  		} else {
  			return null;
  		}
  	}
  
  	public Object newInstance(Object parent)
  	{
  		return new CopletData();
  	}
  
  	public void resetValue(Object object)
  	{
  		((CopletInstanceData)object).setCopletData(null);
  	}
  
  	public void setValue(Object object, Object value)
  	{
  		CopletData copletData = (CopletData)getObjectMap().get(value);
  		if (copletData == null)
  			throw new IllegalArgumentException("Referenced Coplet Data "+value+" does not exist.");
  		((CopletInstanceData)object).setCopletData(copletData);
  	}
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/util/MapItem.java
  
  Index: MapItem.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  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.portal.util;
  
  
  /**
   * Used by the AspectDataFieldHandler for Castor.
   *
   * @author <a href="mailto:bluetkemeier@s-und-n.de">Björn Lütkemeier</a>
   * 
   * @version CVS $Id: MapItem.java,v 1.1 2003/05/26 14:29:52 cziegeler Exp $
   */
  public class MapItem
  extends org.exolab.castor.mapping.MapItem {
  
  	public MapItem() {
  		super();
  	}
  
  	public MapItem(Object key, Object value) {
  		super(key, value);
  	}
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/util/ParameterFieldHandler.java
  
  Index: ParameterFieldHandler.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  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.portal.util;
  
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  
  import org.apache.cocoon.portal.layout.Parameters;
  import org.exolab.castor.mapping.FieldHandler;
  import org.exolab.castor.mapping.MapItem;
  
  /**
   * Field handler for parameters.
   *
   * @author <a href="mailto:bluetkemeier@s-und-n.de">Björn Lütkemeier</a>
   * 
   * @version CVS $Id: ParameterFieldHandler.java,v 1.1 2003/05/26 14:29:52 cziegeler Exp $
   */
  public class ParameterFieldHandler
  implements FieldHandler
  {
  	public void checkValidity(Object object)
  	{
  	}
  
  	public Object getValue(Object object) 
  	{
  		HashMap map = new HashMap();
  		Iterator iterator = ((Parameters)object).getParameters().entrySet().iterator();
  		Map.Entry entry;
  		Object key;
  		while (iterator.hasNext()) {
  			entry = (Map.Entry)iterator.next();
  			key = entry.getKey();
  			map.put(key, new MapItem(key, entry.getValue()));
  		}
  		return map;
  	}
  
  	public Object newInstance(Object parent)
  	{
  		return new MapItem();
  	}
  
  	public void resetValue(Object object)
  	{
  		((Parameters)object).getParameters().clear();
  	}
  
  	public void setValue(Object object, Object value)
  	{
  		MapItem item = (MapItem)value;
  		((Parameters)object).getParameters().put(item.getKey(), item.getValue());
  	}
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/util/CopletInstanceDataFieldHandler.java
  
  Index: CopletInstanceDataFieldHandler.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  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.portal.util;
  
  import java.util.Iterator;
  import java.util.Map;
  import java.util.Vector;
  
  import org.apache.cocoon.portal.coplet.CopletInstanceData;
  import org.apache.cocoon.portal.profile.impl.CopletInstanceDataManager;
  import org.exolab.castor.mapping.FieldHandler;
  
  
  /**
   * Field handler for CopletInstanceData instances.
   *
   * @author <a href="mailto:bluetkemeier@s-und-n.de">Björn Lütkemeier</a>
   * 
   * @version CVS $Id: CopletInstanceDataFieldHandler.java,v 1.1 2003/05/26 14:29:52 cziegeler Exp $
   */
  public class CopletInstanceDataFieldHandler 
  implements FieldHandler {
  
  	public void checkValidity(Object object)
  	{
  	}
  
  	public Object getValue(Object object) 
  	{
  		Map map = ((CopletInstanceDataManager)object).getCopletInstanceData();
  		Vector result = new Vector(map.size());
  		
  		Iterator iterator = map.values().iterator();
  		while (iterator.hasNext())
  			result.addElement(iterator.next());
  		
  		return result;
  	}
  
  	public Object newInstance(Object parent)
  	{
  		return new CopletInstanceData();
  	}
  
  	public void resetValue(Object object)
  	{
  		((CopletInstanceDataManager)object).getCopletInstanceData().clear();
  	}
  
  	public void setValue(Object object, Object value)
  	{
  		CopletInstanceData data = (CopletInstanceData)value;
  		((CopletInstanceDataManager)object).getCopletInstanceData().put(data.getId(), data);
  	}
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/util/AttributesFieldHandler.java
  
  Index: AttributesFieldHandler.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  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.portal.util;
  
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  
  import org.apache.cocoon.portal.coplet.CopletData;
  import org.exolab.castor.mapping.FieldHandler;
  import org.exolab.castor.mapping.MapItem;
  
  /**
   * Field handler for attributes of a CopletData object.
   *
   * @author <a href="mailto:bluetkemeier@s-und-n.de">Björn Lütkemeier</a>
   * 
   * @version CVS $Id: AttributesFieldHandler.java,v 1.1 2003/05/26 14:29:52 cziegeler Exp $
   */
  public class AttributesFieldHandler
  implements FieldHandler
  {
  	public void checkValidity(Object object)
  	{
  	}
  
  	public Object getValue(Object object) 
  	{
  		HashMap map = new HashMap();
  		Iterator iterator = ((CopletData)object).getAttributes().entrySet().iterator();
  		Map.Entry entry;
  		Object key;
  		while (iterator.hasNext()) {
  			entry = (Map.Entry)iterator.next();
  			key = entry.getKey();
  			map.put(key, new MapItem(key, entry.getValue()));
  		}
  		return map;
  	}
  
  	public Object newInstance(Object parent)
  	{
  		return new MapItem();
  	}
  
  	public void resetValue(Object object)
  	{
  		((CopletData)object).getAttributes().clear();
  	}
  
  	public void setValue(Object object, Object value)
  	{
  		MapItem item = (MapItem)value;
  		((CopletData)object).setAttribute((String)item.getKey(), item.getValue());
  	}
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/util/CopletBaseDataReferenceFieldHandler.java
  
  Index: CopletBaseDataReferenceFieldHandler.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  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.portal.util;
  
  import org.apache.cocoon.portal.coplet.CopletBaseData;
  import org.apache.cocoon.portal.coplet.CopletData;
  
  
  /**
   * Field handler for external CopletBaseData references.
   *
   * @author <a href="mailto:bluetkemeier@s-und-n.de">Björn Lütkemeier</a>
   * 
   * @version CVS $Id: CopletBaseDataReferenceFieldHandler.java,v 1.1 2003/05/26 14:29:52 cziegeler Exp $
   */
  public class CopletBaseDataReferenceFieldHandler 
  extends ReferenceFieldHandler {
  
  	public void checkValidity(Object object)
  	{
  	}
  
  	public Object getValue(Object object) 
  	{
  		CopletBaseData copletBaseData = ((CopletData)object).getCopletBaseData();
  		if (copletBaseData != null) {
  			return copletBaseData.getId();
  		} else {
  			return null;
  		}
  	}
  
  	public Object newInstance(Object parent)
  	{
  		return new CopletBaseData();
  	}
  
  	public void resetValue(Object object)
  	{
  		((CopletData)object).setCopletBaseData(null);
  	}
  
  	public void setValue(Object object, Object value)
  	{
  		CopletBaseData copletBaseData = (CopletBaseData)getObjectMap().get(value);
  		if (copletBaseData == null)
  			throw new IllegalArgumentException("Referenced Coplet Base Data "+value+" does not exist.");
  		((CopletData)object).setCopletBaseData(copletBaseData);
  	}
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/util/CopletDataFieldHandler.java
  
  Index: CopletDataFieldHandler.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  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.portal.util;
  
  import java.util.Iterator;
  import java.util.Map;
  import java.util.Vector;
  
  import org.apache.cocoon.portal.coplet.CopletData;
  import org.apache.cocoon.portal.profile.impl.CopletDataManager;
  import org.exolab.castor.mapping.FieldHandler;
  
  
  /**
   * Field handler for CopletData instances.
   *
   * @author <a href="mailto:bluetkemeier@s-und-n.de">Björn Lütkemeier</a>
   * 
   * @version CVS $Id: CopletDataFieldHandler.java,v 1.1 2003/05/26 14:29:52 cziegeler Exp $
   */
  public class CopletDataFieldHandler 
  implements FieldHandler {
  
  	public void checkValidity(Object object)
  	{
  	}
  
  	public Object getValue(Object object) 
  	{
  		Map map = ((CopletDataManager)object).getCopletData();
  		Vector result = new Vector(map.size());
  		
  		Iterator iterator = map.values().iterator();
  		while (iterator.hasNext())
  			result.addElement(iterator.next());
  		
  		return result;
  	}
  
  	public Object newInstance(Object parent)
  	{
  		return new CopletData();
  	}
  
  	public void resetValue(Object object)
  	{
  		((CopletDataManager)object).getCopletData().clear();
  	}
  
  	public void setValue(Object object, Object value)
  	{
  		CopletData data = (CopletData)value;
  		((CopletDataManager)object).getCopletData().put(data.getId(), data);
  	}
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/util/CopletInstanceDataReferenceFieldHandler.java
  
  Index: CopletInstanceDataReferenceFieldHandler.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  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.portal.util;
  
  import org.apache.cocoon.portal.coplet.CopletInstanceData;
  import org.apache.cocoon.portal.layout.impl.CopletLayout;
  
  /**
   * Field handler for external CopletInstanceData references.
   *
   * @author <a href="mailto:bluetkemeier@s-und-n.de">Björn Lütkemeier</a>
   * 
   * @version CVS $Id: CopletInstanceDataReferenceFieldHandler.java,v 1.1 2003/05/26 14:29:52 cziegeler Exp $
   */
  public class CopletInstanceDataReferenceFieldHandler
  extends ReferenceFieldHandler {
  
  	public void checkValidity(Object object) {
  	}
  
  	public Object getValue(Object object) {
  		CopletInstanceData copletInstanceData = ((CopletLayout)object).getCopletInstanceData();
  		if (copletInstanceData != null) {
  			return copletInstanceData.getId();
  		} else {
  			return null;
  		}
  	}
  
  	public Object newInstance(Object parent) {
  		return new CopletInstanceData();
  	}
  
  	public void resetValue(Object object) {
  		((CopletLayout)object).setCopletInstanceData(null);
  	}
  
  	public void setValue(Object object, Object value) {
  		CopletInstanceData copletInstanceData = (CopletInstanceData)getObjectMap().get(value);
  		if (copletInstanceData == null)
  			throw new IllegalArgumentException("Referenced Coplet Instance Data "+value+" does not exist.");
  		((CopletLayout)object).setCopletInstanceData(copletInstanceData);
  	}
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/util/ReferenceFieldHandler.java
  
  Index: ReferenceFieldHandler.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  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.portal.util;
  
  import java.util.HashMap;
  import java.util.Map;
  
  import org.exolab.castor.mapping.FieldHandler;
  
  /**
   * Field handler superclass for external references.
   *
   * @author <a href="mailto:bluetkemeier@s-und-n.de">Björn Lütkemeier</a>
   * 
   * @version CVS $Id: ReferenceFieldHandler.java,v 1.1 2003/05/26 14:29:52 cziegeler Exp $
   */
  public abstract class ReferenceFieldHandler
  implements FieldHandler
  {
  	/**
  	 * Used to pass resolvable objects to the field handler.
  	 */
  	private static ThreadLocal threadLocalMap = new InheritableThreadLocal();
  	
  	/**
  	 * Gets the map used to pass resolvable objects to the field handler.
  	 */
  	public static Map getObjectMap() {
  		Map map = (Map)threadLocalMap.get();
  
  		if (map == null) {
  			map = new HashMap();
  			threadLocalMap.set(map);
  		}
  
  		return map;
  	}
  
  	/**
  	 * Sets the map used to pass resolvable objects to the field handler.
  	 */
  	public static void setObjectMap(Map objectMap) {
  		if (objectMap == null) {
  			threadLocalMap.set(new HashMap());
  		} else {
  			threadLocalMap.set(objectMap);
  		}
  	}
  }
  
  
  
  1.3       +53 -28    cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/MapSourceAdapter.java
  
  Index: MapSourceAdapter.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/MapSourceAdapter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MapSourceAdapter.java	22 May 2003 15:19:42 -0000	1.2
  +++ MapSourceAdapter.java	26 May 2003 14:29:53 -0000	1.3
  @@ -66,6 +66,7 @@
   import org.apache.avalon.framework.thread.ThreadSafe;
   import org.apache.cocoon.components.persistance.CastorSourceConverter;
   import org.apache.cocoon.portal.profile.ProfileLS;
  +import org.apache.cocoon.portal.util.*;
   import org.apache.cocoon.xml.dom.DOMUtil;
   import org.apache.excalibur.source.Source;
   import org.apache.excalibur.source.SourceResolver;
  @@ -99,15 +100,23 @@
   
   		Configuration config = ((Configuration)mapKey.get("config")).getChild("profiles");
   		Object type = map.get("type");
  -		String uri = null;
  -		if (type == null) {
  -			uri = config.getChild(profile+"-load").getAttribute("uri");
  -		} else if (type.equals("global")) {
  -			uri = config.getChild(profile+"-global-load").getAttribute("uri");
  -		} else if (type.equals("role")) {
  -			uri = config.getChild(profile+"-role-load").getAttribute("uri");
  -		} else if (type.equals("user")) {
  -			uri = config.getChild(profile+"-user-load").getAttribute("uri");
  +		String uri = null, configKey = null;
  +		try {
  +			if (type == null) {
  +				configKey = profile+"-load";
  +				uri = config.getChild(configKey).getAttribute("uri");
  +			} else if (type.equals("global")) {
  +				configKey = profile+"-global-load";
  +				uri = config.getChild(configKey).getAttribute("uri");
  +			} else if (type.equals("role")) {
  +				configKey = profile+"-role-load";
  +				uri = config.getChild(configKey).getAttribute("uri");
  +			} else if (type.equals("user")) {
  +				configKey = profile+"-user-load";
  +				uri = config.getChild(configKey).getAttribute("uri");
  +			}
  +		} catch (Exception e) {
  +			throw new ConfigurationException("Error reading URI from configuration "+configKey, e);
   		}
   		buffer.append(uri);
   
  @@ -152,15 +161,23 @@
   
   		Configuration config = ((Configuration)mapKey.get("config")).getChild("profiles");
   		Object type = map.get("type");
  -		String uri = null;
  -		if (type == null) {
  -			uri = config.getChild(profileName+"-save").getAttribute("uri");
  -		} else if (type.equals("global")) {
  -			uri = config.getChild(profileName+"-global-save").getAttribute("uri");
  -		} else if (type.equals("role")) {
  -			uri = config.getChild(profileName+"-role-save").getAttribute("uri");
  -		} else if (type.equals("user")) {
  -			uri = config.getChild(profileName+"-user-save").getAttribute("uri");
  +		String uri = null, configKey = null;
  +		try {
  +			if (type == null) {
  +				configKey = profileName+"-save";
  +				uri = config.getChild(configKey).getAttribute("uri");
  +			} else if (type.equals("global")) {
  +				configKey = profileName+"-global-save";
  +				uri = config.getChild(configKey).getAttribute("uri");
  +			} else if (type.equals("role")) {
  +				configKey = profileName+"-role-save";
  +				uri = config.getChild(configKey).getAttribute("uri");
  +			} else if (type.equals("user")) {
  +				configKey = profileName+"-user-save";
  +				uri = config.getChild(configKey).getAttribute("uri");
  +			}
  +		} catch (Exception e) {
  +			throw new ConfigurationException("Error reading URI from configuration "+configKey, e);
   		}
   		buffer.append(uri);
   
  @@ -218,15 +235,23 @@
   
   			Configuration config = ((Configuration)mapKey.get("config")).getChild("profiles");
   			Object type = map.get("type");
  -			String uri = null;
  -			if (type == null) {
  -				uri = config.getChild(profile+"-load").getAttribute("uri");
  -			} else if (type.equals("global")) {
  -				uri = config.getChild(profile+"-global-load").getAttribute("uri");
  -			} else if (type.equals("role")) {
  -				uri = config.getChild(profile+"-role-load").getAttribute("uri");
  -			} else if (type.equals("user")) {
  -				uri = config.getChild(profile+"-user-load").getAttribute("uri");
  +			String uri = null, configKey = null;
  +			try {
  +				if (type == null) {
  +					configKey = profile+"-load";
  +					uri = config.getChild(configKey).getAttribute("uri");
  +				} else if (type.equals("global")) {
  +					configKey = profile+"-global-load";
  +					uri = config.getChild(configKey).getAttribute("uri");
  +				} else if (type.equals("role")) {
  +					configKey = profile+"-role-load";
  +					uri = config.getChild(configKey).getAttribute("uri");
  +				} else if (type.equals("user")) {
  +					configKey = profile+"-user-load";
  +					uri = config.getChild(configKey).getAttribute("uri");
  +				}
  +			} catch (Exception e) {
  +				throw new ConfigurationException("Error reading URI from configuration "+configKey, e);
   			}
   			buffer.append(uri);
   
  
  
  
  1.3       +1 -14     cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/CopletInstanceDataManager.java
  
  Index: CopletInstanceDataManager.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/CopletInstanceDataManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CopletInstanceDataManager.java	20 May 2003 14:32:35 -0000	1.2
  +++ CopletInstanceDataManager.java	26 May 2003 14:29:53 -0000	1.3
  @@ -51,7 +51,6 @@
   package org.apache.cocoon.portal.profile.impl;
   
   import java.util.HashMap;
  -import java.util.Iterator;
   import java.util.Map;
   
   import org.apache.cocoon.portal.coplet.CopletInstanceData;
  @@ -89,17 +88,5 @@
   	 */
   	public void putCopletInstanceData(CopletInstanceData data) {
   		this.copletInstanceData.put(data.getId(), data);
  -	}
  -	
  -	/**
  -	 * Updates the references to the coplet data to the ones stored in the manager.
  -	 */
  -	public void update(CopletDataManager manager) {
  -		Iterator iterator = this.copletInstanceData.values().iterator();
  -		CopletInstanceData data;
  -		while (iterator.hasNext()) {
  -			data = (CopletInstanceData)iterator.next();
  -			data.setCopletData(manager.getCopletData(data.getCopletData().getId()));
  -		}
   	}
   }
  
  
  
  1.11      +217 -303  cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/SimpleProfileManager.java
  
  Index: SimpleProfileManager.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/profile/impl/SimpleProfileManager.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- SimpleProfileManager.java	23 May 2003 14:20:09 -0000	1.10
  +++ SimpleProfileManager.java	26 May 2003 14:29:53 -0000	1.11
  @@ -51,6 +51,7 @@
   package org.apache.cocoon.portal.profile.impl;
   
   import java.util.HashMap;
  +import java.util.HashSet;
   import java.util.Iterator;
   import java.util.Map;
   
  @@ -70,7 +71,6 @@
   import org.apache.cocoon.portal.layout.Item;
   import org.apache.cocoon.portal.layout.Layout;
   import org.apache.cocoon.portal.layout.LayoutFactory;
  -import org.apache.cocoon.portal.layout.impl.CopletLayout;
   import org.apache.cocoon.portal.profile.ProfileManager;
   import org.apache.cocoon.portal.util.DeltaApplicableReferencesAdjustable;
   import org.apache.cocoon.webapps.authentication.AuthenticationManager;
  @@ -100,6 +100,8 @@
       
       private Map attributes = new HashMap();
       
  +    private ReadWriteLock lock = new ReadWriteLock();
  +    
       /**
        * @see org.apache.avalon.framework.component.Composable#compose(ComponentManager)
        */
  @@ -163,77 +165,46 @@
               }
               
   
  -			Object[] objects = (Object[])service.getAttribute(portalPrefix+"/Layout");
  -			if (objects != null)
  -				layout = (Layout)objects[0];
  -				
  +			layout = (Layout)service.getAttribute(portalPrefix+"/Layout");
   			if (layout == null) {
  -				HashMap map = new HashMap();
  -				map.put("portalname", service.getPortalName());
  -				
  -				// TODO Change to KeyManager usage
  -                RequestState state = this.getRequestState();
  -				UserHandler handler = state.getHandler();
  -				HashMap keyMap = new HashMap();
  -				keyMap.put("user", handler.getUserId());
  -				keyMap.put("role", handler.getContext().getContextInfo().get("role"));
  -				keyMap.put("config", state.getApplicationConfiguration().getConfiguration("portal"));
  -	
  -				// load coplet base data
  -				map.put("profile", "copletbasedata");
  -				map.put("objectmap", null);
  -				Object[] result = this.getProfile(keyMap, map, portalPrefix+"/CopletBaseData", null, null);
  -				if (result[0] == null) {
  -					throw new SourceNotFoundException("Could not find coplet base data profile.");
  -				}
  -				CopletBaseDataManager copletBaseDataManager = (CopletBaseDataManager)result[0];
  -				boolean lastLoaded = ((Boolean)result[1]).booleanValue();
  -	
  -				// load coplet data
  -				map.put("profile", "copletdata");
  -				map.put("objectmap", copletBaseDataManager.getCopletBaseData());
  -				result = this.getDeltaProfile(keyMap, map, portalPrefix+"/CopletData", service, copletFactory, lastLoaded);
  -				if (result[0] == null) {
  -					throw new SourceNotFoundException("Could not find coplet data profile.");
  -				}
  -				CopletDataManager copletDataManager = (CopletDataManager)result[0];
  -				lastLoaded = ((Boolean)result[1]).booleanValue();
  -				// updating
  -				Iterator i = copletDataManager.getCopletData().values().iterator();
  -				while ( i.hasNext()) {
  -					CopletData cd = (CopletData)i.next();
  -					copletFactory.prepare(cd);
  -				}
  -	
  -				// load coplet instance data
  -				map.put("profile", "copletinstancedata");
  -				map.put("objectmap", copletDataManager.getCopletData());
  -				result = this.getOrCreateProfile(keyMap, map, portalPrefix+"/CopletInstanceData", service, copletFactory);
  -				CopletInstanceDataManager copletInstanceDataManager = (CopletInstanceDataManager)result[0];
  -				boolean loaded = ((Boolean)result[1]).booleanValue();
  -				if (lastLoaded && !loaded) {
  -					copletInstanceDataManager.update(copletDataManager);
  +				this.lock.readLock();
  +				try {
  +					HashMap map = new HashMap();
  +					map.put("portalname", service.getPortalName());
  +					
  +					// TODO Change to KeyManager usage
  +					RequestState state = this.getRequestState();
  +					UserHandler handler = state.getHandler();
  +					HashMap keyMap = new HashMap();
  +					keyMap.put("user", handler.getUserId());
  +					keyMap.put("role", handler.getContext().getContextInfo().get("role"));
  +					keyMap.put("config", state.getApplicationConfiguration().getConfiguration("portal"));
  +					
  +					// load coplet base data
  +					map.put("profile", "copletbasedata");
  +					map.put("objectmap", null);
  +					Object[] result = this.getProfile(keyMap, map, portalPrefix+"/CopletBaseData", null);
  +					CopletBaseDataManager copletBaseDataManager = (CopletBaseDataManager)result[0];
  +					
  +					// load coplet data
  +					map.put("profile", "copletdata");
  +					map.put("objectmap", copletBaseDataManager.getCopletBaseData());
  +					CopletDataManager copletDataManager = (CopletDataManager)this.getDeltaProfile(keyMap, map, portalPrefix+"/CopletData", service, copletFactory, ((Boolean)result[1]).booleanValue());
  +					
  +					// load coplet instance data
  +					map.put("profile", "copletinstancedata");
  +					map.put("objectmap", copletDataManager.getCopletData());
  +					CopletInstanceDataManager copletInstanceDataManager = (CopletInstanceDataManager)this.getOrCreateProfile(keyMap, map, portalPrefix+"/CopletInstanceData", service, copletFactory);
  +					
  +					// load layout
  +					map.put("profile", "layout");
  +					map.put("objectmap", copletInstanceDataManager.getCopletInstanceData());
  +					layout = (Layout)this.getOrCreateProfile(keyMap, map, portalPrefix+"/Layout", service, factory);
  +				} finally {
  +					this.lock.releaseLocks();
   				}
  -				lastLoaded = loaded;
  -				// updating
  -				i = copletInstanceDataManager.getCopletInstanceData().values().iterator();
  -				while ( i.hasNext()) {
  -					CopletInstanceData cid = (CopletInstanceData)i.next();
  -					copletFactory.prepare(cid);
  -				}
  -	
  -				// load layout
  -				map.put("profile", "layout");
  -				map.put("objectmap", ((CopletInstanceDataManager)result[0]).getCopletInstanceData());
  -				result = this.getOrCreateProfile(keyMap, map, portalPrefix+"/Layout", service, factory);
  -				layout = (Layout)result[0];
  -				loaded = ((Boolean)result[1]).booleanValue();
  -				if (lastLoaded && !loaded) {
  -					updateLayout(layout, copletInstanceDataManager);
  -				}
  -	            factory.prepareLayout( layout );
   			}
  -
  +			
               return layout;
           } catch (Exception ce) {
               // TODO
  @@ -303,90 +274,94 @@
   		}
       }
       
  -    /**
  -     * Gets a profile and applies possible user and role deltas to it.
  -     * @return result[0] is the profile, result[1] is a Boolean, 
  -     * which signals whether the profile has been loaded or reused.
  -     */
  -    private Object[] getDeltaProfile(Object key, Map map, String location, PortalService service, Object factory, boolean forcedLoad) 
  -    throws Exception {
  -    	Object[] result;
  +	/**
  +	 * Gets a profile.
  +	 * @return result[0] is the profile, result[1] is a Boolean, 
  +	 * which signals whether the profile has been loaded or reused.
  +	 */
  +	private Object[] getProfile(Object key, Map map, String location, Object factory)
  +	throws Exception {
  +		return this.getProfile(key, map, location, factory, false);
  +	}
  +
  +	/**
  +	 * Gets a profile and applies possible user and role deltas to it.
  +	 */
  +	private Object getDeltaProfile(Object key, Map map, String location, PortalService service, Object factory, boolean forcedLoad) 
  +	throws Exception {
  +		DeltaApplicableReferencesAdjustable result;
  +		Object object;
       	
   		// TODO Change to KeyManager usage
   		Map keyMap = (Map)key;
   
  -		// check validities
  +		// load global profile
   		map.put("type", "global");
  -		Object[] globalValidity = this.getValidity(key, map, location, null);
  +		Object global = this.getProfile(key, map, location, factory, forcedLoad)[0];
  +		result = (DeltaApplicableReferencesAdjustable)this.loadProfile(key, map, factory);
  +	
  +		// load role delta
   		map.put("type", "role");
  -		Object[] roleValidity = this.getValidity(key, map, location+"-role-"+keyMap.get("role"), null);
  -		map.put("type", "user");
  -		Object[] userValidity = this.getValidity(key, map, location+"-user", service);
  -		boolean isValid
  -			= ((Boolean)globalValidity[0]).booleanValue()
  -			  &&((Boolean)roleValidity[0]).booleanValue()
  -			  &&((Boolean)userValidity[0]).booleanValue();
  -			  
  -		if (isValid && !forcedLoad) {
  -			Object[] objects = (Object[]) this.attributes.get(location);
  -			result = new Object[] {objects[0], Boolean.FALSE};
  -		} else {
  -			// load global profile
  -			map.put("type", "global");
  -			Object global = this.getProfile(key, map, location, globalValidity, null, factory, forcedLoad)[0];
  -			DeltaApplicableReferencesAdjustable object = (DeltaApplicableReferencesAdjustable)this.loadProfile(key, map, location, (SourceValidity)globalValidity[1], service, factory);
  -			result = new Object[] {object, Boolean.TRUE};
  -		
  -			// load role delta
  -			map.put("type", "role");
  -			result = this.getProfile(key, map, location+"-role-"+keyMap.get("role"), roleValidity, null, factory, forcedLoad);
  -			if (((Boolean)result[1]).booleanValue())
  -				object.applyDelta(result[0]); 		
  -
  -			// load user delta
  -			map.put("type", "user");
  -			result = this.getProfile(key, map, location+"-user", userValidity, service, factory, forcedLoad);
  -			if (((Boolean)result[1]).booleanValue())
  -				object.applyDelta(result[0]);
  -				
  -			// change references to objects where no delta has been applied
  -			object.adjustReferences(global);
  -			
  -			result = new Object[] {object, Boolean.TRUE}; 		
  +		try {
  +			object = this.getProfile(key, map, location+"-role-"+keyMap.get("role"), factory, forcedLoad)[0];
  +			if (object != null)
  +				result.applyDelta(object); 		
  +		} catch (Exception e) {
  +			if (!isSourceNotFoundException(e))
  +				throw e;
   		}
   
  -    	return result;
  -    }
  +		// load user delta
  +		map.put("type", "user");
  +		try {
  +			object = this.loadProfile(key, map, factory);
  +			if (object != null)
  +				result.applyDelta(object);
  +		} catch (Exception e) {
  +			if (!isSourceNotFoundException(e))
  +				throw e;
  +		}
  +		
  +		if (result == null)
  +			throw new SourceNotFoundException("Global "+keyMap.get("profile")+" does not exist.");
  +		
  +		// change references to objects where no delta has been applied
  +		result.adjustReferences(global);
  +		
  +		service.setAttribute(location, result);
  +		
  +		return result;
  +	}
   
   	/**
   	 * Gets a user profile and creates it by copying the role or the global profile.
  -	 * @return result[0] is the profile, result[1] is a Boolean, 
  -	 * which signals whether the profile has been loaded or reused.
   	 */
  -	private Object[] getOrCreateProfile(Object key, Map map, String location, PortalService service, Object factory) 
  +	private Object getOrCreateProfile(Object key, Map map, String location, PortalService service, Object factory) 
   	throws Exception {
  -		Object[] result;
  +		Object result;
       	
   		// TODO Change to KeyManager usage
   		Map keyMap = (Map)key;
   
   		// load user profile
   		map.put("type", "user");
  -		result = this.getProfile(key, map, location, service, factory);
  +		try {
  +			result = this.loadProfile(key, map, factory);
  +		} catch (Exception e1) {
  +			if (!isSourceNotFoundException(e1))
  +				throw e1;
   
  -		if (result[0] == null) {
   			// load role profile
   			map.put("type", "role");
  -			result = this.getProfile(key, map, location+"-role-"+keyMap.get("role"), service, factory);
  +			try {
  +				result = this.loadProfile(key, map, factory);
  +			} catch (Exception e2) {
  +				if (!isSourceNotFoundException(e2))
  +					throw e2;
   
  -			if (result[0] == null) {
   				// load global profile
   				map.put("type", "global");
  -				result = this.getProfile(key, map, location+"-global", service, factory);
  -
  -				if (result[0] == null) {
  -					throw new SourceNotFoundException("Could not find global or role profile to create user profile.");
  -				}
  +				result = this.loadProfile(key, map, factory);
   			}
   			
   			// save profile as user profile
  @@ -394,24 +369,15 @@
   			try {
   				adapter = (MapSourceAdapter) this.manager.lookup(MapSourceAdapter.ROLE);
   				map.put("type", "user");
  -				
  -                // FIXME - disabled saving for testing
  -                // adapter.saveProfile(key, map, result[0]);
  -
  -				// set validity for created user profile
  -				SourceValidity newValidity = adapter.getValidity(key, map);
  -				if (newValidity != null) {
  -					Object[] objects = new Object[] { result[0], newValidity };
  -					this.setAttribute(location, objects, service);
  -				} else {
  -                    Object[] objects = new Object[] { result[0], null };
  -                    this.setAttribute(location, objects, service);
  -				}
  +				// FIXME - disabled saving for testing
  +				// adapter.saveProfile(key, map, result);
   			} finally {
   				this.manager.release(adapter);
   			}
   		}
   		
  +		service.setAttribute(location, result);
  +
   		return result;
   	}
   
  @@ -420,35 +386,30 @@
   	 * @return result[0] is the profile, result[1] is a Boolean, 
   	 * which signals whether the profile has been loaded or reused.
   	 */
  -	private Object[] getProfile(Object key, Map map, String location, PortalService service, Object factory) 
  +	private Object[] getProfile(Object key, Map map, String location, Object factory, boolean forcedLoad) 
   	throws Exception {
   		MapSourceAdapter adapter = null;
   		try {
  -			adapter = (MapSourceAdapter) this.manager.lookup(MapSourceAdapter.ROLE);
  +			adapter = (MapSourceAdapter)this.manager.lookup(MapSourceAdapter.ROLE);
   
  -			Object[] objects = (Object[]) this.getAttribute(location, service);
  -			
  -			// check whether still valid
  -			SourceValidity sourceValidity = null;
  -			if (objects != null)
  -				sourceValidity = (SourceValidity)objects[1];
  -			Object[] validity = this.getValidity(key, map, location, sourceValidity, adapter);
  -			if (((Boolean)validity[0]).booleanValue()) {
  -				if (objects == null) {
  -					return new Object[]{null, Boolean.FALSE};
  -				} else {
  -					return new Object[]{objects[0], Boolean.FALSE};
  -				}
  -			}
  +			Object result = this.checkValidity(key, map, location, forcedLoad, adapter);
  +			if (!(result instanceof SourceValidity))
  +				return new Object[]{result, Boolean.FALSE};
  +			SourceValidity newValidity = (SourceValidity)result; 
  +
  +			this.lock.releaseReadLock();
  +			this.lock.writeLock();
   			
  -			// load profile
  -			SourceValidity newValidity = (SourceValidity)validity[1];
  +			// check validity again in case of another thread has already loaded
  +			result = this.checkValidity(key, map, location, forcedLoad, adapter);
  +			if (!(result instanceof SourceValidity))
  +				return new Object[]{result, Boolean.FALSE};
  +			newValidity = (SourceValidity)result; 
  +
   			Object object = adapter.loadProfile(key, map);
  -			if (object != null)
  -				this.prepareObject(object, factory);
  +			this.prepareObject(object, factory);
   			if (newValidity != null) {
  -				objects = new Object[] { object, newValidity };
  -				this.setAttribute(location, objects, service);
  +				this.attributes.put(location, new Object[] {object, newValidity});
   			}
   
   			return new Object[]{object, Boolean.TRUE};
  @@ -458,68 +419,40 @@
   	}
   	
   	/**
  -	 * Gets a profile by using the specified validity information.
  -	 * @return result[0] is the profile, result[1] is a Boolean, 
  -	 * which signals whether the profile has been loaded or reused.
  +	 * If the profile is valid itself is returned, otherwise a newly created SourceValidity object is returned.
   	 */
  -	private Object[] getProfile(Object key, Map map, String location, Object[] validity, PortalService service, Object factory, boolean forcedLoad) 
  -	throws Exception {
  -		if (forcedLoad) {
  -			try {
  -				return new Object[] {this.loadProfile(key, map, location, (SourceValidity)validity[1], service, factory), Boolean.TRUE};
  -			} catch (SourceNotFoundException e) {
  -				return new Object[] {null, Boolean.FALSE};
  -			}
  -		} else {
  -			MapSourceAdapter adapter = null;
  -			try {
  -				adapter = (MapSourceAdapter) this.manager.lookup(MapSourceAdapter.ROLE);
  +	private Object checkValidity(Object key, Map map, String location, boolean forcedLoad, MapSourceAdapter adapter) {
  +		Object[] objects = (Object[])this.attributes.get(location);
   
  -				// check whether still valid
  -				Object[] objects = (Object[]) this.getAttribute(location, service);
  -				if (((Boolean)validity[0]).booleanValue()) {
  -					if (objects == null) {
  -						return new Object[]{null, Boolean.FALSE};
  -					} else {
  -						return new Object[]{objects[0], Boolean.FALSE};
  -					}
  -				}
  -
  -				// load profile
  -				SourceValidity newValidity = (SourceValidity)validity[1];
  -				Object object = adapter.loadProfile(key, map);
  -				if (object != null)
  -					this.prepareObject(object, factory);
  -				if (newValidity != null) {
  -					objects = new Object[] { object, newValidity };
  -					this.setAttribute(location, objects, service);
  -				}
  +		SourceValidity sourceValidity = null;
  +		int valid = SourceValidity.INVALID;
  +		if (objects != null) {
  +			sourceValidity = (SourceValidity) objects[1];
  +			valid = sourceValidity.isValid();
  +			if (!forcedLoad && valid == SourceValidity.VALID)
  +				return objects[0];
  +		}
   
  -				return new Object[]{object, Boolean.TRUE};
  -			} finally {
  -				this.manager.release(adapter);
  -			}
  +		SourceValidity newValidity = adapter.getValidity(key, map);
  +		if (!forcedLoad && valid == SourceValidity.UNKNWON) {
  +			if (sourceValidity.isValid(newValidity) == SourceValidity.VALID)
  +				return objects[0];
   		}
  +		
  +		return newValidity;
   	}
   
   	/**
  -	 * Loads a profile and reuses the specified validity for storing if it is not null.
  +	 * Loads a profile.
   	 */
  -	private Object loadProfile(Object key, Map map, String location, SourceValidity newValidity, PortalService service, Object factory) 
  +	private Object loadProfile(Object key, Map map, Object factory)
   	throws Exception {
   		MapSourceAdapter adapter = null;
   		try {
   			adapter = (MapSourceAdapter) this.manager.lookup(MapSourceAdapter.ROLE);
   
  -			if (newValidity == null)
  -				newValidity = adapter.getValidity(key, map);
   			Object object = adapter.loadProfile(key, map);
  -			if (object != null)
  -				this.prepareObject(object, factory);
  -			if (newValidity != null) {
  -				Object[] objects = new Object[] { object, newValidity };
  -				this.setAttribute(location, objects, service);
  -			}
  +			this.prepareObject(object, factory);
   
   			return object;
   		} finally {
  @@ -527,55 +460,13 @@
   		}
   	}
   
  -	/**
  -	 * Checks the validity.
  -	 * @return result[0] is a Boolean, which signals whether it is valid, 
  -	 * result[1] may contain a newly created validity or be null if it could be reused.
  -	 */
  -	private Object[] getValidity(Object key, Map map, String location, PortalService service)
  -	throws Exception { 
  -		MapSourceAdapter adapter = null;
  -		try {
  -			adapter = (MapSourceAdapter) this.manager.lookup(MapSourceAdapter.ROLE);
  -
  -			Object[] objects = (Object[]) this.getAttribute(location, service);
  -			SourceValidity sourceValidity = null;
  -			if (objects != null)
  -				sourceValidity = (SourceValidity)objects[1];
  -			
  -			return this.getValidity(key, map, location, sourceValidity, adapter);
  -		} finally {
  -			this.manager.release(adapter);
  -		}
  -	}
  -
  -	/**
  -	 * Checks the specified validity.
  -	 * @return result[0] is a Boolean, which signals whether it is valid, 
  -	 * result[1] may contain a newly created validity or be null if it could be reused.
  -	 */
  -	private Object[] getValidity(Object key, Map map, String location, SourceValidity sourceValidity, MapSourceAdapter adapter) 
  -	throws Exception {
  -		int valid = SourceValidity.INVALID;
  -
  -		if (sourceValidity != null) {
  -			valid = sourceValidity.isValid();
  -			if (valid == SourceValidity.VALID)
  -				return new Object[]{Boolean.TRUE, null};
  +	private boolean isSourceNotFoundException(Throwable t) {
  +		while (t != null) {
  +			if (t instanceof SourceNotFoundException)
  +				return true;
  +			t = t.getCause();
   		}
  -
  -		SourceValidity newValidity = adapter.getValidity(key, map);
  -		
  -		// source does not exist so it is valid
  -		if (newValidity == null)
  -			return new Object[]{Boolean.TRUE, null};
  -		
  -		if (valid == SourceValidity.UNKNWON) {
  -			if (sourceValidity.isValid(newValidity) == SourceValidity.VALID)
  -				return new Object[]{Boolean.TRUE, newValidity};
  -		}
  -
  -		return new Object[]{Boolean.FALSE, newValidity};
  +		return false;
   	}
   	
   	/**
  @@ -583,7 +474,7 @@
   	 */
   	private void prepareObject(Object object, Object factory)
   	throws ProcessingException {
  -		if (factory != null) {
  +		if (factory != null && object != null) {
   			if (object instanceof Layout) {
   				((LayoutFactory)factory).prepareLayout((Layout)object);
   			} else if (object instanceof CopletDataManager) {
  @@ -604,28 +495,6 @@
   		}
   	}
   	
  -	/**
  -	 * If service is null the value is stored in this.attributes otherwise it is stored via the service.
  -	 */
  -	private void setAttribute(String key, Object value, PortalService service) {
  -		if (service == null) {
  -			this.attributes.put(key, value);
  -		} else {
  -			service.setAttribute(key, value);
  -		}
  -	}
  -	
  -	/**
  -	 * If service is null the value is requested from this.attributes otherwise it is stored via the service.
  -	 */
  -	private Object getAttribute(String key, PortalService service) {
  -		if (service == null) {
  -			return this.attributes.get(key);
  -		} else {
  -			return service.getAttribute(key);
  -		}
  -	}
  -
       public CopletInstanceData getCopletInstanceData(String copletID) {
           PortalService service = null;
           String attribute = null;
  @@ -633,13 +502,12 @@
               service = (PortalService) this.manager.lookup(PortalService.ROLE);
   
   			attribute = SimpleProfileManager.class.getName()+"/"+service.getPortalName()+"/CopletInstanceData";
  -			CopletInstanceDataManager copletInstanceDataManager = (CopletInstanceDataManager)((Object[])service.getAttribute(attribute))[0];
  +			CopletInstanceDataManager copletInstanceDataManager = (CopletInstanceDataManager)service.getAttribute(attribute);
   
               return copletInstanceDataManager.getCopletInstanceData(copletID);
           } catch (ComponentException e) {
  -            // TODO Auto-generated catch block
  -            e.printStackTrace();
  -            throw new CascadingRuntimeException("CE", e);
  +            // TODO
  +            throw new CascadingRuntimeException("Arg", e);
           } finally {
               this.manager.release(service);
           }
  @@ -656,22 +524,68 @@
               this.manager.release(service);
           }
       }
  +    
  +    class ReadWriteLock {
  +    	private Thread activeWriter = null;
  +    	private HashSet activeReaders = new HashSet();
  +    	private int waitingWriters = 0;
  +    	
  +    	public void readLock() 
  +    	throws InterruptedException {
  +    		synchronized (ReadWriteLock.this) {
  +				while (this.activeWriter != null || this.waitingWriters != 0) {
  +					ReadWriteLock.this.wait();
  +				}
  +				this.activeReaders.add(Thread.currentThread());
  +    		}
  +    	}
  +    	
  +    	public void writeLock()
  +    	throws InterruptedException {
  +    		synchronized (ReadWriteLock.this) {
  +				Thread current = Thread.currentThread();
  +
  +				if (this.activeWriter != current) {
  +					this.waitingWriters++;
  +					while (this.activeWriter != null || this.activeReaders.size() != 0) {
  +						ReadWriteLock.this.wait();
  +					}
  +					this.waitingWriters--;
  +					this.activeWriter = current;
  +				}
  +    		}
  +    	}
  +    	
  +		public void releaseReadLock() {
  +			synchronized (ReadWriteLock.this) {
  +				Thread current = Thread.currentThread();
  +
  +				this.activeReaders.remove(current);
  +				if (this.activeReaders.size() == 0 && this.waitingWriters > 0) {
  +					ReadWriteLock.this.notifyAll();
  +				}
  +			}
  +		}
   
  -    private void updateLayout(final Layout layout, final CopletInstanceDataManager manager)
  -    throws ProcessingException {
  -        if (layout instanceof CompositeLayout) {
  -            final CompositeLayout compositeLayout = (CompositeLayout)layout;
  -            for (int j = 0; j < compositeLayout.getSize(); j++) {
  -                final Item layoutItem = (Item) compositeLayout.getItem(j);
  -                this.updateLayout(layoutItem.getLayout(), manager);
  -            }
  -        } else if (layout instanceof CopletLayout) {
  -			final CopletLayout copletLayout = (CopletLayout)layout;
  -			if (manager != null) {
  -				String copletId = copletLayout.getCopletInstanceData().getId();
  -				copletLayout.setCopletInstanceData(manager.getCopletInstanceData(copletId)); 
  +    	public void releaseLocks() {
  +			synchronized (ReadWriteLock.this) {
  +				Thread current = Thread.currentThread();
  +				boolean notify = false;
  +				
  +	    		if (this.activeWriter == current) {
  +	    			this.activeWriter = null;
  +	    			notify = true;
  +	    		} 
  +
  +				this.activeReaders.remove(current);
  +				if (this.activeReaders.size() == 0 && this.waitingWriters > 0) {
  +					notify = true;
  +				}
  +
  +				if (notify) {
  +					ReadWriteLock.this.notifyAll();
  +				}
   			}
  -        }
  +       	}
       }
  -
  -}
  +}
  \ No newline at end of file
  
  
  

Mime
View raw message