You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2003/06/13 16:15:04 UTC

cvs commit: cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/util AttributesFieldHandler.java

cziegeler    2003/06/13 07:15:04

  Modified:    src/blocks/portal/java/org/apache/cocoon/portal/coplet
                        CopletData.java CopletInstanceData.java
               src/blocks/portal/java/org/apache/cocoon/portal/util
                        AttributesFieldHandler.java
  Log:
  Adding attributes to coplet instance datas
  
  Revision  Changes    Path
  1.7       +5 -1      cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/coplet/CopletData.java
  
  Index: CopletData.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/coplet/CopletData.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- CopletData.java	22 May 2003 15:19:45 -0000	1.6
  +++ CopletData.java	13 Jun 2003 14:15:04 -0000	1.7
  @@ -148,6 +148,10 @@
           this.copletBaseData = copletBaseData;
       }
   
  +    public void removeAttribute(String key) {
  +        this.attributes.remove(key);
  +    }
  +    
       public Object getAttribute(String key) {
           return this.attributes.get(key);
       }
  
  
  
  1.6       +22 -1     cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/coplet/CopletInstanceData.java
  
  Index: CopletInstanceData.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/coplet/CopletInstanceData.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- CopletInstanceData.java	21 May 2003 13:23:59 -0000	1.5
  +++ CopletInstanceData.java	13 Jun 2003 14:15:04 -0000	1.6
  @@ -50,6 +50,9 @@
   */
   package org.apache.cocoon.portal.coplet;
   
  +import java.util.HashMap;
  +import java.util.Map;
  +
   import org.apache.cocoon.portal.factory.impl.AbstractProducible;
   
   
  @@ -71,6 +74,8 @@
   
   	protected int status = STATUS_MAXIMIZED;
   
  +    protected Map attributes = new HashMap();
  +
   	/**
   	 * Constructor
   	 */
  @@ -107,4 +112,20 @@
   	public void setStatus(int status) {
   		this.status = status;
   	}
  +
  +    public Object getAttribute(String key) {
  +        return this.attributes.get(key);
  +    }
  +
  +    public void setAttribute(String key, Object value) {
  +        this.attributes.put(key, value);
  +    }
  +    
  +    public void removeAttribute(String key) {
  +        this.attributes.remove(key);
  +    }
  +    
  +    public Map getAttributes() {
  +        return this.attributes;
  +    }
   }
  
  
  
  1.2       +18 -8     cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/util/AttributesFieldHandler.java
  
  Index: AttributesFieldHandler.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/util/AttributesFieldHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AttributesFieldHandler.java	26 May 2003 14:29:52 -0000	1.1
  +++ AttributesFieldHandler.java	13 Jun 2003 14:15:04 -0000	1.2
  @@ -55,12 +55,16 @@
   import java.util.Map;
   
   import org.apache.cocoon.portal.coplet.CopletData;
  +import org.apache.cocoon.portal.coplet.CopletInstanceData;
   import org.exolab.castor.mapping.FieldHandler;
   import org.exolab.castor.mapping.MapItem;
   
   /**
    * Field handler for attributes of a CopletData object.
    *
  + * FIXME This is a little bit hacky and should be changed by using
  + * reflection
  + * 
    * @author <a href="mailto:bluetkemeier@s-und-n.de">Bj�rn L�tkemeier</a>
    * 
    * @version CVS $Id$
  @@ -68,14 +72,20 @@
   public class AttributesFieldHandler
   implements FieldHandler
   {
  -	public void checkValidity(Object object)
  -	{
  +	public void checkValidity(Object object) {
   	}
   
  -	public Object getValue(Object object) 
  -	{
  +    protected Map getAttributes(Object object) {
  +        if (object instanceof CopletData) {
  +            return ((CopletData)object).getAttributes();
  +        } else {
  +            return ((CopletInstanceData)object).getAttributes();
  +        }
  +    }
  +    
  +	public Object getValue(Object object) {
   		HashMap map = new HashMap();
  -		Iterator iterator = ((CopletData)object).getAttributes().entrySet().iterator();
  +		Iterator iterator = this.getAttributes( object ).entrySet().iterator();
   		Map.Entry entry;
   		Object key;
   		while (iterator.hasNext()) {
  @@ -93,12 +103,12 @@
   
   	public void resetValue(Object object)
   	{
  -		((CopletData)object).getAttributes().clear();
  +		this.getAttributes( object ).clear();
   	}
   
   	public void setValue(Object object, Object value)
   	{
   		MapItem item = (MapItem)value;
  -		((CopletData)object).setAttribute((String)item.getKey(), item.getValue());
  +        this.getAttributes( object ).put((String)item.getKey(), item.getValue());
   	}
   }