KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > deployment > GBeanDataRegistry


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

17 package org.apache.geronimo.deployment;
18
19 import java.util.Collections JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.Map JavaDoc;
22 import java.util.Set JavaDoc;
23 import java.util.HashSet JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import javax.management.ObjectName JavaDoc;
26
27 import org.apache.geronimo.gbean.GBeanData;
28 import org.apache.geronimo.gbean.GBeanName;
29 import org.apache.geronimo.kernel.GBeanNotFoundException;
30
31 /**
32  * @version $Rev: $ $Date: $
33  */

34 public class GBeanDataRegistry {
35     private final Map JavaDoc registry = new HashMap JavaDoc();
36
37     public void preregister(ObjectName JavaDoc name) {
38         registry.put(name, null);
39     }
40
41     public void register(GBeanData gbean) {
42         registry.put(gbean.getName(), gbean);
43     }
44
45     public synchronized GBeanData getGBeanInstance(ObjectName JavaDoc name) throws GBeanNotFoundException {
46         GBeanData gbeanData = (GBeanData) registry.get(name);
47         if (gbeanData == null) {
48             throw new GBeanNotFoundException(name.getCanonicalName());
49         }
50         return gbeanData;
51     }
52
53     public Set JavaDoc getGBeanNames() {
54         return Collections.unmodifiableSet(registry.keySet());
55     }
56
57     public GBeanData[] getGBeans() {
58         return (GBeanData[])registry.values().toArray(new GBeanData[registry.size()]);
59     }
60
61
62     public Set JavaDoc listGBeans(ObjectName JavaDoc pattern) {
63         Set JavaDoc result = new HashSet JavaDoc();
64         for (Iterator JavaDoc i = registry.entrySet().iterator(); i.hasNext();) {
65             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) i.next();
66             ObjectName JavaDoc name = (ObjectName JavaDoc) entry.getKey();
67             if (pattern.apply(name)) {
68                 result.add(name);
69             }
70         }
71         return result;
72     }
73 }
74
Popular Tags