KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > console > util > ObjectNameConstants


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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
18 package org.apache.geronimo.console.util;
19
20 import java.util.HashMap JavaDoc;
21 import java.util.Map JavaDoc;
22 import java.util.Set JavaDoc;
23
24 import org.apache.geronimo.gbean.AbstractName;
25 import org.apache.geronimo.gbean.AbstractNameQuery;
26 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
27 import org.apache.geronimo.kernel.Kernel;
28 import org.apache.geronimo.kernel.KernelRegistry;
29
30 /**
31  * @version $Rev: 482143 $ $Date: 2006-12-04 06:34:57 -0500 (Mon, 04 Dec 2006) $
32  */

33 public final class ObjectNameConstants {
34
35     // Security object names
36
public static final AbstractName SE_REALM_MBEAN_NAME;
37     public static final AbstractName DEPLOYER_OBJECT_NAME;
38
39     static {
40         Kernel kernel = KernelRegistry.getSingleKernel();
41         SE_REALM_MBEAN_NAME = getUniquename("PropertiesLoginManager", "GBean", kernel);
42         DEPLOYER_OBJECT_NAME = getUniquename("Deployer", "Deployer", kernel);
43     }
44
45     private static AbstractName getUniquename(String JavaDoc name, String JavaDoc type, Kernel kernel) {
46         Map JavaDoc properties = new HashMap JavaDoc(2);
47         properties.put(NameFactory.J2EE_NAME, name);
48         properties.put(NameFactory.J2EE_TYPE, type);
49         AbstractNameQuery query = new AbstractNameQuery(null, properties);
50         Set JavaDoc results = kernel.listGBeans(query);
51         if (results.isEmpty()) {
52             throw new RuntimeException JavaDoc("No services found with name " + name + " and type " + type);
53         }
54         if (results.size() != 1) {
55             throw new RuntimeException JavaDoc("More than one service was found with name " + name + " and type " + type + ", returns: " + results);
56         }
57         return (AbstractName) results.iterator().next();
58     }
59
60 }
61
Popular Tags