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(java.lang.Class c)
          Get a new InterfaceImplementor to implement the passed in interface.
 
Method Summary
protected  boolean buildConstructors()
          If true, build the default constructors.
protected  java.lang.String getDocLink(java.lang.reflect.Constructor con)
          Get the relative javadoc signature for this Constructor.
protected  java.lang.String getDocLink(java.lang.reflect.Method method)
          Get the relative javadoc signature for this method.
protected  java.lang.Class getInterface()
          Get the interface we're implementing.
 java.lang.String getOutClassName()
          Get the name of the class we'll be generating
 java.lang.String getOutPackageName()
          Get the name of the package containing class we'll be generating
protected  java.lang.String getSignature(java.lang.reflect.Method method)
          Get the method signature.
protected  java.lang.String getSignature(java.lang.reflect.Method method, boolean needExceptions)
          Get a String representing this method signature.
protected  java.lang.Class getSuperclass()
          Get the parent class of the generated class.
protected  java.lang.String implement(java.lang.reflect.Method method)
          Implement the given method.
static void main(java.lang.String[] args)
           
 java.lang.String makeSource()
          Generate the source code for the class this object represents.
protected  java.lang.String preConstructors()
          Anything that should appear before the automatically generated constructors.
protected  java.lang.String preMethods()
          Anything that should appear before the automatically generated methods.
 void setOutputClass(java.lang.String to)
          Set the name of the output class.
 void setSuperClass(java.lang.Class c)
          Set an optional superclass that defines some of the methods for the implementation.
 void writeSourceToFile(java.lang.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(java.lang.Class c)
Get a new InterfaceImplementor to implement the passed in interface.

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

getInterface

protected java.lang.Class getInterface()
Get the interface we're implementing.


getSuperclass

protected java.lang.Class getSuperclass()
Get the parent class of the generated class.


getOutClassName

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


getOutPackageName

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


setOutputClass

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


setSuperClass

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

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

getSignature

protected java.lang.String getSignature(java.lang.reflect.Method method)
Get the method signature.

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

getSignature

protected java.lang.String getSignature(java.lang.reflect.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 java.lang.String getDocLink(java.lang.reflect.Method method)
Get the relative javadoc signature for this method.


getDocLink

protected java.lang.String getDocLink(java.lang.reflect.Constructor con)
Get the relative javadoc signature for this Constructor.


implement

protected java.lang.String implement(java.lang.reflect.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 java.lang.String preConstructors()
Anything that should appear before the automatically generated constructors.


preMethods

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


makeSource

public java.lang.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(java.lang.String outdir)
                       throws java.io.IOException
Write this implementation out to a given file.

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

main

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


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