commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <oliver.he...@oliver-heger.de>
Subject Re: [configuration] XMLConfiguration.getDocument
Date Tue, 23 Feb 2010 19:55:41 GMT
Am 23.02.2010 11:57, schrieb Lorenzo Cavina:
> Hi all,
> I'm using XMLConfiguration and in my opinion there's something wrong
> with the getDocument() method.
> Let me explain. I'm creating a brand new void XMLConfiguration as follows:
>
> XMLConfiguration config = new XMLConfiguration();
>
> and the i add some properties as follows:
>
> config.addProperty("frame.width", "100");
> config.addProperty("frame.height", "100");
>
> Now what i would like to do is extract the Document object representig
> current state of the configuration object and so i execute
>
> Document configDocument = config.getDocument();
>
> But configDocument is NULL!
> I really couldn't figure it out why it doesn't create the Document. So i
> tryed and tryed again and finally i discovered that if i execute
>
> config.save(System.out);
>
> BEFORE getting the Document, then the Document is filled and not NULL
> anymore!
> So i had a little look to the source code and i saw that there's a
> protected method called createDocument() that seems to be called on save.
>
> Now i'm asking myself:
> - why getDocument returns NULL even if i added some contet?
> - why i have to save the configuration to get the Document, event if i
> really don't need to save it?
> - is there a way to force Document creation?
>
> Thank you very much.

Well, that's how XMLConfiguration is designed. This class mainly focuses 
on reading XML documents and allowing access to them through the 
Configuration API. It is not intended to be used as XML processing tool. 
I don't know your exact use case, but if you need to create XML 
documents in memory, then maybe a library like jdom is better suited?

The Javadocs of getDocument() mention that the return value is null if 
the configuration was not loaded from a XML document. Maybe this can be 
improved to make the behavior more clear.

The XML document is not constructed before it is actually needed, i.e. 
on a save or load operation. I am not aware of a workaround. Maybe you 
can save the configuration into a ByteArrayOutputStream; then you do not 
have to access a file.

HTH
Oliver

>
> Lorenzo
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message