Interesting. I imagine that your tests work because you're using groovy and not trying to access the class that you've transformed as it's actual type.
@Test public void monitor() { String rootPackage = "org.apache.tapestry5.monitor.test"; DefaultMonitorNameGenerator nameGenerator = new DefaultMonitorNameGenerator(rootPackage); MonitoredProxyFactoryImpl monitoredProxyFactory = new MonitoredProxyFactoryImpl(nameGenerator, rootPackage); // The following results in // java.lang.ClassCastException: org.apache.tapestry5.monitor.test.FakeService cannot be cast to org.apache.tapestry5.monitor.test.FakeService FakeService monitor = monitoredProxyFactory.monitor(FakeService.class); monitor.publicMethod(); } Is what I'm trying to do feasible without replacing the context ClassLoader? On Fri, Jul 29, 2011 at 3:08 PM, Taha Hafeez <tawus.tapes...@gmail.com> wrote: > Hi Josh > > This might help > > http://tawus.wordpress.com/category/plastic/ > > regards > Taha > > On Fri, Jul 29, 2011 at 11:25 PM, Howard Lewis Ship <hls...@gmail.com> wrote: >> On Fri, Jul 29, 2011 at 10:19 AM, Josh Canfield <joshcanfi...@gmail.com> >> wrote: >>> I'd like to integrate some advice used in a tapestry web project into >>> a non-tapestry web project. I can add a dependency on plastic, but not >>> a tapestry-ioc. >>> >>> I'm at the experimental stage at this point and I've hit a snag. I >>> figure I can wade around for a couple hours, or Howard can whip up in >>> example off the top of his head. >>> >>> Here's some pieces of code. >>> >>> plasticManager = PlasticManager >>> .withContextClassLoader() >>> .packages(Collections.singleton(basePackage)) >>> .create(); >>> >>> >>> public <T> T monitor(Class<T> monitoredClass, Object... constructorParams) { >>> >>> return plasticManager.createClass(monitoredClass, new >>> PlasticClassTransformer() { >>> >>> public void transform(PlasticClass plasticClass) { >>> >>> // At this point plasticclass has methodNames, but no methods so the >>> following fails to find my annotation. >>> // Do I need to manually override the methods? >>> >>> List<PlasticMethod> methods = >>> plasticClass.getMethodsWithAnnotation(Monitor.class); >>> for (PlasticMethod method : methods) { >>> final Stopwatch stopwatch = >>> createStopwatch(method.getAnnotation(Monitor.class), method); >>> logger.debug("Adding advice for {}", >>> stopwatch.getName()); >>> method.addAdvice(new MonitorAdvice(stopwatch)); >>> } >>> } >>> >>> }).newInstance(); >>> } >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org >>> For additional commands, e-mail: users-h...@tapestry.apache.org >>> >>> >> >> I think what you are missing is that you don't create a class (that's >> for creating proxies and such, the monitoredClass you pass in becomes >> the base class). >> >> What you want to do is wrap your logic up your PlasticClassTransformer >> inside a StandardDelegate (a trivial internal class). >> >> You can then ask the manager to getClassInstantiator() and >> newInstance() that to get your advised and instantiated instance. >> >> >> -- >> Howard M. Lewis Ship >> >> Creator of Apache Tapestry >> >> The source for Tapestry training, mentoring and support. Contact me to >> learn how I can get you up and productive in Tapestry fast! >> >> (971) 678-5210 >> http://howardlewisship.com >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org >> For additional commands, e-mail: users-h...@tapestry.apache.org >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org