dfh.treepath
Class AttributeLibrary<N>

java.lang.Object
  extended by dfh.treepath.Forester<N>
      extended by dfh.treepath.AttributeLibrary<N>
Type Parameters:
N - the type of node the library should handle (type erasure is going to obliterate this)
All Implemented Interfaces:
Serializable

public class AttributeLibrary<N>
extends Forester<N>

The base class all attribute libraries must extend. This is a bit of a hack to implement mixins in Java for this limited case. To create an attribute library to mix in, create a public class extending this class and make sure it has a public zero-argument constructor. Then call Forester.mixin(Class...), passing in your class object. You may do this ad hoc, or you may do it in your class like so:

 class Foo<N> extends Forester<N> {
        {
                mixin(Library1.class, Library2.class);
        }
        // ...
 }
 
Now this class will have these attributes mixed in. These attributes will not survive serialization, however. If you wish to ensure your Forester has these methods after deserialization, you should override its init method like so:
 @Override
 protected void init() {
        if (attributes == null) {
                super.init();
                mixin(Library1.class, Library2.class);
        }
 }
 

Attribute libraries can do the basic work of finding a node's parent or children (by delegating to a more expert forester), but the tag matching methods -- hasTag(Object, String) and matchesTag(Object, Pattern) -- with throw an error, so don't count on them.

Author:
David F. Houghton - May 10, 2012
See Also:
Serialized Form

Field Summary
 
Fields inherited from class dfh.treepath.Forester
attributeCache, attributes, pathMt
 
Constructor Summary
AttributeLibrary()
           
 
Method Summary
protected  List<N> children(N n, Index<N> i)
          All the children of the context node regardless of whether we are ignoring any node types.
protected  boolean hasTag(N n, String tag)
          Defines what it means for a node in this tree to have a particular tag -- the "b" in the path expression "//b".
protected  boolean matchesTag(N n, Pattern p)
          Defines what it means for a node in this tree to have a tag matching the specified pattern.
protected  N parent(N n, Index<N> i)
          Obtains the parent of the context node.
 
Methods inherited from class dfh.treepath.Forester
ancestors, attribToBoolean, attribute, attribute, attributes, axis, children, closest, depth, descendants, echo, False, following, followingSiblings, getAttributes, getLoggingStream, height, id, index, index, init, isLeaf, isRoot, kids, leaves, log, mixin, Null, path, pick, preceding, precedingSiblings, root, setLoggingStream, siblings, siblings, siblingsOrSelf, size, This, True, tsize, uid, width
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AttributeLibrary

public AttributeLibrary()
Method Detail

children

protected List<N> children(N n,
                           Index<N> i)
Description copied from class: Forester
All the children of the context node regardless of whether we are ignoring any node types.

Specified by:
children in class Forester<N>
Parameters:
n - context node
i - tree index
Returns:
the children of n

hasTag

protected boolean hasTag(N n,
                         String tag)
Description copied from class: Forester
Defines what it means for a node in this tree to have a particular tag -- the "b" in the path expression "//b".

Specified by:
hasTag in class Forester<N>
Parameters:
n - context node
tag - tag
Returns:
whether the node bears the given tag

matchesTag

protected boolean matchesTag(N n,
                             Pattern p)
Description copied from class: Forester
Defines what it means for a node in this tree to have a tag matching the specified pattern. See Forester.hasTag(Object, String).

Specified by:
matchesTag in class Forester<N>
Parameters:
n - context node
p - tag pattern
Returns:
whether the pattern matches the node's tag or tags

parent

protected N parent(N n,
                   Index<N> i)
Description copied from class: Forester
Obtains the parent of the context node.

Specified by:
parent in class Forester<N>
Parameters:
n - context node
i - tree index
Returns:
the parent of n