You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2010/11/17 21:14:08 UTC

svn commit: r1036196 - in /felix/trunk/ipojo: core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ core/src/main/java/org/apache/felix/ipojo/util/ tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ tests/co...

Author: clement
Date: Wed Nov 17 20:14:07 2010
New Revision: 1036196

URL: http://svn.apache.org/viewvc?rev=1036196&view=rev
Log:
Work on FELIX-2694 Instance state not recomputed after reconfiguration when the instance is stopped
I forgot to reset the setter invocation flag.

Modified:
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Property.java
    felix/trunk/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ReconfigurableSimpleType.java
    felix/trunk/ipojo/tests/core/factories/src/main/resources/metadata.xml

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java?rev=1036196&r1=1036195&r2=1036196&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java Wed Nov 17 20:14:07 2010
@@ -304,9 +304,10 @@ public class ConfigurationHandler extend
         }
 
 
-        // 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());
         	}

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Property.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Property.java?rev=1036196&r1=1036195&r2=1036196&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Property.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Property.java Wed Nov 17 20:14:07 2010
@@ -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 @@ import org.osgi.framework.BundleContext;
  * @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 @@ public class Property implements FieldIn
      * 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 @@ public class Property implements FieldIn
      * 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 @@ public class Property implements FieldIn
         } else {
             m_name = name;
         }
-        
+
         m_type = computeType(type, manager.getGlobalContext());
         if (value != null) {
             m_value = create(m_type, value);
@@ -234,13 +234,13 @@ public class Property implements FieldIn
     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 class Property implements FieldIn
     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 @@ public class Property implements FieldIn
         // If all other case, return null.
         return null;
     }
-    
+
     /**
      * Sets the value of the property.
      * @param value the new value.
@@ -309,7 +309,7 @@ public class Property implements FieldIn
                     }
                 } 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 @@ public class Property implements FieldIn
 
         // 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 @@ public class Property implements FieldIn
                  // 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 @@ public class Property implements FieldIn
     }
 
     /**
-     * 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 @@ public class Property implements FieldIn
     }
 
     /**
-     * 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 @@ public class Property implements FieldIn
         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 @@ public class Property implements FieldIn
             setValue(value);
         }
     }
-    
+
     /**
      * Gets the handler managing the property.
      * @return the configuration handler.

Modified: felix/trunk/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ReconfigurableSimpleType.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ReconfigurableSimpleType.java?rev=1036196&r1=1036195&r2=1036196&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ReconfigurableSimpleType.java (original)
+++ felix/trunk/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ReconfigurableSimpleType.java Wed Nov 17 20:14:07 2010
@@ -5,6 +5,7 @@ public class ReconfigurableSimpleType {
 
 	private String prop; // Property.
 
+	private String x; // Property.
 
 	boolean controller;
 
@@ -12,9 +13,18 @@ public class ReconfigurableSimpleType {
 		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")) {

Modified: felix/trunk/ipojo/tests/core/factories/src/main/resources/metadata.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/core/factories/src/main/resources/metadata.xml?rev=1036196&r1=1036195&r2=1036196&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/core/factories/src/main/resources/metadata.xml (original)
+++ felix/trunk/ipojo/tests/core/factories/src/main/resources/metadata.xml Wed Nov 17 20:14:07 2010
@@ -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>