KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > dom > ProcessingInstructionImpl


1 /*
2  * Copyright 1999-2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.xerces.dom;
18
19 import org.w3c.dom.Node JavaDoc;
20 import org.w3c.dom.ProcessingInstruction JavaDoc;
21
22 /**
23  * Processing Instructions (PIs) permit documents to carry
24  * processor-specific information alongside their actual content. PIs
25  * are most common in XML, but they are supported in HTML as well.
26  *
27  * This class inherits from CharacterDataImpl to reuse its setNodeValue method.
28  *
29  * @xerces.internal
30  *
31  * @version $Id: ProcessingInstructionImpl.java,v 1.15 2004/10/05 17:12:49 mrglavas Exp $
32  * @since PR-DOM-Level-1-19980818.
33  */

34 public class ProcessingInstructionImpl
35     extends CharacterDataImpl
36     implements ProcessingInstruction JavaDoc {
37
38     //
39
// Constants
40
//
41

42     /** Serialization version. */
43     static final long serialVersionUID = 7554435174099981510L;
44
45     //
46
// Data
47
//
48

49     protected String JavaDoc target;
50
51     //
52
// Constructors
53
//
54

55     /** Factory constructor. */
56     public ProcessingInstructionImpl(CoreDocumentImpl ownerDoc,
57                                      String JavaDoc target, String JavaDoc data) {
58         super(ownerDoc, data);
59         this.target = target;
60     }
61
62     //
63
// Node methods
64
//
65

66     /**
67      * A short integer indicating what type of node this is. The named
68      * constants for this value are defined in the org.w3c.dom.Node interface.
69      */

70     public short getNodeType() {
71         return Node.PROCESSING_INSTRUCTION_NODE;
72     }
73
74     /**
75      * Returns the target
76      */

77     public String JavaDoc getNodeName() {
78         if (needsSyncData()) {
79             synchronizeData();
80         }
81         return target;
82     }
83
84     //
85
// ProcessingInstruction methods
86
//
87

88     /**
89      * A PI's "target" states what processor channel the PI's data
90      * should be directed to. It is defined differently in HTML and XML.
91      * <p>
92      * In XML, a PI's "target" is the first (whitespace-delimited) token
93      * following the "<?" token that begins the PI.
94      * <p>
95      * In HTML, target is always null.
96      * <p>
97      * Note that getNodeName is aliased to getTarget.
98      */

99     public String JavaDoc getTarget() {
100         if (needsSyncData()) {
101             synchronizeData();
102         }
103         return target;
104
105     } // getTarget():String
106

107     /**
108      * A PI's data content tells the processor what we actually want it
109      * to do. It is defined slightly differently in HTML and XML.
110      * <p>
111      * In XML, the data begins with the non-whitespace character
112      * immediately after the target -- @see getTarget().
113      * <p>
114      * In HTML, the data begins with the character immediately after the
115      * "&lt;?" token that begins the PI.
116      * <p>
117      * Note that getNodeValue is aliased to getData
118      */

119     public String JavaDoc getData() {
120         if (needsSyncData()) {
121             synchronizeData();
122         }
123         return data;
124
125     } // getData():String
126

127     /**
128      * Change the data content of this PI.
129      * Note that setData is aliased to setNodeValue.
130      * @see #getData().
131      * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if node is read-only.
132      */

133     public void setData(String JavaDoc data) {
134         // Hand off to setNodeValue for code-reuse reasons (mutation
135
// events, readonly protection, synchronizing, etc.)
136
setNodeValue(data);
137     } // setData(String)
138

139
140
141    /**
142      * Returns the absolute base URI of this node or null if the implementation
143      * wasn't able to obtain an absolute URI. Note: If the URI is malformed, a
144      * null is returned.
145      *
146      * @return The absolute base URI of this node or null.
147      * @since DOM Level 3
148      */

149     public String JavaDoc getBaseURI() {
150
151         if (needsSyncData()) {
152             synchronizeData();
153         }
154         return ownerNode.getBaseURI();
155     }
156
157
158 } // class ProcessingInstructionImpl
159
Popular Tags