Pull configurations
You might have heard a thousand times, push is good, IoC is good. pull is bad, and I have to agree.
jPOS components get their configurations pushed by the Q2 container when they implement the Configurable interface.
But if you're used to jPOS configurations, which can be filtered at build time by the Gradle build based on the desired target profile, or can be decorated by means of @vsalaman's contributed decorator, you may find yourself reinventing the wheel and figuring out how to get some Configuration object into a non jPOS component (such as a servlet or any other non jPOSsy code).
To solve that in a standard way, we've created QConfig. QConfig is a minimalistic QBean that just register its own Configuration object into the NameRegistrar (with a "config." prefix). So for example, you can deploy something like this:
The word config
has been registered in QFactory.properties so the <config>
element above is equivalent to:
... ...
So non jPOS running inside Q2 can get a reference to 'config' configuration by calling:
Configuration cfg = QConfig.getConfiguration("myconfigname");
While we were at it, we added the ability to merge configuration objects in other QBeans; There many ways to achieve the same without using this technique, for example, you can use <property file="xxx" />
in different QBeans to pull the same config, or you can use XML entities for that, but, because we can, we just offer this additional way to do it, which is quite simple.
Any QBean descriptor now accepts an optional attribute called merge-configuration
that accepts a list of QConfig configurations and merges them on-the-fly at QBean configuration time. Here is a simple example:
deploy/00_config.xml
deploy/01_config.xml
deploy/90_script.xml
Because this merge-configuration
handling is honored by QFactory, used by other components such as the TransactionManager to instantiate its participants, you can use it in TM participants as well (i.e. to pull reused configuration, such as result codes and the like).