net.spy.util
Class InterfaceImplementor

java.lang.Object
  extended by net.spy.SpyObject
      extended by net.spy.util.InterfaceImplementor
Direct Known Subclasses:
ProxyInterfaceImplementor

public class InterfaceImplementor
extends SpyObject

Extend existing classes with missing methods required to implement a specified interface. Think Java Interfaces are a poor replacement for the lack of multiple inheritence? SO DO I! That's why this class exists.

Using InterfaceImplementor, you can write code that's portable among different API specs. You simply implement what you need out of an interface, and InterfaceImplementor writes a class that extends from the class you wrote, and fills in all the blanks for you.

Here's the way you use it:

java net.spy.util.InterfaceImplementor -interface java.sql.ResultSet -superclass test.TestSet -outputclass test.TestSetImpl


Constructor Summary
InterfaceImplementor(Class<?> c)
          Get a new InterfaceImplementor to implement the passed in interface.
 
Method Summary
protected  boolean buildConstructors()
          If true, build the default constructors.
protected  String getDocLink(Constructor<?> con)
          Get the relative javadoc signature for this Constructor.
protected  String getDocLink(Method method)
          Get the relative javadoc signature for this method.
protected  Class<?> getInterface()
          Get the interface we're implementing.
 String getOutClassName()
          Get the name of the class we'll be generating
 String getOutPackageName()
          Get the name of the package containing class we'll be generating
protected  String getSignature(Method method)
          Get the method signature.
protected  String getSignature(Method method, boolean needExceptions)
          Get a String representing this method signature.
protected  Class<?> getSuperclass()
          Get the parent class of the generated class.
protected  String implement(Method method)
          Implement the given method.
static void main(String[] args)
           
 String makeSource()
          Generate the source code for the class this object represents.
protected  String preConstructors()
          Anything that should appear before the automatically generated constructors.
protected  String preMethods()
          Anything that should appear before the automatically generated methods.
 void setOutputClass(String to)
          Set the name of the output class.
 void setSuperClass(Class<?> c)
          Set an optional superclass that defines some of the methods for the implementation.
 void writeSourceToFile(String outdir)
          Write this implementation out to a given file.
 
Methods inherited from class net.spy.SpyObject
getLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InterfaceImplementor

public InterfaceImplementor(Class<?> c)
Get a new InterfaceImplementor to implement the passed in interface.

Parameters:
c - The interface to implement.
Throws:
NullPointerException - if the passed in class is null
IllegalArgumentException - if the passed in class is not an interface
Method Detail

getInterface

protected Class<?> getInterface()
Get the interface we're implementing.


getSuperclass

protected Class<?> getSuperclass()
Get the parent class of the generated class.


getOutClassName

public String getOutClassName()
Get the name of the class we'll be generating


getOutPackageName

public String getOutPackageName()
Get the name of the package containing class we'll be generating


setOutputClass

public void setOutputClass(String to)
Set the name of the output class.


setSuperClass

public void setSuperClass(Class<?> c)
Set an optional superclass that defines some of the methods for the implementation.

Parameters:
c - Superclass
Throws:
NullPointerException - if the passed in class is null
IllegalArgumentException - if the passed in class isn't valid for this operation.

getSignature

protected String getSignature(Method method)
Get the method signature.

Parameters:
method - method needing the signature
Returns:
the method signature, as a String

getSignature

protected String getSignature(Method method,
                              boolean needExceptions)
Get a String representing this method signature.

Parameters:
method - the name of the method
needExceptions - true if exceptions are needed as part of the signature string

getDocLink

protected String getDocLink(Method method)
Get the relative javadoc signature for this method.


getDocLink

protected String getDocLink(Constructor<?> con)
Get the relative javadoc signature for this Constructor.


implement

protected String implement(Method method)
Implement the given method. Subclasses may override this to provide a different method implementation

Parameters:
method - the method to be implemented.
Returns:
the text required to implement this method

preConstructors

protected String preConstructors()
Anything that should appear before the automatically generated constructors.


preMethods

protected String preMethods()
Anything that should appear before the automatically generated methods.


makeSource

public String makeSource()
Generate the source code for the class this object represents.


buildConstructors

protected boolean buildConstructors()
If true, build the default constructors.


writeSourceToFile

public void writeSourceToFile(String outdir)
                       throws IOException
Write this implementation out to a given file.

Parameters:
outdir - the base directory to write the file
Throws:
IOException - if there's a problem writing the file

main

public static void main(String[] args)
                 throws Exception
Throws:
Exception


Copyright © 1995-2007 SPY Internetworking. All Rights Reserved.