001: /* $Id: EntityDeclarationImpl.java,v 1.1 2004/06/21 18:59:45 ryan_shoemaker Exp $
002: *
003: * Copyright (c) 2004, Sun Microsystems, Inc.
004: * All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are
008: * met:
009: *
010: * * Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * * Redistributions in binary form must reproduce the above
014: * copyright notice, this list of conditions and the following
015: * disclaimer in the documentation and/or other materials provided
016: * with the distribution.
017: *
018: * * Neither the name of Sun Microsystems, Inc. nor the names of its
019: * contributors may be used to endorse or promote products derived
020: * from this software without specific prior written permission.
021: *
022: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
023: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
024: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
025: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
026: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
027: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
028: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
029: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
030: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
031: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
032: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
033: */
034: package javanet.staxutils;
035:
036: import javax.xml.stream.Location;
037: import javax.xml.stream.XMLStreamException;
038: import javax.xml.stream.events.EntityDeclaration;
039: import java.io.IOException;
040: import java.io.Writer;
041:
042: /**
043: * Implementation of {@link javax.xml.stream.events.EntityDeclaration}.
044: *
045: * The only reason this class exists is because {@link javax.xml.stream.XMLEventFactory}
046: * doesn't have a factory for this event type and the {@link ContentHandlerToXMLEventWriter}
047: * needs to create one of these event types to handle skippedEntity events.
048: *
049: * @author Ryan.Shoemaker@Sun.COM
050: * @version 1.0
051: */
052: class EntityDeclarationImpl extends EventHelper implements
053: EntityDeclaration {
054:
055: private final String entityName;
056: private final String publicId;
057: private final String systemId;
058: private final String notationName;
059: private final String replacementText;
060:
061: public EntityDeclarationImpl(Location location, String entityName,
062: String publicId, String systemId, String notationName,
063: String replacementText) {
064: super (location);
065: this .entityName = entityName;
066: this .publicId = publicId;
067: this .systemId = systemId;
068: this .notationName = notationName;
069: this .replacementText = replacementText;
070: }
071:
072: public String getBaseURI() {
073: // TODO: ??
074: return null;
075: }
076:
077: public String getName() {
078: return entityName;
079: }
080:
081: public String getNotationName() {
082: return notationName;
083: }
084:
085: public String getPublicId() {
086: return publicId;
087: }
088:
089: public String getReplacementText() {
090: return replacementText;
091: }
092:
093: public String getSystemId() {
094: return systemId;
095: }
096:
097: public int getEventType() {
098: return ENTITY_DECLARATION;
099: }
100:
101: public boolean isEntityReference() {
102: return true;
103: }
104:
105: public void writeAsEncodedUnicode(Writer w)
106: throws XMLStreamException {
107: try {
108: w.write('&');
109: w.write(entityName);
110: w.write(';');
111: } catch (IOException ie) {
112: throw new XMLStreamException(ie);
113: }
114: }
115: }
|