001 package net.sourceforge.pmd.lang.ast.xpath.saxon;
002
003 import net.sf.saxon.Configuration;
004 import net.sf.saxon.event.Receiver;
005 import net.sf.saxon.om.Axis;
006 import net.sf.saxon.om.AxisIterator;
007 import net.sf.saxon.om.DocumentInfo;
008 import net.sf.saxon.om.FastStringBuffer;
009 import net.sf.saxon.om.NamePool;
010 import net.sf.saxon.om.NodeInfo;
011 import net.sf.saxon.om.SequenceIterator;
012 import net.sf.saxon.om.SiblingCountingNode;
013 import net.sf.saxon.om.VirtualNode;
014 import net.sf.saxon.om.Navigator.AxisFilter;
015 import net.sf.saxon.pattern.NodeTest;
016 import net.sf.saxon.trans.XPathException;
017 import net.sf.saxon.value.Value;
018
019 /**
020 * This is a basic implementation of the Saxon NodeInfo and related interfaces.
021 * Most methods are trivial implementations which immediately throw
022 * {@link UnsupportedOperationException}. A few of the methods actually have
023 * useful implementations, such as {@link #iterateAxis(byte, NodeTest)} and
024 * {@link #isSameNodeInfo(NodeInfo)}.
025 */
026 public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
027 /**
028 * {@inheritDoc}
029 */
030 public String getSystemId() {
031 throw createUnsupportedOperationException("Source.getSystemId()");
032 }
033
034 /**
035 * {@inheritDoc}
036 */
037 public void setSystemId(String systemId) {
038 throw createUnsupportedOperationException("Source.setSystemId(String)");
039 }
040
041 /**
042 * {@inheritDoc}
043 */
044 public String getStringValue() {
045 throw createUnsupportedOperationException("ValueRepresentation.getStringValue()");
046 }
047
048 /**
049 * {@inheritDoc}
050 */
051 public CharSequence getStringValueCS() {
052 throw createUnsupportedOperationException("ValueRepresentation.getStringValueCS()");
053 }
054
055 /**
056 * {@inheritDoc}
057 */
058 public SequenceIterator getTypedValue() throws XPathException {
059 throw createUnsupportedOperationException("Item.getTypedValue()");
060 }
061
062 /**
063 * {@inheritDoc}
064 */
065 public Object getUnderlyingNode() {
066 throw createUnsupportedOperationException("VirtualNode.getUnderlyingNode()");
067 }
068
069 /**
070 * {@inheritDoc}
071 */
072 public int getSiblingPosition() {
073 throw createUnsupportedOperationException("SiblingCountingNode.getSiblingPosition()");
074 }
075
076 /**
077 * {@inheritDoc}
078 */
079 public Value atomize() throws XPathException {
080 throw createUnsupportedOperationException("NodeInfo.atomize()");
081 }
082
083 /**
084 * {@inheritDoc}
085 */
086 public int compareOrder(NodeInfo other) {
087 throw createUnsupportedOperationException("NodeInfo.compareOrder(NodeInfo)");
088 }
089
090 /**
091 * {@inheritDoc}
092 */
093 public void copy(Receiver receiver, int whichNamespaces, boolean copyAnnotations, int locationId)
094 throws XPathException {
095 throw createUnsupportedOperationException("ValueRepresentation.copy(Receiver, int, boolean, int)");
096 }
097
098 /**
099 * This implementation considers to NodeInfo objects to be equal, if their
100 * underlying nodes are equal.
101 *
102 * {@inheritDoc}
103 */
104 @Override
105 public boolean equals(Object other) {
106 if (this == other) {
107 return true;
108 }
109 if (other instanceof ElementNode) {
110 return this.getUnderlyingNode() == ((ElementNode) other).getUnderlyingNode();
111 }
112 return false;
113 }
114
115 /**
116 * {@inheritDoc}
117 */
118 public void generateId(FastStringBuffer buffer) {
119 throw createUnsupportedOperationException("NodeInfo.generateId(FastStringBuffer)");
120 }
121
122 /**
123 * {@inheritDoc}
124 */
125 public String getAttributeValue(int fingerprint) {
126 throw createUnsupportedOperationException("NodeInfo.getAttributeValue(int)");
127 }
128
129 /**
130 * {@inheritDoc}
131 */
132 public String getBaseURI() {
133 throw createUnsupportedOperationException("NodeInfo.getBaseURI()");
134 }
135
136 /**
137 * {@inheritDoc}
138 */
139 public int getColumnNumber() {
140 throw createUnsupportedOperationException("NodeInfo.getColumnNumber()");
141 }
142
143 /**
144 * {@inheritDoc}
145 */
146 public Configuration getConfiguration() {
147 throw createUnsupportedOperationException("NodeInfo.getConfiguration()");
148 }
149
150 /**
151 * {@inheritDoc}
152 */
153 public int[] getDeclaredNamespaces(int[] buffer) {
154 throw createUnsupportedOperationException("NodeInfo.getDeclaredNamespaces(int[])");
155 }
156
157 /**
158 * {@inheritDoc}
159 */
160 public String getDisplayName() {
161 throw createUnsupportedOperationException("NodeInfo.getDisplayName()");
162 }
163
164 /**
165 * This implementation always returns 0.
166 *
167 * {@inheritDoc}
168 */
169 public int getDocumentNumber() {
170 return 0;
171 }
172
173 /**
174 * {@inheritDoc}
175 */
176 public DocumentInfo getDocumentRoot() {
177 throw createUnsupportedOperationException("NodeInfo.getDocumentRoot()");
178 }
179
180 /**
181 * {@inheritDoc}
182 */
183 public int getFingerprint() {
184 throw createUnsupportedOperationException("NodeInfo.getFingerprint()");
185 }
186
187 /**
188 * {@inheritDoc}
189 */
190 public int getLineNumber() {
191 throw createUnsupportedOperationException("NodeInfo.getLineNumber()");
192 }
193
194 /**
195 * {@inheritDoc}
196 */
197 public String getLocalPart() {
198 throw createUnsupportedOperationException("NodeInfo.getLocalPart()");
199 }
200
201 /**
202 * {@inheritDoc}
203 */
204 public int getNameCode() {
205 throw createUnsupportedOperationException("NodeInfo.getNameCode()");
206 }
207
208 /**
209 * {@inheritDoc}
210 */
211 public NamePool getNamePool() {
212 throw createUnsupportedOperationException("NodeInfo.getNamePool()");
213 }
214
215 /**
216 * {@inheritDoc}
217 */
218 public int getNodeKind() {
219 throw createUnsupportedOperationException("NodeInfo.getNodeKind()");
220 }
221
222 /**
223 * {@inheritDoc}
224 */
225 public NodeInfo getParent() {
226 throw createUnsupportedOperationException("NodeInfo.getParent()");
227 }
228
229 /**
230 * {@inheritDoc}
231 */
232 public String getPrefix() {
233 throw createUnsupportedOperationException("NodeInfo.getPrefix()");
234 }
235
236 /**
237 * {@inheritDoc}
238 */
239 public NodeInfo getRoot() {
240 throw createUnsupportedOperationException("NodeInfo.getRoot()");
241 }
242
243 /**
244 * {@inheritDoc}
245 */
246 public int getTypeAnnotation() {
247 throw createUnsupportedOperationException("NodeInfo.getTypeAnnotation()");
248 }
249
250 /**
251 * {@inheritDoc}
252 */
253 public String getURI() {
254 throw createUnsupportedOperationException("NodeInfo.getURI()");
255 }
256
257 /**
258 * {@inheritDoc}
259 */
260 public boolean hasChildNodes() {
261 throw createUnsupportedOperationException("NodeInfo.hasChildNodes()");
262 }
263
264 /**
265 * {@inheritDoc}
266 */
267 public boolean isId() {
268 throw createUnsupportedOperationException("NodeInfo.isId()");
269 }
270
271 /**
272 * {@inheritDoc}
273 */
274 public boolean isIdref() {
275 throw createUnsupportedOperationException("NodeInfo.isIdref()");
276 }
277
278 /**
279 * {@inheritDoc}
280 */
281 public boolean isNilled() {
282 throw createUnsupportedOperationException("NodeInfo.isNilled()");
283 }
284
285 /**
286 * This implementation delegates to {@link #equals(Object)}, per the Saxon
287 * documentation's description of this method's behavior.
288 *
289 * {@inheritDoc}
290 */
291 public boolean isSameNodeInfo(NodeInfo other) {
292 return this.equals(other);
293 }
294
295 /**
296 * {@inheritDoc}
297 */
298 public AxisIterator iterateAxis(byte axisNumber) {
299 throw createUnsupportedOperationException("NodeInfo.iterateAxis(byte) for axis '" + Axis.axisName[axisNumber]
300 + "'");
301 }
302
303 /**
304 * This implementation calls {@link #iterateAxis(byte)} to get an
305 * {@link AxisIterator} which is then optionally filtered using
306 * {@link AxisFilter}.
307 *
308 * {@inheritDoc}
309 */
310 public AxisIterator iterateAxis(byte axisNumber, NodeTest nodeTest) {
311 AxisIterator axisIterator = iterateAxis(axisNumber);
312 if (nodeTest != null) {
313 axisIterator = new AxisFilter(axisIterator, nodeTest);
314 }
315 return axisIterator;
316 }
317
318 /**
319 * Used to create a customized instance of UnsupportedOperationException.
320 * The caller of this method is intended to <code>throw</code> the exception.
321 *
322 * @param name Method name that is not supported.
323 * @return A UnsupportedOperationException indicated the method is not supported by the implementation class.
324 */
325 protected UnsupportedOperationException createUnsupportedOperationException(String name) {
326 return new UnsupportedOperationException(name + " is not implemented by " + this.getClass().getName());
327 }
328 }
|