logahawk.formatters
Class ParentObjectArgFormatter

java.lang.Object
  extended by logahawk.formatters.AbstractArgumentFormatter
      extended by logahawk.formatters.ParentObjectArgFormatter
All Implemented Interfaces:
ArgumentFormatter
Direct Known Subclasses:
SwingParentArgFormatter, XmlNodeParentArgFormatter

public abstract class ParentObjectArgFormatter
extends AbstractArgumentFormatter

Formats the object and its parents allowing one to see an object's context in relation to other objects. The parent information will be printed before the the child. This does not actually handle formatting of the original object, that is passed on to the The phrase "parent" does mean to imply that only true parents need to be used, it simply needs to be an associated object that helps describe the original object's context. Note that this class does not use the passed in collection of ArgumentFormatters to format the child or parent objects, it requires those to be passed in as constructor arguments. This is done to avoid any sort of ambiguity where a regular ArgumentFormatter and a ParentObjectArgFormatter can format the same classes (according to their canFormat(Object), and the AbstractArgumentFormatter.getChildObjectFormat(Object, Collection, int) cannot correctly distinguish between the two.


Field Summary
protected  ArgumentFormatter childFormatter
          Formats the child object.
protected  CollectionArgFormatter collectionArgFormatter
          Formats the parents objects.
protected  ArgumentFormatter parentFormatter
          Formats the parent objects.
 
Fields inherited from class logahawk.formatters.AbstractArgumentFormatter
indentor
 
Constructor Summary
protected ParentObjectArgFormatter(ArgumentFormatter childFormatter, ArgumentFormatter parentFormatter, CollectionArgFormatter collectionArgFormatter)
           
 
Method Summary
 boolean canFormat(Object obj)
          Default implementations returns canFormat(Object) on childFormatter.
 String format(Object obj, Collection<ArgumentFormatter> formatters, int indentLevel)
          This converts the object into a String that represent the object.
protected abstract  Object getParent(Object obj)
          Returns the parent of the provided object.
 
Methods inherited from class logahawk.formatters.AbstractArgumentFormatter
findFormatter, getChildObjectFormat, getIndentor, setIndentor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

collectionArgFormatter

protected final CollectionArgFormatter collectionArgFormatter
Formats the parents objects.


childFormatter

protected final ArgumentFormatter childFormatter
Formats the child object.


parentFormatter

protected final ArgumentFormatter parentFormatter
Formats the parent objects. This can return a fully formatted String (as produced by a standard ArgumentFormatter or it can be a simplified formatter just for this purpose. If is recommended to return just the basic information needed to identify the original object, perhaps a type and a name.

Constructor Detail

ParentObjectArgFormatter

protected ParentObjectArgFormatter(ArgumentFormatter childFormatter,
                                   ArgumentFormatter parentFormatter,
                                   CollectionArgFormatter collectionArgFormatter)
Method Detail

canFormat

public boolean canFormat(Object obj)
Default implementations returns canFormat(Object) on childFormatter.


format

public String format(Object obj,
                     Collection<ArgumentFormatter> formatters,
                     int indentLevel)
Description copied from interface: ArgumentFormatter
This converts the object into a String that represent the object. The String may contain line breaks, but should not include a trailing line break. The first line of the result should NOT include any indentation, that should be handled by the calling class. If the object is complex and contains other objects, this ArgumentFormatter may use the provided list of ArgumentFormatter objects to find a more appropriate formatter. To make things look nice, the "indentLevel" is provided. The indent level should always be incremented by one when calling downward into other ArgumentFormatters.


getParent

protected abstract Object getParent(Object obj)
Returns the parent of the provided object. If there is no parent, this should return null.

Parameters:
obj - Either the original object or another parent.