You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by fm...@apache.org on 2009/08/03 09:52:32 UTC

svn commit: r800243 - /felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/ReadOnlyDictionary.java

Author: fmeschbe
Date: Mon Aug  3 07:52:31 2009
New Revision: 800243

URL: http://svn.apache.org/viewvc?rev=800243&view=rev
Log:
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.

Modified:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/ReadOnlyDictionary.java

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/ReadOnlyDictionary.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/ReadOnlyDictionary.java?rev=800243&r1=800242&r2=800243&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/ReadOnlyDictionary.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/ReadOnlyDictionary.java Mon Aug  3 07:52:31 2009
@@ -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()