Tuesday, May 29, 2007

Creating a Spring Bean from a Java 5 Enum

Instances of Java enums, introduced in Java 5, can be a bit tricky to instantiate as Spring beans because the Java compiler hides enum constructors. However, we can create a bean from an enum by using the enum valueOf static method as a factory method.

For example, let's say we have defined an enum class as follows:

package robertmaldon.cafe;

public enum Coffee {

The Spring XML config for a bean instance then looks something like this:

<bean id="latte" class="robertmaldon.cafe.Coffee" factory-method="valueOf">

NOTE: Declaring the bean scope as prototype or singleton makes no difference. For the same class loader a singleton bean is always returned.

If you don't want to declare a bean for each value of an enum you can simply use the enum value name at the point where it is injected into a dependent class. For example, let's say you have a class that is injected with an instance of our enum above:

package robertmaldon.cafe;

public class CoffeeMachine {
private Coffee coffee;

public void setCoffee(Coffee coffee) {
this.coffee = coffee;

In the Spring XML config simply use the enum value as the property value (apparently works with Spring 1.2.2 and beyond):

<bean id="machine" class="robertmaldon.cafe.CoffeeMachine">
<property name="coffee" value="MOCHA"/>

Wednesday, May 23, 2007

Only 7 Band Names Remaining

In the back of my mind I suspected this might happen some day...

According to data released Monday by the International Registry of Rock Band Names, only seven of the estimated 518 million potential names for musical acts remain available.

"Following the selection of 'The Stripped Amygdaloids,' 'A Purple Spray Of Cloth Violets,' and 'Guestowel' this past weekend, it is essential that new bands pick a name as soon as possible," read a statement on the organization's website...

Sunday, May 13, 2007

Live Ink: A Revolutionary Way To Read Text Online

Scientists been examining the way human brains are wired to read blocks of text and found that the brain really struggles to read traditional blocks/paragraphs of text.

Scientific research conducted by Walker Reading Technologies, a small Minnesota startup that has been studying our ability to read for the last ten years, has concluded that the natural field of focus for our eyes is circular, so our eyes view the printed page as if we’re peering through a straw.

And a very bad-behaving straw at that, because not only do our eyes feed our brain the words we’re reading, they’re also uploading characters and words from the two sentences above and below the line we’re reading.

Every time we read block text, we’re forcing our brain to a wage a constant subconscious battle with itself to filter and discard the superfluous inputs. This mental tug of war slows reading speed and diminishes comprehension.

From this research a startup has come up with a new method formatting text for the online world which, having tried it, seems to me to be much easier and quicker to read - but (graphical artists beware) takes up more space.


Tuesday, May 08, 2007

Lotus Notes: still intuitive and easy to use

It's great to be using Notes again...