commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jonathan Su <nox...@gmail.com>
Subject [Commons Configuration] Saving a CombinedConfiguration with ViewNodes
Date Fri, 08 May 2009 00:00:20 GMT
Hi,

I am using the CombinedConfiguration class to combine two XMLConfigurations
and trying to save the result as xml. My code is as follows:

                CombinedConfiguration cc = new CombinedConfiguration(new
OverrideCombiner());
                cc.addConfiguration(firstXMLConfig);
                cc.addConfiguration(secondXMLConfig);
                combinedConfig = new XMLConfiguration(cc);
                combinedConfig.save("path/to/file.xml");

 When I try to do the save operation however, I am getting the following
exception:

Caused by: java.lang.ClassCastException:
org.apache.commons.configuration.tree.ViewNode cannot be cast to
org.apache.commons.configuration.HierarchicalConfiguration$Node
    at
org.apache.commons.configuration.HierarchicalConfiguration$BuilderVisitor.visitBeforeChildren(HierarchicalConfiguration.java:1624)
    at
org.apache.commons.configuration.HierarchicalConfiguration$Node.visit(HierarchicalConfiguration.java:1329)
    at
org.apache.commons.configuration.XMLConfiguration$XMLBuilderVisitor.processDocument(XMLConfiguration.java:1321)
    at
org.apache.commons.configuration.XMLConfiguration.createDocument(XMLConfiguration.java:759)
    at
org.apache.commons.configuration.XMLConfiguration.save(XMLConfiguration.java:878)
    at
org.apache.commons.configuration.AbstractHierarchicalFileConfiguration$FileConfigurationDelegate.save(AbstractHierarchicalFileConfiguration.java:454)
    at
org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:546)
    at
org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:513)
    at
org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:491)
    at
org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:403)
    ... 26 more

It looks like ViewNode is created when firstXMLConfig and secondXMLConfig
have a node with the same key in the combine process. Is there a way to
convert all ViewNodes into HierarchicalConfiguration.Node? Or am I using
this incorrectly?

Thanks,
Jonathan

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message