1 38 39 40 package com.sun.xml.fastinfoset.stax.events ; 41 42 import javax.xml.stream.XMLStreamConstants; 43 import javax.xml.stream.Location; 44 import javax.xml.stream.events.XMLEvent; 45 import javax.xml.stream.events.Characters; 46 import javax.xml.stream.events.EndElement; 47 import javax.xml.stream.events.StartElement; 48 import javax.xml.namespace.QName ; 49 import java.io.Writer ; 50 import com.sun.xml.fastinfoset.CommonResourceBundle; 51 52 53 public abstract class EventBase implements XMLEvent { 54 55 56 protected int _eventType; 57 protected Location _location = null; 58 59 public EventBase() { 60 61 } 62 63 public EventBase(int eventType) { 64 _eventType = eventType; 65 } 66 67 70 public int getEventType() { 71 return _eventType; 72 } 73 74 protected void setEventType(int eventType){ 75 _eventType = eventType; 76 } 77 78 79 public boolean isStartElement() { 80 return _eventType == START_ELEMENT; 81 } 82 83 public boolean isEndElement() { 84 return _eventType == END_ELEMENT; 85 } 86 87 public boolean isEntityReference() { 88 return _eventType == ENTITY_REFERENCE; 89 } 90 91 public boolean isProcessingInstruction() { 92 return _eventType == PROCESSING_INSTRUCTION; 93 } 94 95 public boolean isStartDocument() { 96 return _eventType == START_DOCUMENT; 97 } 98 99 public boolean isEndDocument() { 100 return _eventType == END_DOCUMENT; 101 } 102 103 109 public Location getLocation(){ 110 return _location; 111 } 112 113 public void setLocation(Location loc){ 114 _location = loc; 115 } 116 public String getSystemId() { 117 if(_location == null ) 118 return ""; 119 else 120 return _location.getSystemId(); 121 } 122 123 126 public Characters asCharacters() { 127 if (isCharacters()) { 128 return (Characters)this; 129 } else 130 throw new ClassCastException (CommonResourceBundle.getInstance().getString("message.charactersCast", new Object []{getEventTypeString()})); 131 } 132 133 136 public EndElement asEndElement() { 137 if (isEndElement()) { 138 return (EndElement)this; 139 } else 140 throw new ClassCastException (CommonResourceBundle.getInstance().getString("message.endElementCase", new Object []{getEventTypeString()})); 141 } 142 143 147 public StartElement asStartElement() { 148 if (isStartElement()) { 149 return (StartElement)this; 150 } else 151 throw new ClassCastException (CommonResourceBundle.getInstance().getString("message.startElementCase", new Object []{getEventTypeString()})); 152 } 153 154 160 public QName getSchemaType() { 161 return null; 162 } 163 164 167 public boolean isAttribute() { 168 return _eventType == ATTRIBUTE; 169 } 170 171 174 public boolean isCharacters() { 175 return _eventType == CHARACTERS; 176 } 177 178 181 public boolean isNamespace() { 182 return _eventType == NAMESPACE; 183 } 184 185 186 202 public void writeAsEncodedUnicode(Writer writer) throws javax.xml.stream.XMLStreamException { 203 } 204 205 private String getEventTypeString() { 206 switch (_eventType){ 207 case START_ELEMENT: 208 return "StartElementEvent"; 209 case END_ELEMENT: 210 return "EndElementEvent"; 211 case PROCESSING_INSTRUCTION: 212 return "ProcessingInstructionEvent"; 213 case CHARACTERS: 214 return "CharacterEvent"; 215 case COMMENT: 216 return "CommentEvent"; 217 case START_DOCUMENT: 218 return "StartDocumentEvent"; 219 case END_DOCUMENT: 220 return "EndDocumentEvent"; 221 case ENTITY_REFERENCE: 222 return "EntityReferenceEvent"; 223 case ATTRIBUTE: 224 return "AttributeBase"; 225 case DTD: 226 return "DTDEvent"; 227 case CDATA: 228 return "CDATA"; 229 } 230 return "UNKNOWN_EVENT_TYPE"; 231 } 232 233 } 234 | Popular Tags |