1 55 package org.jboss.axis.message; 56 57 import org.jboss.axis.encoding.DeserializationContext; 58 import org.xml.sax.ContentHandler ; 59 import org.xml.sax.SAXException ; 60 import org.xml.sax.ext.LexicalHandler ; 61 62 66 public class SAX2EventRecorder 67 { 68 69 private static final Integer Z = new Integer (0); 70 71 private static final Integer STATE_SET_DOCUMENT_LOCATOR = new Integer (0); 72 private static final Integer STATE_START_DOCUMENT = new Integer (1); 73 private static final Integer STATE_END_DOCUMENT = new Integer (2); 74 private static final Integer STATE_START_PREFIX_MAPPING = new Integer (3); 75 private static final Integer STATE_END_PREFIX_MAPPING = new Integer (4); 76 private static final Integer STATE_START_ELEMENT = new Integer (5); 77 private static final Integer STATE_END_ELEMENT = new Integer (6); 78 private static final Integer STATE_CHARACTERS = new Integer (7); 79 private static final Integer STATE_IGNORABLE_WHITESPACE = new Integer (8); 80 private static final Integer STATE_PROCESSING_INSTRUCTION = new Integer (9); 81 private static final Integer STATE_SKIPPED_ENTITY = new Integer (10); 82 83 private static final Integer STATE_NEWELEMENT = new Integer (11); 86 87 private static final Integer STATE_START_DTD = new Integer (12); 89 private static final Integer STATE_END_DTD = new Integer (13); 90 private static final Integer STATE_START_ENTITY = new Integer (14); 91 private static final Integer STATE_END_ENTITY = new Integer (15); 92 private static final Integer STATE_START_CDATA = new Integer (16); 93 private static final Integer STATE_END_CDATA = new Integer (17); 94 private static final Integer STATE_COMMENT = new Integer (18); 95 96 org.xml.sax.Locator locator; 97 objArrayVector events = new objArrayVector(); 98 99 public void clear() 100 { 101 locator = null; 102 events = new objArrayVector(); 103 } 104 105 public int getLength() 106 { 107 return events.getLength(); 108 } 109 110 public int setDocumentLocator(org.xml.sax.Locator p1) 111 { 112 locator = p1; 113 return events.add(STATE_SET_DOCUMENT_LOCATOR, Z, Z, Z, Z); 114 } 115 116 public int startDocument() 117 { 118 return events.add(STATE_START_DOCUMENT, Z, Z, Z, Z); 119 } 120 121 public int endDocument() 122 { 123 return events.add(STATE_END_DOCUMENT, Z, Z, Z, Z); 124 } 125 126 public int startPrefixMapping(String p1, String p2) 127 { 128 return events.add(STATE_START_PREFIX_MAPPING, p1, p2, Z, Z); 129 } 130 131 public int endPrefixMapping(String p1) 132 { 133 return events.add(STATE_END_PREFIX_MAPPING, p1, Z, Z, Z); 134 } 135 136 public int startElement(String p1, String p2, String p3, org.xml.sax.Attributes p4) 137 { 138 return events.add(STATE_START_ELEMENT, p1, p2, p3, p4); 139 } 140 141 public int endElement(String p1, String p2, String p3) 142 { 143 return events.add(STATE_END_ELEMENT, p1, p2, p3, Z); 144 } 145 146 public int characters(char[] p1, int p2, int p3) 147 { 148 return events.add(STATE_CHARACTERS, new String (p1, p2, p3), Z, Z, Z); 149 } 150 151 public int ignorableWhitespace(char[] p1, int p2, int p3) 152 { 153 return events.add(STATE_IGNORABLE_WHITESPACE, new String (p1, p2, p3), Z, Z, Z); 154 } 155 156 public int processingInstruction(String p1, String p2) 157 { 158 return events.add(STATE_PROCESSING_INSTRUCTION, p1, p2, Z, Z); 159 } 160 161 public int skippedEntity(String p1) 162 { 163 return events.add(STATE_SKIPPED_ENTITY, p1, Z, Z, Z); 164 } 165 166 public void startDTD(java.lang.String name, 167 java.lang.String publicId, 168 java.lang.String systemId) 169 { 170 events.add(STATE_START_DTD, name, publicId, systemId, Z); 171 } 172 173 public void endDTD() 174 { 175 events.add(STATE_END_DTD, Z, Z, Z, Z); 176 } 177 178 public void startEntity(java.lang.String name) 179 { 180 events.add(STATE_START_ENTITY, name, Z, Z, Z); 181 } 182 183 public void endEntity(java.lang.String name) 184 { 185 events.add(STATE_END_ENTITY, name, Z, Z, Z); 186 } 187 188 public void startCDATA() 189 { 190 events.add(STATE_START_CDATA, Z, Z, Z, Z); 191 } 192 193 public void endCDATA() 194 { 195 events.add(STATE_END_CDATA, Z, Z, Z, Z); 196 } 197 198 public void comment(char[] ch, 199 int start, 200 int length) 201 { 202 events.add(STATE_COMMENT, new String (ch, start, length), Z, Z, Z); 203 } 204 205 public int newElement(SOAPElementAxisImpl elem) 206 { 207 return events.add(STATE_NEWELEMENT, elem, Z, Z, Z); 208 } 209 210 public void replay(ContentHandler handler) throws SAXException 211 { 212 if (events.getLength() > 0) 213 { 214 replay(0, events.getLength() - 1, handler); 215 } 216 } 217 218 public void replay(int start, int stop, ContentHandler handler) throws SAXException 219 { 220 if ((start == 0) && (stop == -1)) 222 { 223 replay(handler); 224 return; 225 } 226 227 if (stop + 1 > events.getLength() || 228 stop < start) 229 { 230 return; } 232 233 LexicalHandler lexicalHandler = null; 234 if (handler instanceof LexicalHandler ) 235 { 236 lexicalHandler = (LexicalHandler )handler; 237 } 238 239 for (int n = start; n <= stop; n++) 240 { 241 Object event = events.get(n, 0); 242 if (event == STATE_START_ELEMENT) 243 { 244 handler.startElement((String )events.get(n, 1), 245 (String )events.get(n, 2), 246 (String )events.get(n, 3), 247 (org.xml.sax.Attributes )events.get(n, 4)); 248 249 } 250 else if (event == STATE_END_ELEMENT) 251 { 252 handler.endElement((String )events.get(n, 1), 253 (String )events.get(n, 2), 254 (String )events.get(n, 3)); 255 256 } 257 else if (event == STATE_CHARACTERS) 258 { 259 char chars[] = ((String )(events.get(n, 1))).toCharArray(); 260 handler.characters(chars, 0, chars.length); 261 262 } 263 else if (event == STATE_IGNORABLE_WHITESPACE) 264 { 265 char chars[] = ((String )(events.get(n, 1))).toCharArray(); 266 handler.ignorableWhitespace(chars, 0, chars.length); 267 268 } 269 else if (event == STATE_PROCESSING_INSTRUCTION) 270 { 271 handler.processingInstruction((String )events.get(n, 1), 272 (String )events.get(n, 2)); 273 274 } 275 else if (event == STATE_SKIPPED_ENTITY) 276 { 277 handler.skippedEntity((String )events.get(n, 1)); 278 279 } 280 else if (event == STATE_SET_DOCUMENT_LOCATOR) 281 { 282 handler.setDocumentLocator(locator); 283 284 } 285 else if (event == STATE_START_DOCUMENT) 286 { 287 handler.startDocument(); 288 289 } 290 else if (event == STATE_END_DOCUMENT) 291 { 292 handler.endDocument(); 293 294 } 295 else if (event == STATE_START_PREFIX_MAPPING) 296 { 297 handler.startPrefixMapping((String )events.get(n, 1), 298 (String )events.get(n, 2)); 299 300 } 301 else if (event == STATE_END_PREFIX_MAPPING) 302 { 303 handler.endPrefixMapping((String )events.get(n, 1)); 304 305 } 306 else if (event == STATE_START_DTD && lexicalHandler != null) 307 { 308 lexicalHandler.startDTD((String )events.get(n, 1), 309 (String )events.get(n, 2), 310 (String )events.get(n, 3)); 311 } 312 else if (event == STATE_END_DTD && lexicalHandler != null) 313 { 314 lexicalHandler.endDTD(); 315 316 } 317 else if (event == STATE_START_ENTITY && lexicalHandler != null) 318 { 319 lexicalHandler.startEntity((String )events.get(n, 1)); 320 321 } 322 else if (event == STATE_END_ENTITY && lexicalHandler != null) 323 { 324 lexicalHandler.endEntity((String )events.get(n, 1)); 325 326 } 327 else if (event == STATE_START_CDATA && lexicalHandler != null) 328 { 329 lexicalHandler.startCDATA(); 330 331 } 332 else if (event == STATE_END_CDATA && lexicalHandler != null) 333 { 334 lexicalHandler.endCDATA(); 335 336 } 337 else if (event == STATE_COMMENT && lexicalHandler != null) 338 { 339 char chars[] = ((String )(events.get(n, 1))).toCharArray(); 340 lexicalHandler.comment(chars, 0, chars.length); 341 342 } 343 else if (event == STATE_NEWELEMENT) 344 { 345 if (handler instanceof DeserializationContext) 346 { 347 DeserializationContext context = 348 (DeserializationContext)handler; 349 context.setCurElement((SOAPElementAxisImpl)(events.get(n, 1))); 350 } 351 } 352 } 353 } 354 355 class objArrayVector 357 { 358 private int RECORD_SIZE = 5; 359 private int currentSize = 0; 360 private Object [] objarray = new Object [50 * RECORD_SIZE]; 362 public int add(Object p1, Object p2, Object p3, Object p4, Object p5) 363 { 364 if (currentSize == objarray.length) 365 { 366 Object [] newarray = new Object [currentSize * 2]; 367 System.arraycopy(objarray, 0, newarray, 0, currentSize); 368 objarray = newarray; 369 } 370 int pos = currentSize / RECORD_SIZE; 371 objarray[currentSize++] = p1; 372 objarray[currentSize++] = p2; 373 objarray[currentSize++] = p3; 374 objarray[currentSize++] = p4; 375 objarray[currentSize++] = p5; 376 return pos; 377 } 378 379 public Object get(int pos, int fld) 380 { 381 return objarray[(pos * RECORD_SIZE) + fld]; 382 } 383 384 public int getLength() 385 { 386 return (currentSize / RECORD_SIZE); 387 } 388 } 389 } 391 | Popular Tags |