Author: clement
Date: Sat Nov  7 10:01:59 2009
New Revision: 833668

URL: http://svn.apache.org/viewvc?rev=833668&view=rev
Log:
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.

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/handlers/configuration/ConfigurationHandlerDescription.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

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=833668&r1=833667&r2=833668&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
 Sat Nov  7 10:01:59 2009
@@ -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;
     }
+    
 
 }

Modified: 
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandlerDescription.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandlerDescription.java?rev=833668&r1=833667&r2=833668&view=diff
==============================================================================
--- 
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandlerDescription.java
 (original)
+++ 
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandlerDescription.java
 Sat Nov  7 10:01:59 2009
@@ -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;
+    }
 
 }

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=833668&r1=833667&r2=833668&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
 Sat Nov  7 10:01:59 2009
@@ -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());
         }

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=833668&r1=833667&r2=833668&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
 Sat Nov  7 10:01:59 2009
@@ -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) {


Reply via email to