FELIX-927 Add support to use a ServiceReference as the data
basis to use the ReadOnlyDictionary as a Map argument to
DS 1.1 bind methods.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@800243 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/helper/ReadOnlyDictionary.java b/scr/src/main/java/org/apache/felix/scr/impl/helper/ReadOnlyDictionary.java
index f0704d8..cb802f1 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/helper/ReadOnlyDictionary.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/helper/ReadOnlyDictionary.java
@@ -27,11 +27,13 @@
import java.util.Map;
import java.util.Set;
+import org.osgi.framework.ServiceReference;
+
/**
- * The <code>ReadOnlyDictionary</code> is a <code>Dictionary</code> whose
- * {@link #put(Object, Object)} and {@link #remove(Object)} methods have
- * no effect and always return <code>null</code>.
+ * The <code>ReadOnlyDictionary</code> is both a <code>Dictionary</code> and
+ * a <code>Map</code> whose modificaiton methods (like {@link #put(Object, Object)},
+ * {@link #remove(Object)}, etc.) have no effect.
*/
public class ReadOnlyDictionary extends Dictionary implements Map
{
@@ -39,6 +41,10 @@
private final Hashtable m_delegatee;
+ /**
+ * Creates a wrapper for the given delegatee dictionary providing read
+ * only access to the data.
+ */
public ReadOnlyDictionary( final Dictionary delegatee )
{
if ( delegatee instanceof Hashtable )
@@ -57,6 +63,26 @@
}
+ /**
+ * Creates a wrapper for the given service reference providing read only
+ * access to the reference properties.
+ */
+ public ReadOnlyDictionary( final ServiceReference serviceReference )
+ {
+ Hashtable properties = new Hashtable();
+ final String[] keys = serviceReference.getPropertyKeys();
+ if ( keys != null )
+ {
+ for ( int j = 0; j < keys.length; j++ )
+ {
+ final String key = keys[j];
+ properties.put( key, serviceReference.getProperty( key ) );
+ }
+ }
+ m_delegatee = properties;
+ }
+
+
//---------- Dictionary API
public Enumeration elements()