aboutsummaryrefslogtreecommitdiffstats
path: root/container-disc/src/main/java/com/yahoo/container/jdisc/RestrictedBundleContext.java
blob: a5abff072e5a9a8ba2e15a989a4343bb957f3406 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.jdisc;

import org.osgi.framework.*;

import java.io.File;
import java.io.InputStream;
import java.util.Collection;
import java.util.Collections;
import java.util.Dictionary;

/**
 * @author Einar M R Rosenvinge
 */
public class RestrictedBundleContext implements BundleContext {

    private final BundleContext wrapped;

    public RestrictedBundleContext(BundleContext wrapped) {
        this.wrapped = wrapped;
    }

    @Override
    public ServiceRegistration<?> registerService(String[] strings, Object o, Dictionary<String, ?> stringDictionary) {
        if (wrapped == null) return null;
        return wrapped.registerService(strings, o, stringDictionary);
    }

    @Override
    public ServiceRegistration<?> registerService(String localHostname, Object o, Dictionary<String, ?> stringDictionary) {
        if (wrapped == null) return null;
        return wrapped.registerService(localHostname, o, stringDictionary);
    }

    @Override
    public <S> ServiceRegistration<S> registerService(Class<S> sClass, S s, Dictionary<String, ?> stringDictionary) {
        if (wrapped == null) return null;
        return wrapped.registerService(sClass, s, stringDictionary);
    }

    @Override
    public <S> ServiceRegistration<S> registerService(Class<S> aClass, ServiceFactory<S> serviceFactory, Dictionary<String, ?> dictionary) {
        return null;
    }

    @Override
    public ServiceReference<?>[] getServiceReferences(String localHostname, String localHostname2) throws InvalidSyntaxException {
        if (wrapped == null) return new ServiceReference<?>[0];
        return wrapped.getServiceReferences(localHostname, localHostname2);
    }

    @Override
    public ServiceReference<?>[] getAllServiceReferences(String localHostname, String localHostname2) throws InvalidSyntaxException {
        if (wrapped == null) return new ServiceReference<?>[0];
        return wrapped.getAllServiceReferences(localHostname, localHostname2);
    }

    @Override
    public ServiceReference<?> getServiceReference(String localHostname) {
        if (wrapped == null) return null;
        return wrapped.getServiceReference(localHostname);
    }

    @Override
    public <S> ServiceReference<S> getServiceReference(Class<S> sClass) {
        if (wrapped == null) return null;
        return wrapped.getServiceReference(sClass);
    }

    @Override
    public <S> Collection<ServiceReference<S>> getServiceReferences(Class<S> sClass, String localHostname) throws InvalidSyntaxException {
        if (wrapped == null) return Collections.<ServiceReference<S>>emptyList();
        return wrapped.getServiceReferences(sClass, localHostname);
    }

    @Override
    public <S> S getService(ServiceReference<S> sServiceReference) {
        if (wrapped == null) return null;
        return wrapped.getService(sServiceReference);
    }

    @Override
    public boolean ungetService(ServiceReference<?> serviceReference) {
        if (wrapped == null) return false;
        return wrapped.ungetService(serviceReference);
    }

    @Override
    public <S> ServiceObjects<S> getServiceObjects(ServiceReference<S> serviceReference) {
        return null;
    }

    @Override
    public String getProperty(String localHostname) {
        throw newException();
    }

    @Override
    public Bundle getBundle() {
        throw newException();
    }

    @Override
    public Bundle installBundle(String localHostname, InputStream inputStream) throws BundleException {
        throw newException();
    }

    @Override
    public Bundle installBundle(String localHostname) throws BundleException {
        throw newException();
    }

    @Override
    public Bundle getBundle(long l) {
        throw newException();
    }

    @Override
    public Bundle[] getBundles() {
        throw newException();
    }

    @Override
    public void addServiceListener(ServiceListener serviceListener, String localHostname) throws InvalidSyntaxException {
        throw newException();
    }

    @Override
    public void addServiceListener(ServiceListener serviceListener) {
        throw newException();
    }

    @Override
    public void removeServiceListener(ServiceListener serviceListener) {
        throw newException();
    }

    @Override
    public void addBundleListener(BundleListener bundleListener) {
        throw newException();
    }

    @Override
    public void removeBundleListener(BundleListener bundleListener) {
        throw newException();
    }

    @Override
    public void addFrameworkListener(FrameworkListener frameworkListener) {
        throw newException();
    }

    @Override
    public void removeFrameworkListener(FrameworkListener frameworkListener) {
        throw newException();
    }

    @Override
    public File getDataFile(String localHostname) {
        throw newException();
    }

    @Override
    public Filter createFilter(String localHostname) throws InvalidSyntaxException {
        throw newException();
    }

    @Override
    public Bundle getBundle(String localHostname) {
        throw newException();
    }

    private RuntimeException newException() {
        return new UnsupportedOperationException("This BundleContext operation is not available to components.");
    }

}