KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > fortress > impl > role > Role2MetaInfoManager


1 /*
2  * Copyright 2003-2004 The Apache Software Foundation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  *
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.avalon.fortress.impl.role;
19
20 import org.apache.avalon.fortress.MetaInfoEntry;
21 import org.apache.avalon.fortress.MetaInfoManager;
22 import org.apache.avalon.fortress.RoleEntry;
23 import org.apache.avalon.fortress.RoleManager;
24
25 /**
26  * Role2MetaInfoManagerTestCase does XYZ
27  *
28  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
29  * @version CVS Revision: 1.1 $
30  */

31 public final class Role2MetaInfoManager implements MetaInfoManager
32 {
33     private final RoleManager m_manager;
34     private final MetaInfoManager m_parent;
35
36     public Role2MetaInfoManager( final RoleManager manager )
37     {
38         this( manager, null );
39     }
40
41     public Role2MetaInfoManager( final RoleManager manager, final MetaInfoManager parent )
42     {
43         m_manager = manager;
44         m_parent = parent;
45     }
46
47     /**
48      * Get a <code>MetaInfoEntry</code> for a short name. The short name is an
49      * alias for a component type.
50      *
51      * @param shortname The shorthand name for the component type.
52      *
53      * @return the proper {@link RoleEntry}
54      */

55     public MetaInfoEntry getMetaInfoForShortName( final String JavaDoc shortname )
56     {
57         final RoleEntry roleEntry = m_manager.getRoleForShortName( shortname );
58
59         if ( roleEntry != null )
60         {
61             return new MetaInfoEntry( roleEntry );
62         }
63         else
64         {
65             return null != m_parent ? m_parent.getMetaInfoForShortName(shortname ) : null;
66         }
67     }
68
69     /**
70      * Get a <code>MetaInfoEntry</code> for a component type. This facilitates
71      * self-healing configuration files where the impl reads the
72      * configuration and translates all <code>&lt;component/&gt;</code>
73      * entries to use the short hand name for readability.
74      *
75      * @param classname The component type name
76      *
77      * @return the proper {@link RoleEntry}
78      */

79     public MetaInfoEntry getMetaInfoForClassname( final String JavaDoc classname )
80     {
81         final RoleEntry roleEntry = m_manager.getRoleForClassname( classname );
82
83         if ( roleEntry != null )
84         {
85             return new MetaInfoEntry( roleEntry );
86         }
87         else
88         {
89             return null != m_parent ? m_parent.getMetaInfoForClassname( classname ) : null;
90         }
91     }
92 }
93
Popular Tags