net.sourceforge.esw.graph.proxy
Class InterfaceNodeFacade

java.lang.Object
  |
  +--net.sourceforge.esw.graph.proxy.InterfaceNodeFacade
All Implemented Interfaces:
java.lang.reflect.InvocationHandler, java.io.Serializable

public class InterfaceNodeFacade
extends java.lang.Object
implements java.lang.reflect.InvocationHandler, java.io.Serializable

Provides an INode instance a facade against an interface to allow the INode instance to implement the given interface.

Utilizes elements of the Facade and Decorator design patterns.

Providing a generalized data structure like an Graph is useful for accessing and manipulating data obtained in varoius ways. However, that does not provide easy mapping to OOP concepts like interface based designs. As such, this InterfaceNodeFacade class will decorate an INode instance with an interface, providing a facade into the INode instance structure via that interface.

To acheive this goal, we require a valid INode instance and an interface class. The naming conventions used are the same as layed out via the Java Beans Specification. If the parent node contains a child named LastName, then when the getLastName() is invoked against the interface, then the value of that node child will be returned.

To create an instance of this InterfaceNodeFacade, see InterfaceNodeFacadeFactory.createFacade().

Examples:

    INode node = NodeFactory.createNode();
    // fill in data for the node instance...

    MyInterface mi;
    mi = ( MyInterface ) InterfaceNodeFacadeFactory.createFacade( node,
                                                                  MyInterface.class )
    // use mi instance as needed...
 

See Also:
NodeFactory, Serialized Form

Field Summary
protected static java.lang.String GET
           
protected  java.lang.Class inter
           
protected  INode node
           
protected static java.lang.String SET
           
 
Constructor Summary
protected InterfaceNodeFacade(INode aNode, java.lang.Class aClass)
          Creates a new instance of this InterfaceNodeFacade.
 
Method Summary
 java.lang.Object invoke(java.lang.Object aProxy, java.lang.reflect.Method aMethod, java.lang.Object[] aArgs)
          Processes a method invocation on a proxy instance and returns the result.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

node

protected INode node

inter

protected java.lang.Class inter

GET

protected static final java.lang.String GET

SET

protected static final java.lang.String SET
Constructor Detail

InterfaceNodeFacade

protected InterfaceNodeFacade(INode aNode,
                              java.lang.Class aClass)
Creates a new instance of this InterfaceNodeFacade.
Parameters:
aNode - the INode instance to be decorated by this facade instance.
aInterface - the class name of the interface to decorate the specified INode instance by this facade instance.
Method Detail

invoke

public java.lang.Object invoke(java.lang.Object aProxy,
                               java.lang.reflect.Method aMethod,
                               java.lang.Object[] aArgs)
                        throws java.lang.Throwable
Processes a method invocation on a proxy instance and returns the result. This method will be invoked on an invocation handler when a method is invoked on a proxy instance that it is associated with.
Specified by:
invoke in interface java.lang.reflect.InvocationHandler
Parameters:
proxy - the proxy instance that the method was invoked on
method - the Method instance corresponding to the interface method invoked on the proxy instance. The declaring class of the Method object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.
args - an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.
Returns:
the value to return from the method invocation on the proxy instance. If the declared return type of the interface method is a primitive type, then the value returned by this method must be an instance of the corresponding primitive wrapper class; otherwise, it must be a type assignable to the declared return type. If the value returned by this method is null and the interface method's return type is primitive, then a NullPointerException will be thrown by the method invocation on the proxy instance. If the value returned by this method is otherwise not compatible with the interface method's declared return type as described above, a ClassCastException will be thrown by the method invocation on the proxy instance.
Throws:
java.lang.Throwable - the exception to throw from the method invocation on the proxy instance. The exception's type must be assignable either to any of the exception types declared in the throws clause of the interface method or to the unchecked exception types java.lang.RuntimeException or java.lang.Error. If a checked exception is thrown by this method that is not assignable to any of the exception types declared in the throws clause of the interface method, then an UndeclaredThrowableException containing the exception that was thrown by this method will be thrown by the method invocation on the proxy instance.
See Also:
UndeclaredThrowableException


Copyright 2002 Free Software Foundation. All Rights Reserved.