Skip to content

new QFactory method to instantiate from Element#669

Merged
ar merged 2 commits intojpos:mainfrom
barspi:qfactory-newInstance
Jan 26, 2026
Merged

new QFactory method to instantiate from Element#669
ar merged 2 commits intojpos:mainfrom
barspi:qfactory-newInstance

Conversation

@barspi
Copy link
Contributor

@barspi barspi commented Jan 22, 2026

A previous PR (#668) fixed the fact that QServer wasn't honoring the enabled attribute of some of its children elements, such as request-listener.

This omission was later discovered also QMUX together with the usage pattern (in many other places) when creating a helper child class. Normally the class attribute is used to create an instance using QFactory from the class name, then setLogger() and setConfiguration are called . In some of this places it was forgotten to check if the component was enabled in the XML.

A new version of QFactory#newinstance is provided to create from the dom Element.
public <T> T newInstance(Element e, boolean autoConf)

It automatically checks the enabled attribute and does the autoconfiguration calls if boolean autoConf is true.
The returned instance can then be further configured in custom code if needed.

This util method may be useful in many other places where a jPOS class creates its own helper configurable objects that may honor the enabled attribute.

This PR includes the refactoring in QServer, QMUX, ChannelAdaptor to start using the new facility.

@alcarraz
Copy link
Contributor

I was ruminating about this these days, triggered by #668 in fact.

@ar
Copy link
Member

ar commented Jan 24, 2026

I like the PR but we don't need the auto-config version. Let's enforce some opinion and make it the default on the regular newInstance method.

@barspi barspi force-pushed the qfactory-newInstance branch from 4bfa268 to 60263d5 Compare January 25, 2026 05:48
@barspi
Copy link
Contributor Author

barspi commented Jan 25, 2026

I used the autoConf boolean to give the client code the chance to do its own configuration, but I have searched the jPOS codebase and there's barely a couple of points where this could have been useful in theory.

So I just I rebased against most recent main and simplified the method and did the necessary refactoring.

I also did some clean up along the way, such as removing old unneeded type casts and replacing a couple of iterator loops with a more moden enhanced-for.

@ar ar merged commit 406b113 into jpos:main Jan 26, 2026
2 checks passed
@barspi barspi deleted the qfactory-newInstance branch January 26, 2026 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants