KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > annotations > AbstractAnnotatedModule


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;
16
17 import org.apache.hivemind.service.Autowiring;
18
19 /**
20  * Ancestor for annotated module classes. Provides convenience methods
21  * for the access to {@link TypedRegistry} and {@link Autowiring}.
22  *
23  * @author Achim Huegen
24  */

25 public class AbstractAnnotatedModule
26 {
27     private TypedRegistry _typedRegistry;
28
29     /**
30      * @return the registry the module is loaded in
31      */

32     public TypedRegistry getRegistry()
33     {
34         return _typedRegistry;
35     }
36
37     /**
38      * This setter is used to inject the registry reference.
39      * @param typedRegistry the registry
40      */

41     public void setRegistry(TypedRegistry typedRegistry)
42     {
43         _typedRegistry = typedRegistry;
44     }
45     
46     /**
47      * @return a reference to the {@link Autowiring} service.
48      */

49     protected Autowiring getAutowiring()
50     {
51         return _typedRegistry.getAutowiring();
52     }
53     
54     /**
55      * Autowires any object by use of the {@link Autowiring} service.
56      * @param target the object to wire
57      * @return the wired object
58      */

59     protected <T> T autowireProperties(T target)
60     {
61         return (T) getAutowiring().autowireProperties(target);
62     }
63     
64     /**
65      * Returns a service from the registry.
66      *
67      * @see org.apache.hivemind.Registry#getService(String, Class)
68      */

69     protected <T> T service(String JavaDoc serviceId, Class JavaDoc<T> serviceInterface)
70     {
71         return _typedRegistry.getService(serviceId, serviceInterface);
72     }
73
74     /**
75      * Finds a service that implements the provided interface.
76      * Exactly one such service may exist or an exception is thrown.
77      *
78      * @see org.apache.hivemind.Registry#getService(Class)
79      */

80     protected <T> T service(Class JavaDoc<T> serviceInterface)
81     {
82         return _typedRegistry.getService(serviceInterface);
83     }
84     
85     /**
86      * Returns the specified configuration from the registry.
87      *
88      * @see org.apache.hivemind.Registry#getConfiguration(String)
89      */

90     protected <T> T configuration(String JavaDoc configurationId, Class JavaDoc<T> configurationType)
91     {
92         return _typedRegistry.getConfiguration(configurationId, configurationType);
93     }
94     
95     /**
96      * Finds a configuration by its type.
97      * Exactly one such configuration may exist or an exception is thrown.
98      *
99      * @see org.apache.hivemind.Registry#getConfiguration(String)
100      */

101     protected <T> T configuration(Class JavaDoc<T> configurationType)
102     {
103         return _typedRegistry.getConfiguration(configurationType);
104     }
105
106 }
107
Popular Tags