KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > definition > impl > RegistryDefinitionImpl


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.definition.impl;
16
17 import java.util.ArrayList JavaDoc;
18 import java.util.Collection JavaDoc;
19 import java.util.Collections JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.hivemind.ApplicationRuntimeException;
27 import org.apache.hivemind.definition.ConfigurationPointDefinition;
28 import org.apache.hivemind.definition.DefinitionMessages;
29 import org.apache.hivemind.definition.ModuleDefinition;
30 import org.apache.hivemind.definition.RegistryDefinition;
31 import org.apache.hivemind.definition.RegistryDefinitionPostProcessor;
32 import org.apache.hivemind.definition.ServicePointDefinition;
33 import org.apache.hivemind.events.RegistryInitializationListener;
34 import org.apache.hivemind.util.IdUtils;
35
36 /**
37  * Default implementation of {@link RegistryDefinition}.
38  *
39  * @author Achim Huegen
40  */

41 public class RegistryDefinitionImpl implements RegistryDefinition
42 {
43     private static final Log LOG = LogFactory.getLog(RegistryDefinitionImpl.class);
44
45     private Map JavaDoc _modules = new HashMap JavaDoc();
46
47     private List JavaDoc _postProcessors = new ArrayList JavaDoc();
48     
49     private List JavaDoc _initializationListeners = new ArrayList JavaDoc();
50
51     public RegistryDefinitionImpl()
52     {
53     }
54     
55     /**
56      * @see org.apache.hivemind.definition.RegistryDefinition#addModule(org.apache.hivemind.definition.ModuleDefinition)
57      */

58     public void addModule(ModuleDefinition module) throws ApplicationRuntimeException
59     {
60         if (_modules.containsKey(module.getId()))
61         {
62             throw new ApplicationRuntimeException(DefinitionMessages.duplicateModuleId(module.getId()));
63         }
64         else
65         {
66             if (LOG.isDebugEnabled())
67                 LOG.debug("Adding module " + module.getId() + " to registry definition");
68
69             _modules.put(module.getId(), module);
70         }
71     }
72     
73     /**
74      * @see org.apache.hivemind.definition.RegistryDefinition#addPostProcessor(org.apache.hivemind.definition.RegistryDefinitionPostProcessor)
75      */

76     public void addPostProcessor(RegistryDefinitionPostProcessor postProcessor)
77     {
78         _postProcessors.add(postProcessor);
79     }
80
81     /**
82      * @see org.apache.hivemind.definition.RegistryDefinition#getPostProcessors()
83      */

84     public List JavaDoc getPostProcessors()
85     {
86         return Collections.unmodifiableList(_postProcessors);
87     }
88
89     /**
90      * @see org.apache.hivemind.definition.RegistryDefinition#addRegistryInitializationListener(org.apache.hivemind.events.RegistryInitializationListener)
91      */

92     public void addRegistryInitializationListener(RegistryInitializationListener listener)
93     {
94         _initializationListeners.add(listener);
95     }
96
97     /**
98      * @see org.apache.hivemind.definition.RegistryDefinition#getRegistryInitializationListeners()
99      */

100     public List JavaDoc getRegistryInitializationListeners()
101     {
102         return Collections.unmodifiableList(_initializationListeners);
103     }
104     
105     /**
106      * @see org.apache.hivemind.definition.RegistryDefinition#getModules()
107      */

108     public Collection JavaDoc getModules()
109     {
110         return Collections.unmodifiableCollection(_modules.values());
111     }
112
113     /**
114      * @see org.apache.hivemind.definition.RegistryDefinition#getModule(java.lang.String)
115      */

116     public ModuleDefinition getModule(String JavaDoc id)
117     {
118         return (ModuleDefinition) _modules.get(id);
119     }
120
121     /**
122      * @see org.apache.hivemind.definition.RegistryDefinition#getServicePoint(java.lang.String)
123      */

124     public ServicePointDefinition getServicePoint(String JavaDoc qualifiedServicePointId)
125     {
126         String JavaDoc moduleId = IdUtils.extractModule(qualifiedServicePointId);
127         String JavaDoc servicePointId = IdUtils.stripModule(qualifiedServicePointId);
128
129         ServicePointDefinition servicePoint = null;
130         ModuleDefinition module = getModule(moduleId);
131         if (module != null)
132         {
133             servicePoint = module.getServicePoint(servicePointId);
134         }
135         return servicePoint;
136     }
137
138     /**
139      * @see org.apache.hivemind.definition.RegistryDefinition#getConfigurationPoint(java.lang.String)
140      */

141     public ConfigurationPointDefinition getConfigurationPoint(String JavaDoc qualifiedConfigurationPointId)
142     {
143         String JavaDoc moduleId = IdUtils.extractModule(qualifiedConfigurationPointId);
144         String JavaDoc configurationPointId = IdUtils.stripModule(qualifiedConfigurationPointId);
145
146         ConfigurationPointDefinition configurationPoint = null;
147         ModuleDefinition module = getModule(moduleId);
148         if (module != null)
149         {
150             configurationPoint = module.getConfigurationPoint(configurationPointId);
151         }
152         return configurationPoint;
153     }
154
155 }
156
Popular Tags