ca.quine.jcommons.sourceexporter
Class ChainOfResponsibility

java.lang.Object
  |
  +--ca.quine.jcommons.sourceexporter.ChainOfResponsibility

public class ChainOfResponsibility
extends Object

Implements a Chain of Responsibility along the lines of the pattern described in "Design Patterns", Gamma et. al., and provides helper methods to use the chain to export (or "marshal") objects as source code. Each marshaller in the chain gets a chance at marshalling the object, and the first one (in order) that indicates that it can handle the marshalling will be called to marshal it.

This class is called by SourceExporter to do the actual work of marshalling the object.


Constructor Summary
ChainOfResponsibility()
           
 
Method Summary
 void addMarshaller(SourceMarshaller sourceMarshaller)
           
 String marshal(MarshallingContext context, ClassSource classSource, Object object, boolean marshalAsObject)
          Tests each marshaller in the ChainOfResponsibility to see if it can marshal the given object, and passes on the request to marshal it to that marshaller.
 boolean marshal(String filename, String packageName, String testClassName, String className, String methodName, Object object)
          Creates a new marshalling context and passes all parameters on to marshal(String, String, String, String, String, Object, MarshallingContext).
 boolean marshal(String filename, String packageName, String testClassName, String className, String methodName, Object object, MarshallingContext context)
          Tests each marshaller in the ChainOfResponsibility to see if it can marshal the given object, and passes on the request to marshal it to that marshaller.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChainOfResponsibility

public ChainOfResponsibility()
Method Detail

addMarshaller

public void addMarshaller(SourceMarshaller sourceMarshaller)

marshal

public boolean marshal(String filename,
                       String packageName,
                       String testClassName,
                       String className,
                       String methodName,
                       Object object)
                throws IOException,
                       IllegalArgumentException,
                       IllegalAccessException,
                       InvocationTargetException,
                       ClassNotFoundException,
                       InstantiationException
Creates a new marshalling context and passes all parameters on to marshal(String, String, String, String, String, Object, MarshallingContext).

Parameters:
filename -
packageName -
testClassName -
className -
methodName -
object -
Returns:
Throws:
IOException
IllegalArgumentException
IllegalAccessException
InvocationTargetException
ClassNotFoundException
InstantiationException

marshal

public boolean marshal(String filename,
                       String packageName,
                       String testClassName,
                       String className,
                       String methodName,
                       Object object,
                       MarshallingContext context)
                throws IOException,
                       IllegalArgumentException,
                       IllegalAccessException,
                       InvocationTargetException,
                       ClassNotFoundException,
                       InstantiationException
Tests each marshaller in the ChainOfResponsibility to see if it can marshal the given object, and passes on the request to marshal it to that marshaller. This method will be called by code outside of the SourceExporter in order to start the export at the "top" or "outer" class.

Parameters:
filename -
packageName -
testClassName -
className -
methodName -
object -
context - holds any state required by the marshallers (so that the marshallers can be reused in a threaded environment)
Returns:
true if a marshaller is found (this method will always return true unless the DefaultMarshaller has been removed from the chain)
Throws:
IOException
IllegalArgumentException
IllegalAccessException
InvocationTargetException
ClassNotFoundException
InstantiationException

marshal

public String marshal(MarshallingContext context,
                      ClassSource classSource,
                      Object object,
                      boolean marshalAsObject)
               throws IOException,
                      IllegalArgumentException,
                      IllegalAccessException,
                      InvocationTargetException,
                      ClassNotFoundException,
                      InstantiationException
Tests each marshaller in the ChainOfResponsibility to see if it can marshal the given object, and passes on the request to marshal it to that marshaller. This method will be called by code inside the SourceExporter to marshal classes referenced by the "top" or "outer" class where marshalling began.

Parameters:
context -
classSource -
object -
marshalAsObject -
Returns:
a source code snippet that will be used in a setter call or for a return value
Throws:
IOException
IllegalArgumentException
IllegalAccessException
InvocationTargetException
ClassNotFoundException
InstantiationException