KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > archie > sync > SynchronizedNode


1 package org.sapia.archie.sync;
2
3 import java.util.Iterator JavaDoc;
4
5 import org.sapia.archie.DuplicateException;
6 import org.sapia.archie.Name;
7 import org.sapia.archie.NameParser;
8 import org.sapia.archie.NamePart;
9 import org.sapia.archie.Node;
10 import org.sapia.archie.ProcessingException;
11
12 /**
13  * @author Yanick Duchesne
14  * <dl>
15  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
16  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
17  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
18  * </dl>
19  */

20 public class SynchronizedNode implements Node{
21   
22   private Node _node;
23   private Synchronizer _sync = new SynchronizerAdapter();
24   
25   /**
26    * @param node the <code>Node</code> that this instance encapsulates.
27    */

28   public SynchronizedNode(Node node){
29     _node = node;
30   }
31   
32   /**
33    * @param sync a <code>Synchronizer</code> instance.
34    */

35   public void setSynchronizer(Synchronizer sync){
36     _sync = sync;
37   }
38   
39   /**
40    * @return the <code>Synchronizer</code> that this instance uses.
41    */

42   public Synchronizer getSynchronizer(){
43     return _sync;
44   }
45   
46   /**
47    * This method should be called when needing to synchronize the
48    * content of this node with a "putValue" that occurred at another
49    * node.
50    *
51    * @param valueName the <code>NamePart</code> corresponding to the
52    * name of the value to synchronize.
53    * @param toSync the value to put into this node, under the given name.
54    *
55    */

56   public void synchronizePut(NamePart valueName, Object JavaDoc toSync, boolean overwrite){
57     _node.putValue(valueName, toSync, overwrite);
58   }
59
60   /**
61    * This method should be called when needing to synchronize the
62    * content of this node with a "removeValue" that occurred at another
63    * node.
64    *
65    * @param valueName the <code>NamePart</code> corresponding to the
66    * name of the value to remove.
67    *
68    */

69   public void synchronizeRemove(NamePart valueName){
70     _node.removeValue(valueName);
71   }
72   
73   /**
74    * This method should be called when needing to synchronize a lookup that
75    * occurred at another node.
76    *
77    * @param valueName the <code>NamePart</code> corresponding to the
78    * name of the value to look up.
79    *
80    * @return the <code>Object</code> corresponding to the given name, or
81    * <code>null</code> if no object exists for that name.
82    */

83   public Object JavaDoc synchronizeGet(NamePart valueName){
84     return _node.getValue(valueName);
85   }
86   
87   /**
88    * @see org.sapia.archie.Node#createChild(org.sapia.archie.NamePart)
89    */

90   public Node createChild(NamePart name) throws DuplicateException,
91       ProcessingException {
92     return _node.createChild(name);
93   }
94   /**
95    * @see org.sapia.archie.Node#getAbsolutePath()
96    */

97   public Name getAbsolutePath() {
98     return _node.getAbsolutePath();
99   }
100   /**
101    * @see org.sapia.archie.Node#getChild(org.sapia.archie.NamePart)
102    */

103   public Node getChild(NamePart name) {
104     return _node.getChild(name);
105   }
106   /**
107    * @see org.sapia.archie.Node#getChildren()
108    */

109   public Iterator JavaDoc getChildren() {
110     return _node.getChildren();
111   }
112   /**
113    * @see org.sapia.archie.Node#getChildrenCount()
114    */

115   public int getChildrenCount() {
116     return _node.getChildrenCount();
117   }
118   /**
119    * @see org.sapia.archie.Node#getChildrenNames()
120    */

121   public Iterator JavaDoc getChildrenNames() {
122     return _node.getChildrenNames();
123   }
124   /**
125    * @see org.sapia.archie.Node#getEntries()
126    */

127   public Iterator JavaDoc getEntries() {
128     return _node.getEntries();
129   }
130   /**
131    * @see org.sapia.archie.Node#getName()
132    */

133   public NamePart getName() {
134     return _node.getName();
135   }
136   /**
137    * @see org.sapia.archie.Node#getNameParser()
138    */

139   public NameParser getNameParser() {
140     return _node.getNameParser();
141   }
142   /**
143    * @see org.sapia.archie.Node#getParent()
144    */

145   public Node getParent() {
146     return _node.getParent();
147   }
148   /**
149    * @see org.sapia.archie.Node#getValue(org.sapia.archie.NamePart)
150    */

151   public Object JavaDoc getValue(NamePart name) {
152     Object JavaDoc toReturn = _node.getValue(name);
153     if(toReturn == null){
154       toReturn = _sync.onGetValue((Name)getAbsolutePath().clone(), name);
155     }
156     return toReturn;
157   }
158   /**
159    * @see org.sapia.archie.Node#getValueCount()
160    */

161   public int getValueCount() {
162     return _node.getValueCount();
163   }
164   /**
165    * @see org.sapia.archie.Node#getValueNames()
166    */

167   public Iterator JavaDoc getValueNames() {
168     return _node.getValueNames();
169   }
170   /**
171    * @see org.sapia.archie.Node#putValue(org.sapia.archie.NamePart, java.lang.Object, boolean)
172    */

173   public boolean putValue(NamePart name, Object JavaDoc value, boolean overwrite) {
174     boolean put = _node.putValue(name, value, overwrite);
175     _sync.onPutValue((Name)getAbsolutePath().clone(), name, value, overwrite);
176     return put;
177   }
178   /**
179    * @see org.sapia.archie.Node#removeChild(org.sapia.archie.NamePart)
180    */

181   public Node removeChild(NamePart name) {
182     return _node.removeChild(name);
183   }
184   /**
185    * @see org.sapia.archie.Node#removeValue(org.sapia.archie.NamePart)
186    */

187   public Object JavaDoc removeValue(NamePart name) {
188     Object JavaDoc toReturn = _node.removeValue(name);
189     _sync.onRemoveValue((Name)getAbsolutePath().clone(), name);
190     return toReturn;
191   }
192   /**
193    * @see org.sapia.archie.Node#setUp(org.sapia.archie.Node, org.sapia.archie.NamePart)
194    */

195   public void setUp(Node parent, NamePart nodeName) {
196     _node.setUp(parent, nodeName);
197   }
198 }
199
Popular Tags