001//////////////////////////////////////////////////////////////////////////////// 002// checkstyle: Checks Java source code for adherence to a set of rules. 003// Copyright (C) 2001-2020 the original author or authors. 004// 005// This library is free software; you can redistribute it and/or 006// modify it under the terms of the GNU Lesser General Public 007// License as published by the Free Software Foundation; either 008// version 2.1 of the License, or (at your option) any later version. 009// 010// This library is distributed in the hope that it will be useful, 011// but WITHOUT ANY WARRANTY; without even the implied warranty of 012// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013// Lesser General Public License for more details. 014// 015// You should have received a copy of the GNU Lesser General Public 016// License along with this library; if not, write to the Free Software 017// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 018//////////////////////////////////////////////////////////////////////////////// 019 020package com.puppycrawl.tools.checkstyle.xpath; 021 022import com.puppycrawl.tools.checkstyle.api.DetailAST; 023import net.sf.saxon.om.NodeInfo; 024import net.sf.saxon.tree.iter.AxisIterator; 025import net.sf.saxon.type.Type; 026 027/** 028 * Represents attribute of the element. 029 * 030 */ 031public class AttributeNode extends AbstractNode { 032 033 /** The name of the attribute. */ 034 private final String name; 035 036 /** The value of the attribute. */ 037 private final String value; 038 039 /** 040 * Creates a new {@code AttributeNode} instance. 041 * 042 * @param name name of the attribute 043 * @param value value of the attribute 044 */ 045 public AttributeNode(String name, String value) { 046 super(null); 047 this.name = name; 048 this.value = value; 049 } 050 051 /** 052 * Compares current object with specified for order. 053 * Throws {@code UnsupportedOperationException} because functionality not required here. 054 * @param nodeInfo another {@code NodeInfo} object 055 * @return number representing order of current object to specified one 056 */ 057 @Override 058 public int compareOrder(NodeInfo nodeInfo) { 059 throw throwUnsupportedOperationException(); 060 } 061 062 /** 063 * Returns attribute value. Throws {@code UnsupportedOperationException} because attribute node 064 * has no attributes. 065 * 066 * @param namespace namespace 067 * @param localPart actual name of the attribute 068 * @return attribute value 069 */ 070 @Override 071 public String getAttributeValue(String namespace, String localPart) { 072 throw throwUnsupportedOperationException(); 073 } 074 075 /** 076 * Returns local part. 077 * 078 * @return local part 079 */ 080 @Override 081 public String getLocalPart() { 082 return name; 083 } 084 085 /** 086 * Returns type of the node. 087 * 088 * @return node kind 089 */ 090 @Override 091 public int getNodeKind() { 092 return Type.ATTRIBUTE; 093 } 094 095 /** 096 * Returns parent. Never called for attribute node, throws 097 * {@code UnsupportedOperationException}. 098 * has no attributes. 099 * 100 * @return parent 101 */ 102 @Override 103 public NodeInfo getParent() { 104 throw throwUnsupportedOperationException(); 105 } 106 107 /** 108 * Returns root. Never called for attribute node, throws 109 * {@code UnsupportedOperationException}. 110 * 111 * @return root 112 */ 113 @Override 114 public NodeInfo getRoot() { 115 throw throwUnsupportedOperationException(); 116 } 117 118 /** 119 * Returns string value. 120 * 121 * @return string value 122 */ 123 @Override 124 public String getStringValue() { 125 return value; 126 } 127 128 /** 129 * Determines axis iteration algorithm. Attribute node can not be iterated, throws 130 * {@code UnsupportedOperationException}. 131 * 132 * @param axisNumber element from {@code AxisInfo} 133 * @return {@code AxisIterator} object 134 */ 135 @Override 136 public AxisIterator iterateAxis(byte axisNumber) { 137 throw throwUnsupportedOperationException(); 138 } 139 140 /** 141 * Returns line number. Attribute node has no line number, throws 142 * {@code UnsupportedOperationException}. 143 * 144 * @return line number 145 */ 146 @Override 147 public int getLineNumber() { 148 throw throwUnsupportedOperationException(); 149 } 150 151 /** 152 * Returns column number. Attribute node has no column number, throws 153 * {@code UnsupportedOperationException}. 154 * 155 * @return column number 156 */ 157 @Override 158 public int getColumnNumber() { 159 throw throwUnsupportedOperationException(); 160 } 161 162 /** 163 * Getter method for token type. Attribute node has no token type, throws 164 * {@code UnsupportedOperationException}. 165 * 166 * @return token type 167 */ 168 @Override 169 public int getTokenType() { 170 throw throwUnsupportedOperationException(); 171 } 172 173 /** 174 * Returns underlying node. Attribute node has no underlying node, throws 175 * {@code UnsupportedOperationException}. 176 * 177 * @return underlying node 178 */ 179 @Override 180 public DetailAST getUnderlyingNode() { 181 throw throwUnsupportedOperationException(); 182 } 183 184 /** 185 * Returns UnsupportedOperationException exception. 186 * 187 * @return UnsupportedOperationException exception 188 */ 189 private static UnsupportedOperationException throwUnsupportedOperationException() { 190 return new UnsupportedOperationException("Operation is not supported"); 191 } 192 193}