felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r1492171 - in /felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice: ProvidedService.java ProvidedServiceDescription.java
Date Wed, 12 Jun 2013 12:19:42 GMT
Author: clement
Date: Wed Jun 12 12:19:42 2013
New Revision: 1492171

URL: http://svn.apache.org/r1492171
Log:
FELIX-4114 - Applied patch.

Modified:
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
    felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription.java

Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java?rev=1492171&r1=1492170&r2=1492171&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
(original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
Wed Jun 12 12:19:42 2013
@@ -83,6 +83,12 @@ public class ProvidedService implements 
     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 @@ public class ProvidedService implements 
     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 @@ public class ProvidedService implements 
      * @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 @@ public class ProvidedService implements 
 
         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 @@ public class ProvidedService implements 
                     break;
             }
         }
+        m_strategy = strategy;
     }
 
     /**
@@ -228,8 +248,8 @@ public class ProvidedService implements 
      * @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 @@ public class ProvidedService implements 
         m_postUnregistration = cb;
     }
 
+    public int getPolicy() {
+        return m_policy;
+    }
+
+    public Class<? extends CreationStrategy> getCreationStrategy() {
+        return m_strategy.getClass();
+    }
+
     /**
      * Service Controller.
      */

Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription.java?rev=1492171&r1=1492170&r2=1492171&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription.java
(original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceDescription.java
Wed Jun 12 12:19:42 2013
@@ -154,6 +154,13 @@ public class ProvidedServiceDescription 
     public Object[] getServices() {
         return m_ps.getInstanceManager().getPojoObjects();
     }
-    
+
+    public int getPolicy() {
+        return m_ps.getPolicy();
+    }
+
+    public Class<? extends CreationStrategy> getCreationStrategy() {
+        return m_ps.getCreationStrategy();
+    }
 
 }



Mime
View raw message