KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > aspect > impl > AbstractAspectalizable


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.aspect.impl;
17
18 import java.util.HashMap JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import org.apache.cocoon.portal.aspect.AspectDataHandler;
23 import org.apache.cocoon.portal.aspect.Aspectalizable;
24
25 /**
26  *
27  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
28  * @author <a HREF="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
29  *
30  * @version CVS $Id: AbstractAspectalizable.java 148910 2005-01-28 18:19:44Z cziegeler $
31  */

32 public abstract class AbstractAspectalizable
33     implements Aspectalizable, Cloneable JavaDoc {
34
35     transient protected AspectDataHandler aspectDataHandler;
36     
37     transient protected Map JavaDoc persistentDatas;
38     
39     /**
40      * Is this aspect supported
41      */

42     public boolean isAspectSupported(String JavaDoc aspectName) {
43         return this.aspectDataHandler.isAspectSupported( aspectName );
44     }
45
46     public Object JavaDoc getAspectData(String JavaDoc aspectName) {
47         return this.aspectDataHandler.getAspectData(this, aspectName);
48     }
49     
50     public void setAspectData(String JavaDoc aspectName, Object JavaDoc data) {
51         this.aspectDataHandler.setAspectData(this, aspectName, data);
52     }
53     
54     public Map JavaDoc getAspectDatas(){
55         return this.aspectDataHandler.getAspectDatas(this);
56     }
57     
58     public Map JavaDoc getPersistentAspectData(){
59         if (this.aspectDataHandler == null) {
60             return this.persistentDatas;
61         }
62         return this.aspectDataHandler.getPersistentAspectDatas(this);
63     }
64
65     /**
66      * This method is invoked once to set the handler
67      */

68     public void setAspectDataHandler(AspectDataHandler handler) {
69         this.aspectDataHandler = handler;
70         if ( this.persistentDatas != null ) {
71             Iterator JavaDoc iter = this.persistentDatas.entrySet().iterator();
72             Map.Entry JavaDoc entry;
73             while (iter.hasNext()) {
74                 entry = (Map.Entry JavaDoc)iter.next();
75                 handler.setAspectData(this, (String JavaDoc)entry.getKey(), entry.getValue());
76             }
77             this.persistentDatas = null;
78         }
79     }
80
81     public void addPersistentAspectData(String JavaDoc aspectName, Object JavaDoc data) {
82         if ( this.persistentDatas == null ) {
83             this.persistentDatas = new HashMap JavaDoc();
84         }
85         this.persistentDatas.put(aspectName, data);
86     }
87
88     /* (non-Javadoc)
89      * @see java.lang.Object#clone()
90      */

91     protected Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
92         AbstractAspectalizable clone = (AbstractAspectalizable)super.clone();
93         
94         clone.aspectDataHandler = this.aspectDataHandler;
95         final Map JavaDoc datas = this.aspectDataHandler.getAspectDatas(this);
96         final Iterator JavaDoc i = datas.entrySet().iterator();
97         while ( i.hasNext() ) {
98             final Map.Entry JavaDoc e = (Map.Entry JavaDoc)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