1 20 21 25 26 package org.ozoneDB.xml.dom; 27 28 import java.io.*; 29 import org.w3c.dom.*; 30 31 32 49 public class EntityImpl extends NodeImpl implements EntityProxy, Externalizable { 50 51 final static long serialVersionUID = 1; 52 53 54 public short getNodeType() { 55 return ENTITY_NODE; 56 } 57 58 59 public final void setNodeValue( String value ) { 60 throw new DOMExceptionImpl( DOMException.NO_DATA_ALLOWED_ERR, "This node type does not support values." ); 61 } 62 63 64 public String getPublicId() { 65 return _publicId; 66 } 67 68 69 public void setPublicId( String publicId ) { 70 _publicId = publicId; 71 } 72 73 74 public String getSystemId() { 75 return _systemId; 76 } 77 78 79 public void setSystemId( String systemId ) { 80 _systemId = systemId; 81 } 82 83 84 public String getNotationName() { 85 return _notation; 86 } 87 88 89 public void setNotationName( String notation ) { 90 _notation = notation; 91 } 92 93 94 public final String getInternal() { 95 return _internalValue; 96 } 97 98 99 105 public boolean isUnparsed() { 106 return _notation != null; 107 } 108 109 110 121 public boolean isInternal() { 122 return _internalValue != null; 123 } 124 125 126 public void setInternal( String internalValue ) { 127 _internalValue = internalValue; 128 } 129 130 131 136 public short getState() { 137 return _state; 138 } 139 140 141 148 public void setState( short newState ) { 149 if (_state == STATE_DECLARED && newState == STATE_PARSING || _state == STATE_NOT_FOUND && newState 150 == STATE_DECLARED) { 151 _state = newState; 152 } else if ((_state == STATE_DECLARED || _state == STATE_PARSING) && (newState == STATE_PARSED || newState 153 == STATE_NOT_FOUND)) { 154 _state = newState; 155 } else { 156 throw new IllegalStateException ( "Cannot switch from state " + _state + " to state " + newState + "." ); 157 } 158 } 159 160 161 public synchronized boolean equals( Object other ) { 162 EntityProxy otherX; 163 164 if (super.equals( other )) { 167 otherX = (EntityProxy)other; 168 if (this.isInternal()) { 171 return otherX.isInternal() && this.getInternal().equals( otherX.getInternal() ); 172 } 173 return 176 (this.getPublicId() == null && otherX.getPublicId() == null || this.getPublicId() != null 177 && this.getPublicId().equals( otherX.getPublicId() )) && (this.getSystemId() == null 178 && otherX.getSystemId() == null || this.getSystemId() != null && this.getSystemId().equals( 179 otherX.getSystemId() )) && (this.getNotationName() == null && otherX.getNotationName() == null 180 || this.getNotationName() != null && this.getNotationName().equals( otherX.getNotationName() )); 181 } 182 return false; 183 } 184 185 186 public final Object clone() { 187 EntityProxy clone = null; 188 try { 189 clone = (EntityProxy)database().createObject( EntityImpl.class.getName() ); 190 clone.init( _ownerDocument, getNodeName() ); 191 cloneInto( clone, true ); 192 } catch (Exception except) { 193 throw new DOMExceptionImpl( DOMExceptionImpl.PDOM_ERR, except.getMessage() ); 194 } 195 return clone; 196 } 197 198 199 public final Node cloneNode( boolean deep ) { 200 EntityProxy clone = null; 201 try { 202 clone = (EntityProxy)database().createObject( EntityImpl.class.getName() ); 203 clone.init( _ownerDocument, getNodeName() ); 204 cloneInto( clone, deep ); 205 } catch (Exception except) { 206 throw new DOMExceptionImpl( DOMExceptionImpl.PDOM_ERR, except.getMessage() ); 207 } 208 return clone; 209 } 210 211 212 public String toString() { 213 String name; 214 String value; 215 216 name = getNodeName(); 217 if (name.length() > 32) { 218 name = name.substring( 0, 32 ) + ".."; 219 } 220 if (isInternal()) { 221 value = getInternal(); 222 if (value.length() > 64) { 223 value = value.substring( 0, 64 ) + ".."; 224 } 225 name = name + "] [" + value; 226 } else { 227 if (getSystemId() != null) { 228 name = name + "] SYSTEM [" + getSystemId(); 229 } 230 if (getPublicId() != null) { 231 name = name + "] PUBLIC [" + getPublicId(); 232 } 233 if (getNotationName() != null) { 234 name = name + "] NDECL [" + getNotationName(); 235 } 236 } 237 return "Entity decl: [" + name + "]"; 238 } 239 240 241 protected final boolean supportsChildern() { 242 return true; 243 } 244 245 246 public synchronized void cloneInto( NodeProxy into, boolean deep ) { 247 super.cloneInto( into, deep ); 248 ((EntityProxy)into).setSystemId( this._systemId ); 249 ((EntityProxy)into).setPublicId( this._publicId ); 250 ((EntityProxy)into).setNotationName( this._notation ); 251 ((EntityProxy)into).setInternal( this._internalValue ); 252 ((EntityProxy)into).setState( this._state ); 253 } 254 255 256 266 public EntityImpl( DocumentImpl owner, String name, String systemId, String publicId, String notation ) { 267 super( owner, name, null, true ); 268 if (notation == null) { 269 throw new NullPointerException ( "Argument 'notation' cannot be null." ); 270 } else { 271 init( owner, name, systemId, publicId, notation ); 272 } 273 } 274 275 276 285 public EntityImpl( DocumentImpl owner, String name, String systemId, String publicId ) { 286 super( owner, name, null, true ); 287 if (systemId == null) { 288 throw new NullPointerException ( "Argument 'systemId' cannot be null." ); 289 } else { 290 init( owner, name, systemId, publicId ); 291 } 292 } 293 294 295 302 public EntityImpl( DocumentImpl owner, String name, String internalValue ) { 303 super( owner, name, null, true ); 304 if (internalValue == null) { 305 throw new NullPointerException ( "Argument 'internalValue' cannot be null." ); 306 } else { 307 init( owner, name, internalValue ); 308 } 309 } 310 311 312 private EntityImpl( DocumentImpl owner, String name ) { 313 super( owner, name, null, true ); 314 } 315 316 317 public EntityImpl() { 318 super(); 319 } 320 321 322 public void init( DocumentProxy owner, String name ) { 323 super.init( owner, name, null, true ); 324 } 325 326 327 public void init( DocumentProxy owner, String name, String value ) { 328 _systemId = null; 329 _publicId = null; 330 _notation = null; 331 _state = STATE_DECLARED; 332 _internalValue = value; 333 } 334 335 336 public void init( DocumentProxy owner, String name, String systemId, String publicId ) { 337 _systemId = systemId; 338 _publicId = publicId; 339 _notation = null; 340 _state = STATE_DECLARED; 341 } 342 343 344 public void init( DocumentProxy owner, String name, String systemId, String publicId, String notation ) { 345 _systemId = systemId; 346 _publicId = publicId; 347 } 348 349 350 351 public void writeExternal( ObjectOutput out ) throws IOException { 352 super.writeExternal( out ); 353 out.writeObject( _notation ); 354 out.writeObject( _systemId ); 355 out.writeObject( _publicId ); 356 out.writeShort( _state ); 357 out.writeObject( _internalValue ); 358 } 359 360 361 362 public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { 363 super.readExternal( in ); 364 _notation = (String )in.readObject(); 365 _systemId = (String )in.readObject(); 366 _publicId = (String )in.readObject(); 367 _state = in.readShort(); 368 _internalValue = (String )in.readObject(); 369 } 370 371 372 375 protected String _notation; 376 377 380 protected String _systemId; 381 382 385 protected String _publicId; 386 387 391 private short _state; 392 393 396 private String _internalValue; 397 398 403 public final static short STATE_DECLARED = 0; 404 405 409 public final static short STATE_PARSING = 1; 410 411 415 public final static short STATE_PARSED = 2; 416 417 420 public final static short STATE_NOT_FOUND = 3; 421 422 } 423 | Popular Tags |