01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.geronimo.console.util;
17:
18: import java.util.HashMap;
19: import java.util.Map;
20: import java.util.Set;
21:
22: import org.apache.geronimo.gbean.AbstractName;
23: import org.apache.geronimo.gbean.AbstractNameQuery;
24: import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
25: import org.apache.geronimo.kernel.Kernel;
26: import org.apache.geronimo.kernel.KernelRegistry;
27:
28: /**
29: * @version $Rev: 566146 $ $Date: 2007-08-15 06:43:23 -0700 (Wed, 15 Aug 2007) $
30: */
31: public final class ObjectNameConstants {
32:
33: // Security object names
34: public static final AbstractName SE_REALM_MBEAN_NAME;
35: public static final AbstractName DEPLOYER_OBJECT_NAME;
36:
37: static {
38: Kernel kernel = KernelRegistry.getSingleKernel();
39: SE_REALM_MBEAN_NAME = getUniquename("PropertiesLoginManager",
40: "GBean", kernel);
41: DEPLOYER_OBJECT_NAME = getUniquename("Deployer", "Deployer",
42: kernel);
43: }
44:
45: private static AbstractName getUniquename(String name, String type,
46: Kernel kernel) {
47: Map properties = new HashMap(2);
48: properties.put(NameFactory.J2EE_NAME, name);
49: properties.put(NameFactory.J2EE_TYPE, type);
50: AbstractNameQuery query = new AbstractNameQuery(null,
51: properties);
52: Set results = kernel.listGBeans(query);
53: if (results.isEmpty()) {
54: throw new RuntimeException("No services found with name "
55: + name + " and type " + type);
56: }
57: if (results.size() != 1) {
58: throw new RuntimeException(
59: "More than one service was found with name " + name
60: + " and type " + type + ", returns: "
61: + results);
62: }
63: return (AbstractName) results.iterator().next();
64: }
65:
66: }
|