1 28 29 package com.caucho.relaxng.program; 30 31 import com.caucho.log.Log; 32 import com.caucho.relaxng.RelaxException; 33 import com.caucho.util.L10N; 34 import com.caucho.util.LruCache; 35 import com.caucho.xml.QName; 36 37 import java.util.HashSet ; 38 import java.util.Iterator ; 39 import java.util.logging.Logger ; 40 41 44 public class MemoItem extends Item { 45 protected final static L10N L = new L10N(MemoItem.class); 46 protected final static Logger log = Log.open(MemoItem.class); 47 48 private LruCache<Object ,Item> _memoMap; 49 private Item _item; 50 51 public MemoItem(Item item, LruCache<Object ,Item> memoMap) 52 { 53 _item = item; 54 _memoMap = memoMap; 55 } 56 57 public MemoItem(Item item) 58 { 59 _item = item; 60 _memoMap = new LruCache<Object ,Item>(256); 61 } 62 63 66 public void firstSet(HashSet <QName> set) 67 { 68 _item.firstSet(set); 69 } 70 71 74 public void requiredFirstSet(HashSet <QName> set) 75 { 76 _item.requiredFirstSet(set); 77 } 78 79 82 public boolean allowEmpty() 83 { 84 return _item.allowEmpty(); 85 } 86 87 90 public Iterator <Item> getItemsIterator() 91 { 92 return itemIterator( _item ); 93 } 94 95 96 103 public Item startElement(QName name) 104 throws RelaxException 105 { 106 Item item = _item.startElement(name); 107 108 if (item == null) 109 return null; 110 else if (item == this) 111 return this; 112 else 113 return new MemoItem(item, _memoMap); 114 } 115 116 119 public void attributeSet(HashSet <QName> set) 120 { 121 _item.attributeSet(set); 122 } 123 124 132 public boolean allowAttribute(QName name, String value) 133 throws RelaxException 134 { 135 return _item.allowAttribute(name, value); 136 } 137 138 146 public Item setAttribute(QName name, String value) 147 throws RelaxException 148 { 149 Item item = _item.setAttribute(name, value); 150 151 if (item == null) 152 return null; 153 else if (item == this) 154 return this; 155 else 156 return new MemoItem(item, _memoMap); 157 } 158 159 162 public Item attributeEnd() 163 { 164 Item item = _item.attributeEnd(); 165 166 if (item == null) 167 return null; 168 else if (item == this) 169 return this; 170 else 171 return new MemoItem(item, _memoMap); 172 } 173 174 177 public Item text(String text) 178 throws RelaxException 179 { 180 Item item = _item.text(text); 181 182 if (item == null) 183 return null; 184 else if (item == this) 185 return this; 186 else 187 return new MemoItem(item, _memoMap); 188 } 189 190 193 public Item endElement() 194 throws RelaxException 195 { 196 Item item = _item.endElement(); 197 198 if (item == null) 199 return null; 200 else if (item == this) 201 return this; 202 else 203 return new MemoItem(item, _memoMap); 204 } 205 } 206 207 | Popular Tags |