commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oliver Heger (JIRA)" <>
Subject [jira] [Commented] (CONFIGURATION-655) Reading configuration from InputStream - improvement
Date Sun, 26 Mar 2017 19:38:41 GMT


Oliver Heger commented on CONFIGURATION-655:

Thanks for creating this ticket. There is for sure room for improvements in this area.

Currently, I don't have yet a bright idea how to integrate better support for streams into
the existing API. It is certainly preferrable to use already existing concepts rather than
inventig something completely new. So would it be possible to extend the {{FileLocator}} and
{{FileHandler}} classes in a way that an input stream could be specified similar to a File
or an URL? We could for instance introduce a {{StreamProvider}} interface which just has a
_getInputStream()_ method. Such a provider would become a property of {{FileLocator}} and
{{FileHandler}}, and it would also be supported by file-based builder parameters.

With such extensions one could create a configuration in the following way:
XMLConfiguration cfg = new FileBasedConfigurationBuilder<>(XMLConfiguration.class)
    .configure(new Parameters().xml().setStreamProvider(new MyStreamProvider()))

I am not yet sure how this approach would affect the current loading mechanism and the file
location strategy (which operates on URLs rather than streams). Probably, a {{StreamProvider}}
would take precedence over other properties. Some experiments would need to be done to verify
that nothing gets broken.

But would you in general agree to such an approach or do you have other suggestions?

> Reading configuration from InputStream - improvement
> ----------------------------------------------------
>                 Key: CONFIGURATION-655
>                 URL:
>             Project: Commons Configuration
>          Issue Type: Improvement
>            Reporter: RafaƂ Figas
> The point of this improvement is better handling of configurations loaded from input
> Currently to load configuration from input stream following code should be used:
> {code}
> XMLConfiguration cfg = new BasicConfigurationBuilder<>(XMLConfiguration.class).configure(new
> FileHandler fh = new FileHandler(cfg);
> fh.load(stream);
> {code}
> In general this looks a little bit odd, because FileHandler is involved, what suggests
that configuration has something to do with file, while it is not necessary true. Maybe it
would be clearer if either builder, or configuration would be responsible for loading data.
I think builder would be even better, because what I expect from builder is to get the configuration
object that is complete, contains data and I can work with it's content. From where I get
the data should be responsibility of builder. And if I want to save such configuration I should
be able to get it as string for example (or byte array or stream) and it is my own responsibility
of what will I do with it (save to file, push to webservice etc.).
> AFAIR there is also some kind of configuratio autoupdate feature, but what comes first
to my mind is to add such feature to builder. Then builder could create a configuration that
is wrapped in appropriate handler responsible for saving updates.
> Just a few humble suggestions that could improve working with this nice library :-).
I believe that minimum improvement would be a clear remark in user guide how to load configuration
from stream in current version as it is not obvious.

This message was sent by Atlassian JIRA

View raw message