1 package org.sapia.archie; 2 3 import java.util.Iterator ; 4 import java.util.Map ; 5 6 import org.sapia.archie.impl.*; 7 8 9 19 public abstract class AbstractNode implements Node { 20 protected Map _children; 21 protected NodeFactory _fac; 22 private NamePart _name; 23 private Name _absolutePath = new Name(); 24 private Node _parent; 25 private NameParser _parser; 26 27 protected AbstractNode(NameParser parser, Map children, NodeFactory fac) 28 throws ProcessingException { 29 _children = children; 30 _fac = fac; 31 _parser = parser; 32 33 _name = parser.parse("/").first(); 35 _absolutePath.add(_name); 36 } 37 38 protected AbstractNode(Map children, NodeFactory fac) 39 throws ProcessingException { 40 this(new DefaultNameParser(), children, fac); 41 } 42 43 46 public Node createChild(NamePart name) 47 throws DuplicateException, ProcessingException { 48 if (_children.containsKey(name)) { 49 throw new DuplicateException(name.asString()); 50 } 51 52 Node n = _fac.newNode(); 53 n.setUp(this, name); 54 _children.put(name, n); 55 return n; 56 } 57 58 61 public Node getChild(NamePart name) { 62 return (Node)_children.get(name); 63 } 64 65 68 public Node removeChild(NamePart name) { 69 return (Node)_children.remove(name); 70 } 71 72 75 public Iterator getChildren() { 76 return _children.values().iterator(); 77 } 78 79 82 public NamePart getName() { 83 return _name; 84 } 85 86 89 public Name getAbsolutePath() { 90 return (Name)_absolutePath.clone(); 91 } 92 93 96 public int getChildrenCount() { 97 return _children.size(); 98 } 99 100 103 public Iterator getChildrenNames() { 104 return _children.keySet().iterator(); 105 } 106 107 110 public Node getParent() { 111 return _parent; 112 } 113 114 117 public NameParser getNameParser() { 118 return _parser; 119 } 120 121 124 public void setUp(Node parent, NamePart name) { 125 _parent = parent; 126 _absolutePath = new Name().add(parent.getAbsolutePath()); 127 _name = name; 128 _absolutePath.add(name); 129 } 130 131 public String toString() { 132 return _name.toString(); 133 } 134 } 135 | Popular Tags |