KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > regis > remote > RemoteNode


1 package org.sapia.regis.remote;
2
3 import java.rmi.Remote JavaDoc;
4 import java.util.ArrayList JavaDoc;
5 import java.util.Collection JavaDoc;
6 import java.util.Iterator JavaDoc;
7 import java.util.Map JavaDoc;
8
9 import org.sapia.regis.Node;
10 import org.sapia.regis.Path;
11 import org.sapia.regis.Property;
12 import org.sapia.regis.Query;
13
14 /**
15  * An instance of this class wraps a <code>Node</code> to make it
16  * remotable.
17  *
18  * @author yduchesne
19  *
20  */

21 public class RemoteNode implements Node, Remote JavaDoc{
22   
23   private Node delegate;
24   
25   RemoteNode(Node delegate){
26     this.delegate = delegate;
27   }
28
29   public Path getAbsolutePath() {
30     return node().getAbsolutePath();
31   }
32
33   public Node getChild(Path path) {
34     return wrap(node().getChild(path));
35   }
36
37   public Node getChild(String JavaDoc name) {
38     return wrap(node().getChild(name));
39   }
40
41   public Collection JavaDoc getChildren() {
42     return wrap(node().getChildren());
43   }
44
45   public Collection JavaDoc getLinks(boolean prepended) {
46     return wrap(node().getLinks(prepended));
47   }
48   
49   public Collection JavaDoc getIncludes() {
50     return wrap(node().getIncludes());
51   }
52   
53   public Collection JavaDoc getNodes(Query query) {
54     return wrap(node().getNodes(query));
55   }
56
57   public String JavaDoc getName() {
58     return node().getName();
59   }
60
61   public Node getParent() {
62     return wrap(node().getParent());
63   }
64
65   public Map JavaDoc getProperties() {
66     return node().getProperties();
67   }
68  
69   public Map JavaDoc getProperties(Map JavaDoc values) {
70     return node().getProperties(values);
71   }
72
73   public Property getProperty(String JavaDoc key) {
74     return node().getProperty(key);
75   }
76
77   public Collection JavaDoc getPropertyKeys() {
78     return node().getPropertyKeys();
79   }
80
81   public String JavaDoc getType() {
82     return node().getType();
83   }
84
85   public boolean isInheritsParent() {
86     return node().isInheritsParent();
87   }
88
89   public boolean isRoot() {
90     return node().isRoot();
91   }
92
93   public long lastModifChecksum() {
94     return node().lastModifChecksum();
95   }
96
97   public Property renderProperty(String JavaDoc key) {
98     return node().renderProperty(key);
99   }
100   
101   public Property renderProperty(String JavaDoc key, Map JavaDoc values) {
102     return node().renderProperty(key, values);
103   }
104   
105   private Collection JavaDoc wrap(Collection JavaDoc nodes){
106     Collection JavaDoc toReturn = new ArrayList JavaDoc(nodes.size());
107     Iterator JavaDoc itr = nodes.iterator();
108     while(itr.hasNext()){
109       Node n = (Node)itr.next();
110       toReturn.add(new RemoteNode(n));
111     }
112     return toReturn;
113   }
114   
115   private Node wrap(Node node){
116     if (node == null) {
117       return null;
118     } else {
119       return new RemoteNode(node);
120     }
121   }
122   
123   Node node(){
124     return RemoteSessions.get().attach(delegate);
125   }
126 }
127
Popular Tags