BaseBundleCheck.java 2.31 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.osgi.framework.Bundle
 *  org.osgi.framework.BundleContext
 *  org.osgi.framework.InvalidSyntaxException
 *  org.osgi.service.cm.Configuration
 *  org.osgi.service.cm.ConfigurationAdmin
 */
package com.adobe.granite.bundles.hc.impl;

import java.io.IOException;
import java.util.Dictionary;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;

public class BaseBundleCheck {
    protected String bundleName = "";
    protected String serviceName = "";

    protected BaseBundleCheck(String bundleName, String serviceName) {
        this.bundleName = bundleName;
        this.serviceName = serviceName;
    }

    protected boolean isConfigurationUnbound(Configuration[] config) {
        return config == null || config.length == 1 && config[0].getBundleLocation() == null;
    }

    protected boolean isLazyActivation(Bundle b) {
        return "lazy".equals(b.getHeaders().get("Bundle-ActivationPolicy"));
    }

    protected boolean isBundleActive(BundleContext bundleContext) {
        boolean bundleFound = false;
        if (this.bundleName != null) {
            Bundle[] bundles;
            for (Bundle bundle : bundles = bundleContext.getBundles()) {
                String symbolicName;
                Dictionary headers = bundle.getHeaders();
                if (headers == null || (symbolicName = (String)headers.get("Bundle-SymbolicName")) == null || !this.bundleName.equals(symbolicName)) continue;
                if (bundle.getState() != 32 && (bundle.getState() != 8 || !this.isLazyActivation(bundle))) break;
                bundleFound = true;
                break;
            }
        }
        return bundleFound;
    }

    protected Configuration[] getServletConfigs(ConfigurationAdmin configurationAdmin) {
        Configuration[] servletCfgs = null;
        String filter = "(service.pid=" + this.serviceName + ")";
        try {
            servletCfgs = configurationAdmin.listConfigurations(filter);
        }
        catch (IOException var4_4) {
        }
        catch (InvalidSyntaxException var4_5) {
            // empty catch block
        }
        return servletCfgs;
    }
}