FELIX-3377 Commit my latest patch (FELIX-3377-4-fmeschbe.patch) including input from David Jencks (thanks alot).

  - Activate, Modified, Deactivate methods may return Map to set service properties
  - Namespace "http://felix.apache.org/xmlns/scr/v1.2.0-felix" is required for component
    declaration to support this feature
  - ExtComponentContext provides setServiceProperties method to explicitly set the
    service registration properties at any time

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1336331 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/test/java/org/apache/felix/scr/impl/helper/ActivateMethodTest.java b/scr/src/test/java/org/apache/felix/scr/impl/helper/ActivateMethodTest.java
index 0b74bba..1bcd45a 100644
--- a/scr/src/test/java/org/apache/felix/scr/impl/helper/ActivateMethodTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/impl/helper/ActivateMethodTest.java
@@ -55,7 +55,7 @@
     {
         super.setUp();
 
-        m_ctx = (ComponentContext) EasyMock.createNiceMock( ComponentContext.class );
+        m_ctx = (ComponentContext) EasyMock.createNiceMock(ComponentContext.class);
         EasyMock.expect( m_ctx.getProperties() ).andReturn( new Hashtable() ).anyTimes();
         EasyMock.replay( new Object[]
             { m_ctx } );
@@ -272,7 +272,7 @@
         };
         ImmediateComponentManager icm = new ImmediateComponentManager( null, null, metadata );
         ActivateMethod am = new ActivateMethod( icm, methodName, methodName != null, obj.getClass() );
-        am.invoke( obj, new ActivateMethod.ActivatorParameter( m_ctx, -1 ), false );
+        am.invoke( obj, new ActivateMethod.ActivatorParameter( m_ctx, -1 ), null );
         Method m = get(am, "m_method");
         assertNotNull( m );
         assertEquals( methodName, m.getName() );
@@ -300,7 +300,7 @@
         };
         ImmediateComponentManager icm = new ImmediateComponentManager( null, null, metadata );
         ActivateMethod am = new ActivateMethod( icm, methodName, methodName != null, obj.getClass() );
-        am.invoke( obj, new ActivateMethod.ActivatorParameter( m_ctx, -1 ), false );
+        am.invoke( obj, new ActivateMethod.ActivatorParameter( m_ctx, -1 ), null );
         assertNull( get( am, "m_method" ) );
         assertNull( obj.getCalledMethod() );
     }
@@ -310,7 +310,7 @@
         throws NoSuchMethodException
     {
         Method method = ACCEPT_METHOD_CLASS.getDeclaredMethod( methodName, null );
-        boolean accepted = BaseMethod.accept( method, acceptPrivate, acceptPackage );
+        boolean accepted = BaseMethod.accept( method, acceptPrivate, acceptPackage, false );
         assertEquals( expected, accepted );
     }
 
diff --git a/scr/src/test/java/org/apache/felix/scr/impl/helper/BindMethodTest.java b/scr/src/test/java/org/apache/felix/scr/impl/helper/BindMethodTest.java
index 0a9aead..4ad5c3f 100644
--- a/scr/src/test/java/org/apache/felix/scr/impl/helper/BindMethodTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/impl/helper/BindMethodTest.java
@@ -441,7 +441,7 @@
         ImmediateComponentManager icm = new ImmediateComponentManager( null, null, metadata );
         BindMethod bm = new BindMethod( icm, methodName, component.getClass(), "reference",
             FakeService.class.getName() );
-        bm.invoke( component, m_service, true );
+        bm.invoke( component, m_service, null );
         assertEquals( expectCallPerformed, component.callPerformed );
     }
 }
diff --git a/scr/src/test/java/org/apache/felix/scr/impl/metadata/XmlHandlerTest.java b/scr/src/test/java/org/apache/felix/scr/impl/metadata/XmlHandlerTest.java
index 9fa9864..bd32067 100644
--- a/scr/src/test/java/org/apache/felix/scr/impl/metadata/XmlHandlerTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/impl/metadata/XmlHandlerTest.java
@@ -106,7 +106,7 @@
         final List metadataList = readMetadataFromString( "<scr:component xmlns:scr=\"http://www.osgi.org/xmlns/scr/v1.1.0\" name=\"n\" ><implementation class=\"n\"/></scr:component>" );
         assertEquals( "1 Descriptor expected", 1, metadataList.size() );
         final ComponentMetadata metadata = ( ComponentMetadata ) metadataList.get( 0 );
-        assertEquals( "Expect NS 1.0.0", XmlHandler.DS_VERSION_1_1, metadata.getNamespaceCode() );
+        assertEquals( "Expect NS 1.1.0", XmlHandler.DS_VERSION_1_1, metadata.getNamespaceCode() );
     }
 
 
@@ -115,7 +115,25 @@
         final List metadataList = readMetadataFromString( "<scr:component xmlns:scr=\"http://felix.apache.org/xmlns/scr/v1.1.0-felix\" name=\"n\" ><implementation class=\"n\"/></scr:component>" );
         assertEquals( "1 Descriptor expected", 1, metadataList.size() );
         final ComponentMetadata metadata = ( ComponentMetadata ) metadataList.get( 0 );
-        assertEquals( "Expect NS 1.0.0", XmlHandler.DS_VERSION_1_1_FELIX, metadata.getNamespaceCode() );
+        assertEquals( "Expect NS 1.1.0-felix", XmlHandler.DS_VERSION_1_1_FELIX, metadata.getNamespaceCode() );
+    }
+
+
+    public void test_namespace_1_2_0() throws Exception
+    {
+        final List metadataList = readMetadataFromString( "<scr:component xmlns:scr=\"http://www.osgi.org/xmlns/scr/v1.2.0\" name=\"n\" ><implementation class=\"n\"/></scr:component>" );
+        assertEquals( "1 Descriptor expected", 1, metadataList.size() );
+        final ComponentMetadata metadata = ( ComponentMetadata ) metadataList.get( 0 );
+        assertEquals( "Expect NS 1.2.0", XmlHandler.DS_VERSION_1_2, metadata.getNamespaceCode() );
+    }
+
+
+    public void test_namespace_1_2_0_felix() throws Exception
+    {
+        final List metadataList = readMetadataFromString( "<scr:component xmlns:scr=\"http://felix.apache.org/xmlns/scr/v1.2.0-felix\" name=\"n\" ><implementation class=\"n\"/></scr:component>" );
+        assertEquals( "1 Descriptor expected", 1, metadataList.size() );
+        final ComponentMetadata metadata = ( ComponentMetadata ) metadataList.get( 0 );
+        assertEquals( "Expect NS 1.2.0-felix", XmlHandler.DS_VERSION_1_2_FELIX, metadata.getNamespaceCode() );
     }
 
 
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java b/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java
index 318ce49..b589301 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java
@@ -35,7 +35,7 @@
     static
     {
         // uncomment to enable debugging of this test class
-        // paxRunnerVmOption = DEBUG_VM_OPTION;
+        //  paxRunnerVmOption = DEBUG_VM_OPTION;
     }
 
 
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/MutablePropertiesTest.java b/scr/src/test/java/org/apache/felix/scr/integration/MutablePropertiesTest.java
index e406c01..bc4bb61 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/MutablePropertiesTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/MutablePropertiesTest.java
@@ -30,6 +30,7 @@
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 
 
@@ -40,20 +41,22 @@
     static
     {
         // uncomment to enable debugging of this test class
-//        paxRunnerVmOption = DEBUG_VM_OPTION;
+        // paxRunnerVmOption = DEBUG_VM_OPTION;
 
         descriptorFile = "/integration_test_mutable_properties.xml";
     }
 
 
     @Test
-    public void test_mutable_properties()
+    public void test_mutable_properties() throws InvalidSyntaxException
     {
         final Component component = findComponentByName( "components.mutable.properties" );
         TestCase.assertNotNull( component );
         TestCase.assertEquals( Component.STATE_REGISTERED, component.getState() );
 
-        ServiceReference serviceReference = bundleContext.getServiceReference( MutatingService.class.getName() );
+        ServiceReference[] serviceReferences = bundleContext.getServiceReferences( MutatingService.class.getName(), "(service.pid=components.mutable.properties)" );
+        TestCase.assertEquals( 1, serviceReferences.length );
+        ServiceReference serviceReference = serviceReferences[0];
         checkProperties( serviceReference, 8, "otherValue", "p1", "p2" );
 
         //update theValue
@@ -62,20 +65,52 @@
         TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
         Dictionary d = new Hashtable(Collections.singletonMap( PROP_NAME, "anotherValue" ));
         s.updateProperties(d);
-        checkProperties(serviceReference, 8, "anotherValue", "p1", "p2");
+        checkProperties(serviceReference, 5, "anotherValue", "p1", "p2");
 
         //configure with configAdmin
         configure( "components.mutable.properties" );
         delay();
-        checkProperties(serviceReference, 8, PROP_NAME, "p1", "p2");
+        //no change
+        checkProperties(serviceReference, 5, "anotherValue", "p1", "p2");
 
-        //check that a property from config admin can't be changed
+        //check that removing config switches back to defaults modified by config admin
+        s.updateProperties(null);
+        checkProperties( serviceReference, 8, "theValue", "p1", "p2" );
+
+        bundleContext.ungetService(serviceReference);
+    }
+
+    @Test
+    public void test_mutable_properties_returned() throws InvalidSyntaxException
+    {
+        final Component component = findComponentByName( "components.mutable.properties2" );
+        TestCase.assertNotNull( component );
+        TestCase.assertEquals( Component.STATE_REGISTERED, component.getState() );
+
+        ServiceReference[] serviceReferences = bundleContext.getServiceReferences( MutatingService.class.getName(), "(service.pid=components.mutable.properties2)" );
+        TestCase.assertEquals( 1, serviceReferences.length );
+        ServiceReference serviceReference = serviceReferences[0];
+        checkProperties( serviceReference, 8, "otherValue", "p1", "p2" );
+
+        //update theValue
+        MutatingService s = ( MutatingService ) bundleContext.getService( serviceReference );
+        Assert.assertNotNull(s);
+        checkProperties( serviceReference, 8, "anotherValue1", "p1", "p2" );
+        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+        Dictionary d = new Hashtable(Collections.singletonMap( PROP_NAME, "anotherValue" ));
         s.updateProperties(d);
-        checkProperties(serviceReference, 8, PROP_NAME, "p1", "p2");
+        checkProperties(serviceReference, 5, "anotherValue", "p1", "p2");
 
-        //check that another one can
-        s.updateProperties(new Hashtable(Collections.singletonMap( "p1", "changed" )));
-        checkProperties(serviceReference, 8, PROP_NAME, "changed", "p2");
+        //configure with configAdmin
+        configure( "components.mutable.properties2" );
+        delay();
+        delay();
+        //no change
+        checkProperties(serviceReference, 8, "anotherValue2", "p1", "p2");
+
+        //check that removing config switches back to defaults modified by config admin
+        s.updateProperties(null);
+        checkProperties( serviceReference, 8, "theValue", "p1", "p2" );
 
         bundleContext.ungetService(serviceReference);
     }
@@ -83,8 +118,10 @@
     private void checkProperties(ServiceReference serviceReference, int count, String otherValue, String p1, String p2) {
         Assert.assertEquals("wrong property count", count, serviceReference.getPropertyKeys().length);
         Assert.assertEquals(otherValue, serviceReference.getProperty(PROP_NAME));
-        Assert.assertEquals(p1, serviceReference.getProperty("p1"));
-        Assert.assertEquals(p2, serviceReference.getProperty("p2"));
+        if ( count > 5 ) {
+            Assert.assertEquals(p1, serviceReference.getProperty("p1"));
+            Assert.assertEquals(p2, serviceReference.getProperty("p2"));
+        }
     }
 
 
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/components/MutatingServiceImpl.java b/scr/src/test/java/org/apache/felix/scr/integration/components/MutatingServiceImpl.java
index 6ae2ff6..faf9554 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/components/MutatingServiceImpl.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/components/MutatingServiceImpl.java
@@ -20,6 +20,8 @@
 
 
 import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Map;
 
 import org.apache.felix.scr.component.ExtComponentContext;
 import org.osgi.service.component.ComponentContext;
@@ -39,8 +41,30 @@
 
     }
 
+    private Map activateMutate( ComponentContext activateContext )
+    {
+        this.activateContext = activateContext;
+        Map result = new Hashtable( (Map )activateContext.getProperties() );
+        result.put( "theValue", "anotherValue1");
+        return result;
+    }
+
+    private Map modifiedMutate( ComponentContext activateContext )
+    {
+        Map result = new Hashtable( (Map )activateContext.getProperties() );
+        result.put( "theValue", "anotherValue2");
+        return result;
+    }
+
+    private Map deactivateMutate( ComponentContext activateContext )
+    {
+        Map result = new Hashtable( (Map )activateContext.getProperties() );
+        result.put( "theValue", "anotherValue3");
+        return result;
+    }
+
     public void updateProperties(Dictionary changes) {
-        ((ExtComponentContext)activateContext).updateProperties(changes);
+        ((ExtComponentContext)activateContext).setServiceProperties(changes);
     }
 
 }
diff --git a/scr/src/test/resources/integration_test_mutable_properties.xml b/scr/src/test/resources/integration_test_mutable_properties.xml
index 5dc0473..d9052cf 100644
--- a/scr/src/test/resources/integration_test_mutable_properties.xml
+++ b/scr/src/test/resources/integration_test_mutable_properties.xml
@@ -19,7 +19,7 @@
 -->
 <components>
     <scr:component name="components.mutable.properties"
-            xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"
+            xmlns:scr="http://felix.apache.org/xmlns/scr/v1.2.0-felix"
             enabled="true"
             configuration-policy="optional"
             activate="activate"
@@ -33,4 +33,20 @@
         <property name="p1" value="p1" />
         <property name="p2" value="p2" />
     </scr:component>
+    <scr:component name="components.mutable.properties2"
+            xmlns:scr="http://felix.apache.org/xmlns/scr/v1.2.0-felix"
+            enabled="true"
+            configuration-policy="optional"
+            activate="activateMutate"
+            modified="modifiedMutate"
+            deactivate="deactivateMutate">
+        <implementation class="org.apache.felix.scr.integration.components.MutatingServiceImpl" />
+        <service>
+            <provide interface="org.apache.felix.scr.integration.components.MutatingService" />
+        </service>
+        <property name="service.pid" value="components.mutable.properties2" />
+        <property name="theValue" value="otherValue" />
+        <property name="p1" value="p1" />
+        <property name="p2" value="p2" />
+    </scr:component>
 </components>