uk.ac.soton.itinnovation.grid.client.proxy
Class HelperProxyFactory

java.lang.Object
  extended by uk.ac.soton.itinnovation.grid.client.proxy.HelperProxyFactory
All Implemented Interfaces:
ProxyFactory

public class HelperProxyFactory
extends Object
implements ProxyFactory

Creates augmented Java proxy objects for other proxies. This allows you to add or redefine methods on proxies. For example, if older versions of a service don't support some method, you can fallback to using an older operation that is supported.

It is also possible to add entirely new methods, although this is discouraged. It is cleaner to write a separate helper class in this case.

See Also:
RawProxyInterface

Constructor Summary
HelperProxyFactory(ProxyFactory rawProxyFactory, Map<Class,Class<? extends ProxyHelpers>> helperRegistry)
          Constructor.
 
Method Summary
 void addHelper(Class<?> iface, Class<? extends ProxyHelpers> helpers)
          Add a helper class to a proxy class
<T> T
createProxy(org.apache.axis.message.addressing.EndpointReferenceType target, Class<T> iface)
          Create a proxy.
 ProxyFactory getRawProxyFactory()
           
 void validateHelper(Class<?> iface, Class<? extends ProxyHelpers> helpers)
          Check that helper is valid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HelperProxyFactory

public HelperProxyFactory(ProxyFactory rawProxyFactory,
                          Map<Class,Class<? extends ProxyHelpers>> helperRegistry)
Constructor.

Parameters:
rawProxyFactory - a factory which produces the proxies to be wrapped
helperRegistry - maps from interfaces (as passed to createProxy(org.apache.axis.message.addressing.EndpointReferenceType, java.lang.Class)) to their helpers
Method Detail

getRawProxyFactory

public ProxyFactory getRawProxyFactory()

addHelper

public void addHelper(Class<?> iface,
                      Class<? extends ProxyHelpers> helpers)
Add a helper class to a proxy class

Parameters:
iface - the class of the proxy
helper - the class of the helper for the proxy

validateHelper

public void validateHelper(Class<?> iface,
                           Class<? extends ProxyHelpers> helpers)
Check that helper is valid. Every method in iface must be a method on the helper or a method on the raw proxy interface.


createProxy

public <T> T createProxy(org.apache.axis.message.addressing.EndpointReferenceType target,
                         Class<T> iface)
Create a proxy. First, a raw proxy is created using the rawProxyFactory. If iface is a key in the helperRegistry, the corresponding helper class is instantiated and passed the factory and the raw proxy as arguments. A new proxy is returned that will invoke methods on the helper if available, or on the original proxy if not. If no helpers are registered, the raw proxy is returned directly.

Specified by:
createProxy in interface ProxyFactory
Parameters:
target - the EPR of the remote resource
iface - the Java interface which the proxy object will implement
Returns:
a proxy to target of the given type


Copyright © 2001-2008 University of Southampton IT Innovation Centre. All Rights Reserved.