Skip to content

Instantly share code, notes, and snippets.

@wojtekerbetowski
Created January 2, 2013 08:19
Show Gist options
  • Save wojtekerbetowski/4433014 to your computer and use it in GitHub Desktop.
Save wojtekerbetowski/4433014 to your computer and use it in GitHub Desktop.
Putting things together
final def advice = new MethodAdvice() {
@Override
void advise(MethodInvocation invocation) {
logger.debug("Entering method")
invocation.proceed()
}
}
def transformer = new PlasticClassTransformer() {
@Override
void transform(PlasticClass plasticClass) {
def method = plasticClass.methods.find {it.description.methodName == 'myBusinessMethod'}
method.addAdvice(advice)
}
}
def delegate = new StandardDelegate(transformer)
def plasticManager = PlasticManager
.withContextClassLoader()
.packages(['pl.erbetowski.plastic.logging'])
.delegate(delegate)
.create()
def instantiator = plasticManager.getClassInstantiator('pl.erbetowski.plastic.logging.FakeService')
return instantiator.newInstance()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment