001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements.  See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership.  The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the
007     * "License"); you may not use this file except in compliance
008     * with the License.  You may obtain a copy of the License at
009     *
010     *   http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing,
013     * software distributed under the License is distributed on an
014     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     * KIND, either express or implied.  See the License for the
016     * specific language governing permissions and limitations
017     * under the License.
018     */
019    package org.apache.geronimo.mail;
020    
021    import java.net.URL;
022    
023    import java.util.concurrent.ConcurrentMap;
024    import java.util.concurrent.ConcurrentHashMap;
025    
026    import org.osgi.framework.Bundle;
027    import org.osgi.framework.BundleEvent;
028    import org.osgi.service.log.LogService;
029    import org.osgi.util.tracker.BundleTrackerCustomizer;
030    
031    public class MailProviderBundleTrackerCustomizer implements BundleTrackerCustomizer {
032        // our base Activator (used as a service source)
033        private Activator activator;
034        // the bundle hosting the activation code
035        private Bundle activationBundle;
036    
037        public MailProviderBundleTrackerCustomizer(Activator a, Bundle b) {
038            activator = a;
039            activationBundle = b;
040        }
041    
042        /**
043         * Handle the activation of a new bundle.
044         *
045         * @param bundle The source bundle.
046         * @param event  The bundle event information.
047         *
048         * @return A return object.
049         */
050        public Object addingBundle(Bundle bundle, BundleEvent event) {
051            if (bundle.equals(activationBundle)) {
052                return null;
053            }
054    
055            return MailProviderRegistry.registerBundle(bundle);
056        }
057    
058    
059        public void modifiedBundle(Bundle bundle, BundleEvent event, Object object) {
060            // this will update for the new bundle
061            MailProviderRegistry.registerBundle(bundle);
062        }
063    
064        public void removedBundle(Bundle bundle, BundleEvent event, Object object) {
065            MailProviderRegistry.unregisterBundle(bundle);
066        }
067    
068        private void log(int level, String message) {
069            activator.log(level, message);
070        }
071    
072        private void log(int level, String message, Throwable th) {
073            activator.log(level, message, th);
074        }
075    }