commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Carsten Kaiser" <carsten.kai...@valtech.de>
Subject [Configuration] Bugfix for XMLConfiguration.clone()
Date Wed, 28 Feb 2007 15:09:47 GMT
Hi there,



the clone() operation on a XMLConfiguration does not work correctly due
to the following problem:



    private class XMLFileConfigurationDelegate extends
FileConfigurationDelegate

    {

        public void load(InputStream in) throws ConfigurationException

        {

            XMLConfiguration.this.load(in);

        }

    }



Obviously the delegate references the XMLConfiguration instance it is
created in. Thus when calling



    public Object clone()

    {

        XMLConfiguration copy = (XMLConfiguration) super.clone();



        // clear document related properties

        copy.document = null;

        copy.setDelegate(createDelegate());

        // clear all references in the nodes, too

        copy.getRoot().visit(new NodeVisitor()

        {

            public void visitBeforeChildren(Node node, ConfigurationKey
key)

            {

                node.setReference(null);

            }

        }, null);



        return copy;

    }



the delegate still references the original XMLConfiguration, thus will
save the content of the original one

to file instead of the clone as expected! Changing the code like this



        copy.setDelegate(copy.createDelegate());



solves the problem! Now the cloned XMLConfiguration with all its applied
changes can be saved!



Regards,

CAK

-- 
Carsten Kaiser
Principal Consultant
mailto:carsten.kaiser@valtech.de
Mobile: +49 (0)170 5270206

Valtech GmbH
Werner-Heisenberg-Straße 2
63263 Neu-Isenburg
Germany

Phone: +49 (0)6102 88468-0
Fax: +49 (0)6102 88468-28

http://www.valtech.de

Geschäftsführer: Ingo Kriescher
Amtsgericht Düsseldorf HRB48672

Mime
  • Unnamed multipart/alternative (inline, 7-Bit, 0 bytes)
View raw message