1 16 package org.apache.cocoon.portal.util; 17 18 import java.util.HashMap ; 19 import java.util.Iterator ; 20 import java.util.Map ; 21 22 import org.apache.cocoon.portal.coplet.CopletData; 23 import org.apache.cocoon.portal.coplet.CopletInstanceData; 24 import org.exolab.castor.mapping.MapItem; 25 26 36 public class AttributesFieldHandler extends AbstractFieldHandler { 37 38 protected Map getAttributes(Object object) { 39 if (object instanceof CopletData) { 40 return ((CopletData) object).getAttributes(); 41 } 42 return ((CopletInstanceData) object).getAttributes(); 43 } 44 45 public Object getValue(Object object) { 46 HashMap map = new HashMap (); 47 Iterator iterator = this.getAttributes(object).entrySet().iterator(); 48 Map.Entry entry; 49 Object key; 50 while (iterator.hasNext()) { 51 entry = (Map.Entry ) iterator.next(); 52 key = entry.getKey(); 53 map.put(key, new MapItem(key, entry.getValue())); 54 } 55 return map; 56 } 57 58 public Object newInstance(Object parent) { 59 return new MapItem(); 60 } 61 62 public void resetValue(Object object) { 63 this.getAttributes(object).clear(); 64 } 65 66 public void setValue(Object object, Object value) { 67 MapItem item = (MapItem) value; 68 this.getAttributes(object).put(item.getKey(), item.getValue()); 69 } 70 } 71 | Popular Tags |