As a bit more detail....

The invocation handler has a selection of member variables, if set the
getters from the common interface return the proxy values, otherwise
they return the values from the referenced subject.

This is a snippet from the code:

public class MyProxy implements InvocationHandler
{
  private static final String GET_NAME_METHOD = "getName";
  private static final String GET_DESCRIPTION_METHOD = "getDescription";

  private String _subjectId = null;
  private transient MyInterface _subject = null;
  private Class<? extends MyInterface> _subjectType = null;
  private String _name = null;
  private String _description = null;


  public MyProxy(String subjectId, Class<? extends MyInterface> type,
String name, String description)
  {
    _subjectType = type;
    _subjectId = subjectId;
    _name = name;
    _description = description;
  }

  private String getName()
  {
    ...
  }

  private String getDescription()
  {
    ...
  }

  /**
   * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object,
java.lang.reflect.Method, java.lang.Object[])
   */
  public Object invoke(Object obj, Method method, Object[] args)
      throws Throwable
  {
    String methodName = method.getName();

    if (GET_NAME_METHOD.equals(methodName))
    {
      return getName();
    }

    if (GET_DESCRIPTION_METHOD.equals(methodName))
    {
      return getDescription();
    }

    return method.invoke(obj, args);
  }

}

Regards,

Mike

2009/5/26 Mike Watson <michael.f.wat...@gmail.com>:
> Hi,
>
> If I have two classes C1 and C2, with valid bindings and implementing
> a common interface, and I want to use the java.lang.reflect.Proxy
> approach to create a dynamic proxy with either C1 or C2 as the subject
> (i.e. implementing an InvocationHandler). Is there any way I can
> create a binding for two instances of the dynamic proxies (say C1Proxy
> and C2Proxy)?
>
> It seems like I should be able to do this through the use of a factory
> and/or custom serializer but I can't quite see how I could reuse the
> same proxy code for both types. Can anyone think of how I might do
> this or am I dreaming?
>
> Regards,
>
> Mike
>

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to