aboutsummaryrefslogtreecommitdiffstats
path: root/container-disc/src/main/java/com/yahoo/container/jdisc/DisableOsgiFramework.java
blob: 07726f3356f83ee28d36b9ec1371fbd8b146729a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.jdisc;

import com.yahoo.jdisc.application.OsgiFramework;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;

import java.util.List;

/**
 * @author tonytv
 */
public final class DisableOsgiFramework implements OsgiFramework {
    private final RestrictedBundleContext restrictedBundleContext;

    public DisableOsgiFramework() {
        this.restrictedBundleContext = null;
    }

    public DisableOsgiFramework(RestrictedBundleContext restrictedBundleContext) {
        this.restrictedBundleContext = restrictedBundleContext;
    }

    @Override
    public List<Bundle> installBundle(String bundleLocation) throws BundleException {
        throw newException();
    }

    @Override
    public void startBundles(List<Bundle> bundles, boolean privileged) throws BundleException {
        throw newException();
    }

    @Override
    public void refreshPackages() {
        throw newException();
    }

    @Override
    public BundleContext bundleContext() {
        if (restrictedBundleContext == null) {
            throw newException();
        }
        return restrictedBundleContext;
    }

    @Override
    public List<Bundle> bundles() {
        throw newException();
    }

    @Override
    public void start() throws BundleException {
        throw newException();
    }

    @Override
    public void stop() throws BundleException {
        throw newException();
    }

    private RuntimeException newException() {
        return new UnsupportedOperationException("The OSGi framework is not available to components.");
    }
}