Promoting loose coupling through XQuery/XPath
Quinton Wall's Blog |
September 7, 2005 3:03 PM
|
Comments (0)
I managed to get some time over the long weekend and last night to
work on Reeter. I changed the internals of how I am fetching the
sydnication urls to utilize The Rome Project instead of trying to craft (and support)
my own schemas for the different syndication formations (RSS, ATOM etc).Thanks to the recommendation of a BEA collegue, Mark Nottingham,
Reeter will now support anything that the Rome Project can handle!
With the actual fetching handled now I started to turn my attention
to the content writers; in particular the writer for BEA CMS support.
As is normal in development I found that I needed to add a few things
here and remove a few things there from the reeterconfig.xml. This
file contains all the repository and feed information for Reeter.
Right now I am changing this regularily and found that I had to keep
changing my XML Beans to
reflect the new structure.
After a few times of refactoring things I began to get the feeling of
Shotgun Surgery where I was continously making small changes throughout
the code tree. I thought for a second and decided that my problem was
that this sort of change is inevitable in a config file as functionality
grew or was depreciated etc. I am very congizant of designing for today
and avoid the habit of throwing in a bunch of bells and whistles
because it was cool, but this was a concern today that I knew would only
get worse. So I decided to rely on the power of XQuery/XPath and XMLBeans support of it.
With a small amount of rework all of my calls to the config document
are now via xquery selects. The investment is already paying off. Last night I changed the config schema again and the only change I had to
do was update a properties file which contains all my xquery select
statements. Hopefully I can now concentrate on the implementing the
writers and then I should be ready to release it.
The code snippet below
may give you an indication of how you may be able to utilize XQuery/XPath
and XMLBeans to promote loose coupling between generated objects.
Except from ReeterContext.java
ReeterContext is a singleton class which is responsible for maintaining
the current running config and return data from it. The method
below accepts a key (for a ResourceBundle) for the required xquery to be executed against
the XMLBean
public String queryConfig(String querykey)
{
XmlCursor cursor = _doc.newCursor();
cursor.toFirstChild();
cursor.selectPath(getXQuery(querykey));
cursor.toNextSelection();
return cursor.getTextValue();
}
Now in my code whenever I need to retrieve a value from the config
document all I have to do is something like the following:
String repositoryType = ctx.queryConfig("repository.type");
instead of the tightly coupled approach I had previously:
String repositoryType =
_doc.getReeterConfig().getConfig().getDocument().getRespository().getType();
Comments
Comments are listed in date ascending order (oldest first) | Post Comment
|