1 22 23 package org.xquark.extractor.metadata; 24 25 import java.util.ArrayList ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 29 32 public abstract class NamedNode { 34 35 private static final String RCSRevision = "$Revision: 1.4 $"; 36 private static final String RCSName = "$Name: $"; 37 38 protected String _name; 39 protected List _children; 40 protected NamedNode _father; 41 protected String _alias; 42 43 public NamedNode() {} 44 45 48 public NamedNode(String name) { 49 setName(name); 50 } 51 52 57 public String getName() { 58 return _name; 59 } 60 61 65 public void setName(String aName) { 66 _name = aName; 67 } 68 69 public String getAlias() { 70 return _alias; 71 } 72 73 public void setAlias(String alias) { 74 _alias = alias; 75 } 76 77 80 public void addChild(NamedNode child) { 81 if (null == _children) 82 _children = new ArrayList (); 83 _children.add(child); 84 child.setFather(this); 85 return; 86 } 87 88 91 public void setChildren(List children) { 92 _children = children; 93 if (null != _children) { 94 for (int i = 0; i < _children.size(); i++) { 95 ((NamedNode) _children.get(i)).setFather(this); 96 } 97 } 98 } 99 100 104 public NamedNode findChild(String childName) { 105 NamedNode retVal = null; 106 107 if (null != _children && null != childName) { 108 Iterator iter = _children.iterator(); 109 NamedNode item; 110 while (iter.hasNext()) { 111 item = (NamedNode) iter.next(); 112 if (childName.equalsIgnoreCase(item.getName())) { 113 retVal = item; 114 break; 115 } 116 } 117 } 118 return retVal; 119 } 120 121 public NamedNode findChildByAlias(String childName) { 122 NamedNode retVal = null; 123 124 if (null != _children && null != childName) { 125 Iterator iter = _children.iterator(); 126 NamedNode item; 127 while (iter.hasNext()) { 128 item = (NamedNode) iter.next(); 129 if (childName.equals(item.getAlias())) { 130 retVal = item; 131 break; 132 } 133 } 134 } 135 return retVal; 136 } 137 138 141 public List getChildren() { 142 return _children; 143 } 144 145 public void setFather(NamedNode father) { 146 _father = father; 147 } 148 149 public NamedNode getFather() { 150 return _father; 151 } 152 153 public abstract String pprint(); 154 } 155 | Popular Tags |