001: /*
002: * $Id: ProcessingInstructionEvent.java,v 1.2 2006/04/01 06:01:34 jeffsuttor Exp $
003: */
004:
005: /*
006: * The contents of this file are subject to the terms
007: * of the Common Development and Distribution License
008: * (the License). You may not use this file except in
009: * compliance with the License.
010: *
011: * You can obtain a copy of the license at
012: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
013: * See the License for the specific language governing
014: * permissions and limitations under the License.
015: *
016: * When distributing Covered Code, include this CDDL
017: * Header Notice in each file and include the License file
018: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
019: * If applicable, add the following below the CDDL Header,
020: * with the fields enclosed by brackets [] replaced by
021: * you own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * [Name of File] [ver.__] [Date]
025: *
026: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
027: */
028:
029: package com.sun.xml.stream.events;
030:
031: import java.io.Writer;
032: import javax.xml.stream.Location;
033: import javax.xml.stream.XMLStreamConstants;
034: import javax.xml.stream.XMLStreamException;
035: import javax.xml.stream.events.ProcessingInstruction;
036:
037: /** Implements Processing Instruction Event
038: *
039: *@author Neeraj Bajaj, Sun Microsystems.
040: *
041: */
042:
043: public class ProcessingInstructionEvent extends DummyEvent implements
044: ProcessingInstruction {
045:
046: /** Processing Instruction Name */
047: private String fName;
048: /** Processsing instruction content */
049: private String fContent;
050:
051: public ProcessingInstructionEvent() {
052: init();
053: }
054:
055: public ProcessingInstructionEvent(String targetName, String data) {
056: this (targetName, data, null);
057: }
058:
059: public ProcessingInstructionEvent(String targetName, String data,
060: Location loc) {
061: init();
062: this .fName = targetName;
063: fContent = data;
064: setLocation(loc);
065: }
066:
067: protected void init() {
068: setEventType(XMLStreamConstants.PROCESSING_INSTRUCTION);
069: }
070:
071: public String getTarget() {
072: return fName;
073: }
074:
075: public void setTarget(String targetName) {
076: fName = targetName;
077: }
078:
079: public void setData(String data) {
080: fContent = data;
081: }
082:
083: public String getData() {
084: return fContent;
085: }
086:
087: public String toString() {
088: if (fContent != null && fName != null)
089: return "<?" + fName + fContent + "?>";
090: if (fName != null)
091: return "<?" + fName + "?>";
092: if (fContent != null)
093: return "<?" + fContent + "?>";
094: else
095: return "<??>";
096: }
097:
098: /** This method will write the XMLEvent as per the XML 1.0 specification as Unicode characters.
099: * No indentation or whitespace should be outputted.
100: *
101: * Any user defined event type SHALL have this method
102: * called when being written to on an output stream.
103: * Built in Event types MUST implement this method,
104: * but implementations MAY choose not call these methods
105: * for optimizations reasons when writing out built in
106: * Events to an output stream.
107: * The output generated MUST be equivalent in terms of the
108: * infoset expressed.
109: *
110: * @param writer The writer that will output the data
111: * @throws XMLStreamException if there is a fatal error writing the event
112: */
113: public void writeAsEncodedUnicode(Writer writer)
114: throws XMLStreamException {
115: }
116:
117: }
|