View Javadoc

1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.lang.ast.xpath.saxon;
5   
6   import net.sf.saxon.Configuration;
7   import net.sf.saxon.event.Receiver;
8   import net.sf.saxon.om.Axis;
9   import net.sf.saxon.om.AxisIterator;
10  import net.sf.saxon.om.DocumentInfo;
11  import net.sf.saxon.om.FastStringBuffer;
12  import net.sf.saxon.om.NamePool;
13  import net.sf.saxon.om.NodeInfo;
14  import net.sf.saxon.om.SequenceIterator;
15  import net.sf.saxon.om.SiblingCountingNode;
16  import net.sf.saxon.om.VirtualNode;
17  import net.sf.saxon.om.Navigator.AxisFilter;
18  import net.sf.saxon.pattern.NodeTest;
19  import net.sf.saxon.trans.XPathException;
20  import net.sf.saxon.value.Value;
21  
22  /**
23   * This is a basic implementation of the Saxon NodeInfo and related interfaces.
24   * Most methods are trivial implementations which immediately throw
25   * {@link UnsupportedOperationException}.  A few of the methods actually have
26   * useful implementations, such as {@link #iterateAxis(byte, NodeTest)} and
27   * {@link #isSameNodeInfo(NodeInfo)}.
28   */
29  public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
30      /**
31       * {@inheritDoc}
32       */
33      public String getSystemId() {
34  	throw createUnsupportedOperationException("Source.getSystemId()");
35      }
36  
37      /**
38       * {@inheritDoc}
39       */
40      public void setSystemId(String systemId) {
41  	throw createUnsupportedOperationException("Source.setSystemId(String)");
42      }
43  
44      /**
45       * {@inheritDoc}
46       */
47      public String getStringValue() {
48  	throw createUnsupportedOperationException("ValueRepresentation.getStringValue()");
49      }
50  
51      /**
52       * {@inheritDoc}
53       */
54      public CharSequence getStringValueCS() {
55  	throw createUnsupportedOperationException("ValueRepresentation.getStringValueCS()");
56      }
57  
58      /**
59       * {@inheritDoc}
60       */
61      public SequenceIterator getTypedValue() throws XPathException {
62  	throw createUnsupportedOperationException("Item.getTypedValue()");
63      }
64  
65      /**
66       * {@inheritDoc}
67       */
68      public Object getUnderlyingNode() {
69  	throw createUnsupportedOperationException("VirtualNode.getUnderlyingNode()");
70      }
71  
72      /**
73       * {@inheritDoc}
74       */
75      public int getSiblingPosition() {
76  	throw createUnsupportedOperationException("SiblingCountingNode.getSiblingPosition()");
77      }
78  
79      /**
80       * {@inheritDoc}
81       */
82      public Value atomize() throws XPathException {
83  	throw createUnsupportedOperationException("NodeInfo.atomize()");
84      }
85  
86      /**
87       * {@inheritDoc}
88       */
89      public int compareOrder(NodeInfo other) {
90  	throw createUnsupportedOperationException("NodeInfo.compareOrder(NodeInfo)");
91      }
92  
93      /**
94       * {@inheritDoc}
95       */
96      public void copy(Receiver receiver, int whichNamespaces, boolean copyAnnotations, int locationId)
97  	    throws XPathException {
98  	throw createUnsupportedOperationException("ValueRepresentation.copy(Receiver, int, boolean, int)");
99      }
100 
101     /**
102      * This implementation considers to NodeInfo objects to be equal, if their
103      * underlying nodes are equal.
104      *
105      * {@inheritDoc}
106      */
107     @Override
108     public boolean equals(Object other) {
109 	if (this == other) {
110 	    return true;
111 	}
112 	if (other instanceof ElementNode) {
113 	    return this.getUnderlyingNode() == ((ElementNode) other).getUnderlyingNode();
114 	}
115 	return false;
116     }
117 
118     /**
119      * {@inheritDoc}
120      */
121     public void generateId(FastStringBuffer buffer) {
122 	throw createUnsupportedOperationException("NodeInfo.generateId(FastStringBuffer)");
123     }
124 
125     /**
126      * {@inheritDoc}
127      */
128     public String getAttributeValue(int fingerprint) {
129 	throw createUnsupportedOperationException("NodeInfo.getAttributeValue(int)");
130     }
131 
132     /**
133      * {@inheritDoc}
134      */
135     public String getBaseURI() {
136 	throw createUnsupportedOperationException("NodeInfo.getBaseURI()");
137     }
138 
139     /**
140      * {@inheritDoc}
141      */
142     public int getColumnNumber() {
143 	throw createUnsupportedOperationException("NodeInfo.getColumnNumber()");
144     }
145 
146     /**
147      * {@inheritDoc}
148      */
149     public Configuration getConfiguration() {
150 	throw createUnsupportedOperationException("NodeInfo.getConfiguration()");
151     }
152 
153     /**
154      * {@inheritDoc}
155      */
156     public int[] getDeclaredNamespaces(int[] buffer) {
157 	throw createUnsupportedOperationException("NodeInfo.getDeclaredNamespaces(int[])");
158     }
159 
160     /**
161      * {@inheritDoc}
162      */
163     public String getDisplayName() {
164 	throw createUnsupportedOperationException("NodeInfo.getDisplayName()");
165     }
166 
167     /**
168      * This implementation always returns 0.
169      *
170      * {@inheritDoc}
171      */
172     public int getDocumentNumber() {
173 	return 0;
174     }
175 
176     /**
177      * {@inheritDoc}
178      */
179     public DocumentInfo getDocumentRoot() {
180 	throw createUnsupportedOperationException("NodeInfo.getDocumentRoot()");
181     }
182 
183     /**
184      * {@inheritDoc}
185      */
186     public int getFingerprint() {
187 	throw createUnsupportedOperationException("NodeInfo.getFingerprint()");
188     }
189 
190     /**
191      * {@inheritDoc}
192      */
193     public int getLineNumber() {
194 	throw createUnsupportedOperationException("NodeInfo.getLineNumber()");
195     }
196 
197     /**
198      * {@inheritDoc}
199      */
200     public String getLocalPart() {
201 	throw createUnsupportedOperationException("NodeInfo.getLocalPart()");
202     }
203 
204     /**
205      * {@inheritDoc}
206      */
207     public int getNameCode() {
208 	throw createUnsupportedOperationException("NodeInfo.getNameCode()");
209     }
210 
211     /**
212      * {@inheritDoc}
213      */
214     public NamePool getNamePool() {
215 	throw createUnsupportedOperationException("NodeInfo.getNamePool()");
216     }
217 
218     /**
219      * {@inheritDoc}
220      */
221     public int getNodeKind() {
222 	throw createUnsupportedOperationException("NodeInfo.getNodeKind()");
223     }
224 
225     /**
226      * {@inheritDoc}
227      */
228     public NodeInfo getParent() {
229 	throw createUnsupportedOperationException("NodeInfo.getParent()");
230     }
231 
232     /**
233      * {@inheritDoc}
234      */
235     public String getPrefix() {
236 	throw createUnsupportedOperationException("NodeInfo.getPrefix()");
237     }
238 
239     /**
240      * {@inheritDoc}
241      */
242     public NodeInfo getRoot() {
243 	throw createUnsupportedOperationException("NodeInfo.getRoot()");
244     }
245 
246     /**
247      * {@inheritDoc}
248      */
249     public int getTypeAnnotation() {
250 	throw createUnsupportedOperationException("NodeInfo.getTypeAnnotation()");
251     }
252 
253     /**
254      * {@inheritDoc}
255      */
256     public String getURI() {
257 	throw createUnsupportedOperationException("NodeInfo.getURI()");
258     }
259 
260     /**
261      * {@inheritDoc}
262      */
263     public boolean hasChildNodes() {
264 	throw createUnsupportedOperationException("NodeInfo.hasChildNodes()");
265     }
266 
267     /**
268      * {@inheritDoc}
269      */
270     public boolean isId() {
271 	throw createUnsupportedOperationException("NodeInfo.isId()");
272     }
273 
274     /**
275      * {@inheritDoc}
276      */
277     public boolean isIdref() {
278 	throw createUnsupportedOperationException("NodeInfo.isIdref()");
279     }
280 
281     /**
282      * {@inheritDoc}
283      */
284     public boolean isNilled() {
285 	throw createUnsupportedOperationException("NodeInfo.isNilled()");
286     }
287 
288     /**
289      * This implementation delegates to {@link #equals(Object)}, per the Saxon
290      * documentation's description of this method's behavior.
291      *
292      * {@inheritDoc}
293      */
294     public boolean isSameNodeInfo(NodeInfo other) {
295 	return this.equals(other);
296     }
297 
298     /**
299      * {@inheritDoc}
300      */
301     public AxisIterator iterateAxis(byte axisNumber) {
302 	throw createUnsupportedOperationException("NodeInfo.iterateAxis(byte) for axis '" + Axis.axisName[axisNumber]
303 		+ "'");
304     }
305 
306     /**
307      * This implementation calls {@link #iterateAxis(byte)} to get an
308      * {@link AxisIterator} which is then optionally filtered using
309      * {@link AxisFilter}.
310      *
311      * {@inheritDoc}
312      */
313     public AxisIterator iterateAxis(byte axisNumber, NodeTest nodeTest) {
314 	AxisIterator axisIterator = iterateAxis(axisNumber);
315 	if (nodeTest != null) {
316 	    axisIterator = new AxisFilter(axisIterator, nodeTest);
317 	}
318 	return axisIterator;
319     }
320 
321     /**
322      * Used to create a customized instance of UnsupportedOperationException.
323      * The caller of this method is intended to <code>throw</code> the exception.
324      *
325      * @param name Method name that is not supported.
326      * @return A UnsupportedOperationException indicated the method is not supported by the implementation class.
327      */
328     protected UnsupportedOperationException createUnsupportedOperationException(String name) {
329 	return new UnsupportedOperationException(name + " is not implemented by " + this.getClass().getName());
330     }
331 }