KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > excalibur > system > ConfigurableRoleManager


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

8 package org.apache.avalon.excalibur.system;
9
10 import java.util.Collections JavaDoc;
11 import java.util.HashMap JavaDoc;
12 import java.util.Map JavaDoc;
13 import org.apache.avalon.framework.configuration.Configurable;
14 import org.apache.avalon.framework.configuration.Configuration;
15 import org.apache.avalon.framework.configuration.ConfigurationException;
16 import org.apache.avalon.framework.logger.AbstractLoggable;
17
18 /**
19  * Configurable RoleManager implementation. It populates the RoleManager
20  * from a configuration hierarchy. This is based on the DefaultRoleManager
21  * in the org.apache.avalon.component package.
22  *
23  * @author <a HREF="mailto:bloritsch@apache.org">Berin Loritsch</a>
24  * @version CVS $Revision: 1.3 $ $Date: 2002/01/30 15:44:06 $
25  * @since 4.1
26  */

27 public class ConfigurableRoleManager
28     extends AbstractRoleManager
29     implements Configurable
30 {
31     /**
32      * Default constructor--this RoleManager has no parent.
33      */

34     public ConfigurableRoleManager()
35     {
36         super( null );
37     }
38
39
40     /**
41      * Alternate constructor--this RoleManager has the specified
42      * parent.
43      *
44      * @param parent The parent <code>RoleManager</code>.
45      */

46     public ConfigurableRoleManager(RoleManager parent)
47     {
48         super( parent, Thread.currentThread().getContextClassLoader() );
49     }
50
51     /**
52      * Alternate constructor--this RoleManager has the specified
53      * parent and a classloader.
54      *
55      * @param parent The parent <code>RoleManager</code>.
56      */

57     public ConfigurableRoleManager(RoleManager parent, ClassLoader JavaDoc loader)
58     {
59         super( parent, loader );
60     }
61
62
63     /**
64      * Reads a configuration object and creates the role, shorthand,
65      * and class name mapping.
66      *
67      * @param configuration The configuration object.
68      * @throws ConfigurationException if the configuration is malformed
69      */

70     public final void configure( final Configuration configuration )
71         throws ConfigurationException
72     {
73         final Map JavaDoc shorts = new HashMap JavaDoc();
74         final Map JavaDoc classes = new HashMap JavaDoc();
75         final Map JavaDoc handlers = new HashMap JavaDoc();
76         final Map JavaDoc hintclasses = new HashMap JavaDoc();
77
78         final Configuration[] roles = configuration.getChildren( "role" );
79
80         for( int i = 0; i < roles.length; i++ )
81         {
82             final String JavaDoc role = roles[ i ].getAttribute( "name" );
83             Configuration[] components = roles[i].getChildren( "component" );
84
85             for ( int j = 0; i < components.length; j++)
86             {
87                 final String JavaDoc shorthand = components[ j ].getAttribute( "shorthand" );
88                 final String JavaDoc className =
89                     components[ j ].getAttribute( "class", null );
90                 final String JavaDoc handlerClassName =
91                     components[ j ].getAttribute( "handler",
92                     "org.apache.avalon.excalibur.system.handler.PerThreadComponentHandler" );
93
94                 setup( shorts, classes, handlers, shorthand, role, className, handlerClassName );
95             }
96         }
97
98         m_shorthands = Collections.unmodifiableMap( shorts );
99         m_classNames = Collections.unmodifiableMap( classes );
100         m_handlerNames = Collections.unmodifiableMap( handlers );
101     }
102 }
103
Popular Tags