minuteAspect is a collection of reusable aspects based on AspectJ.
This is a subproject of minuteTools, but can be deployed independently.
Download the current version of minuteAspects.
The aspect BoundPropertySupport together with its support classes enables annotation-based implementation of the bound property feature of JavaBeans.
To make all properties of a JavaBean class bound properties, you only have to apply the annotation SupportBoundProperties on the repective JavaBean. E.g.:
@SupportBoundProperties
public class SampleBean {
private Float amount;
public Float getAmount() {
return this.amount;
}
public void setAmount(Float amount) {
this.amount = amount;
}
// ... some more fields, getters and setters
}
Now you can register a listener for changes of any or all properties of your JavaBean, e.g.:
// ...
((BoundPropertyObservable) sampleBean).addPropertyChangeListener(generalChangeListener);
((BoundPropertyObservable) sampleBean).addPropertyChangeListener("Amount",amountChangeListener);
// ...
For a working example, see the unit test classes in package com/minutefforts/aspects/property/support.
Sometimes you want to explicitly exclude a property from the property change support (e.g. because this getter/setter pair is some implementation detail and not part of the intended JavaBean interface). You can do this by using an annotation on the setter of the property:
// ...
private String internalValue;
@UnboundProperty
public void setInternalValue(String internalValue) {
this.internalValue = internalValue;
}
// ...
Depending on the features you plan to use, you only need to include the librarie's JAR file minuteAspect.jar in your project plus a recent version of the AspectJ runtime library.
Any feedback is welcome - questions, critique, praise and suggestions alike. :-)
Sent email to achim[at]minutefforts.com.