001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.osgi;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    
020    import org.osgi.framework.Bundle;
021    import org.osgi.framework.BundleEvent;
022    
023    /**
024     * @author Raymond Augé
025     */
026    public class BundleListener implements org.osgi.framework.BundleListener {
027    
028            public void bundleChanged(BundleEvent bundleEvent) {
029                    try {
030                            int type = bundleEvent.getType();
031    
032                            Bundle bundle = bundleEvent.getBundle();
033    
034                            Log log = LogFactoryUtil.getLog(bundle.getSymbolicName());
035    
036                            if (!log.isInfoEnabled()) {
037                                    return;
038                            }
039    
040                            if (type == BundleEvent.INSTALLED) {
041                                    log.info("[INSTALLED]");
042                            }
043                            else if (type == BundleEvent.LAZY_ACTIVATION) {
044                                    log.info("[LAZY_ACTIVATION]");
045                            }
046                            else if (type == BundleEvent.RESOLVED) {
047                                    log.info("[RESOLVED]");
048                            }
049                            else if (type == BundleEvent.STARTED) {
050                                    log.info("[STARTED]");
051                            }
052                            else if (type == BundleEvent.STARTING) {
053                                    log.info("[STARTING]");
054                            }
055                            else if (type == BundleEvent.STOPPED) {
056                                    log.info("[STOPPED]");
057                            }
058                            else if (type == BundleEvent.STOPPING) {
059                                    log.info("[STOPPING]");
060                            }
061                            else if (type == BundleEvent.UNINSTALLED) {
062                                    log.info("[UNINSTALLED]");
063                            }
064                            else if (type == BundleEvent.UNRESOLVED) {
065                                    log.info("[UNRESOLVED]");
066                            }
067                            else if (type == BundleEvent.UPDATED) {
068                                    log.info("[UPDATED]");
069                            }
070                    }
071                    catch (Exception e) {
072                            _log.error(e, e);
073                    }
074            }
075    
076            private static Log _log = LogFactoryUtil.getLog(BundleListener.class);
077    
078    }