Saturday, 16 January 2010

Where Sheep May Safely Graze

I've just uploaded a collection of short stories and poems to Smashwords.

It is called Where Sheep May Safely Graze because one of the longer stories is called that.
There are several about cats, especially our (departed) cats and there's some NZ culture/history buried in there as well.

Excerpt from 'Catflap"

The cat stared up at him as though it knew all about the entry and he was being tiresome about it. Then it proceeded to have a bath, the kind of cello-playing bath one feels obliged to look away from unless one knows the cat well.

Most of them are very short and it is all free.

Where Sheep May Safely Graze

You'll find my other writings on smashwords too:
Summon Your Dragons
The White Fox

I have to put in a word for Smashwords here. These clever people are making it easy for people like me to publish fiction. Publishing conventionally is hard, very hard. Writers have to work at getting a publisher to take notice of them. But actually most of us just want to write. I have no expectations of getting wildly popular, I just want somewhere to put what I've written and people can find it if they want. Smashwords does a fine job of that, they automatically convert the work into formats readable by various devices such as eBook readers and phones (yes, people read this stuff on their smart phones). They also allow me to collect a small fee or give it away free.

My first book: Summon Your Dragons, is free. The sequel, The White Fox, has a tiny charge on it. This is mostly because people download things and don't necessarily read them. I figure if they like the first book and then PAY to download the second they probably actually like it, especially since they can read half of the second one for free. That encourages me to spend some time writing the third book.

Now, my stuff is okay if you like historical fantasy, but for a really good read check out my wife's writing. These are stories set in 19th century New Zealand and they are brilliant.

Start with Sentence of Marriage and you probably won't be able to put them down.

Wednesday, 6 January 2010

Open documents

I was given a file on a CD yesterday. It is a .pub file, so I think it is a Microsoft Publisher file. Now, why is it a good idea to ever pass an MS Pub file around to people?

MS Word files are a de facto standard of sorts, though you cannot assume everyone runs Word. But there are several other products which read Word files and MS provide a free reader so that is a reasonable enough approach. Of course the free reader doesn't run on Linux but that's okay, Open Office reads them. It doesn't handle some of the odd templates I come across but it is usable.

But MS Pub doesn't have a reader, free or otherwise. You can install the whole thing on a trial basis and, I think I have this right, when the trial expires it will still read. Well... okay, but that doesn't help me on Linux does it?

This is just a document. PDF, ascii, Word, HTML are all reasonable options here, even better is my own MaduraDocs format which, like HTML can be viewed in a browser. But this is a pub file, so I have to boot Windows, download a product I don't want to use and then figure out how to drive it.


Sunday, 3 January 2010

Autowiring Spring collections

The problem: an undefined number of classes that need to be added to a collection which is then injected into a class. Assume Springframeworks for the injection.

The obvious thing to do is this:

<bean id="ContainerBean" class="test.example.ContainerBean">
<property name="MyList">
<bean class="test.example.InjectedBean1"/>
<bean class="test.example.InjectedBean2"/>
<bean class="test.example.InjectedBean3"/>

But that means every time I add a class I have to change the wiring.

Instead, using Spring 2.5 we can do this:

<context:component-scan base-package="test.example"/>

yes, apart from the usual stuff at the top, that's all I need in this file. The injected beans all have this in their declaration:

public class InjectedBean1 implements InjectedBeanInterface

and in the container bean we have this:

private List m_myList;

...along with the usual getter and setter, of course.

With that in place Spring happily finds the relevant classes and adds them to the collection. If I add one more injected bean then I just have to remember to add the @Component annotation to it and it will end up in the collection. I use this pattern quite a lot these days. Often other people are implementing the injected beans and I need to keep the list of things they have to remember as small as possible. This approach helps.

Spring is happy enough with a typed List or an array, so my bean implementers don't need to know what they are being injected into. In fact in my current project these injected beans are being generated by some other software. I can customise that to add the annotation automatically, but I don't have to figure out how to automatically edit the beans file.

References which helped me get there:

There's a complete code example on my website