1 package org.sapia.regis.loader; 2 3 import java.util.HashMap ; 4 import java.util.Map ; 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 nodes = new HashMap (); 13 private RWNode parent; 14 private String defaultOperation; 15 16 public ConfigContext(RWNode parent, Map nodes){ 17 this.parent = parent; 18 this.nodes = nodes; 19 } 20 21 public Map getNodes(){ 22 return nodes; 23 } 24 25 public RWNode getParent(){ 26 return parent; 27 } 28 29 public String getDefaultOperation() { 30 return defaultOperation; 31 } 32 33 public void setDefaultOperation(String defaultOperation) { 34 this.defaultOperation = defaultOperation; 35 } 36 37 public Node getNodeFor(String 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 |