001    /**
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    
018    package org.apache.geronimo.console.util;
019    
020    import java.util.HashMap;
021    import java.util.Map;
022    import java.util.Set;
023    
024    import org.apache.geronimo.gbean.AbstractName;
025    import org.apache.geronimo.gbean.AbstractNameQuery;
026    import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
027    import org.apache.geronimo.kernel.Kernel;
028    import org.apache.geronimo.kernel.KernelRegistry;
029    
030    /**
031     * @version $Rev: 482143 $ $Date: 2006-12-04 06:34:57 -0500 (Mon, 04 Dec 2006) $
032     */
033    public final class ObjectNameConstants {
034    
035        // Security object names
036        public static final AbstractName SE_REALM_MBEAN_NAME;
037        public static final AbstractName DEPLOYER_OBJECT_NAME;
038    
039        static {
040            Kernel kernel = KernelRegistry.getSingleKernel();
041            SE_REALM_MBEAN_NAME = getUniquename("PropertiesLoginManager", "GBean", kernel);
042            DEPLOYER_OBJECT_NAME = getUniquename("Deployer", "Deployer", kernel);
043        }
044    
045        private static AbstractName getUniquename(String name, String type, Kernel kernel) {
046            Map properties = new HashMap(2);
047            properties.put(NameFactory.J2EE_NAME, name);
048            properties.put(NameFactory.J2EE_TYPE, type);
049            AbstractNameQuery query = new AbstractNameQuery(null, properties);
050            Set results = kernel.listGBeans(query);
051            if (results.isEmpty()) {
052                throw new RuntimeException("No services found with name " + name + " and type " + type);
053            }
054            if (results.size() != 1) {
055                throw new RuntimeException("More than one service was found with name " + name + " and type " + type + ", returns: " + results);
056            }
057            return (AbstractName) results.iterator().next();
058        }
059    
060    }