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.i18n;
019
020 import org.apache.commons.logging.Log;
021 import org.apache.commons.logging.LogFactory;
022 import org.apache.geronimo.gbean.GBeanInfo;
023 import org.apache.geronimo.gbean.GBeanInfoBuilder;
024 import org.apache.geronimo.gbean.GBeanLifecycle;
025
026 /**
027 * This GBean provides a way for console extension to register its classloader to
028 * ConsoleResourceRegistry. ConsoleResourceRegistry will use the classloaders to
029 * load the resource bundle.
030 */
031 public class ConsoleResourceGBean implements GBeanLifecycle {
032 private static final Log log = LogFactory.getLog(ConsoleResourceGBean.class);
033 public static final GBeanInfo GBEAN_INFO;
034 private ClassLoader classloader;
035 private ConsoleResourceRegistry consoleResourceRegistry;
036
037 public ConsoleResourceGBean(ClassLoader classloader, ConsoleResourceRegistry consoleResourceRegistry) {
038 this.classloader = classloader;
039 this.consoleResourceRegistry = consoleResourceRegistry;
040 }
041
042 /*
043 * Called when the GBean is started
044 * @see org.apache.geronimo.gbean.GBeanLifecycle#doStart()
045 */
046 public synchronized void doStart() throws Exception {
047 consoleResourceRegistry.registerConsoleResource(classloader);
048 }
049
050 /*
051 * Called when the GBean is stopped
052 * @see org.apache.geronimo.gbean.GBeanLifecycle#doStop()
053 */
054 public synchronized void doStop() throws Exception {
055 consoleResourceRegistry.removeConsoleResource(classloader);
056 }
057
058 /*
059 * Called when the GBean fails
060 * @see org.apache.geronimo.gbean.GBeanLifecycle#doFail()
061 */
062 public synchronized void doFail() {
063 log.warn("AdminConsoleExtensionGBean for failed.");
064 }
065
066 /*
067 * Standard GBean information
068 */
069 static {
070 GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("ConsoleResourceGBean", ConsoleResourceGBean.class);
071
072 infoFactory.addAttribute("classLoader", ClassLoader.class, false);
073 infoFactory.addReference("ConsoleResourceRegistry", ConsoleResourceRegistry.class, null);
074 infoFactory.setConstructor(new String[]{
075 "classLoader",
076 "ConsoleResourceRegistry"});
077 GBEAN_INFO = infoFactory.getBeanInfo();
078 }
079
080 public static GBeanInfo getGBeanInfo() {
081 return GBEAN_INFO;
082 }
083 }