[Obix-framework-tipsandtricks] Deep copy of Configuration
Brought to you by:
eobinna
From: Aleksi K. <ale...@cs...> - 2007-03-30 07:38:34
|
Hello all, I have found this piece of code useful (see the end of message). I guess achieving this is not possible using imports? If there is a more direct way of achieving the same result I'd like to hear about. If not, something like this could be added to framework... Best regards, -- Aleksi Kallio, Application Architect, Scientific Software Development P.O. BOX 405, 02101 Espoo, Finland, Tel +358 9 457 2297 CSC is the Finnish IT center for science, www.csc.fi e-mail: ale...@cs... **** /** * Do a deep copy (recursive copy of submodules) of source Configuration content into target Configuration. * @param source content to be copied, is not altered * @param target Configuration to be written to */ private static void deepCopy(Configuration source, Configuration target) { // copy values for (Object entry : source.values()) { target.addEntry((ConfigurationEntry)entry); } // recurse into modules for (Object module : source.getModuleNames()) { String moduleName = (String)module; Configuration sourceModule = source.getModule(moduleName); if (!target.containsModule(moduleName)) { target.createConfiguration(moduleName); } deepCopy(sourceModule, target.getModule(moduleName)); } } |