Blame 0001-Allow-building-against-OSGi-APIs-newer-than-R4.patch

454dc8f
From 46dbf7151b5d8b1a854863305297cc7b4a70af44 Mon Sep 17 00:00:00 2001
454dc8f
From: Mat Booth <mat.booth@redhat.com>
454dc8f
Date: Wed, 18 Sep 2019 16:00:51 +0100
454dc8f
Subject: [PATCH] Allow building against OSGi APIs newer than R4
454dc8f
454dc8f
---
454dc8f
 .../ctc/wstx/osgi/WstxBundleActivator.java    | 23 ++++++++++++++++---
454dc8f
 1 file changed, 20 insertions(+), 3 deletions(-)
454dc8f
454dc8f
diff --git a/src/main/java/com/ctc/wstx/osgi/WstxBundleActivator.java b/src/main/java/com/ctc/wstx/osgi/WstxBundleActivator.java
454dc8f
index 0ad8402..26b1f0f 100644
454dc8f
--- a/src/main/java/com/ctc/wstx/osgi/WstxBundleActivator.java
454dc8f
+++ b/src/main/java/com/ctc/wstx/osgi/WstxBundleActivator.java
454dc8f
@@ -1,5 +1,9 @@
454dc8f
 package com.ctc.wstx.osgi;
454dc8f
 
454dc8f
+import java.util.Dictionary;
454dc8f
+import java.util.Hashtable;
454dc8f
+import java.util.Properties;
454dc8f
+
454dc8f
 import org.osgi.framework.BundleActivator;
454dc8f
 import org.osgi.framework.BundleContext;
454dc8f
 
454dc8f
@@ -27,16 +31,29 @@ public class WstxBundleActivator
454dc8f
     public void start(BundleContext ctxt)
454dc8f
     {
454dc8f
         InputFactoryProviderImpl inputP = new InputFactoryProviderImpl();
454dc8f
-        ctxt.registerService(Stax2InputFactoryProvider.class.getName(), inputP, inputP.getProperties());
454dc8f
+        ctxt.registerService(Stax2InputFactoryProvider.class.getName(), inputP, convertPropsToDict(inputP.getProperties()));
454dc8f
         OutputFactoryProviderImpl outputP = new OutputFactoryProviderImpl();
454dc8f
-        ctxt.registerService(Stax2OutputFactoryProvider.class.getName(), outputP, outputP.getProperties());
454dc8f
+        ctxt.registerService(Stax2OutputFactoryProvider.class.getName(), outputP, convertPropsToDict(outputP.getProperties()));
454dc8f
         ValidationSchemaFactoryProviderImpl[] impls = ValidationSchemaFactoryProviderImpl.createAll();
454dc8f
         for (int i = 0, len = impls.length; i < len; ++i) {
454dc8f
             ValidationSchemaFactoryProviderImpl impl = impls[i];
454dc8f
-            ctxt.registerService(Stax2ValidationSchemaFactoryProvider.class.getName(), impl, impl.getProperties());
454dc8f
+            ctxt.registerService(Stax2ValidationSchemaFactoryProvider.class.getName(), impl, convertPropsToDict(impl.getProperties()));
454dc8f
         }
454dc8f
     }
454dc8f
 
454dc8f
+    /**
454dc8f
+     * A Properties object is a Dictionary<Object,Object> but the OSGi API got
454dc8f
+     * more restrictive and requires a Dictionary<String,Object>, so we must do
454dc8f
+     * a quick conversion here.
454dc8f
+     */
454dc8f
+    private Dictionary<String,Object> convertPropsToDict(Properties props) {
454dc8f
+		Dictionary<String,Object> dict = new Hashtable<String,Object>();
454dc8f
+		for (Object key : props.keySet()) {
454dc8f
+			dict.put(key.toString(), props.get(key));
454dc8f
+		}
454dc8f
+		return dict;
454dc8f
+    }
454dc8f
+
454dc8f
     @Override
454dc8f
     public void stop(BundleContext ctxt) {
454dc8f
         // Nothing to do here: OSGi automatically de-registers services upon
454dc8f
-- 
454dc8f
2.20.1
454dc8f