Class Attribute


  • public final class Attribute
    extends Object
    Represents an XPath attribute of a specific node. Attributes know their name, the node they wrap, and have access to their value.

    Two attributes are equal if they have the same name and their parent nodes are equal.

    Note that attributes do not support just any type, but a restricted set of value types that can be mapped to XPath types. The exact supported types are not specified, but include at least Java primitives and String.

    See Also:
    Node.getXPathAttributesIterator()
    • Constructor Detail

      • Attribute

        public Attribute​(@NonNull Node parent,
                         @NonNull String name,
                         @NonNull MethodHandle handle,
                         @NonNull Method method)
        Creates a new attribute belonging to the given node using its accessor.
        Parameters:
        handle - A method handle, used to fetch the attribute.
        method - The method corresponding to the method handle. This is used to perform reflective queries, eg to find annotations on the attribute getter, but only the method handle is ever invoked.
      • Attribute

        public Attribute​(@NonNull Node parent,
                         @NonNull String name,
                         @Nullable String value)
        Creates a new attribute belonging to the given node using its string value.
    • Method Detail

      • getType

        public Type getType()
        Gets the generic type of the value of this attribute.
      • getName

        public @NonNull String getName()
        Return the name of the attribute (without leading @ sign).
      • getParent

        public @NonNull Node getParent()
        Return the node that owns this attribute.
      • isDeprecated

        public boolean isDeprecated()
        Return whether this attribute was deprecated. This is the case if the getter has the annotation Deprecated or DeprecatedAttribute.
      • getValue

        public Object getValue()
        Return the value of the attribute. This may return null. The getter is invoked at most once.
      • getStringValue

        public @NonNull String getStringValue()
        Return the string value of the attribute. If the getter returned null, then return the empty string (which is a falsy value in XPath). Otherwise, return a string representation of the value (e.g. with Object.toString(), but this is not guaranteed).
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object