|
IWG - Interface Wrapper Generator
IWG is a tool for generating wrapper classes. The wrapper implements an interface, and takes an object
implementing this interface as constructor parameter.
Each implemented method of the wrapper then calls the corresponding method of this original
object.
IWG is especially useful if you want to inherit from a class which cannot be inherited
(e.g. a singleton or a final class, or EJBs which you want to enhance for new functionalities).
Then you can create a new class, implementing
the same interface, and redirecting all but some overwritten methods to the old class.
Additionally, you can change the wrapped object without re-creating a new wrapper object. This allows
dynamic changed behaviour, or class-reloading of singletons.
IWG is able to implement many interfaces at once.
For an example, see below.
|
Current files
complete
sources only
binary files only
|
Change History
- now handling relative pathnames for sourcepath correctly
- sorting fields, methods and imports
- generating missing brackets for constructor
|
Example
You want to inherit from a class my.package.DatabaseManager, to add connection pooling.
But this class is a singleton (and therefore has a private constructor), so you cannot do this. But you can create a wrapper, which then looks like:
import java.sql.Connection;
import my.package.IDatabaseManager;
public class NewDataManager implements IDatabaseManager // IDatabaseManager is the base interface
{
private IDatabaseManager _origDatabaseManager=null;
public NewDatabaseManager(IDatabaseManager aDatabaseManager)
{
_origDatabaseManager=aDatabaseManager;
}
public Connection getConnection()
{
// owerwritten method here
}
public void shutdown()
{
_origDatabaseManager.shutdown();
}
public boolean isOpen()
{
return _origDatabaseManager.isOpen();
}
public void openDatabase(String name)
{
_origDatabase.open(name);
}
}
all method calls except for the overwritten one are redirected to the orginal manager.
|
|