+
+ public class GlobalSchemaServiceProxy implements AutoCloseable, SchemaService, Delegator<SchemaService> {
+
+ private BundleContext bundleContext;
+ private ServiceReference<SchemaService> reference;
+ private SchemaService delegate;
+
+ public GlobalSchemaServiceProxy(final BundleContext bundleContext, final ServiceReference<SchemaService> ref) {
+ this.bundleContext = bundleContext;
+ this.reference = ref;
+ this.delegate = bundleContext.getService(reference);
+ }
+
+ @Override
+ public void close() throws Exception {
+ if (delegate != null) {
+ delegate = null;
+
+ try {
+ bundleContext.ungetService(reference);
+ } catch (IllegalStateException e) {
+ // Indicates the service was already unregistered which can happen normally
+ // on shutdown.
+ LOG.debug( "Error unregistering service", e );
+ }
+
+ reference = null;
+ bundleContext = null;
+ }
+ }
+
+ @Override
+ public void addModule(final Module arg0) {
+ delegate.addModule(arg0);
+ }
+
+ @Override
+ public SchemaContext getGlobalContext() {
+ return delegate.getGlobalContext();
+ }
+
+ @Override
+ public SchemaContext getSessionContext() {
+ return delegate.getSessionContext();
+ }
+
+ @Override
+ public ListenerRegistration<SchemaServiceListener> registerSchemaServiceListener(final SchemaServiceListener arg0) {
+ return delegate.registerSchemaServiceListener(arg0);
+ }
+
+ @Override
+ public void removeModule(final Module arg0) {
+ delegate.removeModule(arg0);
+ }
+
+ @Override
+ public SchemaService getDelegate() {
+ return delegate;
+ }
+
+ }