Fix issue  FELIX-1854
Ease the usage of service.* properties

Fix issue FELIX-1741
The managed.service.pid value is not 'introspectable' from the architecture service.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@833668 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 b359bd9..abd6629 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
@@ -251,7 +251,7 @@
             }
         }
 
-        m_description = new ConfigurationHandlerDescription(this, m_configurableProperties);
+        m_description = new ConfigurationHandlerDescription(this, m_configurableProperties, m_managedServicePID);
 
     }
 
@@ -536,5 +536,6 @@
     public HandlerDescription getDescription() {
         return m_description;
     }
+    
 
 }
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandlerDescription.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandlerDescription.java
index 7083046..d8bdb4b 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandlerDescription.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandlerDescription.java
@@ -38,18 +38,26 @@
      * The property descriptions.
      */
     private PropertyDescription[] m_properties;
+    
+    /**
+     * The Managed Service PID.
+     * <code>null</code> if not set.
+     */
+    private String m_pid;
 
     /**
      * Creates the description object for the configuration handler description.
      * @param handler the configuration handler.
      * @param props the list of properties.
+     * @param pid the managed service pid or <code>null</code> if not set.
      */
-    public ConfigurationHandlerDescription(Handler handler, List/*<Property>*/ props) {
+    public ConfigurationHandlerDescription(Handler handler, List/*<Property>*/ props, String pid) {
         super(handler);
         m_properties = new PropertyDescription[props.size()];
         for (int i = 0; i < props.size(); i++) {
             m_properties[i] = new PropertyDescription((Property) props.get(i));
-        }
+        }        
+        m_pid = pid;
     }
     
     /**
@@ -59,6 +67,11 @@
      */
     public Element getHandlerInfo() {
         Element elem = super.getHandlerInfo();
+        
+        if (m_pid != null) {
+            elem.addAttribute(new Attribute("managed.service.pid", m_pid));
+        }
+        
         for (int i = 0; i < m_properties.length; i++) {
             String name = m_properties[i].getName();
             Object value = m_properties[i].getValue();
@@ -85,5 +98,14 @@
     public PropertyDescription[] getProperties() {
         return m_properties;
     }
+    
+    /**
+     * Gets the managed service pid.
+     * @return the managed service pid of <code>null</code>
+     * if not set.
+     */
+    public String getManagedServicePid() {
+        return m_pid;
+    }
 
 }
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
index 05076b3..c2cc372 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
@@ -38,6 +38,7 @@
 import org.apache.felix.ipojo.util.Property;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceFactory;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
@@ -113,8 +114,9 @@
      * @param specification the specifications provided by this provided service
      * @param factoryPolicy the service providing policy
      * @param creationStrategyClass the customized service object creation strategy.
+     * @param conf the instance configuration.
      */
-    public ProvidedService(ProvidedServiceHandler handler, String[] specification, int factoryPolicy, Class creationStrategyClass) {
+    public ProvidedService(ProvidedServiceHandler handler, String[] specification, int factoryPolicy, Class creationStrategyClass, Dictionary conf) {
         m_handler = handler;
 
         m_serviceSpecification = specification;
@@ -123,9 +125,25 @@
         try {
             addProperty(new Property("instance.name", null, null, handler.getInstanceManager().getInstanceName(), String.class.getName(), handler.getInstanceManager(), handler));
             addProperty(new Property("factory.name", null, null, handler.getInstanceManager().getFactory().getFactoryName(), String.class.getName(), handler.getInstanceManager(), handler));
+         
             if (handler.getInstanceManager().getFactory().getVersion() != null) {
                 addProperty(new Property("factory.version", null, null, handler.getInstanceManager().getFactory().getVersion(), String.class.getName(), handler.getInstanceManager(), handler));
             }
+
+            // Add the service.* if defined
+            if (conf.get(Constants.SERVICE_PID) != null) {
+                addProperty(new Property(Constants.SERVICE_PID, null, null, (String) conf.get(Constants.SERVICE_PID), String.class.getName(), handler.getInstanceManager(), handler));
+            }
+            if (conf.get(Constants.SERVICE_RANKING) != null) {
+                addProperty(new Property(Constants.SERVICE_RANKING, null, null, (String) conf.get(Constants.SERVICE_RANKING), "int", handler.getInstanceManager(), handler));                
+            }
+            if (conf.get(Constants.SERVICE_VENDOR) != null) {
+                addProperty(new Property(Constants.SERVICE_VENDOR, null, null, (String) conf.get(Constants.SERVICE_VENDOR), String.class.getName(), handler.getInstanceManager(), handler));
+            }
+            if (conf.get(Constants.SERVICE_DESCRIPTION) != null) {
+                addProperty(new Property(Constants.SERVICE_DESCRIPTION, null, null, (String) conf.get(Constants.SERVICE_DESCRIPTION), String.class.getName(), handler.getInstanceManager(), handler));
+            }
+
         } catch (ConfigurationException e) {
             m_handler.error("An exception occurs when adding instance.name and factory.name property : " + e.getMessage());
         }
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
index 901521f..ff0e073 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
@@ -138,7 +138,7 @@
             }
             
             // Then create the provided service
-            ProvidedService svc = new ProvidedService(this, serviceSpecifications, factory, custom);
+            ProvidedService svc = new ProvidedService(this, serviceSpecifications, factory, custom, configuration);
 
             Element[] props = providedServices[i].getElements("Property");
             if (props != null) {
@@ -447,7 +447,7 @@
     }
 
     /**
-     * Add properties to all provided services.
+     * Adds properties to all provided services.
      * @param dict : dictionary of properties to add
      */
     public void addProperties(Dictionary dict) {