FELIX-4114 - Applied patch.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1492171 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java b/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
index 88e5e84..339ce5c 100644
--- a/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
+++ b/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
@@ -83,6 +83,12 @@
     public static final int INSTANCE_STRATEGY = 3;
 
     /**
+     * Factory policy : CUSTOMIZED.
+     * Custom creation strategy
+     */
+    public static final int CUSTOM_STRATEGY = -1;
+
+    /**
      * At this time, it is only the java interface full name.
      */
     private String[] m_serviceSpecifications = new String[0];
@@ -104,9 +110,14 @@
     private Property[] m_properties;
 
     /**
+     * Service providing policy.
+     */
+    private final int m_policy;
+
+    /**
      * Service Object creation policy.
      */
-    private CreationStrategy m_strategy;
+    private final CreationStrategy m_strategy;
 
     /**
      * Were the properties updated during the processing.
@@ -143,10 +154,17 @@
      * @param conf the instance configuration.
      */
     public ProvidedService(ProvidedServiceHandler handler, String[] specification, int factoryPolicy, Class creationStrategyClass, Dictionary conf) {
+        CreationStrategy strategy;
         m_handler = handler;
 
         m_serviceSpecifications = specification;
 
+        if (creationStrategyClass == null) {
+            m_policy = factoryPolicy;
+        } else {
+            m_policy = CUSTOM_STRATEGY;
+        }
+
         // Add instance name, factory name and factory version is set.
         try {
             addProperty(new Property(Factory.INSTANCE_NAME_PROPERTY, null, null, handler.getInstanceManager().getInstanceName(), String.class.getName(), handler.getInstanceManager(), handler));
@@ -176,42 +194,43 @@
 
         if (creationStrategyClass != null) {
             try {
-                m_strategy = (CreationStrategy) creationStrategyClass.newInstance();
+                strategy = (CreationStrategy) creationStrategyClass.newInstance();
             } catch (IllegalAccessException e) {
+                strategy = null;
                 m_handler.error("["
                         + m_handler.getInstanceManager().getInstanceName()
                         + "] The customized service object creation policy "
                         + "(" + creationStrategyClass.getName() + ") is not accessible: "
                         + e.getMessage(), e);
                 getInstanceManager().stop();
-                return;
             } catch (InstantiationException e) {
+                strategy = null;
                 m_handler.error("["
                         + m_handler.getInstanceManager().getInstanceName()
                         + "] The customized service object creation policy "
                         + "(" + creationStrategyClass.getName() + ") cannot be instantiated: "
                         + e.getMessage(), e);
                 getInstanceManager().stop();
-                return;
             }
         } else {
             switch (factoryPolicy) {
                 case SINGLETON_STRATEGY:
-                    m_strategy = new SingletonStrategy();
+                    strategy = new SingletonStrategy();
                     break;
                 case SERVICE_STRATEGY:
                 case STATIC_STRATEGY:
                     // In this case, we need to try to create a new pojo object,
                     // the factory method will handle the creation.
-                    m_strategy = new FactoryStrategy();
+                    strategy = new FactoryStrategy();
                     break;
                 case INSTANCE_STRATEGY:
-                    m_strategy = new PerInstanceStrategy();
+                    strategy = new PerInstanceStrategy();
                     break;
                 // Other policies:
                 // Thread : one service object per asking thread
                 // Consumer : one service object per consumer
                 default:
+                    strategy = null;
                     List specs = Arrays.asList(m_serviceSpecifications);
                     m_handler.error("["
                             + m_handler.getInstanceManager().getInstanceName()
@@ -221,6 +240,7 @@
                     break;
             }
         }
+        m_strategy = strategy;
     }
 
     /**
@@ -228,8 +248,8 @@
      * @param props : the properties to attached to the service registration
      */
     protected void setProperties(Property[] props) {
-        for (int i = 0; i < props.length; i++) {
-            addProperty(props[i]);
+        for (Property prop : props) {
+            addProperty(prop);
         }
     }
 
@@ -697,6 +717,14 @@
         m_postUnregistration = cb;
     }
 
+    public int getPolicy() {
+        return m_policy;
+    }
+
+    public Class<? extends CreationStrategy> getCreationStrategy() {
+        return m_strategy.getClass();
+    }
+
     /**
      * Service Controller.
      */
diff --git a/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription.java b/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription.java
index 2973b41..3709edf 100644
--- a/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription.java
+++ b/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription.java
@@ -154,6 +154,13 @@
     public Object[] getServices() {
         return m_ps.getInstanceManager().getPojoObjects();
     }
-    
+
+    public int getPolicy() {
+        return m_ps.getPolicy();
+    }
+
+    public Class<? extends CreationStrategy> getCreationStrategy() {
+        return m_ps.getCreationStrategy();
+    }
 
 }