KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > loom > components > util > ConfigurationConverter


1 /*
2  * Copyright (C) The Loom Group. All rights reserved.
3  *
4  * This software is published under the terms of the Loom
5  * Software License version 1.1, a copy of which has been included
6  * with this distribution in the LICENSE.txt file.
7  */

8 package org.codehaus.loom.components.util;
9
10 import org.apache.avalon.framework.configuration.Configuration;
11 import org.apache.avalon.framework.configuration.DefaultConfiguration;
12
13 /**
14  * Utility class to convert DNA Configuration objects into Avalon Configuraiton
15  * objects.
16  *
17  * @author Peter Donald
18  * @version $Revision: 1.3 $ $Date: 2004/06/20 17:46:56 $
19  * @deprecated Use org.codehaus.spice.alchemist.configuration.ConfigurationAlchemist
20  */

21 public class ConfigurationConverter
22 {
23     public static Configuration toConfiguration(
24         final org.codehaus.dna.Configuration configuration )
25     {
26         final DefaultConfiguration result =
27             new DefaultConfiguration( configuration.getName(),
28                                       configuration.getLocation() );
29         final String JavaDoc[] names = configuration.getAttributeNames();
30         for( int i = 0; i < names.length; i++ )
31         {
32             final String JavaDoc name = names[ i ];
33             final String JavaDoc value = configuration.getAttribute( name, null );
34             result.setAttribute( name, value );
35         }
36
37         final org.codehaus.dna.Configuration[] children =
38             configuration.getChildren();
39         for( int i = 0; i < children.length; i++ )
40         {
41             final Configuration child = toConfiguration( children[ i ] );
42             result.addChild( child );
43         }
44
45         final String JavaDoc value = configuration.getValue( null );
46         if( null != value )
47         {
48             result.setValue( value );
49         }
50
51         return result;
52     }
53 }
54
Popular Tags