KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > profile > impl > CopletDataManager


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.profile.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.coplet.CopletData;
23 import org.apache.cocoon.portal.util.DeltaApplicableReferencesAdjustable;
24
25 /**
26  * Holds instances of CopletData.
27  *
28  * @author <a HREF="mailto:bluetkemeier@s-und-n.de">Bj&ouml;rn L&uuml;tkemeier</a>
29  *
30  * @version CVS $Id: CopletDataManager.java 30932 2004-07-29 17:35:38Z vgritsenko $
31  */

32 public class CopletDataManager
33 implements DeltaApplicableReferencesAdjustable {
34
35     /**
36      * The coplet data instances.
37      */

38     private Map JavaDoc copletData = new HashMap JavaDoc();
39     
40     /**
41      * Signals whether a delta has been applied.
42      */

43     private boolean deltaApplied = false;
44     
45     /**
46      * Gets all coplet data.
47      */

48     public Map JavaDoc getCopletData() {
49         return this.copletData;
50     }
51
52     /**
53      * Gets the specified coplet data.
54      */

55     public CopletData getCopletData(String JavaDoc name) {
56         return (CopletData)this.copletData.get(name);
57     }
58     
59     /**
60      * Puts the specified coplet data to the manager.
61      */

62     public void putCopletData(CopletData data) {
63         this.copletData.put(data.getId(), data);
64     }
65     
66     /**
67      * Applies the specified delta.
68      * @throws ClassCastException If the object is not of the expected type.
69      */

70     public boolean applyDelta(Object JavaDoc object) {
71         CopletDataManager manager = (CopletDataManager)object;
72         
73         this.deltaApplied = true;
74
75         Iterator JavaDoc iterator = manager.getCopletData().values().iterator();
76         CopletData data, delta;
77         while (iterator.hasNext()) {
78             delta = (CopletData)iterator.next();
79             data = this.getCopletData(delta.getId());
80             if (data == null) {
81                 this.putCopletData(delta);
82             } else {
83                 data.applyDelta(delta);
84             }
85         }
86         
87         return true;
88     }
89     
90     /**
91      * Checks if a delta has been applied.
92      */

93     public boolean deltaApplied() {
94         return this.deltaApplied;
95     }
96
97     /**
98      * Updates the references to contained DeltaApplicable objects
99      * if no delta has been applied to them.
100      * @throws ClassCastException If the object is not of the expected type.
101      */

102     public void adjustReferences(Object JavaDoc object) {
103         CopletDataManager manager = (CopletDataManager)object;
104         
105         Iterator JavaDoc iterator = this.copletData.values().iterator();
106         CopletData data, other;
107         while (iterator.hasNext()) {
108             data = (CopletData)iterator.next();
109             if (!data.deltaApplied()) {
110                 other = manager.getCopletData(data.getId());
111                 if (other != null) {
112                     this.putCopletData(other);
113                 }
114             }
115         }
116     }
117 }
118
Popular Tags