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    package org.apache.geronimo.console.util;
018    
019    import java.lang.reflect.Array;
020    import java.util.ArrayList;
021    import java.util.Arrays;
022    import java.util.Collections;
023    import java.util.HashMap;
024    import java.util.Iterator;
025    import java.util.List;
026    import java.util.Map;
027    import java.util.Set;
028    import javax.security.auth.Subject;
029    import javax.security.auth.callback.Callback;
030    import javax.security.auth.callback.CallbackHandler;
031    import javax.security.auth.callback.NameCallback;
032    import javax.security.auth.callback.PasswordCallback;
033    import javax.security.auth.callback.UnsupportedCallbackException;
034    import javax.security.auth.login.LoginException;
035    import javax.security.auth.spi.LoginModule;
036    
037    import org.apache.geronimo.gbean.AbstractName;
038    import org.apache.geronimo.gbean.AbstractNameQuery;
039    import org.apache.geronimo.gbean.GBeanData;
040    import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
041    import org.apache.geronimo.kernel.GBeanNotFoundException;
042    import org.apache.geronimo.kernel.Kernel;
043    import org.apache.geronimo.kernel.Naming;
044    import org.apache.geronimo.kernel.config.Configuration;
045    import org.apache.geronimo.kernel.config.ConfigurationInfo;
046    import org.apache.geronimo.kernel.config.ConfigurationManager;
047    import org.apache.geronimo.kernel.config.ConfigurationModuleType;
048    import org.apache.geronimo.kernel.config.ConfigurationUtil;
049    import org.apache.geronimo.kernel.config.EditableConfigurationManager;
050    import org.apache.geronimo.kernel.config.InvalidConfigException;
051    import org.apache.geronimo.kernel.config.NoSuchStoreException;
052    import org.apache.geronimo.kernel.management.State;
053    import org.apache.geronimo.kernel.proxy.ProxyManager;
054    import org.apache.geronimo.kernel.repository.Artifact;
055    import org.apache.geronimo.management.AppClientModule;
056    import org.apache.geronimo.management.EJB;
057    import org.apache.geronimo.management.EJBModule;
058    import org.apache.geronimo.management.J2EEDeployedObject;
059    import org.apache.geronimo.management.J2EEModule;
060    import org.apache.geronimo.management.J2EEResource;
061    import org.apache.geronimo.management.JDBCDataSource;
062    import org.apache.geronimo.management.JDBCDriver;
063    import org.apache.geronimo.management.JDBCResource;
064    import org.apache.geronimo.management.JMSResource;
065    import org.apache.geronimo.management.Servlet;
066    import org.apache.geronimo.management.geronimo.J2EEApplication;
067    import org.apache.geronimo.management.geronimo.J2EEDomain;
068    import org.apache.geronimo.management.geronimo.J2EEServer;
069    import org.apache.geronimo.management.geronimo.JCAAdminObject;
070    import org.apache.geronimo.management.geronimo.JCAConnectionFactory;
071    import org.apache.geronimo.management.geronimo.JCAManagedConnectionFactory;
072    import org.apache.geronimo.management.geronimo.JCAResource;
073    import org.apache.geronimo.management.geronimo.JVM;
074    import org.apache.geronimo.management.geronimo.ResourceAdapter;
075    import org.apache.geronimo.management.geronimo.ResourceAdapterModule;
076    import org.apache.geronimo.management.geronimo.WebModule;
077    import org.apache.geronimo.security.jaas.JaasLoginModuleUse;
078    import org.apache.geronimo.system.logging.SystemLog;
079    
080    /**
081     * An implementation of the ManagementHelper interface that uses a Geronimo
082     * kernel. That must be an in-VM kernel.
083     *
084     * @version $Rev:386276 $ $Date: 2007-06-14 15:38:13 -0400 (Thu, 14 Jun 2007) $
085     */
086    public class KernelManagementHelper implements ManagementHelper {
087        private final Kernel kernel;
088    
089        public KernelManagementHelper(Kernel kernel) {
090            this.kernel = kernel;
091        }
092    
093        public J2EEDomain[] getDomains() {
094            Set domainNames = kernel.listGBeans(new AbstractNameQuery(J2EEDomain.class.getName()));
095            J2EEDomain[] result = new J2EEDomain[domainNames.size()];
096            int i = 0;
097            for (Iterator iterator = domainNames.iterator(); iterator.hasNext();) {
098                AbstractName domainName = (AbstractName) iterator.next();
099                result[i++] = (J2EEDomain) kernel.getProxyManager().createProxy(domainName, J2EEDomain.class);
100            }
101            return result;
102        }
103    
104        public J2EEServer[] getServers(J2EEDomain domain) {
105            return domain.getServerInstances();
106        }
107    
108        public J2EEDeployedObject[] getDeployedObjects(J2EEServer server) {
109            return server.getDeployedObjectInstances();
110        }
111    
112        public J2EEApplication[] getApplications(J2EEServer server) {
113            return server.getApplications();
114        }
115    
116        public AppClientModule[] getAppClients(J2EEServer server) {
117            return server.getAppClients();
118        }
119    
120        public WebModule[] getWebModules(J2EEServer server) {
121            return server.getWebModules();
122        }
123    
124        public EJBModule[] getEJBModules(J2EEServer server) {
125            return server.getEJBModules();
126        }
127    
128        public ResourceAdapterModule[] getRAModules(J2EEServer server) {
129            return server.getResourceAdapterModules();
130        }
131    
132        public JCAManagedConnectionFactory[] getOutboundFactories(J2EEServer server, String connectionFactoryInterface) {
133            List list = new ArrayList();
134            ResourceAdapterModule[] modules = server.getResourceAdapterModules();
135            for (int i = 0; i < modules.length; i++) {
136                ResourceAdapterModule module = modules[i];
137                ResourceAdapter[] adapters = module.getResourceAdapterInstances();
138                for (int j = 0; j < adapters.length; j++) {
139                    ResourceAdapter adapter = adapters[j];
140                    JCAResource[] resources = adapter.getJCAResourceImplementations();
141                    for (int k = 0; k < resources.length; k++) {
142                        JCAResource resource = resources[k];
143                        JCAManagedConnectionFactory[] outboundFactories = resource.getOutboundFactories();
144                        list.addAll(Arrays.asList(outboundFactories));
145                    }
146                }
147    
148            }
149            return (JCAManagedConnectionFactory[]) list.toArray(new JCAManagedConnectionFactory[list.size()]);
150        }
151    
152        public ResourceAdapterModule[] getOutboundRAModules(J2EEServer server, String connectionFactoryInterface) {
153            return getOutboundRAModules(server, new String[]{connectionFactoryInterface});
154        }
155    
156        public ResourceAdapterModule[] getOutboundRAModules(J2EEServer server, String[] connectionFactoryInterfaces) {
157            List list = new ArrayList();
158    
159            ResourceAdapterModule[] modules = server.getResourceAdapterModules();
160    
161            outer:
162            for (int i = 0; i < modules.length; i++) {
163                ResourceAdapterModule module = modules[i];
164                ResourceAdapter[] adapters = module.getResourceAdapterInstances();
165                for (int j = 0; j < adapters.length; j++) {
166                    ResourceAdapter adapter = adapters[j];
167                    JCAResource[] resources = adapter.getJCAResourceImplementations();
168                    for (int k = 0; k < resources.length; k++) {
169                        JCAResource resource = resources[k];
170                        JCAManagedConnectionFactory[] outboundFactories = resource.getOutboundFactories(connectionFactoryInterfaces);
171                        if (outboundFactories.length > 0) {
172                            list.add(module);
173                            continue outer;
174                        }
175                    }
176                }
177    
178            }
179            return (ResourceAdapterModule[]) list.toArray(new ResourceAdapterModule[list.size()]);
180        }
181    
182        public ResourceAdapterModule[] getAdminObjectModules(J2EEServer server, String[] adminObjectInterfaces) {
183            List list = new ArrayList();
184    
185            ResourceAdapterModule[] modules = server.getResourceAdapterModules();
186    
187            outer:
188            for (int i = 0; i < modules.length; i++) {
189                ResourceAdapterModule module = modules[i];
190                ResourceAdapter[] adapters = module.getResourceAdapterInstances();
191                for (int j = 0; j < adapters.length; j++) {
192                    ResourceAdapter adapter = adapters[j];
193                    JCAResource[] resources = adapter.getJCAResourceImplementations();
194                    for (int k = 0; k < resources.length; k++) {
195                        JCAResource resource = resources[k];
196                        JCAAdminObject[] adminObjects = resource.getAdminObjectInstances(adminObjectInterfaces);
197                        if (adminObjects.length > 0) {
198                            list.add(module);
199                            continue outer;
200                        }
201                    }
202                }
203    
204            }
205            return (ResourceAdapterModule[]) list.toArray(new ResourceAdapterModule[list.size()]);
206        }
207    
208        public JCAManagedConnectionFactory[] getOutboundFactories(ResourceAdapterModule module) {
209            return getOutboundFactories(module, (String[]) null);
210        }
211    
212        public JCAManagedConnectionFactory[] getOutboundFactories(ResourceAdapterModule module, String connectionFactoryInterface) {
213            return getOutboundFactories(module, new String[]{connectionFactoryInterface});
214        }
215    
216        public JCAManagedConnectionFactory[] getOutboundFactories(ResourceAdapterModule module, String[] connectionFactoryInterfaces) {
217            List list = new ArrayList();
218    
219            ResourceAdapter[] resourceAdapters = module.getResourceAdapterInstances();
220            for (int i = 0; i < resourceAdapters.length; i++) {
221                ResourceAdapter resourceAdapter = resourceAdapters[i];
222                JCAResource[] jcaResources = resourceAdapter.getJCAResourceImplementations();
223                for (int j = 0; j < jcaResources.length; j++) {
224                    JCAResource jcaResource = jcaResources[j];
225                    JCAManagedConnectionFactory[] outboundFactories = jcaResource.getOutboundFactories(connectionFactoryInterfaces);
226                    list.addAll(Arrays.asList(outboundFactories));
227                }
228            }
229    
230            return (JCAManagedConnectionFactory[]) list.toArray(new JCAManagedConnectionFactory[list.size()]);
231        }
232    
233        public JCAAdminObject[] getAdminObjects(ResourceAdapterModule module, String[] adminObjectInterfaces) {
234            List list = new ArrayList();
235            ResourceAdapter[] resourceAdapters = module.getResourceAdapterInstances();
236            for (int i = 0; i < resourceAdapters.length; i++) {
237                ResourceAdapter resourceAdapter = resourceAdapters[i];
238                JCAResource[] jcaResources = resourceAdapter.getJCAResourceImplementations();
239                for (int j = 0; j < jcaResources.length; j++) {
240                    JCAResource jcaResource = jcaResources[j];
241                    JCAAdminObject[] adminObjects  = jcaResource.getAdminObjectInstances(adminObjectInterfaces);
242                    list.addAll(Arrays.asList(adminObjects));
243                }
244            }
245    
246            return (JCAAdminObject[]) list.toArray(new JCAAdminObject[list.size()]);
247        }
248    
249        public J2EEResource[] getResources(J2EEServer server) {
250            return server.getResourceInstances();
251        }
252    
253        public JCAResource[] getJCAResources(J2EEServer server) {
254            List list = new ArrayList();
255            ResourceAdapterModule[] modules = server.getResourceAdapterModules();
256            for (int i = 0; i < modules.length; i++) {
257                ResourceAdapterModule module = modules[i];
258                ResourceAdapter[] adapters = module.getResourceAdapterInstances();
259                for (int j = 0; j < adapters.length; j++) {
260                    ResourceAdapter adapter = adapters[j];
261                    JCAResource[] resources = adapter.getJCAResourceImplementations();
262                    list.addAll(Arrays.asList(resources));
263                }
264    
265            }
266            return (JCAResource[]) list.toArray(new JCAResource[list.size()]);
267        }
268    
269        public JDBCResource[] getJDBCResources(J2EEServer server) {
270            return new JDBCResource[0]; // Geronimo uses JCA resources for this
271        }
272    
273        public JMSResource[] getJMSResources(J2EEServer server) {
274            return new JMSResource[0];  // Geronimo uses JCA resources for this
275        }
276    
277        public JVM[] getJavaVMs(J2EEServer server) {
278            return server.getJavaVMInstances();
279        }
280    
281        public SystemLog getSystemLog(JVM jvm) {
282            return jvm.getSystemLog();
283        }
284    
285        // application properties
286        public J2EEModule[] getModules(J2EEApplication application) {
287            return application.getModulesInstances();
288        }
289    
290        public AppClientModule[] getAppClients(J2EEApplication application) {
291            return application.getClientModules();
292        }
293    
294        public WebModule[] getWebModules(J2EEApplication application) {
295            return application.getWebModules();
296        }
297    
298        public EJBModule[] getEJBModules(J2EEApplication application) {
299            return application.getEJBModules();
300        }
301    
302        public ResourceAdapterModule[] getRAModules(J2EEApplication application) {
303            return application.getRAModules();
304        }
305    
306    
307        public JCAResource[] getJCAResources(J2EEApplication application) {
308            List list = new ArrayList();
309            ResourceAdapterModule[] modules = application.getRAModules();
310            for (int i = 0; i < modules.length; i++) {
311                ResourceAdapterModule module = modules[i];
312                ResourceAdapter[] adapters = module.getResourceAdapterInstances();
313                for (int j = 0; j < adapters.length; j++) {
314                    ResourceAdapter adapter = adapters[j];
315                    JCAResource[] resources = adapter.getJCAResourceImplementations();
316                    list.addAll(Arrays.asList(resources));
317                }
318    
319            }
320            return (JCAResource[]) list.toArray(new JCAResource[list.size()]);
321        }
322    
323        public JDBCResource[] getJDBCResources(J2EEApplication application) {
324            return new JDBCResource[0];  // Geronimo uses JCAResources for this
325        }
326    
327        public JMSResource[] getJMSResources(J2EEApplication application) {
328            return new JMSResource[0];  // Geronimo uses JCAResources for this
329        }
330    
331        // module properties
332        public EJB[] getEJBs(EJBModule module) {
333            return new EJB[0];  //todo
334        }
335    
336        public Servlet[] getServlets(WebModule module) {
337            return new Servlet[0];  //todo
338        }
339    
340        public ResourceAdapter[] getResourceAdapters(ResourceAdapterModule module) {
341            return module.getResourceAdapterInstances();
342        }
343    
344        // resource adapter properties
345        public JCAResource[] getRAResources(ResourceAdapter adapter) {
346            return adapter.getJCAResourceImplementations();
347        }
348    
349        // resource properties
350        public JDBCDataSource[] getDataSource(JDBCResource resource) {
351            return new JDBCDataSource[0];  //todo
352        }
353    
354        public JDBCDriver[] getDriver(JDBCDataSource dataSource) {
355            return new JDBCDriver[0];  //todo
356        }
357    
358        public JCAConnectionFactory[] getConnectionFactories(JCAResource resource) {
359            return resource.getConnectionFactoryInstances();
360        }
361    
362        public JCAAdminObject[] getAdminObjects(JCAResource resource) {
363            return resource.getAdminObjectInstances();
364        }
365    
366        public JCAManagedConnectionFactory getManagedConnectionFactory(JCAConnectionFactory factory) {
367            return factory.getManagedConnectionFactoryInstance();
368        }
369    
370        public Object getObject(AbstractName objectName) {
371            ClassLoader cl = null;
372            try {
373                cl = kernel.getClassLoaderFor(objectName);
374            } catch(GBeanNotFoundException e) {
375                cl = KernelManagementHelper.class.getClassLoader();
376            }
377            return kernel.getProxyManager().createProxy(objectName, cl);
378        }
379    
380        public Artifact getConfigurationNameFor(AbstractName abstractName) {
381            return abstractName.getArtifact();
382        }
383    
384        public String getGBeanDescription(AbstractName abstractName) {
385            try {
386                return kernel.getGBeanInfo(abstractName).getName();
387            } catch (GBeanNotFoundException e) {
388                return null;
389            }
390        }
391    
392        public void testLoginModule(J2EEServer server, LoginModule module, Map options) {
393            options.put(JaasLoginModuleUse.KERNEL_NAME_LM_OPTION, kernel.getKernelName());
394            options.put(JaasLoginModuleUse.SERVERINFO_LM_OPTION, server.getServerInfo());
395            if (!options.containsKey(JaasLoginModuleUse.CLASSLOADER_LM_OPTION)) {
396                options.put(JaasLoginModuleUse.CLASSLOADER_LM_OPTION, module.getClass().getClassLoader());
397            }
398            module.initialize(null, null, new HashMap(), options);
399        }
400    
401        public Subject testLoginModule(final J2EEServer server, final LoginModule module, final Map options, final String username, final String password) throws LoginException {
402            options.put(JaasLoginModuleUse.KERNEL_NAME_LM_OPTION, kernel.getKernelName());
403            if (!options.containsKey(JaasLoginModuleUse.CLASSLOADER_LM_OPTION)) {
404                options.put(JaasLoginModuleUse.CLASSLOADER_LM_OPTION, module.getClass().getClassLoader());
405            }
406            options.put(JaasLoginModuleUse.SERVERINFO_LM_OPTION, server.getServerInfo());
407            Subject sub = new Subject();
408            CallbackHandler handler = new CallbackHandler() {
409                public void handle(Callback[] callbacks) throws UnsupportedCallbackException {
410                    for (int i = 0; i < callbacks.length; i++) {
411                        Callback callback = callbacks[i];
412                        if (callback instanceof PasswordCallback) {
413                            ((PasswordCallback) callback).setPassword(password.toCharArray());
414                        } else if (callback instanceof NameCallback) {
415                            ((NameCallback) callback).setName(username);
416                        } else {
417                            throw new UnsupportedCallbackException(callback);
418                        }
419                    }
420                }
421            };
422            module.initialize(sub, handler, new HashMap(), options);
423            if (module.login() && module.commit()) {
424                return sub;
425            } else {
426                module.abort();
427            }
428            return null;
429        }
430    
431        public Object[] findByInterface(Class iface) {
432            Set set = kernel.listGBeans(new AbstractNameQuery(iface.getName()));
433            Object[] result = new Object[set.size()];
434            int i = 0;
435            for (Iterator it = set.iterator(); it.hasNext();) {
436                AbstractName name = (AbstractName) it.next();
437                result[i++] = kernel.getProxyManager().createProxy(name, iface.getClassLoader());
438            }
439            return result;
440        }
441    
442        public AbstractName getNameFor(Object component) {
443            return kernel.getAbstractNameFor(component);
444        }
445    
446        public ConfigurationData[] getConfigurations(ConfigurationModuleType type, boolean includeChildModules) {
447            ConfigurationManager mgr = ConfigurationUtil.getConfigurationManager(kernel);
448            List stores = mgr.listStores();
449            List results = new ArrayList();
450            for (Iterator i = stores.iterator(); i.hasNext();) {
451                AbstractName storeName = (AbstractName) i.next();
452                try {
453                    List infos = mgr.listConfigurations(storeName);
454                    for (Iterator j = infos.iterator(); j.hasNext();) {
455                        ConfigurationInfo info = (ConfigurationInfo) j.next();
456                        AbstractName configuration = Configuration.getConfigurationAbstractName(info.getConfigID());
457                        if (type == null || type.getValue() == info.getType().getValue()) {
458                            J2EEDeployedObject module = getModuleForConfiguration(info.getConfigID());
459                            results.add(new ConfigurationData(info.getConfigID(), configuration, null, info.getState(), info.getType(), module == null ? null : kernel.getAbstractNameFor(module)));
460                        }
461                        if (includeChildModules && info.getType().getValue() == ConfigurationModuleType.EAR.getValue() && info.getState().toInt() == State.RUNNING_INDEX)
462                        {
463                            J2EEApplication app = (J2EEApplication) getModuleForConfiguration(info.getConfigID());
464                            if (app == null) {
465                                throw new IllegalStateException("Unable to load children for J2EE Application '" + info.getConfigID() + "' (no J2EEApplication found)");
466                            }
467                            Object[] modules = null;
468                            if (type == null) {
469                                modules = app.getModulesInstances();
470                            } else if (type.equals(ConfigurationModuleType.CAR)) {
471                                modules = app.getClientModules();
472                            } else if (type.equals(ConfigurationModuleType.EJB)) {
473                                modules = app.getEJBModules();
474                            } else if (type.equals(ConfigurationModuleType.RAR)) {
475                                modules = app.getRAModules();
476                            } else if (type.equals(ConfigurationModuleType.WAR)) {
477                                modules = app.getWebModules();
478                            } //todo: handle dynamically registered module types, etc.
479                            if (modules == null) continue;
480                            for (int k = 0; k < modules.length; k++) {
481                                Object module = modules[k];
482                                ConfigurationModuleType moduleType = type;
483                                if (moduleType == null) {
484                                    if (module instanceof WebModule) {
485                                        moduleType = ConfigurationModuleType.WAR;
486                                    } else if (module instanceof EJBModule) {
487                                        moduleType = ConfigurationModuleType.EJB;
488                                    } else if (module instanceof ResourceAdapterModule) {
489                                        moduleType = ConfigurationModuleType.RAR;
490                                    } else if (module instanceof AppClientModule) moduleType = ConfigurationModuleType.CAR;
491                                }
492                                String moduleName;
493                                if (type != null && type.equals(ConfigurationModuleType.WAR)) {
494                                    moduleName = ((WebModule) module).getWARName();
495                                } else {
496                                    //todo: solutions for other module types
497                                    moduleName = (String) kernel.getAbstractNameFor(module).getName().get(NameFactory.J2EE_NAME);
498                                }
499                                results.add(new ConfigurationData(info.getConfigID(), configuration, moduleName, info.getState(), moduleType, kernel.getAbstractNameFor(module)));
500                            }
501                        }
502                    }
503                } catch (NoSuchStoreException e) {
504                    // we just got this list so this should not happen
505                    // in the unlikely event it does, just continue
506                } catch (InvalidConfigException e) {
507                    throw new RuntimeException("Bad configID; should never happen", e);
508                }
509            }
510            Collections.sort(results);
511            return (ConfigurationData[]) results.toArray(new ConfigurationData[results.size()]);
512        }
513    
514        /**
515         * Gets a JSR-77 Module (WebModule, EJBModule, etc.) for the specified configuration.
516         * Note: this only works if the configuration is running at the time you ask.
517         *
518         * @return The Module, or null if the configuration is not running.
519         */
520        public J2EEDeployedObject getModuleForConfiguration(Artifact configuration) {
521            ConfigurationManager manager = ConfigurationUtil.getConfigurationManager(kernel);
522            Configuration config = manager.getConfiguration(configuration);
523            if (config == null || !manager.isRunning(configuration)) {
524                return null; // The configuration is not running, so we can't get its contents
525            }
526            ConfigurationModuleType type = config.getModuleType();
527            AbstractName result;
528            try {
529                if (type.equals(ConfigurationModuleType.CAR)) {
530                    result = config.findGBean(new AbstractNameQuery(AppClientModule.class.getName()));
531                } else if (type.equals(ConfigurationModuleType.EAR)) {
532                    result = config.findGBean(new AbstractNameQuery(J2EEApplication.class.getName()));
533                } else if (type.equals(ConfigurationModuleType.EJB)) {
534                    result = config.findGBean(new AbstractNameQuery(EJBModule.class.getName()));
535                } else if (type.equals(ConfigurationModuleType.RAR)) {
536                    result = config.findGBean(new AbstractNameQuery(ResourceAdapterModule.class.getName()));
537                } else if (type.equals(ConfigurationModuleType.WAR)) {
538                    result = config.findGBean(new AbstractNameQuery(WebModule.class.getName()));
539                } else {
540                    return null;
541                }
542                return (J2EEDeployedObject) kernel.getProxyManager().createProxy(result, getClass().getClassLoader());
543            } catch (GBeanNotFoundException e) {
544                throw new IllegalStateException("Bad config ID: " + e.getMessage(), e);
545            }
546        }
547    
548        public Object[] getGBeansImplementing(Class iface) {
549            Set set = kernel.listGBeans(new AbstractNameQuery(iface.getName()));
550            Object[] result = (Object[]) Array.newInstance(iface, set.size());
551            int index = 0;
552            ProxyManager mgr = kernel.getProxyManager();
553            for (Iterator it = set.iterator(); it.hasNext();) {
554                AbstractName name = (AbstractName) it.next();
555                result[index++] = mgr.createProxy(name, iface);
556            }
557            return result;
558        }    
559        
560        /**
561         * Adds a new GBean to an existing Configuration.
562         * @param configID  The configuration to add the GBean to.
563         * @param gbean     The data representing the GBean to add.
564         * @param start     If true, the GBean should be started as part of this call.
565         */
566        public void addGBeanToConfiguration(Artifact configID, GBeanData gbean, boolean start) {
567            EditableConfigurationManager mgr = ConfigurationUtil.getEditableConfigurationManager(kernel);
568            try {
569                mgr.addGBeanToConfiguration(configID, gbean, start);
570            } catch (InvalidConfigException e) {
571                throw new RuntimeException("Bad configID. configID = "+configID, e);
572            } finally {
573                ConfigurationUtil.releaseConfigurationManager(kernel, mgr);
574            }
575        }
576    
577        /**
578         * This method returns the Naming object of the kernel.
579         */
580        public Naming getNaming() {
581            return kernel.getNaming();
582        }
583    
584        /**
585         * Helper method to connect to a remote kernel.
586         */
587        public static KernelManagementHelper getRemoteKernelManager(String host, String user, String password) throws java.io.IOException {
588            String uri = "jmx:rmi://" + host + "/jndi/rmi:/JMXConnector";
589            java.util.Map environment = new java.util.HashMap();
590            String[] credentials = new String[]{user, password};
591            environment.put(javax.management.remote.JMXConnector.CREDENTIALS, credentials);
592            javax.management.remote.JMXServiceURL address = new javax.management.remote.JMXServiceURL("service:" + uri);
593            javax.management.remote.JMXConnector jmxConnector = javax.management.remote.JMXConnectorFactory.connect(address, environment);
594            javax.management.MBeanServerConnection mbServerConnection = jmxConnector.getMBeanServerConnection();
595            Kernel kernel = new org.apache.geronimo.system.jmx.KernelDelegate(mbServerConnection);
596            return new KernelManagementHelper(kernel);
597        }
598    }