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 package org.apache.geronimo.deployment.plugin.jmx; 18 19 import java.util.ArrayList; 20 import java.util.Collection; 21 import java.util.Set; 22 23 import org.slf4j.Logger; 24 import org.slf4j.LoggerFactory; 25 import org.apache.geronimo.deployment.ModuleConfigurer; 26 import org.apache.geronimo.gbean.AbstractName; 27 import org.apache.geronimo.gbean.AbstractNameQuery; 28 import org.apache.geronimo.kernel.GBeanNotFoundException; 29 import org.apache.geronimo.kernel.Kernel; 30 31 /** 32 * Connects to a kernel in the same VM. 33 * 34 * @version $Rev: 697438 $ $Date: 2008-09-20 17:45:30 -0700 (Sat, 20 Sep 2008) $ 35 */ 36 public class LocalDeploymentManager extends JMXDeploymentManager { 37 private static final Logger log = LoggerFactory.getLogger(LocalDeploymentManager.class); 38 private static final AbstractNameQuery CONFIGURER_QUERY = new AbstractNameQuery(ModuleConfigurer.class.getName()); 39 40 public LocalDeploymentManager(Kernel kernel) { 41 super(loadModuleConfigurers(kernel)); 42 initialize(kernel); 43 } 44 45 private static Collection<ModuleConfigurer> loadModuleConfigurers(Kernel kernel) { 46 Collection<ModuleConfigurer> moduleConfigurers = new ArrayList<ModuleConfigurer>(); 47 Set configurerNames = kernel.listGBeans(CONFIGURER_QUERY); 48 for (Object configurerName : configurerNames) { 49 AbstractName name = (AbstractName) configurerName; 50 try { 51 Object o = kernel.getGBean(name); 52 if (!(o instanceof ModuleConfigurer)) { 53 log.error("Gbean classloader: " + o.getClass().getClassLoader()); 54 log.error("ModuleConfigurer classloader: " + ModuleConfigurer.class.getClassLoader()); 55 } 56 ModuleConfigurer configurer = (ModuleConfigurer) o; 57 moduleConfigurers.add(configurer); 58 } catch (GBeanNotFoundException e) { 59 log.warn("No gbean found for name returned in query : " + name); 60 } 61 } 62 return moduleConfigurers; 63 } 64 65 }