Re: [Obix-framework-tipsandtricks] Obix-framework-tipsandtricks Digest, Vol 1, Issue 2
Brought to you by:
eobinna
From: Vinuth M. <vin...@gm...> - 2007-04-06 06:21:21
|
On 4/6/07, obi...@li... > Date: Fri, 30 Mar 2007 10:38:25 +0300 > From: Aleksi Kallio <ale...@cs...> > Subject: [Obix-framework-tipsandtricks] Deep copy of Configuration > To: obi...@li... > Message-ID: <460...@cs...> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > > 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)); > } > } I agree. I had want something like this for my project. It can be useful when we have multiple config files, which can hierarchically override values read from previous config files. Also useful when the client doesn't have to bother under which module a certain value is stored. So, having a flat structure even while maintained in multiple config files would be useful. But along with this deepCopy() function, a new kind of tag (maybe <configuration-include>) or an extra attribute to <configuration-import> tag, something like: <configuration-import import-type="deepCopy"> would be useful. |