View Javadoc

    1   package net.sourceforge.pmd.lang.ast.xpath.saxon;
    2
    3   import net.sf.saxon.Configuration;
    4   import net.sf.saxon.event.Receiver;
    5   import net.sf.saxon.om.Axis;
    6   import net.sf.saxon.om.AxisIterator;
    7   import net.sf.saxon.om.DocumentInfo;
    8   import net.sf.saxon.om.FastStringBuffer;
    9   import net.sf.saxon.om.NamePool;
    10  import net.sf.saxon.om.NodeInfo;
    11  import net.sf.saxon.om.SequenceIterator;
    12  import net.sf.saxon.om.SiblingCountingNode;
    13  import net.sf.saxon.om.VirtualNode;
    14  import net.sf.saxon.om.Navigator.AxisFilter;
    15  import net.sf.saxon.pattern.NodeTest;
    16  import net.sf.saxon.trans.XPathException;
    17  import net.sf.saxon.value.Value;
    18
    19  /**
    20   * This is a basic implementation of the Saxon NodeInfo and related interfaces.
    21   * Most methods are trivial implementations which immediately throw
    22   * {@link UnsupportedOperationException}.  A few of the methods actually have
    23   * useful implementations, such as {@link #iterateAxis(byte, NodeTest)} and
    24   * {@link #isSameNodeInfo(NodeInfo)}.
    25   */
    26  public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode {
    27      /**
    28       * {@inheritDoc}
    29       */
    30      public String getSystemId() {
    31  	throw createUnsupportedOperationException("Source.getSystemId()");
    32      }
    33
    34      /**
    35       * {@inheritDoc}
    36       */
    37      public void setSystemId(String systemId) {
    38  	throw createUnsupportedOperationException("Source.setSystemId(String)");
    39      }
    40
    41      /**
    42       * {@inheritDoc}
    43       */
    44      public String getStringValue() {
    45  	throw createUnsupportedOperationException("ValueRepresentation.getStringValue()");
    46      }
    47
    48      /**
    49       * {@inheritDoc}
    50       */
    51      public CharSequence getStringValueCS() {
    52  	throw createUnsupportedOperationException("ValueRepresentation.getStringValueCS()");
    53      }
    54
    55      /**
    56       * {@inheritDoc}
    57       */
    58      public SequenceIterator getTypedValue() throws XPathException {
    59  	throw createUnsupportedOperationException("Item.getTypedValue()");
    60      }
    61
    62      /**
    63       * {@inheritDoc}
    64       */
    65      public Object getUnderlyingNode() {
    66  	throw createUnsupportedOperationException("VirtualNode.getUnderlyingNode()");
    67      }
    68
    69      /**
    70       * {@inheritDoc}
    71       */
    72      public int getSiblingPosition() {
    73  	throw createUnsupportedOperationException("SiblingCountingNode.getSiblingPosition()");
    74      }
    75
    76      /**
    77       * {@inheritDoc}
    78       */
    79      public Value atomize() throws XPathException {
    80  	throw createUnsupportedOperationException("NodeInfo.atomize()");
    81      }
    82
    83      /**
    84       * {@inheritDoc}
    85       */
    86      public int compareOrder(NodeInfo other) {
    87  	throw createUnsupportedOperationException("NodeInfo.compareOrder(NodeInfo)");
    88      }
    89
    90      /**
    91       * {@inheritDoc}
    92       */
    93      public void copy(Receiver receiver, int whichNamespaces, boolean copyAnnotations, int locationId)
    94  	    throws XPathException {
    95  	throw createUnsupportedOperationException("ValueRepresentation.copy(Receiver, int, boolean, int)");
    96      }
    97
    98      /**
    99       * 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 }