/*-
 * ~~~~~~licensing~~~~~~
 * system-commons
 * ==========
 * Copyright (C) 2020 - 2021 EmDev LLC
 * ==========
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ~~~~~~/licensing~~~~~~
 */
package ru.entaxy.esb.system.common.osgi;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleEvent;
import org.osgi.util.tracker.BundleTrackerCustomizer;

public abstract class UniformBundleTracker implements BundleTrackerCustomizer {

    @Override
    public Object addingBundle(Bundle bundle, BundleEvent event) {
        if (event == null) {
            // existing bundles first added to the tracker with no event change
            checkInitialBundle(bundle);
        } else {
            bundleChanged(event);
        }
        return bundle;
    }

    @Override
    public void modifiedBundle(Bundle bundle, BundleEvent event, Object object) {
        if (event == null) {
            // cannot think of why we would be interested in a modified bundle with no bundle event
            return;
        }
        bundleChanged(event);
    }

    @Override
    public void removedBundle(Bundle bundle, BundleEvent event, Object object) {
        // TODO Auto-generated method stub

    }

    protected abstract void checkInitialBundle(Bundle bundle);

    protected abstract void bundleChanged(BundleEvent event);

}
