Work on FELIX-2694 Instance state not recomputed after reconfiguration when the instance is stopped
I forgot to reset the setter invocation flag.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1036196 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
index 374dca0..3d0e7f8 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
@@ -304,9 +304,10 @@
         }
 
 
-        // Give initial values
+        // Give initial values and reset the 'invoked' flag.
         for (int i = 0; i < m_configurableProperties.size(); i++) {
         	Property prop = (Property) m_configurableProperties.get(i);
+        	prop.reset(); // Clear the invoked flag.
         	if (prop.hasField() && prop.getValue() != Property.NO_VALUE && prop.getValue() != null) {
         		getInstanceManager().onSet(null, prop.getField(), prop.getValue());
         	}
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Property.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Property.java
index 5d7ef66..f7bc98c 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Property.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Property.java
@@ -1,4 +1,4 @@
-/* 

+/*

  * Licensed to the Apache Software Foundation (ASF) under one

  * or more contributor license agreements.  See the NOTICE file

  * distributed with this work for additional information

@@ -37,7 +37,7 @@
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>

  */

 public class Property implements FieldInterceptor {

-    

+

     /**

      * Object used for an unvalued property.

      */

@@ -65,9 +65,9 @@
      * The value of the property.

      */

     private Object m_value = NO_VALUE;

-    

+

     /**

-     * Flag tracking is the method was 

+     * Flag tracking is the method was

      * already called for the current value.

      */

     private boolean m_invoked;

@@ -81,14 +81,14 @@
      * The handler object to get the logger.

      */

     private final Handler m_handler;

-    

+

     /**

      * The instance manager.

      */

     private final InstanceManager m_manager;

 

     /**

-     * Creates a property. 

+     * Creates a property.

      * At least the method or the field need

      * to be specified.

      * @param name the name of the property (optional)

@@ -114,7 +114,7 @@
         } else {

             m_name = name;

         }

-        

+

         m_type = computeType(type, manager.getGlobalContext());

         if (value != null) {

             m_value = create(m_type, value);

@@ -234,13 +234,13 @@
     public String getField() {

         return m_field;

     }

-    

+

     public String getType() {

         return m_type.getName();

     }

 

     /**

-     * Gets the method name, 

+     * Gets the method name,

      * <code>null</code> if no method.

      * @return the method name.

      */

@@ -264,12 +264,12 @@
     public boolean hasField() {

         return m_field != null;

     }

-    

+

     public synchronized Object getValue() {

         return m_value;

     }

 

-    

+

     /**

      * Gets the NO VALUE Object.

      * This method returns the object to inject when the property

@@ -289,7 +289,7 @@
         // If all other case, return null.

         return null;

     }

-    

+

     /**

      * Sets the value of the property.

      * @param value the new value.

@@ -309,7 +309,7 @@
                     }

                 } else {

                     // Error, the given property cannot be injected.

-                    throw new ClassCastException("Incompatible type for the property " + m_name + " " + m_type.getName() + " expected, " 

+                    throw new ClassCastException("Incompatible type for the property " + m_name + " " + m_type.getName() + " expected, "

                                                  + value.getClass() + " found");

                 }

             }

@@ -364,9 +364,9 @@
 

         // Array :

         if (type.isArray()) {

-            return createArrayObject(type.getComponentType(), ParseUtils.parseArrays(strValue)); 

+            return createArrayObject(type.getComponentType(), ParseUtils.parseArrays(strValue));

         }

-        

+

         // Enum :

         if (type.getSuperclass() != null  && type.getSuperclass().getName().equals("java.lang.Enum")) {

             try {

@@ -377,14 +377,14 @@
                  // Invoke the static method

                 return valueOf.invoke(null, new String[] {strValue});

             } catch (InvocationTargetException e) {

-                throw new ConfigurationException("Cannot create an enumerated value for " + type 

+                throw new ConfigurationException("Cannot create an enumerated value for " + type

                         + " with " + strValue + " : " + e.getTargetException());

             } catch (Exception e) {

-                throw new ConfigurationException("Cannot create an enumerated value for " + type 

+                throw new ConfigurationException("Cannot create an enumerated value for " + type

                         + " with " + strValue + " : " + e.getMessage());

             }

         }

-        

+

         // Else it is a neither a primitive type neither a String -> create

         // the object by calling a constructor with a string in argument.

         try {

@@ -407,7 +407,7 @@
     }

 

     /**

-     * Creates an array object containing the type component type from 

+     * Creates an array object containing the type component type from

      * the String array 'values'.

      * @param interntype the internal type of the array.

      * @param values the String array

@@ -495,7 +495,16 @@
     }

 

     /**

-     * Invokes the setter method on the given pojo object. 

+     * Clears the invoked flag.

+     * Then, despite the setter was already called,

+     * it will be invoked another times.

+     */

+    public synchronized void reset() {

+    	m_invoked = false;

+    }

+

+    /**

+     * Invokes the setter method on the given pojo object.

      * If no specified pojo object, it calls on each created pojo object.

      * @param instance the created object (could be <code>null</code>)

      * @see org.apache.felix.ipojo.Handler#onCreation(java.lang.Object)

@@ -504,12 +513,12 @@
         if (m_invoked) {

             return; // Already called.

         }

-        

+

         if (m_value == NO_VALUE) {

             // Don't call method if no value

             return;

         }

-        

+

         try {

             if (instance == null) {

                 m_method.call(new Object[] { m_value });

@@ -556,7 +565,7 @@
             setValue(value);

         }

     }

-    

+

     /**

      * Gets the handler managing the property.

      * @return the configuration handler.

diff --git a/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ReconfigurableSimpleType.java b/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ReconfigurableSimpleType.java
index fdd4d94..b84c40f 100644
--- a/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ReconfigurableSimpleType.java
+++ b/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ReconfigurableSimpleType.java
@@ -5,6 +5,7 @@
 
 	private String prop; // Property.
 
+	private String x; // Property.
 
 	boolean controller;
 
@@ -12,9 +13,18 @@
 		if (prop == null || prop.equals("KO")) {
 			throw new IllegalStateException("Bad Configuration : " + prop);
 		}
+
+		if (x == null) {
+			throw new IllegalStateException("x is null");
+		}
+
 		System.out.println("OK !!!!");
 	}
 
+	public void setX(String v) {
+		x = v;
+	}
+
 	public void setProp(String p) {
 		prop = p;
 		if (prop == null || prop.equals("KO")) {
diff --git a/ipojo/tests/core/factories/src/main/resources/metadata.xml b/ipojo/tests/core/factories/src/main/resources/metadata.xml
index b7b6ef8..7037a19 100644
--- a/ipojo/tests/core/factories/src/main/resources/metadata.xml
+++ b/ipojo/tests/core/factories/src/main/resources/metadata.xml
@@ -132,6 +132,7 @@
 	<component classname="org.apache.felix.ipojo.test.scenarios.component.ReconfigurableSimpleType" architecture="true">

 		<properties>

 			<property name="prop" field="prop"/>

+			<property name="x" method="setX" value="x"/>

 		</properties>

 		<callback transition="validate" method="start"/>

 	</component>

@@ -140,6 +141,7 @@
 		architecture="true" immediate="true">

 		<properties>

 			<property name="prop" method="setProp"/>

+			<property name="x" method="setX" value="x"/>

 		</properties>

 		<controller field="controller"/>

 	</component>

@@ -148,6 +150,7 @@
 		architecture="true" immediate="true">

 		<properties>

 			<property name="controller" method="setController" field="controller"/>

+			<property name="x" method="setX" value="x"/>

 		</properties>

 		<controller field="controller"/>

 	</component>