@Test public void proxy_class() { JavaScriptSupport delegate = newMock(JavaScriptSupport.class); Environment env = mockEnvironment(); train_peekRequired(env, JavaScriptSupport.class, delegate); expect(delegate.allocateClientId("fred")).andReturn("barney"); replay(); EnvironmentalShadowBuilder builder = new EnvironmentalShadowBuilderImpl(getService("PlasticProxyFactory", PlasticProxyFactory.class), env); JavaScriptSupport proxy = builder.build(JavaScriptSupport.class); assertEquals(proxy.allocateClientId("fred"), "barney"); verify(); }
public <T> T build(final Class<T> serviceType) { ClassInstantiator<T> instantiator = proxyFactory.createProxy(serviceType, new PlasticClassTransformer() { public void transform(PlasticClass plasticClass) { PlasticMethod delegateMethod = plasticClass.introducePrivateMethod( PlasticUtils.toTypeName(serviceType), "delegate", null, null); delegateMethod.addAdvice(new MethodAdvice() { public void advise(MethodInvocation invocation) { invocation.setReturnValue(environment.peekRequired(serviceType)); } }); for (Method method : serviceType.getMethods()) { plasticClass.introduceMethod(method).delegateTo(delegateMethod); } plasticClass.addToString(String.format("<EnvironmentalProxy for %s>", serviceType.getName())); } }); return instantiator.newInstance(); }
EnvironmentalShadowBuilderImpl implements EnvironmentalShadowBuilder { public <T> T build(final Class<T> serviceType) { ClassInstantiator<T> instantiator = proxyFactory.createProxy(serviceType, new PlasticClassTransformer() { public void transform(PlasticClass plasticClass) { PlasticMethod delegateMethod = plasticClass.introducePrivateMethod( PlasticUtils.toTypeName(serviceType), "delegate", null, null); delegateMethod.addAdvice(new MethodAdvice() { public void advise(MethodInvocation invocation) { invocation.setReturnValue(environment.peekRequired(serviceType)); } }); for (Method method : serviceType.getMethods()) { plasticClass.introduceMethod(method).delegateTo(delegateMethod); } plasticClass.addToString(String.format("<EnvironmentalProxy for %s>", serviceType.getName())); } }); return instantiator.newInstance(); } }
EnvironmentalShadowBuilderImpl implements EnvironmentalShadowBuilder { public <T> T build(final Class<T> serviceType) { ClassInstantiator<T> instantiator = proxyFactory.createProxy(serviceType, new PlasticClassTransformer() { public void transform(PlasticClass plasticClass) { PlasticMethod delegateMethod = plasticClass.introducePrivateMethod( PlasticUtils.toTypeName(serviceType), "delegate", null, null); delegateMethod.addAdvice(new MethodAdvice() { public void advise(MethodInvocation invocation) { invocation.setReturnValue(environment.peekRequired(serviceType)); } }); for (Method method : serviceType.getMethods()) { plasticClass.introduceMethod(method).delegateTo(delegateMethod); } plasticClass.addToString(String.format("<EnvironmentalProxy for %s>", serviceType.getName())); } }); return instantiator.newInstance(); } EnvironmentalShadowBuilderImpl(@Builtin
    PlasticProxyFactory proxyFactory,

    Environment environment); }
EnvironmentalShadowBuilderImpl implements EnvironmentalShadowBuilder { public <T> T build(final Class<T> serviceType) { ClassInstantiator<T> instantiator = proxyFactory.createProxy(serviceType, new PlasticClassTransformer() { public void transform(PlasticClass plasticClass) { PlasticMethod delegateMethod = plasticClass.introducePrivateMethod( PlasticUtils.toTypeName(serviceType), "delegate", null, null); delegateMethod.addAdvice(new MethodAdvice() { public void advise(MethodInvocation invocation) { invocation.setReturnValue(environment.peekRequired(serviceType)); } }); for (Method method : serviceType.getMethods()) { plasticClass.introduceMethod(method).delegateTo(delegateMethod); } plasticClass.addToString(String.format("<EnvironmentalProxy for %s>", serviceType.getName())); } }); return instantiator.newInstance(); } EnvironmentalShadowBuilderImpl(@Builtin
    PlasticProxyFactory proxyFactory,

    Environment environment); T build(final Class<T> serviceType); }
EnvironmentalShadowBuilderImpl implements EnvironmentalShadowBuilder { public <T> T build(final Class<T> serviceType) { ClassInstantiator<T> instantiator = proxyFactory.createProxy(serviceType, new PlasticClassTransformer() { public void transform(PlasticClass plasticClass) { PlasticMethod delegateMethod = plasticClass.introducePrivateMethod( PlasticUtils.toTypeName(serviceType), "delegate", null, null); delegateMethod.addAdvice(new MethodAdvice() { public void advise(MethodInvocation invocation) { invocation.setReturnValue(environment.peekRequired(serviceType)); } }); for (Method method : serviceType.getMethods()) { plasticClass.introduceMethod(method).delegateTo(delegateMethod); } plasticClass.addToString(String.format("<EnvironmentalProxy for %s>", serviceType.getName())); } }); return instantiator.newInstance(); } EnvironmentalShadowBuilderImpl(@Builtin
    PlasticProxyFactory proxyFactory,

    Environment environment); T build(final Class<T> serviceType);  }