01: /*
02: * $Id: EntityReferenceEvent.java,v 1.2 2006/04/01 06:01:34 jeffsuttor Exp $
03: */
04:
05: /*
06: * The contents of this file are subject to the terms
07: * of the Common Development and Distribution License
08: * (the License). You may not use this file except in
09: * compliance with the License.
10: *
11: * You can obtain a copy of the license at
12: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
13: * See the License for the specific language governing
14: * permissions and limitations under the License.
15: *
16: * When distributing Covered Code, include this CDDL
17: * Header Notice in each file and include the License file
18: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
19: * If applicable, add the following below the CDDL Header,
20: * with the fields enclosed by brackets [] replaced by
21: * you own identifying information:
22: * "Portions Copyrighted [year] [name of copyright owner]"
23: *
24: * [Name of File] [ver.__] [Date]
25: *
26: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
27: */
28:
29: package com.sun.xml.stream.events;
30:
31: import javax.xml.stream.events.EntityReference;
32: import java.io.Writer;
33: import javax.xml.stream.events.EntityDeclaration;
34: import javax.xml.stream.events.XMLEvent;
35:
36: /** Implements EntityReference event.
37: *
38: *@author Neeraj Bajaj, Sun Microsystems,
39: */
40: public class EntityReferenceEvent extends DummyEvent implements
41: EntityReference {
42: private EntityDeclaration fEntityDeclaration;
43: private String fEntityName;
44:
45: public EntityReferenceEvent() {
46: init();
47: }
48:
49: public EntityReferenceEvent(String entityName,
50: EntityDeclaration entityDeclaration) {
51: init();
52: fEntityName = entityName;
53: fEntityDeclaration = entityDeclaration;
54: }
55:
56: public String getName() {
57: return fEntityName;
58: }
59:
60: public String toString() {
61: String text = fEntityDeclaration.getReplacementText();
62: if (text == null)
63: text = "";
64: return "&" + getName() + ";='" + text + "'";
65: }
66:
67: /** This method will write the XMLEvent as per the XML 1.0 specification as Unicode characters.
68: * No indentation or whitespace should be outputted.
69: *
70: * Any user defined event type SHALL have this method
71: * called when being written to on an output stream.
72: * Built in Event types MUST implement this method,
73: * but implementations MAY choose not call these methods
74: * for optimizations reasons when writing out built in
75: * Events to an output stream.
76: * The output generated MUST be equivalent in terms of the
77: * infoset expressed.
78: *
79: * @param writer The writer that will output the data
80: * @throws XMLStreamException if there is a fatal error writing the event
81: */
82: public void writeAsEncodedUnicode(Writer writer)
83: throws javax.xml.stream.XMLStreamException {
84: }
85:
86: public EntityDeclaration getDeclaration() {
87: return fEntityDeclaration;
88: }
89:
90: protected void init() {
91: setEventType(XMLEvent.ENTITY_REFERENCE);
92: }
93:
94: }
|