| At line 1 added 53 lines |
| %%( background-color: #c0c0c0; border: 1px dotted black; padding: 0.2em; font-size: 200%; text-align: center) |
| --= OLD=-- |
| %% |
|
| %%( background-color: #c0c0c0; text-align: center) |
| As of RSF 0.7, all framework uses of RunnableWrapper were replaced by the slightly more streamlined [RunnableInvoker] |
| %% |
|
| RunnableWrapper is a really prime RSF [OLI], whose entire code looks as follows: |
|
| {{{ |
| public interface RunnableWrapper { |
| public Runnable wrapRunnable(Runnable towrap); |
| } |
| }}} |
|
| A RunnableWrapper is a "machine", which takes in one unit of work (specified by a standard java.lang.Runnable), and spits out another one, wrapped in some extra logic. |
|
| This idea will be familiar to aficionados of [AOP], since it is really an equivalent (although a massively more "environmentally friendly" equivalent) of an AOP "execute around" advice. In [Chapter 6|http://www.springframework.org/docs/reference/aop.html] of the Spring manual, you can see examples of Spring AOP in action, in particular the "MethodInterceptor" type. Since RSF lives in a request-scope IoC world, the need to express arbitrary "kitchen-sink" interception with support for arbitrary parameters is much lower - rather than pass these values into the wrapping bean as arguments, it is far cleaner for it to fetch them itself as request-scope dependencies. |
|
| Here is an example illustrating this point from the RSF [LogonTest] sample: |
|
| {{{ |
| public class SecurityWrapper implements RunnableWrapper { |
| private ViewParameters viewparams; |
| private LogonBean logonbean; |
|
| public void setViewParameters(ViewParameters viewparams) { |
| this.viewparams = viewparams; |
| } |
|
| public void setLogonBean(LogonBean logonbean) { |
| this.logonbean = logonbean; |
| } |
|
| public Runnable wrapRunnable(final Runnable towrap) { |
| return new Runnable() { |
| public void run() { |
| if (logonbean.name == null |
| && !(LogonProducer.VIEW_ID.equals(viewparams.viewID))) { |
| throw new SecurityException("Cannot view page " + viewparams.viewID |
| + " while not logged on"); |
| } |
| towrap.run(); |
| } |
| }; |
| } |
| } |
| }}} |
|
| As we can see, all the inner context for the wrapper is injected in via the request-scope dependencies ViewParameters and LogonBean, and we can keep our clean "nullary interface" to the wrapper itself. |
|
| Ruby fans will also recognise the {{towrap.run();}} call as the equivalent of a zero-args {{yield}} call. What in Java requires a lot of reflective and AOP sweat (although in RSF, a bit less sweat), is simply part of the language in Ruby, with its powerful support for code-block arguments and "continuation" programming style. |