Skip to content
Tyler Treat edited this page Jun 15, 2013 · 5 revisions

The infinitum.cfg.xml file provides configuration settings for Infinitum. For information on how to set it up, see the Infinitum Core wiki page on it. This page provides information on how to configure it for use with the AOP module.

Application Configuration

The AOP module makes use of some optional properties defined in the application node. The methodCaching property is used to enable or disable the cache abstraction feature. When enabled, methods can be marked for caching with the Cache annotation so that results can be retrieved without invoking the method on subsequent calls with the same arguments. This is particularly valuable for computation- or resource- intensive code. This feature is disabled by default.

The events property is used to enable or disable framework events, which is part of Core. It is also disabled by default.

<application>
    <property name="methodCaching">true</property> <!-- [true | false] -->
    <property name="events">true</property> <!-- [true | false] -->
</application>

Aspect Configuration

Like beans, aspects are configured either through XML or using annotations (see the Aspect annotation). In order to declare aspects using annotations, component-scan must be enabled in infinitum.cfg.xml:

<component-scan base-package="com.foo.bar" />

Aspects are declared in XML in a similar fashion to beans. The difference is that aspects contain one or more advice, which declare the methods to invoke and the locations in which they should be invoked.

<aspect id="loggingAspect" class="com.foo.bar.aspect.LoggingAspect">
    <advice id="logBefore" type="before" pointcut="beans" value="myService" />
    <advice id="logAfter" type="after" pointcut="beans" value="myService" />
    <advice id="logAround" type="around" pointcut="within" value="com.foo.bar.dao" />
</aspect>

The above aspect declaration is used for the class below. The method logBefore is called before every invocation of a method in the bean myService, and the method logAfter is called after every myService invocation. The method logAround is called when any bean method within the package com.foo.bar.dao is invoked.

public class LoggingAspect {

    public void logBefore(JoinPoint joinPoint) {
        Log.d("LoggingAspect", "Before advice: " + joinPoint.getMethod().getName());
    }

    public void logAfter(JoinPoint joinPoint) {
        Log.d("LoggingAspect", "After advice: " + joinPoint.getMethod().getName());
    }

    public Object logAround(ProceedingJoinPoint joinPoint) throws Exception {
        Log.d("LoggingAspect", "Around advice: " + joinPoint.getMethod().getName());
        Object result = joinPoint.proceed();
        Log.d("LoggingAspect", "Around advice: " + joinPoint.getMethod().getName());
        return result;
    }

}
Clone this wiki locally