KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > annotations > internal > TypedRegistryImpl


1 // Copyright 2007 The Apache Software Foundation
2
//
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 implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.hivemind.annotations.internal;
16
17 import org.apache.hivemind.annotations.TypedRegistry;
18 import org.apache.hivemind.internal.Module;
19 import org.apache.hivemind.internal.RegistryInfrastructure;
20 import org.apache.hivemind.service.Autowiring;
21 import org.apache.hivemind.util.IdUtils;
22
23 /**
24  * Implementation of {@link TypedRegistry}.
25  * Wraps an instance of {@link RegistryInfrastructure} to provide registry access.
26  *
27  * @author Huegen
28  */

29 public class TypedRegistryImpl implements TypedRegistry
30 {
31     private Module _callingModule;
32
33     private RegistryInfrastructure _delegate;
34
35     /**
36      * @param callingModule the module that gets access registry access by this instance.
37      * Used for visibility checks when services and configurations are retrieved.
38      * Can be null, in this case only public extension points are visible.
39      * @param delegate
40      */

41     public TypedRegistryImpl(Module callingModule, RegistryInfrastructure delegate)
42     {
43         _callingModule = callingModule;
44         _delegate = delegate;
45     }
46
47     /**
48      * @see org.apache.hivemind.annotations.TypedRegistry#getConfiguration(java.lang.String, java.lang.Class)
49      */

50     public <T> T getConfiguration(String JavaDoc configurationId, Class JavaDoc<T> configurationType)
51     {
52         String JavaDoc qualifiedConfigurationId = qualifyExtensionPointId(configurationId);
53         Object JavaDoc configuration = _delegate.getConfiguration(
54                 qualifiedConfigurationId,
55                 _callingModule);
56         return (T) configuration;
57     }
58
59     private String JavaDoc qualifyExtensionPointId(String JavaDoc extensionPointId)
60     {
61         if (_callingModule == null) {
62             return extensionPointId;
63         } else {
64             return IdUtils.qualify(
65                     _callingModule.getModuleId(),
66                     extensionPointId);
67         }
68     }
69
70     /**
71      * @see org.apache.hivemind.annotations.TypedRegistry#getConfiguration(java.lang.Class)
72      */

73     public <T> T getConfiguration(Class JavaDoc<T> configurationType)
74     {
75         Object JavaDoc configuration = _delegate.getConfiguration(configurationType, _callingModule);
76         return (T) configuration;
77     }
78
79     /**
80      * @see org.apache.hivemind.annotations.TypedRegistry#getService(java.lang.String, java.lang.Class)
81      */

82     public <T> T getService(String JavaDoc serviceId, Class JavaDoc<T> serviceInterface)
83     {
84         String JavaDoc qualifiedServiceId = qualifyExtensionPointId(serviceId);
85         Object JavaDoc service = _delegate.getService(qualifiedServiceId, serviceInterface, _callingModule);
86         return (T) service;
87     }
88
89     /**
90      * @see org.apache.hivemind.annotations.TypedRegistry#getService(java.lang.Class)
91      */

92     public <T> T getService(Class JavaDoc<T> serviceInterface)
93     {
94         Object JavaDoc service = _delegate.getService(serviceInterface, _callingModule);
95         return (T) service;
96     }
97
98     /**
99      * @see org.apache.hivemind.annotations.TypedRegistry#getAutowiring()
100      */

101     public Autowiring getAutowiring()
102     {
103         return getService(Autowiring.class);
104     }
105
106     /**
107      * @see org.apache.hivemind.annotations.TypedRegistry#shutdown()
108      */

109     public void shutdown()
110     {
111         _delegate.shutdown();
112         
113     }
114
115 }
116
Popular Tags