Related Topics: ColdFusion on Ulitzer, Java Developer Magazine

CFDJ: Article

ColdFusion Developer's Journal Special "Frameworks" Focus Issue: ColdSpring

A framework for ColdFusion Components – Pet Market implementation

Here we see the service configured with a value for the tax rate, inner beans for the ShippingMethodGateway and OrderDAO components, and references to the Product and User Services, as we discussed before. Next, we'll look at the configuration of the logOrderAdvisor, which is an instance of a ColdSpring "NamedMethodPointcutAdvisor":


<bean id="logOrderAdvisor"
class="coldspring.aop.support.NamedMethodPointcutAdvisor">
<property name="advice">
<bean id="logOrderAdvice" class="petmarket.aspects.LogOrderAdvice">
<property name="filename">
<value>petstoreOrders</value>
</property>
</bean>
</property>
<property name="mappedNames">
<value>placeOrder</value>
</property>
</bean>
The logOrderAdvisor has two properties: the Advice to configure and the mappedNames, which are the method names it will try to match. In this application, the advice is written specifically for the placeOrder method and that is what we supply as the mappedNames. However, more generalized logging advice could be applied just as easily to all methods by supplying "*" for mappedNames. The Advice components you write must extend one of the provided coldspring.aop.Advice components: BeforeAdvice, AfterReturningAdvice, ThrowsAdvice, and MethodInterceptor, which is also known as "around advice." For this application we've used an AfterReturningAdvice, so that we can check the value returned from placeOrder() and only log successful orders. The last piece of configuration is for the ProxyFactoryBean to generate the proxy object.

<bean id="OrderService" class="coldspring.aop.framework.ProxyFactoryBean">
<property name="target">
<ref bean="OrderServiceTarget" />
</property>
<property name="interceptorNames">
<list>
<value>logOrderAdvisor</value>
</list>
</property>
</bean>
Here we simply supply the target object and a list of any configured Advisors you would like to use on the component. It is worth noting that if you skip the configuration of a NamedPointcutAdvisor and simply put the name of a configured Advice bean in the list of interceptorNames, the ProxyFactory will automatically create a DefaultPointcutAdvisor for you, meaning that you would like to apply this advice to all methods in the target obejct. We give the ProxyFactoryBean the ID of OrderService, and when your application requests that service component with getBean('OrderService'), all the details of creating the proxy and wiring up all the necessary components will be handled for you, and, of course, as noted earlier, your application will treat the proxy as if it is the target component. It's also worth noting that the life cycle of these components are also completely managed for you, so successive calls to getBean() will not generally create new instances of these components, unless you have configured the bean to do so, as a non-singleton.

Hopefully this article and the accompanying code will give you a good idea of what ColdSpring intends to do: it manages your model. ColdSpring is "non-invasive", meaning your model components will have no idea they are being managed by ColdSpring. ColdSpring's features enable you to write components that are easier to reuse and test, because they don't contain "hard-coded" knowledge of how to resolve their own dependencies. ColdSpring enables you to declaratively configure an application, and application maintenance becomes easier because you can quickly swap out your components or transparently add behavior via AOP. We believe that as your codebase gets larger, ColdSpring will be the tool you use to keep your model under control.

More Stories By Dave Ross

David Ross is a ColdFusion Developer.

More Stories By Chris Scott

Chris Scott is a ColdFusion Developer.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.