By the way...
This content is now pretty old: check the homepage for the latest.
This session, let's have a brief look at some of the other in the richclient-application-context.xml file, and see if we can at least work out roughly what they're for. First however, a word about ApplicationServices.
The ApplicationServices singleton
It looks like ApplicationServices is implemented as an old fashioned singleton bean. Have a look at the method below as an example of a service initialisation performed in this class:
Most of the other services are similarly initialised.
This means that ApplicationServices looks for beans to help in configuring the application backbone, but doesn't have to have them. If it can't find the relevant bean, it'll just create a default and use that.
How is it used? Well, there are lots of calls in the code like this:
Let's dive off on a tangent for a moment. Why is this class necessary? After all, with dependency injection, why have a central singleton defining services at all? Surely various beans would simply have their dependencies wired up as and when they need them, rather than referring to a central dependency. Is this class a legacy requirement, or does it prevent us having pages of standard spring wiring XML which is inefficient, difficult to maintain, and unnecessary?
I'd be interested in finding out your thoughts on this, especially if you are further along the "way of the Rich Client" than I - feel free to leave a comment.
Right, on to some of the other beans. I feel we're getting diminishing returns from looking at these, but we'll press on with a few.
The componentFactory is of type DefaultComponentFactory, and is one of the Application Services mentioned in the previous section.
Searching for files which access ApplicationServices' getComponentFactory() method turns up a whole bunch of results in the Rich Client source, but not very much in the Petclinic source. Looks like the component factory is used to create components all over the place in the main Rich Client source. I'm guessing that the Petclinic does not require the ability to create many components - and a quick look at some of the code confirms this to be the case. More on this later.
Here's the "imageSource" bean definition:
This provides a "broken image indicator" path - useful, so we can actually see the dodgy images like on a web page, rather than just having invisible ones).
The bean references imageResourcesFactory, which create a Map of strings to resource locations, for the imageSource bean to use, from a couple more properties files.
There's another "standard" Rich Client properties file here (just as there was one for the messageSource bean last session) which defines paths for basic icons (like those for "New", "Open", "Save" etc). These ship in spring-richclient-resources.jar, so you can use them out of the box. If you don't want to, simply define your own icon location with the same name in your own images.properties. Easy.
This one looks straightforward - it appears to simply be the event transport for the application context, and is part of standard Spring from the classpath. That looks to be how events are passed around the application.
This seems to provide sets of rules to use when validating entered data. Looking at the source for PetClinicValidationRulesSource, the class being instantiated, it sets up certain constraints for the owner and pet data that is entered into the app. More on this in a future session, when we create our own data entry box.
Right, that's enough. Apart from the ui beans which we'll cover next session, the other beans all look far too scary. Plus, I'm bored with looking at XML. I think we'll learn more going forward by looking at some of the windows, views and dialogs represented by the GUI beans.
Mmm. GUI beans. Now there's a thought.
We've come some way today in understanding the Rich Client architecture, and how the core ApplicationServices code initialises and configures itself. We discussed the ApplicationServices class and it's usefulness/right to exist, without really knowing the answer. Comments welcome.
We also went through a few more of the beans in the richclient-application-context.xml and didn't learn all that much, apart from one important thing - we've come to the end of this file's usefulness in teaching us anything new.
Next session: windows, views, dialog boxes and perhaps even a field or two.