001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.portal.coplet;
018:
019: import java.util.HashMap;
020: import java.util.Map;
021: import java.util.Collection;
022: import java.util.Set;
023: import java.util.HashSet;
024: import java.util.Iterator;
025:
026: import org.apache.cocoon.portal.factory.impl.AbstractProducible;
027: import org.apache.cocoon.portal.pluto.om.common.PreferenceSetImpl;
028: import org.apache.cocoon.portal.util.AttributedMapItem;
029: import org.apache.pluto.om.common.PreferenceSet;
030:
031: /**
032: *
033: * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
034: * @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
035: * @author <a href="mailto:bluetkemeier@s-und-n.de">Björn Lütkemeier</a>
036: *
037: * @version CVS $Id: CopletInstanceData.java 603311 2007-12-11 17:24:31Z cziegeler $
038: */
039: public final class CopletInstanceData extends AbstractProducible {
040:
041: protected CopletData copletData;
042:
043: protected Map attributes = new HashMap(3);
044:
045: /** Temporary attributes are not persisted */
046: protected Map temporaryAttributes = new HashMap(3);
047:
048: /** Portlet preferences */
049: protected PreferenceSetImpl preferences = new PreferenceSetImpl();
050:
051: private String title;
052:
053: /**
054: * Constructor
055: */
056: public CopletInstanceData() {
057: // Nothing to do
058: }
059:
060: /**
061: * @return CopletData
062: */
063: public CopletData getCopletData() {
064: return copletData;
065: }
066:
067: /**
068: * Sets the copletData.
069: * @param copletData The copletData to set
070: */
071: public void setCopletData(CopletData copletData) {
072: this .copletData = copletData;
073: }
074:
075: public Object getAttribute(String key) {
076: return this .attributes.get(key);
077: }
078:
079: public void setAttribute(String key, Object value) {
080: this .attributes.put(key, value);
081: }
082:
083: public Object removeAttribute(String key) {
084: return this .attributes.remove(key);
085: }
086:
087: public Map getAttributes() {
088: return this .attributes;
089: }
090:
091: public final Collection getCastorAttributes() {
092: Set set = new HashSet(this .attributes.size());
093: Iterator iterator = this .attributes.entrySet().iterator();
094: Map.Entry entry;
095: while (iterator.hasNext()) {
096: entry = (Map.Entry) iterator.next();
097: AttributedMapItem item = new AttributedMapItem();
098: item.setKey(entry.getKey());
099: item.setValue(entry.getValue());
100: set.add(item);
101: }
102: return set;
103: }
104:
105: public void addAttribute(AttributedMapItem item) {
106: this .attributes.put(item.getKey(), item.getValue());
107: }
108:
109: public Object getTemporaryAttribute(String key) {
110: return this .temporaryAttributes.get(key);
111: }
112:
113: public void setTemporaryAttribute(String key, Object value) {
114: this .temporaryAttributes.put(key, value);
115: }
116:
117: public Object removeTemporaryAttribute(String key) {
118: return this .temporaryAttributes.remove(key);
119: }
120:
121: public Map getTemporaryAttributes() {
122: return this .temporaryAttributes;
123: }
124:
125: public String getTitle() {
126: if (this .title != null) {
127: return this .title;
128: }
129: return this .getCopletData().getTitle();
130: }
131:
132: public String getInstanceTitle() {
133: return this .title;
134: }
135:
136: public void setTitle(String title) {
137: this .title = title;
138: }
139:
140: public void setPreferences(PreferenceSetImpl preferences) {
141: this .preferences = preferences;
142: }
143:
144: public PreferenceSet getPreferences() {
145: return this .preferences;
146: }
147:
148: public PreferenceSet getCastorPreferences() {
149: return getPreferences();
150: }
151:
152: public void setCastorPreferences(PreferenceSet castorPreferences) {
153: setPreferences((PreferenceSetImpl) castorPreferences);
154: }
155:
156: /**
157: * @see java.lang.Object#clone()
158: */
159: protected Object clone() throws CloneNotSupportedException {
160: CopletInstanceData clone = (CopletInstanceData) super .clone();
161:
162: clone.copletData = this .copletData;
163: clone.attributes = new HashMap(this .attributes);
164: clone.temporaryAttributes = new HashMap(
165: 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: // ignore
177: return null;
178: }
179: }
180: }
|