net.sf.jaxme.js.pattern
Class ProxyGenerator

java.lang.Object
  extended bynet.sf.jaxme.js.pattern.ProxyGenerator

public class ProxyGenerator
extends java.lang.Object

This class is a generator for the proxy object pattern. A proxy object performs the same task as an object created by the Proxy class: It delegates its method calls to an internal instance.

In the case of Proxy this works by calling a so-called InvocationHandler. The InvocationHandler calls the actual object via Java reflection.

In our case, the proxy object is an instance of a generated class. The main advantage of the generated approach is that you can customize the proxy class quite easily by overwriting it. Compared to the creation of an InvocationHandler, this saves a lot of hazzle.

Version:
$Id: ProxyGenerator.java,v 1.2 2003/06/17 20:12:52 joe Exp $
Author:
Jochen Wiedmann

Nested Class Summary
protected static class ProxyGenerator.GeneratedMethod
          This class describes a generated method.
static class ProxyGenerator.InterfaceDescription
          This class describes the properties of an interface, which is extended by the generated class.
 
Constructor Summary
ProxyGenerator()
           
 
Method Summary
 JavaSource generate(JavaSourceFactory pFactory, JavaQName pTargetName, ProxyGenerator.InterfaceDescription[] pInterfaces)
          Generates a class implementing the given interfaces.
protected  void generateInterfaceMethods(JavaSource pJs, java.util.Map pGeneratedMethods, ProxyGenerator.InterfaceDescription pDescription)
          Generates the methods for a given interface.
protected  JavaField getBackingObjectField(JavaSource pJs, ProxyGenerator.InterfaceDescription[] pInterfaces)
          Generates the backingObject field.
protected  JavaConstructor getConstructor(JavaSource pJs, ProxyGenerator.InterfaceDescription[] pInterfaces)
          Creates a constructor with protected access and a single argument, the backing object.
 JavaQName getExtendedClass()
          Returns the class extended by the generated proxy class.
protected  ProxyGenerator.GeneratedMethod getGeneratedMethod(java.lang.reflect.Method pMethod)
          Converts the given ProxyGenerator.GeneratedMethod into an instance of ProxyGenerator.GeneratedMethod.
protected  JavaMethod getInterfaceMethod(JavaSource pJs, ProxyGenerator.InterfaceDescription pInterfaceDescription, java.lang.reflect.Method pMethod)
          Generated an instance of JavaMethod for the given ProxyGenerator.GeneratedMethod.
protected  JavaSource getJavaSource(JavaSourceFactory pFactory, JavaQName pTargetName)
          Creates the class.
 void setExtendedClass(JavaQName pExtendedClass)
          Sets the class extended by the generated proxy class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProxyGenerator

public ProxyGenerator()
Method Detail

getExtendedClass

public JavaQName getExtendedClass()

Returns the class extended by the generated proxy class. Defaults to Object.


setExtendedClass

public void setExtendedClass(JavaQName pExtendedClass)

Sets the class extended by the generated proxy class. Defaults to Object.


getGeneratedMethod

protected ProxyGenerator.GeneratedMethod getGeneratedMethod(java.lang.reflect.Method pMethod)

Converts the given ProxyGenerator.GeneratedMethod into an instance of ProxyGenerator.GeneratedMethod.


getInterfaceMethod

protected JavaMethod getInterfaceMethod(JavaSource pJs,
                                        ProxyGenerator.InterfaceDescription pInterfaceDescription,
                                        java.lang.reflect.Method pMethod)

Generated an instance of JavaMethod for the given ProxyGenerator.GeneratedMethod.


generateInterfaceMethods

protected void generateInterfaceMethods(JavaSource pJs,
                                        java.util.Map pGeneratedMethods,
                                        ProxyGenerator.InterfaceDescription pDescription)

Generates the methods for a given interface.

Parameters:
pJs - The Java class being generated
pGeneratedMethods - A set of already generated methods; each entry in the set is an instance of ProxyGenerator.GeneratedMethod. The method creates a new instance of ProxyGenerator.GeneratedMethod and adds it to the set. A warning is written to System.err, if the method isn't unique.

getConstructor

protected JavaConstructor getConstructor(JavaSource pJs,
                                         ProxyGenerator.InterfaceDescription[] pInterfaces)

Creates a constructor with protected access and a single argument, the backing object.


getJavaSource

protected JavaSource getJavaSource(JavaSourceFactory pFactory,
                                   JavaQName pTargetName)

Creates the class.


getBackingObjectField

protected JavaField getBackingObjectField(JavaSource pJs,
                                          ProxyGenerator.InterfaceDescription[] pInterfaces)

Generates the backingObject field.


generate

public JavaSource generate(JavaSourceFactory pFactory,
                           JavaQName pTargetName,
                           ProxyGenerator.InterfaceDescription[] pInterfaces)

Generates a class implementing the given interfaces.

Parameters:
pFactory - The ProxyGenerator will use this factory for creating instances of JavaSource.
pTargetName - Name of the generated class
pInterfaces - The interfaces being implemented by the generated class.