1 29 30 package com.caucho.relaxng.program; 31 32 import com.caucho.relaxng.RelaxException; 33 import com.caucho.relaxng.pattern.ElementPattern; 34 import com.caucho.util.L10N; 35 import com.caucho.xml.QName; 36 37 import java.util.HashSet ; 38 import java.util.Iterator ; 39 40 43 public class ElementItem extends Item { 44 protected final static L10N L = new L10N(ElementItem.class); 45 46 private ElementPattern _element; 47 48 private NameClassItem _nameItem; 49 private Item _item; 50 private Item _childrenItem; 51 52 public ElementItem(ElementPattern element, NameClassItem nameItem) 53 { 54 _element = element; 55 _nameItem = nameItem; 56 } 57 58 public NameClassItem getNameClassItem() 59 { 60 return _nameItem; 61 } 62 63 public void setChildrenItem(Item item) 64 { 65 _childrenItem = item; 66 } 67 68 71 public void firstSet(HashSet <QName> set) 72 { 73 _nameItem.firstSet(set); 74 } 75 76 79 public void requiredFirstSet(HashSet <QName> set) 80 { 81 _nameItem.firstSet(set); 82 } 83 84 87 public boolean allowEmpty() 88 { 89 return false; 90 } 91 92 95 public Iterator <Item> getItemsIterator() 96 { 97 if (_item == null) { 98 _item = InElementItem.create(_childrenItem, 99 EmptyItem.create()); 100 } 101 102 return itemIterator( _item ); 103 } 104 105 106 111 public Item startElement(QName name) 112 throws RelaxException 113 { 114 if (! _nameItem.matches(name)) 115 return null; 116 117 if (_item == null) { 118 _item = InElementItem.create(_childrenItem, 119 EmptyItem.create()); 120 } 121 122 return _item; 123 } 124 125 134 public boolean allowsElement(QName name) 135 { 136 return _nameItem.matches(name); 137 } 138 139 142 public String toSyntaxDescription(int depth) 143 { 144 return _nameItem.toSyntaxDescription(""); 145 } 146 147 150 protected boolean isSimpleSyntax() 151 { 152 return true; 153 } 154 155 158 public int hashCode() 159 { 160 return 87 + _element.getDefName().hashCode(); 161 } 162 163 166 public boolean equals(Object o) 167 { 168 if (this == o) 169 return true; 170 171 if (! (o instanceof ElementItem)) 172 return false; 173 174 ElementItem elt = (ElementItem) o; 175 176 return _element.getDefName().equals(elt._element.getDefName()); 177 } 178 179 public String toString() 180 { 181 return "ElementItem[" + _nameItem + "]"; 182 } 183 } 184 185 | Popular Tags |