KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > coplet > CopletInstanceData


1 /*
2  * Copyright 1999-2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.portal.coplet;
17
18 import java.util.HashMap JavaDoc;
19 import java.util.Map JavaDoc;
20 import java.util.Collection JavaDoc;
21 import java.util.Set JavaDoc;
22 import java.util.HashSet JavaDoc;
23 import java.util.Iterator JavaDoc;
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 /**
32  *
33  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
34  * @author <a HREF="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
35  * @author <a HREF="mailto:bluetkemeier@s-und-n.de">Bj&ouml;rn L&uuml;tkemeier</a>
36  *
37  * @version CVS $Id: CopletInstanceData.java 290668 2005-09-21 09:43:26Z cziegeler $
38  */

39 public final class CopletInstanceData
40     extends AbstractProducible {
41
42     protected CopletData copletData;
43
44     protected Map JavaDoc attributes = new HashMap JavaDoc();
45
46     /** Temporary attributes are not persisted */
47     protected Map JavaDoc temporaryAttributes = new HashMap JavaDoc();
48
49     /** Portlet preferences */
50     protected PreferenceSetImpl preferences = new PreferenceSetImpl();
51
52     private String JavaDoc title;
53
54     /**
55      * Constructor
56      */

57     public CopletInstanceData() {
58         // Nothing to do
59
}
60
61     /**
62      * @return CopletData
63      */

64     public CopletData getCopletData() {
65         return copletData;
66     }
67
68     /**
69      * Sets the copletData.
70      * @param copletData The copletData to set
71      */

72     public void setCopletData(CopletData copletData) {
73         this.copletData = copletData;
74     }
75
76     public Object JavaDoc getAttribute(String JavaDoc key) {
77         return this.attributes.get(key);
78     }
79
80     public void setAttribute(String JavaDoc key, Object JavaDoc value) {
81         this.attributes.put(key, value);
82     }
83     
84     public Object JavaDoc removeAttribute(String JavaDoc key) {
85         return this.attributes.remove(key);
86     }
87     
88     public Map JavaDoc getAttributes() {
89         return this.attributes;
90     }
91
92     public final Collection JavaDoc getCastorAttributes() {
93         Set JavaDoc set = new HashSet JavaDoc(this.attributes.size());
94         Iterator JavaDoc iterator = this.attributes.entrySet().iterator();
95         Map.Entry JavaDoc entry;
96         while (iterator.hasNext()) {
97             entry = (Map.Entry JavaDoc) 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 JavaDoc getTemporaryAttribute(String JavaDoc key) {
111         return this.temporaryAttributes.get(key);
112     }
113
114     public void setTemporaryAttribute(String JavaDoc key, Object JavaDoc value) {
115         this.temporaryAttributes.put(key, value);
116     }
117     
118     public Object JavaDoc removeTemporaryAttribute(String JavaDoc key) {
119         return this.temporaryAttributes.remove(key);
120     }
121     
122     public Map JavaDoc getTemporaryAttributes() {
123         return this.temporaryAttributes;
124     }
125
126     public String JavaDoc getTitle() {
127         if (this.title != null) {
128             return this.title;
129         }
130         return this.getCopletData().getTitle();
131     }
132
133     public String JavaDoc getInstanceTitle() {
134         return this.title;
135     }
136
137     public void setTitle(String JavaDoc 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     /**
158      * @see java.lang.Object#clone()
159      */

160     protected Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
161         CopletInstanceData clone = (CopletInstanceData)super.clone();
162         
163         clone.copletData = this.copletData;
164         clone.attributes = new HashMap JavaDoc(this.attributes);
165         clone.temporaryAttributes = new HashMap JavaDoc(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 JavaDoc cnse) {
176             // ignore
177
return null;
178         }
179     }
180 }
Popular Tags