1 16 package org.apache.cocoon.portal.coplet; 17 18 import java.util.HashMap ; 19 import java.util.Map ; 20 import java.util.Collection ; 21 import java.util.Set ; 22 import java.util.HashSet ; 23 import java.util.Iterator ; 24 25 import org.apache.cocoon.portal.factory.impl.AbstractProducible; 26 import org.apache.cocoon.portal.pluto.om.common.PreferenceSetImpl; 27 import org.apache.cocoon.portal.util.AttributedMapItem; 28 import org.apache.pluto.om.common.PreferenceSet; 29 30 31 39 public final class CopletInstanceData 40 extends AbstractProducible { 41 42 protected CopletData copletData; 43 44 protected Map attributes = new HashMap (); 45 46 47 protected Map temporaryAttributes = new HashMap (); 48 49 50 protected PreferenceSetImpl preferences = new PreferenceSetImpl(); 51 52 private String title; 53 54 57 public CopletInstanceData() { 58 } 60 61 64 public CopletData getCopletData() { 65 return copletData; 66 } 67 68 72 public void setCopletData(CopletData copletData) { 73 this.copletData = copletData; 74 } 75 76 public Object getAttribute(String key) { 77 return this.attributes.get(key); 78 } 79 80 public void setAttribute(String key, Object value) { 81 this.attributes.put(key, value); 82 } 83 84 public Object removeAttribute(String key) { 85 return this.attributes.remove(key); 86 } 87 88 public Map getAttributes() { 89 return this.attributes; 90 } 91 92 public final Collection getCastorAttributes() { 93 Set set = new HashSet (this.attributes.size()); 94 Iterator iterator = this.attributes.entrySet().iterator(); 95 Map.Entry entry; 96 while (iterator.hasNext()) { 97 entry = (Map.Entry ) iterator.next(); 98 AttributedMapItem item = new AttributedMapItem(); 99 item.setKey(entry.getKey()); 100 item.setValue(entry.getValue()); 101 set.add(item); 102 } 103 return set; 104 } 105 106 public void addAttribute(AttributedMapItem item) { 107 this.attributes.put(item.getKey(), item.getValue()); 108 } 109 110 public Object getTemporaryAttribute(String key) { 111 return this.temporaryAttributes.get(key); 112 } 113 114 public void setTemporaryAttribute(String key, Object value) { 115 this.temporaryAttributes.put(key, value); 116 } 117 118 public Object removeTemporaryAttribute(String key) { 119 return this.temporaryAttributes.remove(key); 120 } 121 122 public Map getTemporaryAttributes() { 123 return this.temporaryAttributes; 124 } 125 126 public String getTitle() { 127 if (this.title != null) { 128 return this.title; 129 } 130 return this.getCopletData().getTitle(); 131 } 132 133 public String getInstanceTitle() { 134 return this.title; 135 } 136 137 public void setTitle(String title) { 138 this.title = title; 139 } 140 141 public void setPreferences(PreferenceSetImpl preferences) { 142 this.preferences = preferences; 143 } 144 145 public PreferenceSet getPreferences() { 146 return this.preferences; 147 } 148 149 public PreferenceSet getCastorPreferences() { 150 return getPreferences(); 151 } 152 153 public void setCastorPreferences(PreferenceSet castorPreferences) { 154 setPreferences((PreferenceSetImpl)castorPreferences); 155 } 156 157 160 protected Object clone() throws CloneNotSupportedException { 161 CopletInstanceData clone = (CopletInstanceData)super.clone(); 162 163 clone.copletData = this.copletData; 164 clone.attributes = new HashMap (this.attributes); 165 clone.temporaryAttributes = new HashMap (this.temporaryAttributes); 166 clone.preferences = new PreferenceSetImpl(); 167 clone.preferences.addAll(this.preferences.getPreferences()); 168 169 return clone; 170 } 171 172 public CopletInstanceData copy() { 173 try { 174 return (CopletInstanceData)this.clone(); 175 } catch (CloneNotSupportedException cnse) { 176 return null; 178 } 179 } 180 } | Popular Tags |