KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > regis > loader > ConfigContext


1 package org.sapia.regis.loader;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Map JavaDoc;
5
6 import org.sapia.regis.Node;
7 import org.sapia.regis.Path;
8 import org.sapia.regis.RWNode;
9
10 public class ConfigContext {
11   
12   private Map JavaDoc nodes = new HashMap JavaDoc();
13   private RWNode parent;
14   private String JavaDoc defaultOperation;
15   
16   public ConfigContext(RWNode parent, Map JavaDoc nodes){
17     this.parent = parent;
18     this.nodes = nodes;
19   }
20   
21   public Map JavaDoc getNodes(){
22     return nodes;
23   }
24   
25   public RWNode getParent(){
26     return parent;
27   }
28
29   public String JavaDoc getDefaultOperation() {
30     return defaultOperation;
31   }
32
33   public void setDefaultOperation(String JavaDoc defaultOperation) {
34     this.defaultOperation = defaultOperation;
35   }
36   
37   public Node getNodeFor(String JavaDoc idOrPath, boolean isPath){
38     if(isPath){
39       Node root = getRoot();
40       return root.getChild(Path.parse(idOrPath));
41     }
42     else{
43       return (Node)nodes.get(idOrPath);
44     }
45   }
46   
47   private Node getRoot(){
48     Node current = parent;
49     
50     while(!current.isRoot()){
51       current = current.getParent();
52     }
53     return current;
54   }
55
56 }
57
Popular Tags