felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r713976 [1/3] - in /felix/trunk/ipojo: annotations/src/main/java/org/apache/felix/ipojo/annotations/ composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/ composite/src/main/resources/ core/src/main/java/org/apache/feli...
Date Fri, 14 Nov 2008 11:06:00 GMT
Author: clement
Date: Fri Nov 14 03:05:57 2008
New Revision: 713976

URL: http://svn.apache.org/viewvc?rev=713976&view=rev
Log:
Fix issue Felix-815.
Properties becomes optional by default.
Unvalued properties are not published with the service reference until they receive a value.
Setter methods are not called until properties receive a value
Injected values in fields follow standard Java initialization (null for object and arrays, 0 for numeric types, false for boolean). 
Mandatory properties can be set with the 'mandatory' attribute (supported in XML and in the annotations).
The core.xsd XML Schema is also modified to add the new attribute.

This improvement allows removing default value in properties (such as in the architecture handlers).
Provides test about this new improvement

Fix issue Felix-816
The comparator attribute is now supported for any binding policy.
Provides test about using custom comparator with any binding policy

Fix issue Felix-817
Solve an issue in the ServiceExporter when a service in unregistered twice (throws an IllegalStateException since a recent modification of the Felix framework). 

Fix issue Felix-818
Implement the ServiceReferenceImpl compareTo method (method added in OSGi R4.1). This method reuse the same implementation as the Felix framework ServiceReferenceImpl method.

Remove junit4osgi embedded tests

Added:
    felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/component/PropertyModifier.java
    felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/TestPropertyModifier.java
    felix/trunk/ipojo/tests/core/service-dependency-comparator/   (with props)
    felix/trunk/ipojo/tests/core/service-dependency-comparator/pom.xml
    felix/trunk/ipojo/tests/core/service-dependency-comparator/src/
    felix/trunk/ipojo/tests/core/service-dependency-comparator/src/main/
    felix/trunk/ipojo/tests/core/service-dependency-comparator/src/main/java/
    felix/trunk/ipojo/tests/core/service-dependency-comparator/src/main/java/org/
    felix/trunk/ipojo/tests/core/service-dependency-comparator/src/main/java/org/apache/
    felix/trunk/ipojo/tests/core/service-dependency-comparator/src/main/java/org/apache/felix/
    felix/trunk/ipojo/tests/core/service-dependency-comparator/src/main/java/org/apache/felix/ipojo/
    felix/trunk/ipojo/tests/core/service-dependency-comparator/src/main/java/org/apache/felix/ipojo/test/
    felix/trunk/ipojo/tests/core/service-dependency-comparator/src/main/java/org/apache/felix/ipojo/test/scenarios/
    felix/trunk/ipojo/tests/core/service-dependency-comparator/src/main/java/org/apache/felix/ipojo/test/scenarios/service/
    felix/trunk/ipojo/tests/core/service-dependency-comparator/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/
    felix/trunk/ipojo/tests/core/service-dependency-comparator/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/comparator/
    felix/trunk/ipojo/tests/core/service-dependency-comparator/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/comparator/ComparatorTestCase.java
    felix/trunk/ipojo/tests/core/service-dependency-comparator/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/comparator/component/
    felix/trunk/ipojo/tests/core/service-dependency-comparator/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/comparator/component/CheckServiceProvider.java
    felix/trunk/ipojo/tests/core/service-dependency-comparator/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/comparator/component/GradeComparator.java
    felix/trunk/ipojo/tests/core/service-dependency-comparator/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/comparator/component/GradedFooServiceProvider.java
    felix/trunk/ipojo/tests/core/service-dependency-comparator/src/main/resources/
    felix/trunk/ipojo/tests/core/service-dependency-comparator/src/main/resources/metadata.xml
Removed:
    felix/trunk/ipojo/manipulator/src/main/resources/core.xsd
Modified:
    felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Property.java
    felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/ServiceProperty.java
    felix/trunk/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/ServiceExporter.java
    felix/trunk/ipojo/composite/src/main/resources/metadata.xml
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/PropertyDescription.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/context/ServiceReferenceImpl.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/context/StringMap.java
    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/handlers/dependency/Dependency.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/DependencyModel.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Property.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/ServiceReferenceRankingComparator.java
    felix/trunk/ipojo/core/src/main/resources/core.xsd
    felix/trunk/ipojo/core/src/main/resources/metadata.xml
    felix/trunk/ipojo/examples/junit4osgi/junit4osgi/pom.xml
    felix/trunk/ipojo/handler/eventadmin/metadata.xml
    felix/trunk/ipojo/handler/eventadmin/src/main/java/org/apache/felix/ipojo/handlers/event/publisher/EventAdminPublisherHandler.java
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/FieldCollector.java
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/MethodCollector.java
    felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/Properties.java
    felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/ServiceProdiving.java
    felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/Properties.java
    felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ProvidesProperties.java
    felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ConfigurableCheckServiceProvider.java
    felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderTypeDyn.java
    felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/ConfigurationTestSuite.java
    felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/DynamicallyConfigurableProperties.java
    felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/ManagedServiceConfigurableProperties.java
    felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/SimpleProperties.java
    felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/TestBothProperties.java
    felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/TestFieldProperties.java
    felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/TestMethodProperties.java
    felix/trunk/ipojo/tests/core/configuration/src/main/resources/metadata.xml
    felix/trunk/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/factories/UnacceptableConfigurationTest.java
    felix/trunk/ipojo/tests/core/factories/src/main/resources/metadata.xml
    felix/trunk/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/DynamicProps.java
    felix/trunk/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/DynamicPropsReconfiguration.java
    felix/trunk/ipojo/tests/core/service-providing/src/main/java/org/apache/felix/ipojo/test/scenarios/ps/ProvidedServiceArchitectureTest.java

Modified: felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Property.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Property.java?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Property.java (original)
+++ felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Property.java Fri Nov 14 03:05:57 2008
@@ -41,4 +41,10 @@
      */
     String value() default "";
     
+    /**
+     * Is the property mandatory?
+     * Default: false
+     */
+    boolean mandatory() default false;
+    
 }

Modified: felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/ServiceProperty.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/ServiceProperty.java?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/ServiceProperty.java (original)
+++ felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/ServiceProperty.java Fri Nov 14 03:05:57 2008
@@ -40,5 +40,11 @@
      * Default : empty
      */
     String value() default "";
+    
+    /**
+     * Is the property mandatory?
+     * Default: false
+     */
+    boolean mandatory() default false;
 
 }

Modified: felix/trunk/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/ServiceExporter.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/ServiceExporter.java?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/ServiceExporter.java (original)
+++ felix/trunk/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/ServiceExporter.java Fri Nov 14 03:05:57 2008
@@ -110,7 +110,12 @@
         while (iterator.hasNext()) {
             ServiceReference ref = (ServiceReference) iterator.next();
             ServiceRegistration reg = (ServiceRegistration) m_registrations.get(ref);
-            reg.unregister();
+            try {
+                reg.unregister();
+            } catch (IllegalStateException e) {
+                // The service is already unregistered
+                // Do nothing silently
+            }
         }
         m_registrations.clear();
     }

Modified: felix/trunk/ipojo/composite/src/main/resources/metadata.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/composite/src/main/resources/metadata.xml?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/composite/src/main/resources/metadata.xml (original)
+++ felix/trunk/ipojo/composite/src/main/resources/metadata.xml Fri Nov 14 03:05:57 2008
@@ -39,7 +39,7 @@
 		classname="org.apache.felix.ipojo.composite.architecture.ArchitectureHandler"
 		name="architecture" type="composite" architecture="false">
 		<provides>
-			<property field="m_name" name="architecture.instance" value="" />
+			<property field="m_name" name="architecture.instance"/>
 		</provides>
 	</handler>
 </ipojo>
\ No newline at end of file

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/IPojoFactory.java Fri Nov 14 03:05:57 2008
@@ -424,8 +424,8 @@
                 throw new UnacceptableConfiguration("The property " + props[i] + " cannot be overide : immutable property"); // The instance configuration tries to override an immutable property.
             }
             // Is the property required ?
-            if (props[i].getValue() == null && conf.get(props[i].getName()) == null) {
-                throw new UnacceptableConfiguration("The property " + props[i].getName() + " is missing"); // The property must be set.
+            if (props[i].isMandatory() && props[i].getValue() == null && conf.get(props[i].getName()) == null) {
+                throw new UnacceptableConfiguration("The mandatory property " + props[i].getName() + " is missing"); // The property must be set.
             }
         }
     }

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/PropertyDescription.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/PropertyDescription.java?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/PropertyDescription.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/PropertyDescription.java Fri Nov 14 03:05:57 2008
@@ -47,17 +47,23 @@
     
     /**
      * Immutable property flag
-     * IF true, the property cannot be override by the instance configuration.
+     * If set to <code>true</code>, the property cannot be override by the instance configuration.
      * Moreover, immutable properties are exposed on the factory service too.
      */
     private boolean m_immutable = false;
+    
+    /**
+     * A property is mandatory. So, either the component type description provides a value or
+     * the instance configuration must provide a value. Immutable properties are mandatories. 
+     */
+    private boolean m_isMandatory = false;
 
     /**
      * Constructor.
      * 
-     * @param name : name of the property
-     * @param type : type of the property
-     * @param value : default value of the property
+     * @param name the name of the property
+     * @param type the type of the property
+     * @param value the default value of the property, can be <code>null</code>
      */
     public PropertyDescription(String name, String type, String value) {
         m_name = name;
@@ -68,10 +74,10 @@
     /**
      * Constructor.
      * 
-     * @param name : name of the property
-     * @param type : type of the property
-     * @param value : default value of the property
-     * @param immutable : the property is immutable.
+     * @param name the name of the property
+     * @param type the type of the property
+     * @param value the default value (String form) of the property, can be <code>null</code>
+     * @param immutable the property is immutable.
      */
     public PropertyDescription(String name, String type, String value, boolean immutable) {
         m_name = name;
@@ -81,7 +87,7 @@
     }
 
     /**
-     * Get the current property name.
+     * Gets the current property name.
      * @return the property name.
      */
     public String getName() {
@@ -89,7 +95,7 @@
     }
 
     /**
-     * Get the current property type.
+     * Gets the current property type.
      * @return the property type.
      */
     public String getType() {
@@ -97,8 +103,9 @@
     }
 
     /**
-     * Get the current property value.
-     * @return the default value for the property.
+     * Gets the current property value.
+     * @return the default value for the property,
+     * <code>null</code> if the property hasn't a value..
      */
     public String getValue() {
         return m_value;
@@ -106,17 +113,39 @@
     
     /**
      * Is the property immutable.
-     * @return true if the property is immutable.
+     * @return <code>true</code> if the property is immutable.
      */
     public boolean isImmutable() {
         return m_immutable;
     }
+    
     /**
-     * Get the object value of the current immutable property.
-     * @param context : bundle context to use to load classes.
-     * @return the object value of the current property.
+     * Sets the property as mandatory.
+     */
+    public void setMandatory() {
+        m_isMandatory = true;
+    }
+    
+    /**
+     * Is the property mandatory.
+     * @return <code>true</code> if the property is mandatory,
+     * <code>false</code> otherwise.
+     */
+    public boolean isMandatory() {
+        return m_isMandatory;
+    }
+    
+    /**
+     * Gets the object value of the current immutable property.
+     * @param context  the bundle context to use to load classes.
+     * @return the object value of the current property or <code>
+     * null</code> if the current value is <code>null</code>.
      */
     public Object getObjectValue(BundleContext context) {
+        if (m_value == null) {
+            return null;
+        }
+        
         Class type = null;
         try {
             type = Property.computeType(m_type, context);

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/context/ServiceReferenceImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/context/ServiceReferenceImpl.java?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/context/ServiceReferenceImpl.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/context/ServiceReferenceImpl.java Fri Nov 14 03:05:57 2008
@@ -22,6 +22,7 @@
 
 import org.apache.felix.ipojo.ComponentInstance;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
 
 /**
@@ -117,15 +118,39 @@
 
     /**
      * Service Reference compare method.
-     * This method is not yet supported.
-     * @param arg0 the object
-     * @return this methods is not yet supported, and throws an {@link UnsupportedOperationException}.
+     * @param reference the service reference
+     * @return this methods is not yet supported, and throws an
+     *         {@link UnsupportedOperationException}.
      * @see org.osgi.framework.ServiceReference#compareTo(java.lang.Object)
-     * TODO implements this method
      */
-    public int compareTo(Object arg0) {
-        throw new UnsupportedOperationException("This feature has not yet been implemented.");
+    public int compareTo(Object reference) {
 
+        ServiceReference other = (ServiceReference) reference;
+
+        Long id = (Long) getProperty(Constants.SERVICE_ID);
+        Long otherId = (Long) other.getProperty(Constants.SERVICE_ID);
+
+        if (id.equals(otherId)) {
+            return 0; // same service
+        }
+
+        Integer rank = (Integer) getProperty(Constants.SERVICE_RANKING);
+        Integer otherRank = (Integer) other
+                .getProperty(Constants.SERVICE_RANKING);
+
+        // If no rank, then spec says it defaults to zero.
+        rank = (rank == null) ? new Integer(0) : rank;
+        otherRank = (otherRank == null) ? new Integer(0) : otherRank;
+
+        // Sort by rank in ascending order.
+        if (rank.compareTo(otherRank) < 0) {
+            return -1; // lower rank
+        } else if (rank.compareTo(otherRank) > 0) {
+            return 1; // higher rank
+        }
+
+        // If ranks are equal, then sort by service id in descending order.
+        return (id.compareTo(otherId) < 0) ? 1 : -1;
     }
 
 }

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/context/StringMap.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/context/StringMap.java?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/context/StringMap.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/context/StringMap.java Fri Nov 14 03:05:57 2008
@@ -18,6 +18,7 @@
  */
 package org.apache.felix.ipojo.context;
 
+import java.io.Serializable;
 import java.util.Comparator;
 import java.util.Map;
 import java.util.TreeMap;
@@ -92,7 +93,12 @@
         ((StringComparator) comparator()).setCaseSensitive(flag);
     }
 
-    private static class StringComparator implements Comparator {
+    private static class StringComparator implements Comparator, Serializable {
+        /**
+         * Id.
+         */
+        private static final long serialVersionUID = 1L;
+        
         /**
          * Is the map case sensitive?
          */

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=713976&r1=713975&r2=713976&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 Fri Nov 14 03:05:57 2008
@@ -152,15 +152,24 @@
             // Is the property set to immutable
             boolean immutable = false;
             String imm = configurables[i].getAttribute("immutable");
-            if (imm != null && imm.equalsIgnoreCase("true")) {
-                immutable = true;
-            }
+            immutable = imm != null && imm.equalsIgnoreCase("true");
+            
+            boolean mandatory = false;
+            String man = configurables[i].getAttribute("mandatory");
+            mandatory =  man != null && man.equalsIgnoreCase("true");
             
+            PropertyDescription pd = null;
             if (value == null) {
-                desc.addProperty(new PropertyDescription(name, type, null, false)); // Cannot be immutable if we have no value.
+                pd = new PropertyDescription(name, type, null, false); // Cannot be immutable if we have no value.
             } else {
-                desc.addProperty(new PropertyDescription(name, type, value, immutable));
+                pd = new PropertyDescription(name, type, value, immutable);
+            }
+            
+            if (mandatory) {
+                pd.setMandatory();
             }
+            
+            desc.addProperty(pd);
         }
     }
 
@@ -194,7 +203,6 @@
             m_managedServicePID = instanceMSPID;
         }
         
-
         for (int i = 0; configurables != null && i < configurables.length; i++) {
             String fieldName = configurables[i].getAttribute("field");
             String methodName = configurables[i].getAttribute("method");
@@ -250,7 +258,9 @@
         if (m_mustPropagate) {
             for (int i = 0; i < m_configurableProperties.size(); i++) {
                 Property prop = (Property) m_configurableProperties.get(i);
-                m_toPropagate.put(prop.getName(), prop.getValue());
+                if (prop.getValue() != Property.NO_VALUE && prop.getValue() != null) { // No injected value, or null
+                    m_toPropagate.put(prop.getName(), prop.getValue());
+                }
             }
             reconfigure(m_toPropagate);
         }

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java Fri Nov 14 03:05:57 2008
@@ -40,7 +40,6 @@
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Filter;
 import org.osgi.framework.ServiceReference;
-import org.osgi.framework.SynchronousBundleListener;
 
 /**
  * Represent a service dependency of the component instance.

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java Fri Nov 14 03:05:57 2008
@@ -273,11 +273,12 @@
      * @return the properties attached to the provided service.
      */
     private Properties getServiceProperties() {
-        // Contruct the service properties list
+        // Build the service properties list
         Properties serviceProperties = new Properties();
         for (int i = 0; i < m_properties.length; i++) {
-            if (m_properties[i].getValue() != null) {
-                serviceProperties.put(m_properties[i].getName(), m_properties[i].getValue());
+            Object value = m_properties[i].getValue();
+            if (value != null && value != Property.NO_VALUE) {
+                serviceProperties.put(m_properties[i].getName(), value);
             }
         }
         return serviceProperties;

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java Fri Nov 14 03:05:57 2008
@@ -454,7 +454,7 @@
             Properties props = new Properties();
             for (int k = 0; k < svc.getProperties().length; k++) {
                 Property prop = svc.getProperties()[k];
-                if (prop.getValue() != null) {
+                if (prop.getValue() != null  && prop.getValue() != Property.NO_VALUE) {
                     props.put(prop.getName(), prop.getValue().toString());
                 }
             }
@@ -548,6 +548,7 @@
                 String value = props[j].getAttribute("value");
                 String type = props[j].getAttribute("type");
                 String field = props[j].getAttribute("field");
+                
 
                 // Get property name :
                 if (field != null && name == null) {
@@ -573,8 +574,14 @@
                 if (imm != null && imm.equalsIgnoreCase("true")) {
                     immutable = true;
                 }
-
-                desc.addProperty(new PropertyDescription(name, type, value, immutable));
+                
+                PropertyDescription pd = new PropertyDescription(name, type, value, immutable);
+                desc.addProperty(pd);
+                
+                String man = props[j].getAttribute("mandatory");
+                if (man != null && man.equalsIgnoreCase("true")) {
+                    pd.setMandatory();
+                }
             }
         }
     }

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/DependencyModel.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/DependencyModel.java?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/DependencyModel.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/DependencyModel.java Fri Nov 14 03:05:57 2008
@@ -319,9 +319,17 @@
         synchronized (this) {
             m_matchingRefs.add(ref);
 
-            // Sort the collection if needed.
+            // Sort the collection if needed, if not sort, services are append to the list.
             if (m_comparator != null) {
-                Collections.sort(m_matchingRefs, m_comparator);
+                // The collection must be sort only if:
+                // The policy is dynamic-priority
+                // No services are already used
+                // If so, sorting can imply a re-binding, and so don't follow the Dynamic Binding policy
+                if (m_policy == DYNAMIC_PRIORITY_BINDING_POLICY
+                       || m_tracker.getUsedServiceReferences() == null
+                       || m_tracker.getUsedServiceReferences().isEmpty()) {
+                    Collections.sort(m_matchingRefs, m_comparator);
+                }
             }
 
             size = m_matchingRefs.size();
@@ -383,6 +391,14 @@
             if (obj == null) {
                 computeDependencyState(); // check if the dependency stills valid.
             } else {
+                // A used service disappears, we have to sort the available providers to choose the best one.
+                // However, the sort has to be done only for scalar dependencies following the dynamic binding
+                // policy. Static dependencies will be broken, DP dependencies are always sorted.
+                // Aggregate dependencies does not need to be sort, as it will change the array
+                // order.
+                if (m_comparator != null && m_policy == DYNAMIC_BINDING_POLICY && ! m_aggregate) {
+                    Collections.sort(m_matchingRefs, m_comparator);
+                }
                 onServiceDeparture(ref);
                 ServiceReference newRef = getServiceReference();
                 if (newRef == null) { // Check if there is another provider.

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=713976&r1=713975&r2=713976&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 Fri Nov 14 03:05:57 2008
@@ -36,6 +36,8 @@
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
 public class Property implements FieldInterceptor {
+    
+    public static final Object NO_VALUE = new Object();
 
     /**
      * The name of the property (field name if not set).
@@ -58,7 +60,7 @@
     /**
      * The value of the property.
      */
-    private Object m_value;
+    private Object m_value = NO_VALUE;
     
     /**
      * Flag tracking is the method was 
@@ -160,7 +162,7 @@
                 } catch (ClassNotFoundException e) {
                     throw new ConfigurationException("Class not found exception in setValue on " + type + " : " + e.getMessage());
                 } catch (SecurityException e) {
-                    throw new ConfigurationException("Security excption in setValue on " + type + " : " + e.getMessage());
+                    throw new ConfigurationException("Security execption in setValue on " + type + " : " + e.getMessage());
                 } catch (IllegalArgumentException e) {
                     throw new ConfigurationException("Argument issue when calling the constructor of the type " + type);
                 }
@@ -252,11 +254,32 @@
     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
+     * was not assigned to a value.
+     * @param type the type of the value.
+     * @return the object to inject when the property has no value.
+     */
+    private static Object getNoValue(Class type) {
+        if (Boolean.TYPE.equals(type)) { return new Boolean(false); }
+        if (Byte.TYPE.equals(type)) { return new Byte((byte) 0); }
+        if (Short.TYPE.equals(type)) { return new Short((short) 0); }
+        if (Integer.TYPE.equals(type)) { return new Integer(0); }
+        if (Long.TYPE.equals(type)) { return new Long(0); }
+        if (Float.TYPE.equals(type)) { return new Float(0); }
+        if (Double.TYPE.equals(type)) { return new Double(0); }
+        if (Character.TYPE.equals(type)) { return new Character((char) 0); }
+        // If all other case, return null.
+        return null;
+    }
+    
     /**
      * Sets the value of the property.
      * @param value the new value.
@@ -451,6 +474,11 @@
             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 });
@@ -478,8 +506,11 @@
      * @return the value if the handler want to inject this value.
      * @see org.apache.felix.ipojo.FieldInterceptor#onGet(java.lang.Object, java.lang.String, java.lang.Object)
      */
-    public Object onGet(Object pojo, String fieldName, Object value) {
-        return getValue();
+    public synchronized Object onGet(Object pojo, String fieldName, Object value) {
+        if (m_value  == NO_VALUE) {
+            return getNoValue(m_type);
+        }
+        return m_value;
     }
 
     /**

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/ServiceReferenceRankingComparator.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/ServiceReferenceRankingComparator.java?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/ServiceReferenceRankingComparator.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/ServiceReferenceRankingComparator.java Fri Nov 14 03:05:57 2008
@@ -18,6 +18,7 @@
  */
 package org.apache.felix.ipojo.util;
 
+import java.io.Serializable;
 import java.util.Comparator;
 
 import org.osgi.framework.Constants;
@@ -28,7 +29,12 @@
  * This comparator follows OSGi Ranking policy.
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
-public class ServiceReferenceRankingComparator implements Comparator {
+public class ServiceReferenceRankingComparator implements Comparator, Serializable {
+
+    /**
+     * Id.
+     */
+    private static final long serialVersionUID = 1L;
 
     /**
      * Compares two service reference.

Modified: felix/trunk/ipojo/core/src/main/resources/core.xsd
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/resources/core.xsd?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/resources/core.xsd (original)
+++ felix/trunk/ipojo/core/src/main/resources/core.xsd Fri Nov 14 03:05:57 2008
@@ -329,30 +329,52 @@
 			</xs:annotation></xs:attribute>
 	</xs:complexType>
 	<xs:complexType name="PropertyType">
-        <xs:annotation>
-        	<xs:documentation>Defines a component property.</xs:documentation>
-        </xs:annotation>
-        <xs:attribute name="field" type="xs:string" use="optional">
-        	<xs:annotation>
-        		<xs:documentation>Field of the property</xs:documentation>
-        	</xs:annotation></xs:attribute>
-        <xs:attribute name="method" type="xs:string" use="optional">
+		<xs:annotation>
+			<xs:documentation>
+				Defines a component property.
+			</xs:documentation>
+		</xs:annotation>
+		<xs:attribute name="field" type="xs:string" use="optional">
+			<xs:annotation>
+				<xs:documentation>
+					Field of the property
+				</xs:documentation>
+			</xs:annotation>
+		</xs:attribute>
+		<xs:attribute name="method" type="xs:string" use="optional">
 			<xs:annotation>
-				<xs:documentation>Setter method of the property. This method is called to inject property value.</xs:documentation>
-			</xs:annotation></xs:attribute>
+				<xs:documentation>
+					Setter method of the property. This method is called
+					to inject property value.
+				</xs:documentation>
+			</xs:annotation>
+		</xs:attribute>
 		<xs:attribute name="name" type="xs:string" use="optional">
 			<xs:annotation>
-				<xs:documentation>Name of the property.</xs:documentation>
-			</xs:annotation></xs:attribute>
+				<xs:documentation>
+					Name of the property.
+				</xs:documentation>
+			</xs:annotation>
+		</xs:attribute>
 		<xs:attribute name="value" type="xs:string" use="optional">
 			<xs:annotation>
-				<xs:documentation>Default value of the property.</xs:documentation>
-			</xs:annotation></xs:attribute>
+				<xs:documentation>
+					Default value of the property.
+				</xs:documentation>
+			</xs:annotation>
+		</xs:attribute>
 		<xs:attribute name="type" type="xs:string" use="optional">
 			<xs:annotation>
-				<xs:documentation>Type of the property.</xs:documentation>
-			</xs:annotation></xs:attribute>
-	</xs:complexType>
+				<xs:documentation>
+					Type of the property.
+				</xs:documentation>
+			</xs:annotation>
+		</xs:attribute>
+        <xs:attribute name="mandatory" type="xs:boolean" use="optional" default="false">
+        	<xs:annotation>
+        		<xs:documentation>Set the property as mandatory. A mandatory property MUST receive a value either in the component type description or in the instance configuration. Properties are optional by default.</xs:documentation>
+        	</xs:annotation></xs:attribute>
+    </xs:complexType>
 	<xs:element name="callback" type="CallbackType" id="callback"></xs:element>
 	<xs:element name="controller" type="ControllerType" id="controller">
 		<xs:annotation>

Modified: felix/trunk/ipojo/core/src/main/resources/metadata.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/resources/metadata.xml?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/resources/metadata.xml (original)
+++ felix/trunk/ipojo/core/src/main/resources/metadata.xml Fri Nov 14 03:05:57 2008
@@ -41,7 +41,7 @@
 		classname="org.apache.felix.ipojo.handlers.architecture.ArchitectureHandler"
 		name="architecture" architecture="false">
 		<provides interface="org.apache.felix.ipojo.architecture.Architecture">
-			<property field="m_name" name="architecture.instance" value="" />
+			<property field="m_name" name="architecture.instance"/>
 		</provides>
 	</handler>
 </ipojo>
\ No newline at end of file

Modified: felix/trunk/ipojo/examples/junit4osgi/junit4osgi/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/examples/junit4osgi/junit4osgi/pom.xml?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/examples/junit4osgi/junit4osgi/pom.xml (original)
+++ felix/trunk/ipojo/examples/junit4osgi/junit4osgi/pom.xml Fri Nov 14 03:05:57 2008
@@ -73,12 +73,13 @@
 							junit.*
 						</Export-Package>
 						<Import-Package>!javax.swing*, *</Import-Package>
-						<Test-Suite>
+						<!-- <Test-Suite>
 							org.apache.felix.ipojo.junit4osgi.test.TestTestCase,
 							org.apache.felix.ipojo.junit4osgi.test.TestOSGiTestCase,
 							org.apache.felix.ipojo.junit4osgi.test.TestTestSuite,
-							org.apache.felix.ipojo.junit4osgi.test.TestOSGiTestSuite
-						</Test-Suite>
+							org.apache.felix.ipojo.junit4osgi.test.TestOSGiTestSuite,
+							org.apache.felix.ipojo.junit4osgi.test.MyTestCase
+						</Test-Suite>  -->
 					</instructions>
 				</configuration>
 			</plugin>

Modified: felix/trunk/ipojo/handler/eventadmin/metadata.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/handler/eventadmin/metadata.xml?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/handler/eventadmin/metadata.xml (original)
+++ felix/trunk/ipojo/handler/eventadmin/metadata.xml Fri Nov 14 03:05:57 2008
@@ -22,7 +22,7 @@
 		name="subscriber"
 		namespace="org.apache.felix.ipojo.handlers.event.EventAdminHandler">
 		<provides>
-			<property field="m_topics" name="event.topics" value=""/>
+			<property field="m_topics" name="event.topics"/>
 		</provides>
 	</handler>
 	

Modified: felix/trunk/ipojo/handler/eventadmin/src/main/java/org/apache/felix/ipojo/handlers/event/publisher/EventAdminPublisherHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/handler/eventadmin/src/main/java/org/apache/felix/ipojo/handlers/event/publisher/EventAdminPublisherHandler.java?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/handler/eventadmin/src/main/java/org/apache/felix/ipojo/handlers/event/publisher/EventAdminPublisherHandler.java (original)
+++ felix/trunk/ipojo/handler/eventadmin/src/main/java/org/apache/felix/ipojo/handlers/event/publisher/EventAdminPublisherHandler.java Fri Nov 14 03:05:57 2008
@@ -87,8 +87,9 @@
 
         // Update the current component description
         Dictionary dict = new Properties();
-        cd.addProperty(new PropertyDescription(TOPICS_PROPERTY,
-                Dictionary.class.getName(), dict.toString()));
+        PropertyDescription pd = new PropertyDescription(TOPICS_PROPERTY,
+                Dictionary.class.getName(), dict.toString());
+        cd.addProperty(pd);
 
         // Get Metadata publishers
         Element[] publishers = metadata.getElements("publisher", NAMESPACE);

Modified: felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/FieldCollector.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/FieldCollector.java?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/FieldCollector.java (original)
+++ felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/FieldCollector.java Fri Nov 14 03:05:57 2008
@@ -294,6 +294,11 @@
          */
         private String m_value;
         
+        /**
+         * Property mandatory aspect.
+         */
+        private String m_mandatory;
+        
         
         /**
          * Constructor.
@@ -320,6 +325,10 @@
                 m_value = arg1.toString();
                 return;
             }
+            if (arg0.equals("mandatory")) {
+                m_mandatory = arg1.toString();
+                return;
+            }
         }
 
         /**
@@ -353,6 +362,9 @@
             if (m_value != null) {
                 prop.addAttribute(new Attribute("value", m_value));
             }
+            if (m_mandatory != null) {
+                prop.addAttribute(new Attribute("mandatory", m_mandatory));
+            }
             
         }
     }

Modified: felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/MethodCollector.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/MethodCollector.java?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/MethodCollector.java (original)
+++ felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/MethodCollector.java Fri Nov 14 03:05:57 2008
@@ -406,6 +406,11 @@
          * Property value. 
          */
         private String m_value;
+        
+        /**
+         * Property mandatory aspect.
+         */
+        private String m_mandatory;
 
         /**
          * Constructor.
@@ -432,6 +437,10 @@
                 m_value = arg1.toString();
                 return;
             }
+            if (arg0.equals("mandatory")) {
+                m_mandatory = arg1.toString();
+                return;
+            }
         }
 
         /**
@@ -464,6 +473,9 @@
             if (m_value != null) {
                 prop.addAttribute(new Attribute("value", m_value));
             }
+            if (m_mandatory != null) {
+                prop.addAttribute(new Attribute("mandatory", m_mandatory));
+            }
 
         }
     }

Modified: felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/Properties.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/Properties.java?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/Properties.java (original)
+++ felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/Properties.java Fri Nov 14 03:05:57 2008
@@ -30,6 +30,8 @@
         assertEquals("Check baa field", "m_baa", baa.getAttribute("field"));
         assertEquals("Check baa name", "baa", baa.getAttribute("name"));
         assertEquals("Check baa method", "setbaa", baa.getAttribute("method"));
+        assertEquals("Check mandatory", "true", baa.getAttribute("mandatory"));
+
         
         //Bar
         Element baz = getPropertyByName(props, "baz");

Modified: felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/ServiceProdiving.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/ServiceProdiving.java?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/ServiceProdiving.java (original)
+++ felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/ServiceProdiving.java Fri Nov 14 03:05:57 2008
@@ -61,6 +61,7 @@
         Element bar = getPropertyByName(props, "bar");
         assertEquals("Check bar field", "bar", bar.getAttribute("field"));
         assertEquals("Check bar value", "4", bar.getAttribute("value"));
+        assertEquals("Check mandatory value", "true", bar.getAttribute("mandatory"));
         //Boo
         Element boo = getPropertyByName(props, "boo");
         assertEquals("Check boo field", "boo", boo.getAttribute("field"));

Modified: felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/Properties.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/Properties.java?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/Properties.java (original)
+++ felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/Properties.java Fri Nov 14 03:05:57 2008
@@ -30,7 +30,7 @@
     @Property(name="baa")
     public int m_baa;
     
-    @Property(value="5")
+    @Property(value="5", mandatory=true)
     public void setbaa(int baa) {
         
     }

Modified: felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ProvidesProperties.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ProvidesProperties.java?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ProvidesProperties.java (original)
+++ felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ProvidesProperties.java Fri Nov 14 03:05:57 2008
@@ -15,7 +15,7 @@
     @ServiceProperty(name = "foo")
     public int m_foo = 0;
     
-    @ServiceProperty(value = "4")
+    @ServiceProperty(value = "4", mandatory=true)
     public int bar;
     
     @ServiceProperty

Modified: felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ConfigurableCheckServiceProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ConfigurableCheckServiceProvider.java?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ConfigurableCheckServiceProvider.java (original)
+++ felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ConfigurableCheckServiceProvider.java Fri Nov 14 03:05:57 2008
@@ -74,14 +74,30 @@
         props.put("c", new Character(c));
         props.put("bool", new Boolean(bool));
         
-        props.put("bs", bs);
-        props.put("ss", ss);
-        props.put("is", is);
-        props.put("ls", ls);
-        props.put("ds", ds);
-        props.put("fs", fs);
-        props.put("cs", cs);
-        props.put("bools", bools);
+        if (bs != null) {
+            props.put("bs", bs);
+        }
+        if (ss != null) {
+            props.put("ss", ss);
+        }
+        if (is != null) {
+            props.put("is", is);
+        }
+        if (ls != null) {
+            props.put("ls", ls);
+        }
+        if (ds != null) {
+            props.put("ds", ds);
+        }
+        if (fs != null) {
+            props.put("fs", fs);
+        }
+        if (cs != null) {
+            props.put("cs", cs);
+        }
+        if (bools != null) {
+            props.put("bools", bools);
+        }
         
         props.put("upb", new Integer(upB));
         props.put("ups", new Integer(upS));
@@ -101,8 +117,13 @@
         props.put("upcs", new Integer(upCs));
         props.put("upbools", new Integer(upBools));
         
-        props.put("string", string);
-        props.put("strings", strings);
+        if (string != null) {
+            props.put("string", string);
+        }
+        if (string != null) {
+            props.put("strings", strings);
+        }
+       
         props.put("upstring", new Integer(upString));
         props.put("upstrings", new Integer(upStrings));
         

Modified: felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderTypeDyn.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderTypeDyn.java?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderTypeDyn.java (original)
+++ felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderTypeDyn.java Fri Nov 14 03:05:57 2008
@@ -33,7 +33,7 @@
 	public boolean foo() {
 		intProp = 3;
 		boolProp = true;
-		if(strProp.equals("foo")) { strProp = "bar"; }
+		if(strProp == null || strProp.equals("foo")) { strProp = "bar"; }
 		else { strProp = "foo"; }
 		strAProp = new String[] {"foo", "bar", "baz"};
 		intAProp = new int[] {3, 2, 1};
@@ -44,9 +44,15 @@
 		Properties p = new Properties();
 		p.put("intProp", new Integer(intProp));
 		p.put("boolProp", new Boolean(boolProp));
-		p.put("strProp", strProp);
-		p.put("strAProp", strAProp);
-		p.put("intAProp", intAProp);
+		if (strProp != null) {
+		      p.put("strProp", strProp);
+		}
+		if (strAProp != null) {
+		    p.put("strAProp", strAProp);
+		}
+		if (intAProp != null) {
+		    p.put("intAProp", intAProp);
+		}
 		return p;
 	}
 	

Added: felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/component/PropertyModifier.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/component/PropertyModifier.java?rev=713976&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/component/PropertyModifier.java (added)
+++ felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/component/PropertyModifier.java Fri Nov 14 03:05:57 2008
@@ -0,0 +1,41 @@
+package org.apache.felix.ipojo.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.configuration.service.CheckService;
+import org.osgi.framework.BundleContext;
+
+public class PropertyModifier implements CheckService {
+    
+    private Class[] classes;
+    private BundleContext context;
+    
+    PropertyModifier(BundleContext bc) {
+        context = bc;
+    }
+
+    public boolean check() {
+        return classes != null;
+    }
+    
+    public void setClasses(String[] classes) throws ClassNotFoundException {
+        Class[] cls = new Class[classes.length];
+        for (int i = 0; i < classes.length; i++) {
+            try {
+                cls[i] = context.getBundle().loadClass(classes[i]);
+            } catch (ClassNotFoundException e) {
+                e.printStackTrace();
+                throw e;
+            }
+        }
+        
+        this.classes = cls;
+    }
+
+    public Properties getProps() {
+        Properties props = new Properties();
+        props.put("classes", classes);
+        return props;
+    }
+
+}

Modified: felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/ConfigurationTestSuite.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/ConfigurationTestSuite.java?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/ConfigurationTestSuite.java (original)
+++ felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/ConfigurationTestSuite.java Fri Nov 14 03:05:57 2008
@@ -35,6 +35,7 @@
 		ots.addTestSuite(TestSuperMethodProperties.class);
 		ots.addTestSuite(ManagedServiceConfigurableProperties.class);
 		ots.addTestSuite(TestComplexProperties.class);
+		ots.addTestSuite(TestPropertyModifier.class);
 		return ots;
 	}
 

Modified: felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/DynamicallyConfigurableProperties.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/DynamicallyConfigurableProperties.java?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/DynamicallyConfigurableProperties.java (original)
+++ felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/DynamicallyConfigurableProperties.java Fri Nov 14 03:05:57 2008
@@ -30,7 +30,7 @@
 
 public class DynamicallyConfigurableProperties extends OSGiTestCase {
 
-	ComponentInstance instance;
+	ComponentInstance instance, instance2;
 	
 	public void setUp() {
 		String type = "CONFIG-FooProviderType-3";
@@ -41,10 +41,17 @@
 		p1.put("bar", "2");
 		p1.put("baz", "baz");
 		instance = Utils.getComponentInstance(context, type, p1);
+		
+		Properties p2 = new Properties();
+        p2.put("instance.name","instance2");
+
+        instance2 = Utils.getComponentInstance(context, type, p2);
 	}
 	
 	public void tearDown() {
 		instance.dispose();
+		instance2.dispose();
+		instance2 = null;
 		instance = null;
 	}
 	
@@ -83,6 +90,41 @@
 		context.ungetService(msRef);
 	}
 	
+	public void testStaticNoValue() {
+        ServiceReference fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance2.getInstanceName());
+        assertNotNull("Check FS availability", fooRef);
+        Object fooP = fooRef.getProperty("foo");
+        Object barP = fooRef.getProperty("bar");
+        Object bazP = fooRef.getProperty("baz");
+        assertEquals("Check foo equality -1", fooP, null);
+        assertEquals("Check bar equality -1", barP, null);
+        assertEquals("Check baz equality -1", bazP, null);
+        
+        ServiceReference msRef = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName(), instance2.getFactory().getName());
+        assertNotNull("Check ManagedServiceFactory availability", msRef);
+        
+        
+        // Configuration of baz
+        Properties conf = new Properties();
+        conf.put("baz", "zab");
+        conf.put("bar", new Integer(2));
+        conf.put("foo", "foo");
+        ManagedServiceFactory ms = (ManagedServiceFactory) context.getService(msRef);
+        try {
+            ms.updated(instance2.getInstanceName(), conf);
+        } catch (ConfigurationException e) { fail("Configuration Exception : " + e); }
+        
+        // Recheck props
+        fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance2.getInstanceName());
+        fooP = (String) fooRef.getProperty("foo");
+        barP = (Integer) fooRef.getProperty("bar");
+        bazP = (String) fooRef.getProperty("baz");
+        assertEquals("Check foo equality -2", fooP, "foo");
+        assertEquals("Check bar equality -2", barP, new Integer(2));
+        assertEquals("Check baz equality -2", bazP, "zab");
+        context.ungetService(msRef);
+    }
+	
 	public void testDynamic() {
     	ServiceReference fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
     	assertNotNull("Check FS availability", fooRef);
@@ -130,6 +172,54 @@
     	context.ungetService(fooRef);
     	context.ungetService(msRef);
     }
+	
+	public void testDynamicNoValue() {
+        ServiceReference fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance2.getInstanceName());
+        assertNotNull("Check FS availability", fooRef);
+        
+        Object fooP = fooRef.getProperty("foo");
+        Object barP = fooRef.getProperty("bar");
+        Object bazP = fooRef.getProperty("baz");
+        assertEquals("Check foo equality -1", fooP, null);
+        assertEquals("Check bar equality -1", barP, null);
+        assertEquals("Check baz equality -1", bazP, null);
+        
+        ServiceReference msRef = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName(), instance2.getFactory().getName());
+        assertNotNull("Check ManagedServiceFactory availability", msRef);
+        
+        // Configuration of baz
+        Properties conf = new Properties();
+        conf.put("baz", "zab");
+        conf.put("foo", "oof");
+        conf.put("bar", new Integer(0));
+        ManagedServiceFactory ms = (ManagedServiceFactory) context.getService(msRef);
+        try {
+            ms.updated(instance2.getInstanceName(), conf);
+        } catch (ConfigurationException e) { fail("Configuration Exception : " + e); }
+        
+        // Recheck props
+        fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance2.getInstanceName());
+        fooP = (String) fooRef.getProperty("foo");
+        barP = (Integer) fooRef.getProperty("bar");
+        bazP = (String) fooRef.getProperty("baz");
+        
+        assertEquals("Check foo equality", fooP, "oof");
+        assertEquals("Check bar equality", barP, new Integer(0));
+        assertEquals("Check baz equality", bazP, "zab");
+        
+        // Check field value
+        FooService fs = (FooService) context.getService(fooRef);
+        Properties p = fs.fooProps();
+        fooP = (String) p.get("foo");
+        barP = (Integer) p.get("bar");
+        
+        assertEquals("Check foo field equality", fooP, "oof");
+        assertEquals("Check bar field equality", barP, new Integer(0));
+        
+        context.ungetService(fooRef);
+        context.ungetService(msRef);
+    }
+
 
     public void testDynamicString() {
 		ServiceReference fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
@@ -224,5 +314,50 @@
 		
 		context.ungetService(msRef);
 	}
+	
+	public void testPropagationNoValue() {
+        ServiceReference fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance2.getInstanceName());
+        assertNotNull("Check FS availability", fooRef);
+        
+        Object fooP = fooRef.getProperty("foo");
+        Object barP = fooRef.getProperty("bar");
+        Object bazP = fooRef.getProperty("baz");
+        assertEquals("Check foo equality -1", fooP, null);
+        assertEquals("Check bar equality -1", barP, null);
+        assertEquals("Check baz equality -1", bazP, null);
+        
+        ServiceReference msRef = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName(), instance2.getFactory().getName());
+        assertNotNull("Check ManagedServiceFactory availability", msRef);
+        
+        // Configuration of baz
+        Properties conf = new Properties();
+        conf.put("baz", "zab");
+        conf.put("foo", "foo");
+        conf.put("bar", new Integer(2));
+        conf.put("propagated1", "propagated");
+        conf.put("propagated2", new Integer(1));
+        ManagedServiceFactory ms = (ManagedServiceFactory) context.getService(msRef);
+        try {
+            ms.updated(instance2.getInstanceName(), conf);
+        } catch (ConfigurationException e) { fail("Configuration Exception : " + e); }
+        
+        // Recheck props
+        fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance2.getInstanceName());
+        fooP = (String) fooRef.getProperty("foo");
+        barP = (Integer) fooRef.getProperty("bar");
+        bazP = (String) fooRef.getProperty("baz");
+        assertNotNull("Check the propagated1 existency", fooRef.getProperty("propagated1"));
+        String prop1 = (String) fooRef.getProperty("propagated1");
+        assertNotNull("Check the propagated2 existency", fooRef.getProperty("propagated2"));
+        Integer prop2 = (Integer) fooRef.getProperty("propagated2");
+        
+        assertEquals("Check foo equality", fooP, "foo");
+        assertEquals("Check bar equality", barP, new Integer(2));
+        assertEquals("Check baz equality", bazP, "zab");
+        assertEquals("Check propagated1 equality", prop1, "propagated");
+        assertEquals("Check propagated2 equality", prop2, new Integer(1));
+        
+        context.ungetService(msRef);
+    }
 
 }

Modified: felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/ManagedServiceConfigurableProperties.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/ManagedServiceConfigurableProperties.java?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/ManagedServiceConfigurableProperties.java (original)
+++ felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/ManagedServiceConfigurableProperties.java Fri Nov 14 03:05:57 2008
@@ -40,6 +40,11 @@
      */
 	ComponentInstance instance2;
 	
+	/**
+     * Instance without configuration. 
+     */
+    ComponentInstance instance3;
+	
 	public void setUp() {
 	    String type = "CONFIG-FooProviderType-4";
         Properties p = new Properties();
@@ -58,13 +63,21 @@
 		p1.put("baz", "baz");
 		p1.put("managed.service.pid", "instance");
 		instance2 = Utils.getComponentInstance(context, type, p1);
+		
+		type = "CONFIG-FooProviderType-3";
+        Properties p2 = new Properties();
+        p2.put("instance.name","instance-3");
+        p2.put("managed.service.pid", "instance-3");
+        instance3 = Utils.getComponentInstance(context, type, p2);
 	}
 	
 	public void tearDown() {
 		instance1.dispose();
 		instance2.dispose();
+		instance3.dispose();
 		instance1 = null;
 		instance2 = null;
+		instance3 = null;
 	}
 	
 	public void testStaticInstance1() {
@@ -137,6 +150,43 @@
         context.ungetService(msRef);
     }
 	
+	public void testStaticInstance3() {
+        ServiceReference fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance3.getInstanceName());
+        assertNotNull("Check FS availability", fooRef);
+        Object fooP = fooRef.getProperty("foo");
+        Object barP =  fooRef.getProperty("bar");
+        Object bazP =  fooRef.getProperty("baz");
+        // No values ... no properties.
+        assertEquals("Check foo equality -1", fooP, null);
+        assertEquals("Check bar equality -1", barP, null);
+        assertEquals("Check baz equality -1", bazP, null);
+        
+        ServiceReference msRef = Utils.getServiceReferenceByPID(context, ManagedService.class.getName(), "instance-3");
+        assertNotNull("Check ManagedService availability", msRef);
+        
+        
+        // Configuration of baz
+        Properties conf = new Properties();
+        conf.put("baz", "zab");
+        conf.put("bar", new Integer(2));
+        conf.put("foo", "foo");
+        ManagedService ms = (ManagedService) context.getService(msRef);
+        try {
+            ms.updated(conf);
+        } catch (ConfigurationException e) { fail("Configuration Exception : " + e); }
+        
+        // Recheck props
+        fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance3.getInstanceName());
+        fooP = (String) fooRef.getProperty("foo");
+        barP = (Integer) fooRef.getProperty("bar");
+        bazP = (String) fooRef.getProperty("baz");
+        assertEquals("Check foo equality -2", fooP, "foo");
+        assertEquals("Check bar equality -2", barP, new Integer(2));
+        assertEquals("Check baz equality -2", bazP, "zab");
+        context.ungetService(fooRef);
+        context.ungetService(msRef);
+    }
+	
 	public void testDynamicInstance1() {
     	ServiceReference fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance1.getInstanceName());
     	assertNotNull("Check FS availability", fooRef);
@@ -232,6 +282,54 @@
         context.ungetService(fooRef);
         context.ungetService(msRef);
     }
+	
+	public void testDynamicInstance3() {
+        ServiceReference fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance3.getInstanceName());
+        assertNotNull("Check FS availability", fooRef);
+        
+        Object fooP = fooRef.getProperty("foo");
+        Object barP =  fooRef.getProperty("bar");
+        Object bazP =  fooRef.getProperty("baz");
+     // No values ... no properties.
+        assertEquals("Check foo equality", fooP, null);
+        assertEquals("Check bar equality", barP, null);
+        assertEquals("Check baz equality", bazP, null);
+        
+        ServiceReference msRef = Utils.getServiceReferenceByPID(context, ManagedService.class.getName(), "instance-3");
+        assertNotNull("Check ManagedServiceFactory availability", msRef);
+        
+        // Configuration of baz
+        Properties conf = new Properties();
+        conf.put("baz", "zab");
+        conf.put("foo", "oof");
+        conf.put("bar", new Integer(0));
+        ManagedService ms = (ManagedService) context.getService(msRef);
+        try {
+            ms.updated(conf);
+        } catch (ConfigurationException e) { fail("Configuration Exception : " + e); }
+        
+        // Recheck props
+        fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance3.getInstanceName());
+        fooP = (String) fooRef.getProperty("foo");
+        barP = (Integer) fooRef.getProperty("bar");
+        bazP = (String) fooRef.getProperty("baz");
+        
+        assertEquals("Check foo equality", fooP, "oof");
+        assertEquals("Check bar equality", barP, new Integer(0));
+        assertEquals("Check baz equality", bazP, "zab");
+        
+        // Check field value
+        FooService fs = (FooService) context.getService(fooRef);
+        Properties p = fs.fooProps();
+        fooP = (String) p.get("foo");
+        barP = (Integer) p.get("bar");
+        
+        assertEquals("Check foo field equality", fooP, "oof");
+        assertEquals("Check bar field equality", barP, new Integer(0));
+        
+        context.ungetService(fooRef);
+        context.ungetService(msRef);
+    }
 
     public void testDynamicStringInstance1() {
         assertEquals("Check instance1 state", ComponentInstance.VALID,instance1.getState());
@@ -427,5 +525,51 @@
         
         context.ungetService(msRef);
     }
+	
+	public void testPropagationInstance3() {
+        ServiceReference fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance3.getInstanceName());
+        assertNotNull("Check FS availability", fooRef);
+        
+        Object fooP = fooRef.getProperty("foo");
+        Object barP =  fooRef.getProperty("bar");
+        Object bazP =  fooRef.getProperty("baz");
+        
+        assertEquals("Check foo equality", fooP, null);
+        assertEquals("Check bar equality", barP, null);
+        assertEquals("Check baz equality", bazP, null);
+        
+        ServiceReference msRef = Utils.getServiceReferenceByPID(context, ManagedService.class.getName(), "instance-3");
+        assertNotNull("Check ManagedService availability", msRef);
+        
+        // Configuration of baz
+        Properties conf = new Properties();
+        conf.put("baz", "zab");
+        conf.put("foo", "foo");
+        conf.put("bar", new Integer(2));
+        conf.put("propagated1", "propagated");
+        conf.put("propagated2", new Integer(1));
+        ManagedService ms = (ManagedService) context.getService(msRef);
+        try {
+            ms.updated(conf);
+        } catch (ConfigurationException e) { fail("Configuration Exception : " + e); }
+        
+        // Recheck props
+        fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance3.getInstanceName());
+        fooP = (String) fooRef.getProperty("foo");
+        barP = (Integer) fooRef.getProperty("bar");
+        bazP = (String) fooRef.getProperty("baz");
+        assertNotNull("Check the propagated1 existency", fooRef.getProperty("propagated1"));
+        String prop1 = (String) fooRef.getProperty("propagated1");
+        assertNotNull("Check the propagated2 existency", fooRef.getProperty("propagated2"));
+        Integer prop2 = (Integer) fooRef.getProperty("propagated2");
+        
+        assertEquals("Check foo equality", fooP, "foo");
+        assertEquals("Check bar equality", barP, new Integer(2));
+        assertEquals("Check baz equality", bazP, "zab");
+        assertEquals("Check propagated1 equality", prop1, "propagated");
+        assertEquals("Check propagated2 equality", prop2, new Integer(1));
+        
+        context.ungetService(msRef);
+    }
 
 }

Modified: felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/SimpleProperties.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/SimpleProperties.java?rev=713976&r1=713975&r2=713976&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/SimpleProperties.java (original)
+++ felix/trunk/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/SimpleProperties.java Fri Nov 14 03:05:57 2008
@@ -30,6 +30,7 @@
 	
 	ComponentInstance fooProvider1;
 	ComponentInstance fooProvider2;
+	ComponentInstance fooProvider3;
 	
 	public void setUp() {
 		String type = "CONFIG-FooProviderType-Conf";
@@ -46,13 +47,19 @@
 		p2.put("strAProp", new String[] {"bar", "foo"});
 		p2.put("intAProp", new int[] {1, 2, 3});
 		fooProvider2 = Utils.getComponentInstance(context, type, p2);
+		
+		Properties p3 = new Properties();
+        p3.put("instance.name","FooProvider-3");
+        fooProvider3 = Utils.getComponentInstance(context, "CONFIG-FooProviderType-ConfNoValue", p3);
 	}
 	
 	public void tearDown() {
 		fooProvider1.dispose();
 		fooProvider2.dispose();
+		fooProvider3.dispose();
 		fooProvider1 = null;
 		fooProvider2 = null;
+		fooProvider3 = null;
 	}
 	
 	public void testComponentTypeConfiguration() {
@@ -167,5 +174,53 @@
 		fs = null;
 		context.ungetService(sr);	
 	}
+	
+	public void testNoValue() {
+        ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-3");
+        assertNotNull("Check the availability of the FS service", sr);
+        
+        FooService fs = (FooService) context.getService(sr);
+        Properties toCheck = fs.fooProps();
+        
+        // Check service properties
+        Integer intProp = (Integer) toCheck.get("intProp");
+        Boolean boolProp = (Boolean) toCheck.get("boolProp");
+        String strProp = (String) toCheck.get("strProp");
+        String[] strAProp = (String[]) toCheck.get("strAProp");
+        int[] intAProp = (int[]) toCheck.get("intAProp");
+        
+        assertEquals("Check intProp equality", intProp, new Integer(0));
+        assertEquals("Check longProp equality", boolProp, new Boolean(false));
+        assertEquals("Check strProp equality", strProp, null);
+        assertNull("Check strAProp nullity", strAProp);
+        assertNull("Check intAProp  nullity", intAProp);
+       
+        assertTrue("invoke fs", fs.foo());
+        toCheck = fs.fooProps();
+        
+        // Re-check the property (change)
+        intProp = (Integer) toCheck.get("intProp");
+        boolProp = (Boolean) toCheck.get("boolProp");
+        strProp = (String) toCheck.get("strProp");
+        strAProp = (String[]) toCheck.get("strAProp");
+        intAProp = (int[]) toCheck.get("intAProp");
+        
+        assertEquals("Check intProp equality", intProp, new Integer(3));
+        assertEquals("Check longProp equality", boolProp, new Boolean(true));
+        assertEquals("Check strProp equality", strProp, new String("bar"));
+        assertNotNull("Check strAProp not nullity", strAProp);
+        String[] v = new String[] {"foo", "bar", "baz"};
+        for (int i = 0; i < strAProp.length; i++) {
+            if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+        }
+        assertNotNull("Check intAProp not nullity", intAProp);
+        int[] v2 = new int[] {3, 2, 1};
+        for (int i = 0; i < intAProp.length; i++) {
+            if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+        }
+        
+        fs = null;
+        context.ungetService(sr);   
+    }
 
 }



Mime
View raw message