public T build() throws ProxyException {

    if (this.root == null) {
      throw new IllegalArgumentException("root must not be null!");
    }

    if (this.interfacesToImplementations.isEmpty()) {
      // nothing to proxy
      return this.root;
    }

    try {
      ProxyMethodHandler methodHandler = new ProxyMethodHandler(root,
              interfacesToImplementations);
      ProxyFactory proxyFactory = new ProxyFactory();
      proxyFactory.setSuperclass(root.getClass());
      proxyFactory.setInterfaces(interfacesToImplementations.keySet().toArray(new Class[]{}));
      return (T) proxyFactory.create(new Class[0], new Object[0], methodHandler);
    } catch (Exception e) {
      throw new ProxyException(e);
    }
  }
public T build ( ) throws ProxyException { if ( this . root == null ) { throw new IllegalArgumentException ( "root must not be null!" ) ; } if ( this . interfacesToImplementations . isEmpty ( ) ) { return this . root ; } try { ProxyMethodHandler methodHandler = new ProxyMethodHandler ( root , interfacesToImplementations ) ; ProxyFactory proxyFactory = new ProxyFactory ( ) ; proxyFactory . setSuperclass ( root . getClass ( ) ) ; proxyFactory . setInterfaces ( interfacesToImplementations . keySet ( ) . toArray ( new Class [ ] { } ) ) ; return ( T ) proxyFactory . create ( new Class [ 0 ] , new Object [ 0 ] , methodHandler ) ; } catch ( Exception e ) { throw new ProxyException ( e ) ; } }
Creates a proxy object out of the specified root object and the specified interfaces
and implementations.

@return a proxy object that is still of type T but additionally implements all specified
interfaces.
@throws ProxyException if the proxy could not be created.