Author: clement
Date: Fri Jul 11 01:49:43 2008
New Revision: 675866

URL: http://svn.apache.org/viewvc?rev=675866&view=rev
Log:
Fix the issue Felix-631
Set components as immediate when they don't provide services and do not 
specified that they are not immediate ("immediate="false"").
This detection is not applied for handlers. Handlers are never immediate, as 
their lifecycle is attached to the instance lifecycle.

Modified:
    
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
    
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/HandlerManagerFactory.java
    
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/PrimitiveHandler.java

Modified: 
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java?rev=675866&r1=675865&r2=675866&view=diff
==============================================================================
--- 
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
 (original)
+++ 
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
 Fri Jul 11 01:49:43 2008
@@ -274,6 +274,22 @@
         if (arch == null || arch.equalsIgnoreCase("true")) {
             list.add(new RequiredHandler("architecture", null));
         }
+        
+        
+        // Determine if the component must be immediate.
+        // A component becomes immediate if it doesn't provide a service,
+        // and does not specified that the component is not immediate.
+        if (m_componentMetadata.getElements("provides") == null) {
+            String imm = m_componentMetadata.getAttribute("immediate");
+            if (imm == null || !imm.equalsIgnoreCase("false")) {
+                getLogger().log(
+                        Logger.WARNING,
+                        "The component " + getFactoryName()
+                                + " becomes immediate");
+                m_componentMetadata.addAttribute(new Attribute("immediate",
+                        "true"));
+            }
+        }
 
         // Add lifecycle callback if immediate = true
         RequiredHandler reqCallback = new RequiredHandler("callback", null);
@@ -282,6 +298,7 @@
             list.add(reqCallback);
         }
 
+
         return list;
     }
 

Modified: 
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/HandlerManagerFactory.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/HandlerManagerFactory.java?rev=675866&r1=675865&r2=675866&view=diff
==============================================================================
--- 
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/HandlerManagerFactory.java
 (original)
+++ 
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/HandlerManagerFactory.java
 Fri Jul 11 01:49:43 2008
@@ -18,7 +18,9 @@
  */
 package org.apache.felix.ipojo;
 
+import java.util.ArrayList;
 import java.util.Dictionary;
+import java.util.List;
 
 import org.apache.felix.ipojo.architecture.ComponentTypeDescription;
 import org.apache.felix.ipojo.metadata.Element;
@@ -135,6 +137,39 @@
         instance.configure(m_componentMetadata, configuration);
         return instance;
     }
+    
+
+    /**
+     * Computes required handlers. This method does not manipulate any
+     * non-immutable fields, so does not need to be synchronized.
+     * This method is overridden to avoid to use the same detection rules
+     * than atomic components. Indeed, architecture is disable by default,
+     * and an handler is never immediate.
+     * @return the required handler list.
+     */
+    public List getRequiredHandlerList() {
+        List list = new ArrayList();
+        Element[] elems = m_componentMetadata.getElements();
+        for (int i = 0; i < elems.length; i++) {
+            Element current = elems[i];
+            if (!"manipulation".equals(current.getName())) {
+                RequiredHandler req = new RequiredHandler(current.getName(),
+                        current.getNameSpace());
+                if (!list.contains(req)) {
+                    list.add(req);
+                }
+            }
+        }
+
+        // Unlike normal components, the architecture is enable only when
+        // specified.
+        String arch = m_componentMetadata.getAttribute("architecture");
+        if (arch != null && arch.equalsIgnoreCase("true")) {
+            list.add(new RequiredHandler("architecture", null));
+        }
+
+        return list;
+    }
 
     private class HandlerTypeDescription extends ComponentTypeDescription {
 

Modified: 
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/PrimitiveHandler.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/PrimitiveHandler.java?rev=675866&r1=675865&r2=675866&view=diff
==============================================================================
--- 
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/PrimitiveHandler.java
 (original)
+++ 
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/PrimitiveHandler.java
 Fri Jul 11 01:49:43 2008
@@ -101,7 +101,7 @@
      * @param value : the value passed to the field
      */
     public void onSet(Object pojo, String fieldName, Object value) {
-        // Nothing do do in the default implementation
+        // Nothing to do in the default implementation
     }
 
     /**
@@ -122,7 +122,7 @@
      * @param args arguments array.
      */
     public void onEntry(Object pojo, Method method, Object[] args) { 
-        // Nothing do do in the default implementation
+        // Nothing to do in the default implementation
     }
 
     /**
@@ -134,7 +134,7 @@
      * @param returnedObj : the returned object (boxed for primitive type)
      */
     public void onExit(Object pojo, Method method, Object returnedObj) { 
-        // Nothing do do in the default implementation
+        // Nothing to do in the default implementation
     }
     
     /**
@@ -144,7 +144,7 @@
      * @param throwable : the thrown exception
      */
     public void onError(Object pojo, Method method, Throwable throwable) {
-        // Nothing do do in the default implementation
+        // Nothing to do in the default implementation
     }
     
     /**
@@ -155,7 +155,7 @@
      * @param method : invoked method.
      */
     public void onFinally(Object pojo, Method method) {
-        // Nothing do do in the default implementation
+        // Nothing to do in the default implementation
     }
     
     /**
@@ -164,7 +164,7 @@
      * @param instance : the created instance
      */
     public void onCreation(Object instance) { 
-        // Nothing do do in the default implementation
+        // Nothing to do in the default implementation
     }
     
     


Reply via email to