KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > regis > local > LocalRegistry


1 package org.sapia.regis.local;
2
3 import java.io.ByteArrayInputStream JavaDoc;
4 import java.io.File JavaDoc;
5 import java.io.FileInputStream JavaDoc;
6 import java.io.InputStream JavaDoc;
7 import java.rmi.RemoteException JavaDoc;
8 import java.util.Properties JavaDoc;
9
10 import org.sapia.regis.Configurable;
11 import org.sapia.regis.Node;
12 import org.sapia.regis.Path;
13 import org.sapia.regis.RWNode;
14 import org.sapia.regis.RegisSession;
15 import org.sapia.regis.Registry;
16 import org.sapia.regis.impl.NodeImpl;
17 import org.sapia.regis.loader.RegistryConfigLoader;
18
19 /**
20  * This class implements an in-memory registy. It does support writes,
21  * but not transactional. This has the following implications:
22  *
23  * <ul>
24  * <li>An instance of this class instantiates <code>RWNode</code>s.
25  * <li>An instance of this class creates <code>RWSession</code>s.
26  * <li>The begin, commit and rollback methods of the <code>RWSession</code>s
27  * that an instance of this class creates have no effect.
28  * </ul>
29  *
30  * @author yduchesne
31  *
32  */

33 public class LocalRegistry implements Registry, Configurable {
34   
35   private RWNode _root;
36   
37   public LocalRegistry(){
38     this(new NodeImpl(null, Node.ROOT_NAME));
39   }
40   
41   public LocalRegistry(RWNode root){
42     _root = root;
43   }
44   
45   public RegisSession open() {
46     return new LocalRegisSession();
47   }
48   
49   public Node getRoot() {
50     return _root;
51   }
52   
53   public void load(File JavaDoc config) throws Exception JavaDoc{
54     load(new FileInputStream JavaDoc(config));
55   }
56   
57   public void load(InputStream JavaDoc is) throws Exception JavaDoc{
58     if(_root == null){
59       _root = new NodeImpl(null, Node.ROOT_NAME);
60     }
61     RegistryConfigLoader loader = new RegistryConfigLoader(_root);
62     loader.load(is);
63   }
64   
65   public void load(Path nodePath, String JavaDoc username, String JavaDoc password, String JavaDoc xmlConf, Properties JavaDoc props) throws RemoteException JavaDoc, Exception JavaDoc {
66     Node child = _root.getChild(nodePath);
67     if(child == null){
68       throw new IllegalStateException JavaDoc("No such node: " + nodePath.toString());
69     }
70     RegistryConfigLoader loader = new RegistryConfigLoader((RWNode)child);
71     loader.load(new ByteArrayInputStream JavaDoc(xmlConf.getBytes()));
72   }
73   
74   public void syncLoad(Path nodePath, String JavaDoc username, String JavaDoc password, String JavaDoc xmlConf, Properties JavaDoc props) throws RemoteException JavaDoc, Exception JavaDoc {
75   }
76   
77   public void close() {
78   }
79
80 }
81
Popular Tags