1 16 package org.apache.cocoon.portal.aspect.impl; 17 18 import java.util.HashMap ; 19 import java.util.Iterator ; 20 import java.util.Map ; 21 22 import org.apache.cocoon.portal.aspect.AspectDataHandler; 23 import org.apache.cocoon.portal.aspect.Aspectalizable; 24 25 32 public abstract class AbstractAspectalizable 33 implements Aspectalizable, Cloneable { 34 35 transient protected AspectDataHandler aspectDataHandler; 36 37 transient protected Map persistentDatas; 38 39 42 public boolean isAspectSupported(String aspectName) { 43 return this.aspectDataHandler.isAspectSupported( aspectName ); 44 } 45 46 public Object getAspectData(String aspectName) { 47 return this.aspectDataHandler.getAspectData(this, aspectName); 48 } 49 50 public void setAspectData(String aspectName, Object data) { 51 this.aspectDataHandler.setAspectData(this, aspectName, data); 52 } 53 54 public Map getAspectDatas(){ 55 return this.aspectDataHandler.getAspectDatas(this); 56 } 57 58 public Map getPersistentAspectData(){ 59 if (this.aspectDataHandler == null) { 60 return this.persistentDatas; 61 } 62 return this.aspectDataHandler.getPersistentAspectDatas(this); 63 } 64 65 68 public void setAspectDataHandler(AspectDataHandler handler) { 69 this.aspectDataHandler = handler; 70 if ( this.persistentDatas != null ) { 71 Iterator iter = this.persistentDatas.entrySet().iterator(); 72 Map.Entry entry; 73 while (iter.hasNext()) { 74 entry = (Map.Entry )iter.next(); 75 handler.setAspectData(this, (String )entry.getKey(), entry.getValue()); 76 } 77 this.persistentDatas = null; 78 } 79 } 80 81 public void addPersistentAspectData(String aspectName, Object data) { 82 if ( this.persistentDatas == null ) { 83 this.persistentDatas = new HashMap (); 84 } 85 this.persistentDatas.put(aspectName, data); 86 } 87 88 91 protected Object clone() throws CloneNotSupportedException { 92 AbstractAspectalizable clone = (AbstractAspectalizable)super.clone(); 93 94 clone.aspectDataHandler = this.aspectDataHandler; 95 final Map datas = this.aspectDataHandler.getAspectDatas(this); 96 final Iterator i = datas.entrySet().iterator(); 97 while ( i.hasNext() ) { 98 final Map.Entry e = (Map.Entry )i.next(); 99 clone.aspectDataHandler.setAspectData(clone, e.getKey().toString(), e.getValue()); 100 } 101 clone.persistentDatas = this.persistentDatas; 102 103 return clone; 104 } 105 } | Popular Tags |