samuel dao xmlbeans

Tue, Dec 20, 2005

The last post on the SAMUEL2 interfaces had the answer staring me in the face all the time! Once you’ve run XMLBeans over the SAML schema, you’re ready to go with SAML functionality, complete and unadulterated. The only problem is, if it’s a problem at all, is that applications that use the generated classes directly are then bound to that version of the SAML schema, as their tightly coupled via the XMLBeans generated classes (xBeans).

So, for best practices, you’re better off with a DAO layer on top of the xBeans, that insulate an application from the shifting SAML sands. It’s a lot of work compared to just providing raw schema functionality but it also lets you add in functionality, such as WS-Security stuff and handy things like saving and loading SAML schema fragments in an implementation agnostic way.

An interesting way to do this is through the XMLBeans Extension Interface facility, where you specify which interfaces each xBean will implement. It’s a bit messy though as each xBean calls out to a static handler, which implements the interface, rather than the xBean implementing it. It’s also not nice to program as, although you’re implementing an interface, you can’t declare this in the implementation! Why? Well, it’s bean based. That crappy ol’ OOP breaker again. e.g.:

public interface BeanExtension {   public doSomethingWithBean(); }

public class BeanExtensionImpl implements BeanExtension {   public static doSomethingWithBean(XmlObject xBean) {   } }

Wrong! BeanExtensionImpl doesn’t implement doSomethingWithBean(), it implements doSomethingWithBean(XmlObject). It if doesn’t, XMLBeans will barf! XMLBeans “injects” a “ghost” object (the xBean class) when calling the static handler. This breaks the interface, so you can’t declare you’re implementing the interface although you sort of are.

Anyway, the solution was there all along. The XAL is the DAO layer. Instead of a DAO getting it’s stuff from a traditional DB persistence layer, it’s getting it from the xBeans, which are “persisting” SAML as Java objects.

comments powered by Disqus