org.apache.ws.jaxme.js.pattern

Class ProxyGenerator

public class ProxyGenerator extends Object

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

In the case of {@link java.lang.reflect.Proxy} this works by invoking a so-called {@link java.lang.reflect.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.

Method Summary
JavaSourcegenerate(JavaSourceFactory pFactory, JavaQName pTargetName, InterfaceDescription[] pInterfaces)

Generates a class implementing the given interfaces.

protected voidgenerateInterfaceMethods(JavaSource pJs, Map pGeneratedMethods, JavaSource pInterface)

Generates the methods for a given interface.

protected JavaFieldgetBackingObjectField(JavaSource pJs, InterfaceDescription[] pInterfaces)

Generates the backingObject field.

protected JavaConstructorgetConstructor(JavaSource pJs, InterfaceDescription[] pInterfaces)

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

JavaQNamegetExtendedClass()

Returns the class extended by the generated proxy class.

protected JavaMethodgetInterfaceMethod(JavaSource pJs, JavaMethod pMethod)

Generated an instance of {@link JavaMethod} for the given {@link JavaMethod}.

protected JavaSourcegetJavaSource(JavaSourceFactory pFactory, JavaQName pTargetName)

Creates the class.

voidsetExtendedClass(JavaQName pExtendedClass)

Sets the class extended by the generated proxy class.

Method Detail

generate

public JavaSource generate(JavaSourceFactory pFactory, JavaQName pTargetName, 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.

Throws: ClassNotFoundException

generateInterfaceMethods

protected void generateInterfaceMethods(JavaSource pJs, Map pGeneratedMethods, JavaSource pInterface)

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 {@link MethodKey}. The method creates a new instance of {@link MethodKey} and adds it to the set. A warning is written to {@link System#err}, if the method isn't unique.

Throws: ClassNotFoundException

getBackingObjectField

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

Generates the backingObject field.

getConstructor

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

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

getExtendedClass

public JavaQName getExtendedClass()

Returns the class extended by the generated proxy class. Defaults to {@link java.lang.Object}.

getInterfaceMethod

protected JavaMethod getInterfaceMethod(JavaSource pJs, JavaMethod pMethod)

Generated an instance of {@link JavaMethod} for the given {@link JavaMethod}.

getJavaSource

protected JavaSource getJavaSource(JavaSourceFactory pFactory, JavaQName pTargetName)

Creates the class.

setExtendedClass

public void setExtendedClass(JavaQName pExtendedClass)

Sets the class extended by the generated proxy class. Defaults to {@link java.lang.Object}.