polyglot.ext.carcov
Class FactoryComposer

java.lang.Object
  extended bypolyglot.ext.carcov.FactoryComposer
All Implemented Interfaces:
java.lang.reflect.InvocationHandler

public class FactoryComposer
extends java.lang.Object
implements java.lang.reflect.InvocationHandler

This class composes two factories, and for any method call on the factory, calls the method on both factories, and decides which newly manufactured object to return. Restrictions: - A FactoryComposer object can be cast to all and only the interfaces implemented by either factory.


Method Summary
 java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method m, java.lang.Object[] args)
          Handle the invocations of methods on the proxy.
static java.lang.Object newInstance(java.lang.ClassLoader cl, java.lang.Object factory1, java.lang.Object factory2)
          Create a new proxy, which implements all the interfaces implemented by factory1 and factory2.
static java.lang.Object newInstance(java.lang.Object factory1, java.lang.Object factory2)
          Create a new proxy, which implements all the interfaces implemented by factory1 and factory2.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newInstance

public static java.lang.Object newInstance(java.lang.Object factory1,
                                           java.lang.Object factory2)
Create a new proxy, which implements all the interfaces implemented by factory1 and factory2. i.e. if factory1 or factory2 is an instance of some interface, then the object returned by this method will also be an instance of that interface. The proxy class is defined in the class loader of the class of factory1.


newInstance

public static java.lang.Object newInstance(java.lang.ClassLoader cl,
                                           java.lang.Object factory1,
                                           java.lang.Object factory2)
Create a new proxy, which implements all the interfaces implemented by factory1 and factory2. i.e. if factory1 or factory2 is an instance of some interface, then the object returned by this method will also be an instance of that interface. The proxy class is defined in the class loader specified.


invoke

public java.lang.Object invoke(java.lang.Object proxy,
                               java.lang.reflect.Method m,
                               java.lang.Object[] args)
                        throws java.lang.Throwable
Handle the invocations of methods on the proxy. Delegate the invocation to one or both of the factories, and return one of the objects created. No guarantees are made as to which factory or factories will have the method invoked. If one of the factories throws an exception during the invocation of its method, then the exception will be rethrown by this method.

Specified by:
invoke in interface java.lang.reflect.InvocationHandler
Throws:
SemanticException - if the two factories return objects with incomparable types.
java.lang.Throwable