KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > dom > ProcessingInstructionImpl


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Xerces" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 1999, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 package com.sun.org.apache.xerces.internal.dom;
59
60 import org.w3c.dom.Node JavaDoc;
61 import org.w3c.dom.ProcessingInstruction JavaDoc;
62
63 /**
64  * Processing Instructions (PIs) permit documents to carry
65  * processor-specific information alongside their actual content. PIs
66  * are most common in XML, but they are supported in HTML as well.
67  *
68  * This class inherits from CharacterDataImpl to reuse its setNodeValue method.
69  *
70  * @version $Id: ProcessingInstructionImpl.java,v 1.12 2003/01/17 22:40:54 elena Exp $
71  * @since PR-DOM-Level-1-19980818.
72  */

73 public class ProcessingInstructionImpl
74     extends CharacterDataImpl
75     implements ProcessingInstruction JavaDoc {
76
77     //
78
// Constants
79
//
80

81     /** Serialization version. */
82     static final long serialVersionUID = 7554435174099981510L;
83
84     //
85
// Data
86
//
87

88     protected String JavaDoc target;
89
90     //
91
// Constructors
92
//
93

94     /** Factory constructor. */
95     public ProcessingInstructionImpl(CoreDocumentImpl ownerDoc,
96                                      String JavaDoc target, String JavaDoc data) {
97         super(ownerDoc, data);
98         this.target = target;
99     }
100
101     //
102
// Node methods
103
//
104

105     /**
106      * A short integer indicating what type of node this is. The named
107      * constants for this value are defined in the org.w3c.dom.Node interface.
108      */

109     public short getNodeType() {
110         return Node.PROCESSING_INSTRUCTION_NODE;
111     }
112
113     /**
114      * Returns the target
115      */

116     public String JavaDoc getNodeName() {
117         if (needsSyncData()) {
118             synchronizeData();
119         }
120         return target;
121     }
122
123     //
124
// ProcessingInstruction methods
125
//
126

127     /**
128      * A PI's "target" states what processor channel the PI's data
129      * should be directed to. It is defined differently in HTML and XML.
130      * <p>
131      * In XML, a PI's "target" is the first (whitespace-delimited) token
132      * following the "<?" token that begins the PI.
133      * <p>
134      * In HTML, target is always null.
135      * <p>
136      * Note that getNodeName is aliased to getTarget.
137      */

138     public String JavaDoc getTarget() {
139         if (needsSyncData()) {
140             synchronizeData();
141         }
142         return target;
143
144     } // getTarget():String
145

146     /**
147      * A PI's data content tells the processor what we actually want it
148      * to do. It is defined slightly differently in HTML and XML.
149      * <p>
150      * In XML, the data begins with the non-whitespace character
151      * immediately after the target -- @see getTarget().
152      * <p>
153      * In HTML, the data begins with the character immediately after the
154      * "&lt;?" token that begins the PI.
155      * <p>
156      * Note that getNodeValue is aliased to getData
157      */

158     public String JavaDoc getData() {
159         if (needsSyncData()) {
160             synchronizeData();
161         }
162         return data;
163
164     } // getData():String
165

166     /**
167      * Change the data content of this PI.
168      * Note that setData is aliased to setNodeValue.
169      * @see #getData().
170      * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if node is read-only.
171      */

172     public void setData(String JavaDoc data) {
173         // Hand off to setNodeValue for code-reuse reasons (mutation
174
// events, readonly protection, synchronizing, etc.)
175
setNodeValue(data);
176     } // setData(String)
177

178
179
180    /**
181      * DOM Level 3 WD - Experimental.
182      * Retrieve baseURI
183      */

184     public String JavaDoc getBaseURI() {
185
186         if (needsSyncData()) {
187             synchronizeData();
188         }
189         return ownerNode.getBaseURI();
190     }
191
192
193 } // class ProcessingInstructionImpl
194
Popular Tags