Main | June 2006 »

April 26, 2006

Sweetwater WiFi

My favorite local coffee cafe, Sweetwaters finally has free wifi. At least the one on Washington has it. Don't know about the one at Kerrytown. I haven't actually tried it yet. Just saw the new sign on the door last Sunday.

This adds to the growing wifi coverage of downtown Ann Arbor.

Posted by jaynes at 09:06 AM | Comments (1) | TrackBack

April 25, 2006

Spring 2.0 - XML Configuration on more steroids

Note: This is my first blog, so there are still formatting issues I haven't figured out yet.

When I saw Memestorm's blog posting on XML configuration on steroids I had to learn more. Read his entry before continuing, as I don't really explain a lot. I'm just showing code. Also, I just figured this out by delving into the Spring code and some of the tags that are available in Spring 2.0. I've got something working, but I'm pretty sure that there are better ways to do what I've done. Hopefully someone will see this blog and tell how I should have done it.

Memestorm's entry was enough to get you started, showing how to create a simple tag. I needed something with embedded tags. I wanted to turn something that, in a traditional Spring config file, looks pretty ugly:

into something that looks like this

It's just a list of service objects, each with a list of pattern objects, each pattern object having two properties, pattern, a string, and allowPublicAccess, a boolean.

XML Schema

So, first, I needed to come up with the XML Schema:

The schema describes the three tags I need, "urlPatten" nested within "service" nested within "services".

Namespace Handler

As Memestorm says, Spring invokes a namespace handler to read your custom XML, and you have to write that handler. Here is what I came up with:

The constructor registers a bean definition parser for the top element, service. The other elements are parsed as part of the code. This is how I saw the Spring code handling nested elements.

The biggest kludge I had to pull, and the part I understand least, has to do with the ListBean class. In the CosignNamespaceHandler the getBeanClass method needs to return the class of the bean that will hold the services element, when it is completely built. That class needs to be instantiated, and properties set in it in the doParse method. But a List is not a bean, and doesn't have properties. After creating the List I didn't know what to do with it. So I created a ListBean that implements List, has a property internalList, and delegates all List methods to this internalList. Then, as the last line in doParse I could call the builder.addPropertyValue method and set the list I had build into a bean. I'm sure there must be some other way to handle this, but I don't know what it is.


When you package this all up into a jar, there are two extra files you need to add to the META-INF directory. The spring.schemas file maps the namespace location to the location of the schema file in the jar:


The spring.handlers file maps the schema namespace to the namespace handler class:


And the final thing is, in the Spring bean configuration XML file, use the XML Schema version rather than the DTD version, and map your new namespace to a URI:

Notice the chain that all these names form: xmlns:cosign="" specifies the URI for the namespace. In the xsi:schemaLocation part of the header, the namespace URI is mapped to a location URI, This location URI, is mapped to a physical location by the spring.schemas file.

Posted by jaynes at 10:31 AM | Comments (1) | TrackBack