|
|||||
|
|||||
Extensibility Compared
In this comparison we are gonna talk about the mechanisms provided by these 3 products to plug-in custom logic into the xml configuration. SpringSpring has FactoryBean for plugging in custom logic. For example, FieldRetreievingFactoryBean is used to read a field value; MethodInvokingFactoryBean is used to invoke a method; TransactionProxyFactoryBean is used to add declarative transaction support etc. For example, if I want to reuse a piece of code that looks up an object from jndi, I'd imagine that a FactoryBean class can be created so that the xml syntax looks like: <bean id="x" class="JndiLookupFactoryBean"> <property key="name"><value>java:comp/env/SimpleStackBean</property> </bean> The JndiLookupFactoryBean class will then look up the name from the jndi registry. NutsNuts treats all components uniformly. There's no special case like Spring's BlahBlahAware or FactoryBean. Rather, Nuts allows custom tags to be built by subclassing the jfun.yan.xml.Nut class. For the "jndi" example, one can expect the target syntax to be: <jndi id="target_object" lookup="java:comp/env/SimpleStackBean"/> We could actually just use <sequence> and <method> tag to achieve the same result: <sequence id="target_object"> <ctor var="ctxt" class="InitialContext" args=""/> <method component="$ctxt" args="java:comp/env/SimpleStackBean"/> </sequence> The <jndi> tag is just more straight-forward and reads simpler. It's gonna help make the configuration file smaller and easier to understand if we need to use the same syntax many times. The Nut class can be written as: package com.mycompany; import jfun.yan.SimpleComponent; public class JndiLookupNut extends ComponentNut{ private String lookup; public void setLookup(String l){ this.lookup = l; } public Component eval(){ checkMandatory("lookup", lookup); return new SimpleComponent(null){ public Object create(){ return new InitialContext().lookup(lookup); } }; } } |
|||||
|
Copyright 2003-2006 - The Codehaus. All rights reserved unless otherwise noted.
Powered by Atlassian Confluence
|
|||||