1 28 29 package com.caucho.relaxng.program; 30 31 import com.caucho.relaxng.RelaxException; 32 import com.caucho.util.L10N; 33 import com.caucho.xml.QName; 34 35 import java.util.HashSet ; 36 import java.util.Iterator ; 37 38 46 public class InElementItem extends Item { 47 protected final static L10N L = new L10N(InElementItem.class); 48 49 private final Item _eltItem; 50 private final Item _contItem; 51 52 private int _hashCode; 53 54 private InElementItem(Item eltItem, Item contItem) 55 { 56 _eltItem = eltItem; 57 _contItem = contItem; 58 } 59 60 public static InElementItem create(Item eltItem, Item contItem) 61 { 62 if (eltItem == null) 63 return null; 64 else if (contItem == null) 65 return null; 66 else 67 return new InElementItem(eltItem, contItem); 68 } 69 70 public Item getFirst() 71 { 72 return _eltItem; 73 } 74 75 public Item getSecond() 76 { 77 return _contItem; 78 } 79 80 public Item getElementItem() 81 { 82 return _eltItem; 83 } 84 85 public Item getContinuationItem() 86 { 87 return _contItem; 88 } 89 90 93 public Item interleaveContinuation(Item cont) 94 { 95 return create(_eltItem, InterleaveItem.create(cont, _contItem)); 96 } 97 98 101 public Item inElementContinuation(Item cont) 102 { 103 return create(_eltItem, create(_contItem, cont)); 104 } 105 106 109 public Item groupContinuation(Item cont) 110 { 111 return create(_eltItem, GroupItem.create(_contItem, cont)); 112 } 113 114 117 public void firstSet(HashSet <QName> set) 118 { 119 _eltItem.firstSet(set); 120 } 121 122 125 public void requiredFirstSet(HashSet <QName> set) 126 { 127 _eltItem.requiredFirstSet(set); 128 } 129 130 133 public boolean allowEmpty() 134 { 135 return _eltItem.allowEmpty(); 136 } 137 138 139 142 public Iterator <Item> getItemsIterator() 143 { 144 return itemIterator( _eltItem ); 145 } 146 147 154 public Item startElement(QName name) 155 throws RelaxException 156 { 157 Item nextElt = _eltItem.startElement(name); 158 159 if (nextElt == null) 160 return null; 161 else if (nextElt == _eltItem) 162 return this; 163 else 164 return nextElt.inElementContinuation(_contItem); 165 } 166 167 174 public Item text(String string) 175 throws RelaxException 176 { 177 Item nextElt = _eltItem.text(string); 178 179 if (nextElt == null) 180 return null; 181 else if (nextElt == _eltItem) 182 return this; 183 else 184 return create(nextElt, _contItem); 185 } 186 187 190 public void attributeSet(HashSet <QName> set) 191 { 192 _eltItem.attributeSet(set); 193 } 194 195 203 public boolean allowAttribute(QName name, String value) 204 throws RelaxException 205 { 206 return _eltItem.allowAttribute(name, value); 207 } 208 209 217 public Item setAttribute(QName name, String value) 218 throws RelaxException 219 { 220 Item nextElt = _eltItem.setAttribute(name, value); 221 222 if (nextElt == null) 223 return create(EmptyItem.create(), _contItem); 224 else if (nextElt == _eltItem) 225 return this; 226 else 227 return create(nextElt, _contItem); 228 } 229 230 233 public Item attributeEnd() 234 { 235 Item nextElt = _eltItem.attributeEnd(); 236 237 if (nextElt == null) 238 return null; 239 else if (nextElt == _eltItem) 240 return this; 241 else 242 return create(nextElt, _contItem); 243 } 244 245 250 public Item endElement() 251 throws RelaxException 252 { 253 if (_eltItem.allowEmpty()) 254 return _contItem; 255 else 256 return null; 257 } 258 259 268 public boolean allowsElement(QName name) 269 { 270 return _eltItem.allowsElement(name); 271 } 272 273 276 public String toSyntaxDescription(int depth) 277 { 278 return _eltItem.toSyntaxDescription(depth); 279 } 280 281 284 public boolean isSimpleSyntax() 285 { 286 return _eltItem.isSimpleSyntax(); 287 } 288 289 292 public int hashCode() 293 { 294 if (_hashCode == 0) 295 _hashCode = calculateHashCode(); 296 297 return _hashCode; 298 } 299 300 303 private int calculateHashCode() 304 { 305 return _eltItem.hashCode() * 65521 + _contItem.hashCode(); 306 } 307 308 311 public boolean equals(Object o) 312 { 313 if (this == o) 314 return true; 315 316 if (! (o instanceof InElementItem)) 317 return false; 318 319 InElementItem seq = (InElementItem) o; 320 321 return _eltItem.equals(seq._eltItem) && _contItem.equals(seq._contItem); 322 } 323 324 public String toString() 325 { 326 return "InElementItem[" + _eltItem + ",cont=" + _contItem + "]"; 327 } 328 } 329 330 | Popular Tags |