// 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 stringDictionary) { if (wrapped == null) return null; return wrapped.registerService(strings, o, stringDictionary); } @Override public ServiceRegistration registerService(String localHostname, Object o, Dictionary stringDictionary) { if (wrapped == null) return null; return wrapped.registerService(localHostname, o, stringDictionary); } @Override public ServiceRegistration registerService(Class sClass, S s, Dictionary stringDictionary) { if (wrapped == null) return null; return wrapped.registerService(sClass, s, stringDictionary); } @Override public ServiceRegistration registerService(Class aClass, ServiceFactory serviceFactory, Dictionary 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 ServiceReference getServiceReference(Class sClass) { if (wrapped == null) return null; return wrapped.getServiceReference(sClass); } @Override public Collection> getServiceReferences(Class sClass, String localHostname) throws InvalidSyntaxException { if (wrapped == null) return Collections.>emptyList(); return wrapped.getServiceReferences(sClass, localHostname); } @Override public S getService(ServiceReference 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 ServiceObjects getServiceObjects(ServiceReference 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."); } }