What we have
- A complex tree model stored across multiple XML files
- Java model classes which represent the XML model
- All classes as POJOs
- All classes annotated with jaxb
- jaxb to read the XML files
- A tree of handler classes
- each handler is responsible for handling a layer inside the model tree or specific elements
- the handler classes are created using guice as DI framework
Some handlers need data that is processed in layers that were parsed earlier.
RootHandler \- ChildHandler \- GrandChildHandler
In this example the GrandChildHandler needs the data which the RootHandler computed. At the moment the code looks similar to this:
# roothandler: Data rootData = compute(); childHandler.handleLayer(rootData); # childHandler: Data childData = compute(); grandChildHandler.handleLayer(rootData, childData);
How should we handle this trickle down of data in the handler tree? Is it acceptable that the methods call 'explode' the further we go down in the tree?
I was also thinking about storing the child data in singletons, but I fear that it will be unintuitive if this data changes depending on each computation from a childHandler.
The Eclipse4 dependency framework supports context sensitive injection. Do you think it would be good to create a context object which contains all the passed down data and every handler just grabs what he needs from there?
Another idea we had was to separate localized data and global data and then pass the global through different methods. My fear here is that the outside has to guarantee that the most recent global data is set.
Is there some standard solution for this? All Dependency injections tutorials just ignore bigger projects :(