You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2009/12/26 12:15:44 UTC

svn commit: r893960 [1/7] - in /felix/trunk/ipojo: annotations/src/main/java/org/apache/felix/ipojo/annotations/ api/ api/src/main/java/org/apache/felix/ipojo/api/ arch/ composite/ composite/src/main/java/org/apache/felix/ipojo/composite/service/provid...

Author: clement
Date: Sat Dec 26 11:15:42 2009
New Revision: 893960

URL: http://svn.apache.org/viewvc?rev=893960&view=rev
Log:
* Fix FELIX-1427
Service dependencies are not able to be injected as smart proxies (generated in bytecode). However the proxies ensure the service object set synchronization.
By default fields now receive proxies (default behavior can be set with the ipojo.depednency.proxy-enabled|disabled system property).

* Fix an interception bug on constructors

* Fix import / package packages of composites and temporal handler as now the core embeds ASM

* Add a classloading issue in the temporal dependencies (Bad classloader)


Added:
    felix/trunk/ipojo/core/LICENSE.asm
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ProxyGenerator.java   (with props)
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ServiceCollection.java   (with props)
    felix/trunk/ipojo/examples/tutorial-maven/hello.client.annotation/src/main/java/ipojo/example/hello/client/MyDummyHello.java   (with props)
    felix/trunk/ipojo/manipulator/src/main/resources/core.xsd   (with props)
    felix/trunk/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/ProxiedCollectionMultipleDependencies.java   (with props)
    felix/trunk/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/ProxiedDelayedMultipleDependencies.java   (with props)
    felix/trunk/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/ProxiedDelayedOptionalDependencies.java   (with props)
    felix/trunk/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/ProxiedDelayedOptionalMultipleDependencies.java   (with props)
    felix/trunk/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/ProxiedDelayedSimpleDependencies.java   (with props)
    felix/trunk/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/ProxiedListMultipleDependencies.java   (with props)
    felix/trunk/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/ProxiedOptionalDependencies.java   (with props)
    felix/trunk/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/ProxiedSetMultipleDependencies.java   (with props)
    felix/trunk/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/ProxiedSimpleDependencies.java   (with props)
    felix/trunk/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/ProxyTest.java   (with props)
    felix/trunk/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/proxy/
    felix/trunk/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/proxy/CheckServiceDelegator.java   (with props)
    felix/trunk/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/proxy/CheckServiceGetAndDelegate.java   (with props)
    felix/trunk/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/proxy/CheckServiceNoDelegate.java   (with props)
    felix/trunk/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/proxy/Helper.java   (with props)
Modified:
    felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Requires.java
    felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Unbind.java
    felix/trunk/ipojo/api/pom.xml
    felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/Dependency.java
    felix/trunk/ipojo/arch/pom.xml
    felix/trunk/ipojo/composite/pom.xml
    felix/trunk/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/CompositionMetadata.java
    felix/trunk/ipojo/core/NOTICE
    felix/trunk/ipojo/core/pom.xml
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyDescription.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandlerDescription.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ServiceUsage.java
    felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/MethodMetadata.java
    felix/trunk/ipojo/core/src/main/resources/core.xsd
    felix/trunk/ipojo/examples/tutorial-maven/hello.client.annotation/src/main/java/ipojo/example/hello/client/HelloClient.java
    felix/trunk/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalDependency.java
    felix/trunk/ipojo/junit4osgi/junit4osgi/metadata.xml
    felix/trunk/ipojo/junit4osgi/maven-junit4osgi-plugin/pom.xml
    felix/trunk/ipojo/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/Junit4osgiPlugin.java
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/FieldCollector.java
    felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/annotations/MethodCollector.java
    felix/trunk/ipojo/metadata/pom.xml
    felix/trunk/ipojo/tests/bundleAsiPOJO/helpers/pom.xml
    felix/trunk/ipojo/tests/bundleAsiPOJO/helpers/src/main/java/org/apache/felix/ipojo/test/helpers/IPOJOHelper.java
    felix/trunk/ipojo/tests/bundleAsiPOJO/pom.xml
    felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/Dependency.java
    felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/Dependency.java
    felix/trunk/ipojo/tests/core/service-dependency-filter/src/main/resources/metadata.xml
    felix/trunk/ipojo/tests/core/service-dependency/pom.xml
    felix/trunk/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/DependencyArchitectureTest.java
    felix/trunk/ipojo/tests/core/service-dependency/src/main/java/org/apache/felix/ipojo/test/scenarios/service/dependency/DependencyTestSuite.java
    felix/trunk/ipojo/tests/core/service-dependency/src/main/resources/metadata.xml
    felix/trunk/ipojo/tests/core/service-providing-strategies/src/main/resources/metadata.xml

Modified: felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Requires.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Requires.java?rev=893960&r1=893959&r2=893960&view=diff
==============================================================================
--- felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Requires.java (original)
+++ felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Requires.java Sat Dec 26 11:15:42 2009
@@ -19,6 +19,7 @@
 package org.apache.felix.ipojo.annotations;
 
 import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
 import java.lang.annotation.Target;
 import java.util.Comparator;
 
@@ -27,6 +28,7 @@
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
 @Target(ElementType.FIELD)
+@Inherited
 public @interface Requires {
     
     /**
@@ -84,4 +86,11 @@
      * This attribute is required for Collection field.
      */
     String specification() default "";
+    
+    /**
+     * Set to true if the service dependency is injected
+     * as a proxy.
+     * Default: true
+     */
+    boolean proxy() default true;
 }

Modified: felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Unbind.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Unbind.java?rev=893960&r1=893959&r2=893960&view=diff
==============================================================================
--- felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Unbind.java (original)
+++ felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/annotations/Unbind.java Sat Dec 26 11:15:42 2009
@@ -77,5 +77,5 @@
      * Set the from attribute.
      */
     String from() default "";
-
+    
 }

Modified: felix/trunk/ipojo/api/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/api/pom.xml?rev=893960&r1=893959&r2=893960&view=diff
==============================================================================
--- felix/trunk/ipojo/api/pom.xml (original)
+++ felix/trunk/ipojo/api/pom.xml Sat Dec 26 11:15:42 2009
@@ -58,7 +58,8 @@
               org.apache.felix.ipojo.api.composite,
               org.apache.felix.ipojo.manipulation,
               org.apache.felix.ipojo.manipulation.annotations,
-              org.objectweb.asm.commons, org.objectweb.asm
+              org.objectweb.asm.commons;version=3.0, 
+              org.objectweb.asm;version=3.0
             </Export-Package>
             <Include-Resource> META-INF/LICENSE=LICENSE,
               META-INF/NOTICE=NOTICE, META-INF/LICENSE.asm=LICENSE.asm

Modified: felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/Dependency.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/Dependency.java?rev=893960&r1=893959&r2=893960&view=diff
==============================================================================
--- felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/Dependency.java (original)
+++ felix/trunk/ipojo/api/src/main/java/org/apache/felix/ipojo/api/Dependency.java Sat Dec 26 11:15:42 2009
@@ -116,6 +116,11 @@
      * Does the dependency supports nullable? 
      */
     private boolean m_nullable = true;
+    
+    /**
+     * Does the dependency enables proxy. 
+     */
+    private boolean m_proxy = true;
 
     /**
      * Gets the dependency metadata.
@@ -174,6 +179,9 @@
         if (m_aggregate) {
             dep.addAttribute(new Attribute("aggregate", "true"));
         }
+        if (! m_proxy) {
+            dep.addAttribute(new Attribute("proxy", "false"));
+        }
         if (m_policy != -1) {
             if (m_policy == DYNAMIC) {
                 dep.addAttribute(new Attribute("policy", "dynamic"));
@@ -251,6 +259,17 @@
     }
     
     /**
+     * Sets if the dependency injects proxies.
+     * @param proxy <code>false</code> if the dependency does not
+     * inject proxies but uses direct references.
+     * @return the current dependency object.
+     */
+    public Dependency setProxy(boolean proxy) {
+        m_proxy = proxy;
+        return this;
+    }
+    
+    /**
      * Sets the dependency bind method.
      * @param bind the bind method name
      * @return the current dependency object.

Modified: felix/trunk/ipojo/arch/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/arch/pom.xml?rev=893960&r1=893959&r2=893960&view=diff
==============================================================================
--- felix/trunk/ipojo/arch/pom.xml (original)
+++ felix/trunk/ipojo/arch/pom.xml Sat Dec 26 11:15:42 2009
@@ -84,9 +84,9 @@
             <ipojo>
               <component classname="org.apache.felix.ipojo.arch.ArchCommandImpl" public="false">
                 <Provides />
-                <requires field="m_archs" optional="true" />
-                <requires field="m_factories" optional="true" />
-                <requires field="m_handlers" optional="true" />
+                <requires field="m_archs" optional="true" proxy="false"/>
+                <requires field="m_factories" optional="true" proxy="false"/>
+                <requires field="m_handlers" optional="true" proxy="false"/>
               </component>
               <instance component="org.apache.felix.ipojo.arch.ArchCommandImpl" name="ArchCommand" />
             </ipojo>

Modified: felix/trunk/ipojo/composite/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/composite/pom.xml?rev=893960&r1=893959&r2=893960&view=diff
==============================================================================
--- felix/trunk/ipojo/composite/pom.xml (original)
+++ felix/trunk/ipojo/composite/pom.xml Sat Dec 26 11:15:42 2009
@@ -80,6 +80,7 @@
               org.apache.felix.ipojo.metadata,
               org.apache.felix.ipojo.parser,
               org.apache.felix.ipojo.util,
+              org.objectweb.asm*;version=3.0,
               org.osgi.framework;version=1.3 </Import-Package>
             <Private-Package>
               org.apache.felix.ipojo.composite.architecture,
@@ -90,7 +91,7 @@
             <Export-Package>
               org.apache.felix.ipojo.composite; version="${ipojo.package.version}" ,
               !org.objectweb.asm.xml*,
-              org.objectweb.asm*;-split-package:=merge-first ,
+              org.objectweb.asm*;version=3.0;-split-package:=merge-first ,
               org.apache.felix.ipojo.manipulation
             </Export-Package>
             <Include-Resource> META-INF/LICENSE=LICENSE,

Modified: felix/trunk/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/CompositionMetadata.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/CompositionMetadata.java?rev=893960&r1=893959&r2=893960&view=diff
==============================================================================
--- felix/trunk/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/CompositionMetadata.java (original)
+++ felix/trunk/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/CompositionMetadata.java Sat Dec 26 11:15:42 2009
@@ -273,6 +273,7 @@
                 Element dep = new Element("requires", "");
                 dep.addAttribute(new Attribute("field", field.getName()));
                 dep.addAttribute(new Attribute("scope", "composite"));
+                dep.addAttribute(new Attribute("proxy", "false"));
                 if (field.getSpecification().isOptional()) {
                     dep.addAttribute(new Attribute("optional", "true"));
                 }

Added: felix/trunk/ipojo/core/LICENSE.asm
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/LICENSE.asm?rev=893960&view=auto
==============================================================================
--- felix/trunk/ipojo/core/LICENSE.asm (added)
+++ felix/trunk/ipojo/core/LICENSE.asm Sat Dec 26 11:15:42 2009
@@ -0,0 +1,29 @@
+Copyright (c) 2000-2005 INRIA, France Telecom
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+3. Neither the name of the copyright holders nor the names of its
+   contributors may be used to endorse or promote products derived from
+   this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+THE POSSIBILITY OF SUCH DAMAGE.

Modified: felix/trunk/ipojo/core/NOTICE
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/NOTICE?rev=893960&r1=893959&r2=893960&view=diff
==============================================================================
--- felix/trunk/ipojo/core/NOTICE (original)
+++ felix/trunk/ipojo/core/NOTICE Sat Dec 26 11:15:42 2009
@@ -12,6 +12,10 @@
 Copyright (c) OSGi Alliance (2000, 2007).
 Licensed under the Apache License 2.0.
 
+This product includes software developed at
+Copyright (c) 2000-2005 INRIA, France Telecom
+Licensed under BSD License.
+
 II. Used Software
 
 This product uses software developed at

Modified: felix/trunk/ipojo/core/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/pom.xml?rev=893960&r1=893959&r2=893960&view=diff
==============================================================================
--- felix/trunk/ipojo/core/pom.xml (original)
+++ felix/trunk/ipojo/core/pom.xml Sat Dec 26 11:15:42 2009
@@ -57,6 +57,17 @@
       <artifactId>org.apache.felix.ipojo.metadata</artifactId>
       <version>${pom.version}</version>
     </dependency>
+    <dependency>
+      <groupId>asm</groupId>
+      <artifactId>asm-all</artifactId>
+      <version>3.0</version>
+      <exclusions>
+        <exclusion>
+          <groupId>asm</groupId>
+          <artifactId>asm-tree</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
   </dependencies>
   <build>
     <plugins>
@@ -102,11 +113,12 @@
               org.apache.felix.ipojo.handlers.configuration; version="${ipojo.package.version}",
               org.apache.felix.ipojo.context; version="${ipojo.package.version}",
               org.osgi.service.cm,
-              org.osgi.service.log
+              org.osgi.service.log,
+              org.objectweb.asm; version=3.0
             </Export-Package>
             <Include-Resource>
               META-INF/LICENSE=LICENSE,
-              META-INF/NOTICE=NOTICE
+              META-INF/NOTICE=NOTICE, META-INF/LICENSE.asm=LICENSE.asm
             </Include-Resource>
             <_donotcopy> (CVS|.svn|.+.bak|~.+|metadata.xml) </_donotcopy>
           </instructions>

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=893960&r1=893959&r2=893960&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 Sat Dec 26 11:15:42 2009
@@ -407,6 +407,10 @@
     public String getVersion() {
         return m_version;
     }
+    
+    public ClassLoader getBundleClassLoader() {
+        return m_classLoader;
+    }
 
     /**
      * this class defines the classloader attached to a factory.

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java?rev=893960&r1=893959&r2=893960&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/InstanceManager.java Sat Dec 26 11:15:42 2009
@@ -37,7 +37,7 @@
 import org.osgi.framework.BundleContext;
 
 /**
- * This class defines the container of primitive instances. It manages content initialization 
+ * This class defines the container of primitive instances. It manages content initialization
  * and handlers cooperation.
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
@@ -59,7 +59,7 @@
 
     /**
      * The current instance state ({@link ComponentInstance#STOPPED} at the beginning).
-     * Possible value are 
+     * Possible value are
      * <li>{@link ComponentInstance#INVALID}</li>
      * <li>{@link ComponentInstance#VALID}</li>
      * <li>{@link ComponentInstance#DISPOSED}</li>
@@ -77,7 +77,7 @@
      * The instance factory.
      */
     private final ComponentFactory m_factory;
-    
+
     /**
      * The instance description.
      */
@@ -113,7 +113,7 @@
 
     /**
      * The factory method used to create content objects.
-     * If <code>null</code>, the regular constructor is used. 
+     * If <code>null</code>, the regular constructor is used.
      * Once set, this field is immutable.
      */
     private String m_factoryMethod = null;
@@ -129,7 +129,7 @@
     private List m_stateQueue = new ArrayList();
 
     /**
-     * The map of [field, value], storing POJO managed 
+     * The map of [field, value], storing POJO managed
      * field value.
      */
     private Map m_fields = new HashMap();
@@ -167,7 +167,7 @@
 
         // Add the name
         m_name = (String) configuration.get("instance.name");
-        
+
         // Check if an object is injected in the instance
         Object obj = configuration.get("instance.object");
         if (obj != null) {
@@ -248,11 +248,11 @@
      */
     public synchronized Object getFieldValue(String fieldName, Object pojo) {
         Object setByContainer = null;
-        
+
         if (m_fields != null) {
             setByContainer = m_fields.get(fieldName);
         }
-        
+
         if (setByContainer == null && pojo != null) { // In the case of no given pojo, return null.
             // If null either the value was not already set or has the null value.
             try {
@@ -289,13 +289,13 @@
                 m_state = -2; // Temporary state.
             }
         }
-        
+
         // Plug handler descriptions
         Handler[] handlers = getRegistredHandlers();
         for (int i = 0; i < handlers.length; i++) {
             m_description.addHandler(handlers[i].getDescription());
         }
-        
+
         for (int i = 0; i < m_handlers.length; i++) {
             m_handlers[i].addInstanceStateListener(this);
             try {
@@ -306,12 +306,12 @@
                 throw e;
             }
         }
-        
+
         // Is an object already contained (i.e. injected)
         if (m_pojoObjects != null && ! m_pojoObjects.isEmpty()) {
             managedInjectedObject();
         }
-        
+
         for (int i = 0; i < m_handlers.length; i++) {
             if (m_handlers[i].getState() != VALID) {
                 setState(INVALID);
@@ -332,11 +332,11 @@
         synchronized (this) {
             if (m_state == STOPPED) { // Instance already stopped
                 return;
-            } 
+            }
             m_stateQueue.clear();
             m_inTransition = false;
         }
-        
+
         setState(INVALID); // Must be called outside a synchronized block.
 
         // Stop all the handlers
@@ -344,7 +344,7 @@
             m_handlers[i].removeInstanceStateListener(this);
             m_handlers[i].stop();
         }
-        
+
         synchronized (this) {
             m_state = STOPPED;
             if (m_listeners != null) {
@@ -379,11 +379,11 @@
             }
             m_listeners = null;
         }
-        
+
         if (state > STOPPED) { // Valid or invalid
             stop(); // Does not hold the lock.
         }
-        
+
         synchronized (this) {
             m_state = DISPOSED;
         }
@@ -406,9 +406,9 @@
     }
 
     /**
-     * Sets the state of the component instance. 
+     * Sets the state of the component instance.
      * If the state changes, calls the {@link PrimitiveHandler#stateChanged(int)} method on the attached handlers.
-     * This method has a reentrant mechanism. If in the flow of the first call the method is called another times, 
+     * This method has a reentrant mechanism. If in the flow of the first call the method is called another times,
      * the second call is stored and executed after the first one finished.
      * @param state the new state
      */
@@ -489,7 +489,7 @@
 
     /**
      * Checks if the instance is started.
-     * An instance is started if the state is either 
+     * An instance is started if the state is either
      * {@link ComponentInstance#VALID} or {@link ComponentInstance#INVALID}.
      * @return <code>true</code> if the instance is started.
      * @see org.apache.felix.ipojo.ComponentInstance#isStarted()
@@ -556,7 +556,7 @@
         }
         return m_pojoObjects.toArray(new Object[m_pojoObjects.size()]);
     }
-    
+
     /**
      * Creates a POJO objects.
      * This method is not synchronized and does require any locks.
@@ -585,9 +585,9 @@
                         cst.setAccessible(true);
                     }
                     Object[] args = new Object[] { this, m_context };
-                    onEntry(null, m_className,  new Object[] {m_context});
+                    onEntry(null, MethodMetadata.BC_CONSTRUCTOR_ID,  new Object[] {m_context});
                     instance = cst.newInstance(args);
-                    onExit(null, m_className, instance);
+                    onExit(instance, MethodMetadata.BC_CONSTRUCTOR_ID, instance);
                 } catch (NoSuchMethodException e) {
                     // Create an instance if no instance are already created with <init>()BundleContext
                     if (instance == null) {
@@ -596,9 +596,9 @@
                             cst.setAccessible(true);
                         }
                         Object[] args = new Object[] {this};
-                        onEntry(null, m_className, new Object[0]);
+                        onEntry(null, MethodMetadata.EMPTY_CONSTRUCTOR_ID, new Object[0]);
                         instance = cst.newInstance(args);
-                        onExit(null, m_className, instance);
+                        onExit(instance, MethodMetadata.EMPTY_CONSTRUCTOR_ID, instance);
                     }
                 }
             } catch (IllegalAccessException e) {
@@ -712,18 +712,18 @@
     }
 
     /**
-     * Creates an instance of the content. 
+     * Creates an instance of the content.
      * This method needs to be called once only for singleton provided service.
      * This methods call the {@link InstanceManager#createObject()} method, and adds
      * the created object to the {@link InstanceManager#m_pojoObjects} list. Then,
-     * it calls the {@link PrimitiveHandler#onCreation(Object)} methods on attached 
+     * it calls the {@link PrimitiveHandler#onCreation(Object)} methods on attached
      * handlers.
      * @return a new instance or <code>null</code> if an error occurs during the
      * creation.
      */
     public Object createPojoObject() {
         Object instance = createObject();
-        
+
         // Add the new instance in the instance list.
         synchronized (this) {
             if (m_pojoObjects == null) {
@@ -736,10 +736,10 @@
             // This methods must be call without the monitor lock.
             ((PrimitiveHandler) m_handlers[i].getHandler()).onCreation(instance);
         }
-        
+
         return instance;
     }
-    
+
     /**
      * Deletes a POJO object.
      * @param pojo the pojo to remove from the list of created pojos.
@@ -751,11 +751,11 @@
     }
 
     /**
-     * Gets the first object created by the instance. 
+     * Gets the first object created by the instance.
      * If no object created, creates and returns a POJO object.
      * This methods call the {@link InstanceManager#createObject()} method, and adds
      * the created object to the {@link InstanceManager#m_pojoObjects} list. Then,
-     * it calls the {@link PrimitiveHandler#onCreation(Object)} methods on attached 
+     * it calls the {@link PrimitiveHandler#onCreation(Object)} methods on attached
      * handlers.
      * <br/>
      * <p>
@@ -781,11 +781,11 @@
                 newPOJO = true;
             }
         }
-        
+
         // Call createInstance on Handlers :
         for (int i = 0; newPOJO && i < m_handlers.length; i++) {
             ((PrimitiveHandler) m_handlers[i].getHandler()).onCreation(pojo);
-        } 
+        }
         //NOTE this method allows returning a POJO object before calling the onCreation on handler:
         // a second thread get the created object before the first one (which created the object),
         // call onCreation.
@@ -805,52 +805,52 @@
         }
         return m_clazz;
     }
-    
+
     /**
      * Configures an injected object in this container.
      */
     private void managedInjectedObject() {
         Object obj = m_pojoObjects.get(0); // Get first object.
-   
+
         if (! (obj instanceof Pojo)) {
             // Error, the injected object is not a POJO.
             throw new RuntimeException("The injected object in " + m_name + " is not a POJO");
         }
-        
+
         load(); // Load the class.
 
         if (! m_clazz.isInstance(obj)) {
             throw new RuntimeException("The injected object in " + m_name + " is not an instance of " + m_className);
         }
-        
+
         // Call _setInstanceManager
         try {
             Method setIM = m_clazz.getDeclaredMethod("_setInstanceManager", new Class[] {this.getClass()});
             setIM.setAccessible(true); // Necessary as the method is private
             setIM.invoke(obj, new Object[] {this});
         } catch (Exception e) {
-            // If anything wrong happened... 
+            // If anything wrong happened...
             throw new RuntimeException("Cannot attach the injected object with the container of " + m_name + " : " + e.getMessage());
         }
-        
+
         // Call createInstance on Handlers :
         for (int i = 0; i < m_handlers.length; i++) {
             // This methods must be call without the monitor lock.
             ((PrimitiveHandler) m_handlers[i].getHandler()).onCreation(obj);
         }
-        
-        
+
+
     }
 
     /**
      * Registers an handler.
      * This methods is called by handler wanting to monitor
-     * fields and/or methods of the implementation class.  
+     * fields and/or methods of the implementation class.
      * @param handler the handler to register
      * @param fields the field metadata list
      * @param methods the method metadata list
      * @deprecated use {@link InstanceManager#register(FieldMetadata, FieldInterceptor)}
-     * and {@link InstanceManager#register(FieldMetadata, MethodInterceptor)} instead. 
+     * and {@link InstanceManager#register(FieldMetadata, MethodInterceptor)} instead.
      */
     public void register(PrimitiveHandler handler, FieldMetadata[] fields, MethodMetadata[] methods) {
         for (int i = 0; fields != null && i < fields.length; i++) {
@@ -861,7 +861,7 @@
         }
 
     }
-    
+
     /**
      * Registers a field interceptor.
      * A field interceptor will be notified of field access of the
@@ -890,7 +890,7 @@
             }
         }
     }
-    
+
     /**
      * Registers a method interceptor.
      * A method interceptor will be notified of method entries, exits
@@ -989,6 +989,7 @@
         }
         MethodInterceptor[] list = (MethodInterceptor[]) m_methodRegistration.get(methodId);
         Method method = getMethodById(methodId);
+        // In case of a constructor, the method is null, and the list is null too.
         for (int i = 0; list != null && i < list.length; i++) {
             list[i].onEntry(pojo, method, args); // Outside a synchronized block.
         }
@@ -999,7 +1000,7 @@
      * The given returned object is an instance of {@link Exception} if the method thrown an
      * exception. If the given object is <code>null</code>, either the method returns <code>void</code>,
      * or the method has returned <code>null</code>
-     * This method calls the {@link PrimitiveHandler#onExit(Object, Method, Object[])} and the 
+     * This method calls the {@link PrimitiveHandler#onExit(Object, Method, Object[])} and the
      * {@link PrimitiveHandler#onFinally(Object, Method)} methods on method interceptors monitoring the method.
      * @param pojo the pojo object on which method was invoked.
      * @param methodId the method id used to compute the {@link Method} object.
@@ -1022,14 +1023,14 @@
     /**
      * Dispatches error method events on registered method interceptors.
      * or the method has returned <code>null</code>
-     * This method calls the {@link PrimitiveHandler#onExit(Object, Method, Object[])} and the 
-     * {@link PrimitiveHandler#onFinally(Object, Method)} methods on method interceptors monitoring 
+     * This method calls the {@link PrimitiveHandler#onExit(Object, Method, Object[])} and the
+     * {@link PrimitiveHandler#onFinally(Object, Method)} methods on method interceptors monitoring
      * the method.
      * @param pojo the pojo object on which the method was invoked
      * @param methodId the method id used to compute the {@link Method} object.
      * @param error the Throwable object.
      */
-    public void onError(Object pojo, String methodId, Throwable error) {        
+    public void onError(Object pojo, String methodId, Throwable error) {
         if (m_methodRegistration == null) {
             return;
         }
@@ -1064,7 +1065,7 @@
                 }
             }
             // If not found, it is a constructor, return null in this case.
-            if (methodId.equals(m_clazz.getName())) {
+            if (methodId.startsWith(MethodMetadata.CONSTRUCTOR_PREFIX)) {
                 // Constructor.
                 return null;
             }
@@ -1077,7 +1078,7 @@
     }
 
     /**
-     * This method is called by the manipulated class each time that a PUTFILED instruction is executed. 
+     * This method is called by the manipulated class each time that a PUTFILED instruction is executed.
      * The method calls the {@link PrimitiveHandler#onSet(Object, String, Object)} method on each field
      * interceptors monitoring this field.
      * This method can be invoked with a <code>null</code> pojo argument when the changes comes from another
@@ -1102,7 +1103,7 @@
         }
     }
 
-    
+
     /**
      * Gets the bundle context used by this component instance.
      * @return the context of the component.
@@ -1121,8 +1122,8 @@
     public BundleContext getGlobalContext() {
         return ((IPojoContext) m_context).getGlobalContext(); // Immutable
     }
-    
-    
+
+
     /**
      * Gets the local service context. This service context gives
      * access to the 'local' service registry (the composite one).
@@ -1151,8 +1152,8 @@
      * such as the instance name.
      * This methods calls the {@link PrimitiveHandler#reconfigure(Dictionary)}
      * methods on each attached handler, and then recompute the instance
-     * state. Note that the reconfiguration process does not deactivate the 
-     * instance. 
+     * state. Note that the reconfiguration process does not deactivate the
+     * instance.
      * @param configuration the new configuration to push
      * @see org.apache.felix.ipojo.ComponentInstance#reconfigure(java.util.Dictionary)
      */
@@ -1177,7 +1178,7 @@
     /**
      * Gets the implementation class of the component type.
      * This method does not need to be synchronized as the
-     * class name is constant once set. 
+     * class name is constant once set.
      * @return the class name of the component implementation.
      */
     public String getClassName() {
@@ -1222,7 +1223,7 @@
     }
 
     /**
-     * Gets the list of registered fields (containing field names). 
+     * Gets the list of registered fields (containing field names).
      * This method is invoked by the POJO itself during
      * its initialization.
      * @return the set of registered fields.
@@ -1235,7 +1236,7 @@
     }
 
     /**
-     * Gets the list of registered methods (containing method ids). 
+     * Gets the list of registered methods (containing method ids).
      * This method is invoked by the POJO itself during its
      * initialization.
      * @return the set of registered methods.

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java?rev=893960&r1=893959&r2=893960&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/Dependency.java Sat Dec 26 11:15:42 2009
@@ -19,6 +19,7 @@
 package org.apache.felix.ipojo.handlers.dependency;
 
 import java.lang.reflect.Array;
+import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
@@ -111,6 +112,16 @@
      * Immutable once set.
      */
     private String m_id;
+    
+    /**
+     * Do we have to inject proxy?
+     */
+    private boolean m_isProxy;
+    
+    /**
+     * Proxy Object.
+     */
+    private Object m_proxyObject;
 
     /**
      * Dependency constructor. After the creation the dependency is not started.
@@ -122,22 +133,25 @@
      * @param isOptional : is the dependency an optional dependency ?
      * @param isAggregate : is the dependency an aggregate dependency
      * @param nullable : describe if the nullable ability is enable or disable
+     * @param isProxy : is the proxied dependency
      * @param identity : id of the dependency, may be null
      * @param context : bundle context (or service context) to use.
      * @param policy : resolution policy
      * @param cmp : comparator to sort references
      * @param defaultImplem : default-implementation class
      */
-    public Dependency(DependencyHandler handler, String field, Class spec, Filter filter, boolean isOptional, boolean isAggregate, boolean nullable, String identity, BundleContext context, int policy, Comparator cmp, String defaultImplem) {
+    public Dependency(DependencyHandler handler, String field, Class spec, Filter filter, boolean isOptional, boolean isAggregate, boolean nullable, boolean isProxy, String identity, BundleContext context, int policy, Comparator cmp, String defaultImplem) {
         super(spec, isAggregate, isOptional, filter, cmp, policy, context, handler, handler.getInstanceManager());
         m_handler = handler;
         m_field = field;
+        m_isProxy = isProxy;
+
         if (field != null) {
             m_usage = new ServiceUsage();
         } else {
             m_usage = null;
         }
-
+        
         m_supportNullable = nullable;
         m_di = defaultImplem;
 
@@ -321,6 +335,7 @@
      * Start the dependency.
      */
     public void start() {
+        
         if (isOptional() && !isAggregate()) {
             if (m_di == null) {
                 // If nullable are supported, create the nullable object.
@@ -357,6 +372,15 @@
                 }
             }
         }
+        
+        if (m_isProxy) {
+            if (isAggregate()) {
+                m_proxyObject = new ServiceCollection(this);
+            } else {
+                ProxyFactory proxyFactory = new ProxyFactory(this.getClass().getClassLoader());
+                m_proxyObject = proxyFactory.getProxy(getSpecification(), this);
+            }
+        }
 
         super.start();
         // Once the dependency is started, access to fields must be synchronized.
@@ -463,6 +487,84 @@
             return Arrays.asList(refs);
         }
     }
+    
+    /**
+     * Called by the proxy to get  service objects to delegate a method.
+     * On aggregate dependencies, it returns a list.
+     * @return a service object or a nullable/default-implementation object.
+     * For aggregate dependencies it returns a list or an empty list.
+     */
+    public Object getService() {
+        // Check that we're in proxy mode.
+        if (! m_isProxy) {
+            throw new IllegalStateException("The dependency is not a proxied dependency");
+        }
+        
+        Usage usage = (Usage) m_usage.get();
+        if (usage.m_stack == 0) { // uninitialized usage.
+            if (usage.m_componentStack > 0) {
+                // We comes from the component who didn't touch the service.
+                // So we initialize the usage.
+                createServiceObject(usage);
+                usage.inc(); // Start the caching, so set the stack level to 1
+                m_usage.set(usage);
+                if (isAggregate()) {
+                    Object obj =  usage.m_object;
+                    if (obj instanceof Set) {
+                        List list = new ArrayList();
+                        list.addAll((Set) obj);
+                        return list;
+                    } else {
+                        // We already have a list
+                        return obj;
+                    }
+                } else {
+                    return usage.m_object;
+                }
+            } else {
+                // External access => Immediate get.
+                if (isAggregate()) {
+                    ServiceReference[] refs = getServiceReferences();
+                    if (refs == null) {
+                        return new ArrayList(0); // Create an empty list.
+                    } else {
+                        List objs = new ArrayList(refs.length);
+                        for (int i = 0; refs != null && i < refs.length; i++) {
+                            ServiceReference ref = refs[i];
+                            objs.add(getService(ref));
+                        }
+                        return objs;
+                    } 
+                } else { // Scalar dependency.
+                    ServiceReference ref = getServiceReference();
+                    if (ref != null) {
+                        return getService(ref);
+                    } else {
+                        // No service available.
+                        // TODO Decide what we have to do.
+                        throw new RuntimeException("Service " + getSpecification() + " unavailable"); 
+                    }
+                }
+            }
+        } else {
+            // Use the copy.
+            // if the copy is a set, transform to a list
+            if (isAggregate()) {
+                Object obj =  usage.m_object;
+                if (obj instanceof Set) {
+                    List list = new ArrayList();
+                    list.addAll((Set) obj);
+                    return list;
+                } else {
+                    // We already have a list
+                    return obj;
+                }
+            } else {
+                return usage.m_object;
+            }
+            
+        }
+    }
 
     /**
      * This method is called by the replaced code in the component
@@ -474,6 +576,7 @@
      * @see org.apache.felix.ipojo.FieldInterceptor#onGet(java.lang.Object, java.lang.String, java.lang.Object)
      */
     public Object onGet(Object pojo, String fieldName, Object value) {
+        
         // Initialize the thread local object is not already touched.
         Usage usage = (Usage) m_usage.get();
         if (usage.m_stack == 0) { // uninitialized usage.
@@ -481,8 +584,11 @@
             usage.inc(); // Start the caching, so set the stack level to 1
             m_usage.set(usage);
         }
-
-        return usage.m_object;
+        if (! m_isProxy) {
+            return usage.m_object;
+        } else {
+            return m_proxyObject;
+        }
 
     }
 
@@ -584,6 +690,7 @@
     public void onEntry(Object pojo, Method method, Object[] args) {
         if (m_usage != null) {
             Usage usage = (Usage) m_usage.get();
+            usage.incComponentStack(); // Increment the number of component access.
             if (usage.m_stack > 0) {
                 usage.inc();
                 m_usage.set(usage); // Set the Thread local as value has been modified
@@ -623,6 +730,7 @@
     public void onFinally(Object pojo, Method method) {
         if (m_usage != null) {
             Usage usage = (Usage) m_usage.get();
+            usage.decComponentStack();
             if (usage.m_stack > 0) {
                 if (usage.dec()) {
                     // Exit the method flow => Release all objects
@@ -645,6 +753,14 @@
         return m_di;
     }
 
+    public boolean isProxy() {
+        return m_isProxy;
+    }
+    
+    public void setProxy(boolean proxy) {
+        m_isProxy = proxy;
+    }
+
     /**
      * Set the type to inject.
      * This method set the dependency as aggregate.
@@ -654,5 +770,74 @@
         setAggregate(true);
         m_type = type;
     }
+    
+    /**
+     * Creates proxy object for proxied scalar dependencies.
+     */
+    private class ProxyFactory extends ClassLoader {
+        
+        /**
+         * Handler classloader, used to load the temporal dependency class. 
+         */
+        private ClassLoader m_handlerCL;
+
+        /**
+         * Creates the proxy classloader.
+         * @param parent the handler classloader.
+         */
+        public ProxyFactory(ClassLoader parent) {
+            super(getHandler().getInstanceManager().getFactory().getBundleClassLoader());
+            m_handlerCL = parent;
+        }
+        
+        /**
+         * Loads a proxy class generated for the given (interface) class.
+         * @param clazz the service specification to proxy
+         * @return the Class object of the proxy.
+         */
+        protected Class getProxyClass(Class clazz) {
+            byte[] clz = ProxyGenerator.dumpProxy(clazz); // Generate the proxy.
+            return defineClass(clazz.getName() + "$$Proxy", clz, 0, clz.length);
+        }
+        
+        /**
+         * Create a proxy object for the given specification. The proxy
+         * uses the given dependency to get the service object.  
+         * @param spec the service specification (interface)
+         * @param dep the temporal dependency used to get the service
+         * @return the proxy object.
+         */
+        public Object getProxy(Class spec, Dependency dep) {
+            try {
+                Class clazz = getProxyClass(getSpecification());
+                Constructor constructor = clazz.getConstructor(
+                        new Class[]{clazz.getClassLoader().loadClass(Dependency.class.getName())});                                               
+                return constructor.newInstance(new Object[] {dep});
+            } catch (Throwable e) {
+                m_handler.error("Cannot create the proxy object", e);
+                m_handler.getInstanceManager().stop();
+                return null;
+            }
+        }
+        
+        /**
+         * Loads the given class.
+         * This class use the classloader of the specification class
+         * or the handler class loader.
+         * @param name the class name
+         * @return the class object
+         * @throws ClassNotFoundException if the class is not found by the two classloaders.
+         * @see java.lang.ClassLoader#loadClass(java.lang.String)
+         */
+        public Class loadClass(String name) throws ClassNotFoundException {
+            try {
+                return getHandler().getInstanceManager().getContext().getBundle().loadClass(name);
+            } catch (ClassNotFoundException e) {
+                return m_handlerCL.loadClass(name);
+            }
+        }
+    }
+    
+    
 
 }

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyDescription.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyDescription.java?rev=893960&r1=893959&r2=893960&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyDescription.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyDescription.java Sat Dec 26 11:15:42 2009
@@ -54,6 +54,9 @@
     
     public String getId() { return m_dependency.getId(); }
     
+    public boolean isProxy() { return m_dependency.isProxy(); }
+
+    
     /**
      * Gets <code>true</code> if the dependency uses Nullable objects.
      * @return true if the dependency is optional and supports nullable object.

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java?rev=893960&r1=893959&r2=893960&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java Sat Dec 26 11:15:42 2009
@@ -49,6 +49,21 @@
 public class DependencyHandler extends PrimitiveHandler implements DependencyStateListener {
 
     /**
+     * Proxy settings property.
+     */
+    public static final String PROXY_SETTINGS_PROPERTY = "ipojo.proxy";
+    
+    /**
+     * Proxy settings value: enabled.
+     */
+    public static final String PROXY_ENABLED = "enabled";
+    
+    /**
+     * Proxy settings value: disabled.
+     */
+    public static final String PROXY_DISABLED = "disabled";
+    
+    /**
      * Dependency field type : Vector
      * The dependency will be injected as a vector.
      */
@@ -174,7 +189,7 @@
      * @return true if the dependency is valid
      * @throws ConfigurationException : the checked dependency is not correct
      */
-    private boolean checkDependency(Dependency dep, PojoMetadata manipulation) throws ConfigurationException {
+    private boolean checkDependency(Dependency dep, PojoMetadata manipulation) throws ConfigurationException {       
         // Check the internal type of dependency
         String field = dep.getField();
         DependencyCallback[] callbacks = dep.getCallbacks();
@@ -225,6 +240,10 @@
             }
             String type = meta.getFieldType();
             if (type.endsWith("[]")) {
+                if (dep.isProxy()) {
+                    warn("Arrays cannot be used for proxied dependencies - Disable the proxy mode");
+                    dep.setProxy(false);
+                }
                 // Set the dependency to multiple
                 dep.setAggregate(true);
                 type = type.substring(0, type.length() - 2);
@@ -233,6 +252,10 @@
                 type = null;
             } else if (type.equals(Vector.class.getName())) {
                 dep.setType(VECTOR);
+                if (dep.isProxy()) {
+                    warn("Vectors cannot be used for proxied dependencies - Disable the proxy mode");
+                    dep.setProxy(false);
+                }
                 type = null;
             } else if (type.equals(Set.class.getName())) {
                 dep.setType(SET);
@@ -246,6 +269,12 @@
             }
             setSpecification(dep, type, true); // Throws an exception if the field type mismatch.
         }
+        
+        // Disables proxy on null (nullable=false)
+        if (dep.isProxy()  && dep.isOptional() && ! dep.supportsNullable()) {
+            dep.setProxy(false);
+            warn("Optional Null Dependencies do not support proxying - Disable the proxy mode");
+        }
 
         // Check that all required info are set
         return dep.getSpecification() != null;
@@ -342,7 +371,29 @@
             
             String nul = deps[i].getAttribute("nullable");
             boolean nullable = nul == null || nul.equalsIgnoreCase("true");
-
+            
+            boolean isProxy = true;
+            // Detect proxy default value.
+            String setting = getInstanceManager().getContext().getProperty(PROXY_SETTINGS_PROPERTY);
+            if (setting == null || PROXY_ENABLED.equals(setting)) { // If not set => Enabled
+                isProxy = true;
+            } else if (setting != null  && PROXY_DISABLED.equals(setting)) {
+                isProxy = false;
+            }
+            
+            String proxy = deps[i].getAttribute("proxy");
+            // If proxy == null, use default value
+            if (proxy != null) {
+                if (proxy.equals("false")) {
+                    isProxy = false;
+                } else if (proxy.equals("true")) {
+                    if (! isProxy) { // The configuration overrides the system setting
+                        warn("The configuration of a service dependency overides the proxy mode");
+                    }
+                    isProxy = true;
+                }   
+            }
+            
             String scope = deps[i].getAttribute("scope");
             BundleContext context = getInstanceManager().getContext(); // Get the default bundle context.
             if (scope != null) {
@@ -401,7 +452,9 @@
 
             int policy = DependencyModel.getPolicy(deps[i]);
             Comparator cmp = DependencyModel.getComparator(deps[i], getInstanceManager().getGlobalContext());
-            Dependency dep = new Dependency(this, field, spec, fil, optional, aggregate, nullable, identitity, context, policy, cmp, defaultImplem);
+
+            
+            Dependency dep = new Dependency(this, field, spec, fil, optional, aggregate, nullable, isProxy, identitity, context, policy, cmp, defaultImplem);
 
             // Look for dependency callback :
             Element[] cbs = deps[i].getElements("Callback");

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandlerDescription.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandlerDescription.java?rev=893960&r1=893959&r2=893960&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandlerDescription.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandlerDescription.java Sat Dec 26 11:15:42 2009
@@ -40,7 +40,7 @@
      */
     private DependencyDescription[] m_dependencies = new DependencyDescription[0];
     
-    // TODO Definie the DependencyStateListener Interface (in ipojo utils)
+    // TODO Define the DependencyStateListener Interface (in ipojo utils)
     
     // TODO Add the list of listener.
     
@@ -123,6 +123,12 @@
                 dep.addAttribute(new Attribute("Aggregate", "false"));
             }
             
+            if (m_dependencies[i].isProxy()) {
+                dep.addAttribute(new Attribute("Proxy", "true"));
+            } else {
+                dep.addAttribute(new Attribute("Proxy", "false"));
+            }
+            
             String policy = "dynamic";
             if (m_dependencies[i].getPolicy() == DependencyModel.STATIC_BINDING_POLICY) {
                 policy = "static";

Added: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ProxyGenerator.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ProxyGenerator.java?rev=893960&view=auto
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ProxyGenerator.java (added)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ProxyGenerator.java Sat Dec 26 11:15:42 2009
@@ -0,0 +1,181 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.handlers.dependency;
+
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.Type;
+
+/**
+ * Generates proxy class delegating operation invocations thanks to a
+ * a dependency.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class ProxyGenerator implements Opcodes {
+    
+    /**
+     * The dependency name. 
+     */
+    private static final String DEPENDENCY = "m_dependency";
+    
+    /**
+     * The dependency descriptor.
+     */
+    private static final String DEPENDENCY_DESC = Type.getDescriptor(Dependency.class);
+    
+    /**
+     * Dependency internal class name. 
+     */
+    private static final String DEPENDENCY_INTERNAL_NAME = "org/apache/felix/ipojo/handlers/dependency/Dependency";
+    
+    /**
+     * Gets the internal names of the given class objects. 
+     * @param classes the classes
+     * @return the array containing internal names of the given class array. 
+     */
+    private static String[] getInternalClassNames(Class[] classes) {
+        final String[] names = new String[classes.length];
+        for (int i = 0; i < names.length; i++) {
+            names[i] = Type.getInternalName(classes[i]);
+        }
+        return names;
+    }
+    
+    /**
+     * Generates a proxy class.
+     * @param spec the proxied service specification
+     * @return the byte[] for the generated proxy class.
+     */
+    public static byte[] dumpProxy(Class spec) {
+        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
+        String internalClassName = Type.getInternalName(spec); // Specification class internal name.
+        String[] itfs = new String[] {internalClassName};  // Implemented interface.
+        String className = internalClassName + "$$Proxy"; // Unique name.
+        Method[] methods = spec.getMethods(); // Method to delegate
+        
+        cw.visit(Opcodes.V1_3, Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, className, null, "java/lang/Object", itfs);
+        addDependencyField(cw);
+        generateConstructor(cw, className);
+        
+        // For each method, create the delegator code.
+        for (int i = 0; i < methods.length; i++) {
+            if ((methods[i].getModifiers() & (Modifier.STATIC | Modifier.FINAL)) == 0) {
+                generateDelegator(cw, methods[i], className, internalClassName);
+            }
+        }        
+        
+        cw.visitEnd();
+        
+        return cw.toByteArray();
+        
+    }
+
+    /**
+     * Generates a delegated method.
+     * @param cw the class writer
+     * @param method the method object to delegate
+     * @param className the generated class name
+     * @param itfName the internal specification class name
+     */
+    private static void generateDelegator(ClassWriter cw, Method method,
+            String className, String itfName) {
+        String methodName = method.getName();
+        String desc = Type.getMethodDescriptor(method);
+        String[] exceptions = getInternalClassNames(method.getExceptionTypes());
+        int modifiers = method.getModifiers()
+                & ~(Modifier.ABSTRACT | Modifier.NATIVE | Modifier.SYNCHRONIZED);
+        Type[] types = Type.getArgumentTypes(method);
+
+        int freeRoom = 1;
+        for (int t = 0; t < types.length; t++) {
+            freeRoom = freeRoom + types[t].getSize();
+        }
+
+        MethodVisitor mv = cw.visitMethod(modifiers, methodName, desc, null,
+                exceptions);
+        mv.visitCode();
+
+        mv.visitVarInsn(ALOAD, 0);
+        mv.visitFieldInsn(GETFIELD, className, DEPENDENCY, DEPENDENCY_DESC);  // The dependency is on the stack.
+        mv.visitMethodInsn(INVOKEVIRTUAL, DEPENDENCY_INTERNAL_NAME, "getService", // Call getService
+                "()Ljava/lang/Object;"); // The service object is on the stack.
+        int varSvc = freeRoom; 
+        freeRoom = freeRoom + 1; // Object Reference.
+        mv.visitVarInsn(ASTORE, varSvc); // Store the service object.
+        
+        // Invoke the method on the service object.
+        mv.visitVarInsn(ALOAD, varSvc);
+        // Push argument on the stack.
+        int i = 1; // Arguments. (non static method)
+        for (int t = 0; t < types.length; t++) {
+            mv.visitVarInsn(types[t].getOpcode(ILOAD), i); 
+            i = i + types[t].getSize();
+        }
+        // Invocation
+        mv.visitMethodInsn(INVOKEINTERFACE, itfName, methodName, desc);
+
+        // Return the result
+        Type returnType = Type.getReturnType(desc);
+        if (returnType.getSort() != Type.VOID) {
+            mv.visitInsn(returnType.getOpcode(IRETURN));
+        } else {
+            mv.visitInsn(RETURN);
+        }
+
+        // End of the method.
+        mv.visitMaxs(0, 0);
+        mv.visitEnd();
+    }
+
+    /**
+     * Generates the constructors. The constructor receives a dependency
+     * and set the {@link ProxyGenerator#DEPENDENCY} field.
+     * @param cw the class writer
+     * @param className the generated class name.
+     */
+    private static void generateConstructor(ClassWriter cw, String className) {
+        MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", '(' + DEPENDENCY_DESC + ")V", null, null);
+        mv.visitCode();
+
+        mv.visitVarInsn(ALOAD, 0); // Load this
+        mv.visitInsn(DUP); // Dup
+        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); // Call  super
+        mv.visitVarInsn(ALOAD, 1); // Load the argument
+        mv.visitFieldInsn(PUTFIELD, className, DEPENDENCY, DEPENDENCY_DESC); // Assign the dependency field
+        mv.visitInsn(RETURN); // Return void
+
+        mv.visitMaxs(0, 0);
+        mv.visitEnd();
+    }
+
+    /**
+     * Adds the dependency field {@link ProxyGenerator#DEPENDENCY}.
+     * @param cw the class writer
+     */
+    private static void addDependencyField(ClassWriter cw) {
+        cw.visitField(Opcodes.ACC_FINAL, DEPENDENCY, DEPENDENCY_DESC, null, null);
+        cw.visitEnd();
+    }
+
+}

Propchange: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ProxyGenerator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ServiceCollection.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ServiceCollection.java?rev=893960&view=auto
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ServiceCollection.java (added)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ServiceCollection.java Sat Dec 26 11:15:42 2009
@@ -0,0 +1,422 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.handlers.dependency;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Set;
+
+/**
+* Maintains a service object collection.
+* This collection wrap the temporal dependency to be accessible from a
+* {@link Collection}, that can be passed to helper objects (Collaborators).
+* 
+* 
+* The {@link Collection#iterator()} method returns an {@link Iterator} iterating
+* on a cached copy of available service objects. In the case that there are no 
+* available services, the policies act as follows:
+* <ul>
+* <li>'null' returns a null iterator</li>
+* <li>'nullable' and default-implementation returns an iterator iterating on one object (the
+*  nullable or default-implementation object</li>
+* <li>'empty' returns an empty iterator.</li>
+* </ul>
+* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+*/
+public class ServiceCollection implements Collection, List, Set {
+    
+    /**
+     * The wrapped dependency.
+     */
+    private Dependency m_dependency;
+        
+    /**
+     * Creates a Service Collection.
+     * @param dep the wrapped dependency
+     */
+    public ServiceCollection(Dependency dep) {
+        m_dependency = dep;
+    }
+
+    /**
+     * Unsupported method.
+     * @param o an object
+     * @return N/A
+     * @see java.util.Collection#add(java.lang.Object)
+     */
+    public boolean add(Object o) {
+        throw new UnsupportedOperationException("Cannot add elements inside this collection");
+    }
+
+    /**
+     * Unsupported method.
+     * @param c an object
+     * @return N/A
+     * @see java.util.Collection#addAll(java.util.Collection)
+     */
+    public boolean addAll(Collection c) {
+        throw new UnsupportedOperationException("Cannot add elements inside this collection");
+    }
+    
+    /**
+     * Unsupported method.
+     * @param index an index
+     * @param obj an object
+     * @see java.util.List#add(int, java.lang.Object)
+     */
+    public void add(int index, Object obj) {
+        throw new UnsupportedOperationException("Cannot add elements inside this collection");
+    }
+
+    /**
+     * Unsupported method.
+     * @param index an index
+     * @param c an object
+     * @return N/A
+     * @see java.util.List#addAll(int, java.util.Collection)
+     */
+    public boolean addAll(int index, Collection c) {
+        throw new UnsupportedOperationException("Cannot add elements inside this collection");
+    }
+
+    /**
+     * Unsupported method.
+     * @see java.util.Collection#clear()
+     */
+    public void clear() {
+        throw new UnsupportedOperationException("Cannot remove elements from this collection");
+    }
+
+    /**
+     * Checks if the wrapped dependency has always access to the
+     * given service object.The method allows knowing if the provider returning the
+     * service object has left. 
+     * @param o  the service object
+     * @return <code>true</code> if the object is still available,
+     * <code>false</code> otherwise.
+     * @see java.util.Collection#contains(java.lang.Object)
+     */
+    public boolean contains(Object o) {
+        List list = (List) m_dependency.getService();
+        return list.contains(o);
+    }
+
+    /**
+     * Checks if the wrapped dependencies has always access to the
+     * given service objects.The method allows knowing if providers returning the
+     * service objects have left. 
+     * @param c the set of service object
+     * @return <code>true</code> if the objects are still available,
+     * <code>false</code> otherwise.
+     * @see java.util.Collection#contains(java.lang.Object)
+     */
+    public boolean containsAll(Collection c) {
+        List list = (List) m_dependency.getService();
+        return list.containsAll(c);
+    }
+
+    /**
+     * Checks if at least one provider matching with the dependency
+     * is available.
+     * @return <code>true</code> if one provider or more satisfying the
+     * dependency are available. Otherwise, returns <code>false</code> 
+     * @see java.util.Collection#isEmpty()
+     */
+    public boolean isEmpty() {
+        return m_dependency.getSize() == 0;
+    }
+
+    /**
+     * Gets an iterator on the current list of available service objects.
+     * The returned iterator iterates on a cached copy of the service
+     * objects.
+     * @return a iterator giving access to service objects.
+     * @see java.util.Collection#iterator()
+     */
+    public Iterator iterator() {
+        List obj = (List) m_dependency.getService();
+        return new ServiceIterator(obj); // Create the service iterator with the service reference list.
+    }
+    
+    /**
+     * Unsupported method.
+     * @param o a object
+     * @return N/A
+     * @see java.util.Collection#remove(java.lang.Object)
+     */
+    public boolean remove(Object o) {
+        throw new UnsupportedOperationException("Cannot remove elements from this collection");
+    }
+
+    /**
+     * Unsupported method.
+     * @param index the index
+     * @return N/A
+     * @see java.util.Collection#remove(java.lang.Object)
+     */
+    public Object remove(int index) {
+        throw new UnsupportedOperationException("Cannot remove elements from this collection");
+    }
+
+    /**
+     * Unsupported method.
+     * @param c a set of objects
+     * @return N/A
+     * @see java.util.Collection#removeAll(java.util.Collection)
+     */
+    public boolean removeAll(Collection c) {
+        throw new UnsupportedOperationException("Cannot remove elements from this collection");
+    }
+
+    /**
+     * Unsupported method.
+     * @param c a set of objects
+     * @return N/A
+     * @see java.util.Collection#retainAll(java.util.Collection)
+     */
+    public boolean retainAll(Collection c) {
+        throw new UnsupportedOperationException("Cannot remove elements from this collection");
+    }
+
+    /**
+     * Gets the number of available providers.
+     * @return the number of matching service providers.
+     * @see java.util.Collection#size()
+     */
+    public int size() {
+        return m_dependency.getSize();
+    }
+
+    /**
+     * Returns an array containing available service objects.
+     * This method executed on timeout policies if no matching
+     * providers when the timeout is reached. 
+     * @return a array containing available service objects.
+     * @see java.util.Collection#toArray()
+     */
+    public Object[] toArray() {
+        return toArray(new Object[0]);
+    }
+    
+    /**
+     * Returns an array containing available service objects.
+     * This method executed on timeout policies if no matching
+     * providers when the timeout is reached. 
+     * @param a the array into which the elements of this collection 
+     * are to be stored, if it is big enough; otherwise, a new array
+     * of the same runtime type is allocated for this purpose. 
+     * @return a array containing available service objects.
+     * @see java.util.Collection#toArray(java.lang.Object[])
+     */
+    public Object[] toArray(Object[] a) {
+        List list = (List) m_dependency.getService();
+        return list.toArray(a);
+    }
+    
+    /**
+     * Gets the object stored at the given index.
+     * @param index the index
+     * @return the service object
+     * @see java.util.List#get(int)
+     */
+    public Object get(int index) {
+        List list = (List) m_dependency.getService();
+        return list.get(index);
+    }
+
+    /**
+     * Gets the index of the given object in the current
+     * collection.
+     * @param o the object 
+     * @return the index of the object of <code>-1</code>
+     * if not found.
+     * @see java.util.List#indexOf(java.lang.Object)
+     */
+    public int indexOf(Object o) {
+        List list = (List) m_dependency.getService();
+        return list.indexOf(o);
+    }
+
+    /**
+     * Gets the last index of the given object in the current
+     * collection.
+     * @param o the object 
+     * @return the index of the object of <code>-1</code>
+     * if not found.
+     * @see java.util.List#lastIndexOf(java.lang.Object)
+     */
+    public int lastIndexOf(Object o) {
+        List list = (List) m_dependency.getService();
+        return list.lastIndexOf(o);
+    }
+
+    /**
+     * Gets a list iterator on the current list of available service objects.
+     * The returned iterator iterates on a cached copy of the service
+     * objects.
+     * @return a iterator giving access to service objects.
+     * @see java.util.List#listIterator()
+     */
+    public ListIterator listIterator() {
+        List obj = (List) m_dependency.getService();
+        return new ServiceIterator(obj); // Create the service iterator with the service reference list.
+    }
+
+    /**
+     * Unsupported Method.
+     * @param index an index
+     * @return N/A
+     * @see java.util.List#listIterator(int)
+     */
+    public ListIterator listIterator(int index) {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Unsupported Method.
+     * @param arg0 an index
+     * @param arg1 an object
+     * @return N/A
+     * @see java.util.List#set(int, E)
+     */
+    public Object set(int arg0, Object arg1) {
+        throw new UnsupportedOperationException("Cannot add elements inside this collection");
+    }
+
+    /**
+     * Returns a sublist from the current list.
+     * @param fromIndex the index of the list beginning
+     * @param toIndex the index of the list end
+     * @return the sub-list
+     * @see java.util.List#subList(int, int)
+     */
+    public List subList(int fromIndex, int toIndex) {
+        List list = (List) m_dependency.getService();
+        return list.subList(fromIndex, toIndex);
+    }
+
+    /**
+     * Iterator on a set of service objects.
+     * This iterator iterates on a cached copy of service objects.
+     */
+    private final class ServiceIterator implements ListIterator {
+        
+        /**
+         * Underlying iterator.
+         */
+        private ListIterator m_iterator;
+        
+        /**
+         * Creates a Service Iterator iterating
+         * on the given set of providers.
+         * @param list the list of service object.
+         */
+        private ServiceIterator(List list) {           
+            m_iterator = list.listIterator();
+        }
+
+        /**
+         * Returns <code>true</code> if the iteration has 
+         * more service objects. 
+         * @return <code>true</code> if the iterator has more elements.
+         * @see java.util.Iterator#hasNext()
+         */
+        public boolean hasNext() {
+            return m_iterator.hasNext();
+        }
+
+        /**
+         * Returns the next service objects in the iteration. 
+         * @return the next service object in the iteration. 
+         * @see java.util.Iterator#next()
+         */
+        public Object next() {
+            return m_iterator.next();
+        }
+
+        /**
+         * Unsupported operation.
+         * @see java.util.Iterator#remove()
+         */
+        public void remove() {
+            throw new UnsupportedOperationException();            
+        }
+
+        /**
+         * Unsupported operation.
+         * @param obj an object
+         * @see java.util.ListIterator#add(E)
+         */
+        public void add(Object obj) {
+            throw new UnsupportedOperationException();                        
+        }
+
+        /**
+         * Checks if the is an element before the currently 
+         * pointed one.
+         * @return true if there is an element before the
+         * current one.
+         * @see java.util.ListIterator#hasPrevious()
+         */
+        public boolean hasPrevious() {
+            return m_iterator.hasPrevious();
+        }
+
+        /**
+         * Gets the index of the next element.
+         * @return the index of the next element.
+         * @see java.util.ListIterator#nextIndex()
+         */
+        public int nextIndex() {
+            return m_iterator.nextIndex();
+        }
+
+        
+        /**
+         * Gets the previous elements.
+         * @return the previous element
+         * @see java.util.ListIterator#previous()
+         */
+        public Object previous() {
+            return m_iterator.previous();
+        }
+
+        /**
+         * Gets the index of the previous element.
+         * @return the index of the previous element.
+         * @see java.util.ListIterator#previousIndex()
+         */
+        public int previousIndex() {
+            return m_iterator.previousIndex();
+        }
+
+        /**
+         * Unsupported operation.
+         * @param obj an object
+         * @see java.util.ListIterator#set(E)
+         */
+        public void set(Object obj) {
+            throw new UnsupportedOperationException();  
+        }
+                  
+    }
+
+}

Propchange: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ServiceCollection.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ServiceUsage.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ServiceUsage.java?rev=893960&r1=893959&r2=893960&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ServiceUsage.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ServiceUsage.java Sat Dec 26 11:15:42 2009
@@ -41,13 +41,27 @@
         Object m_object;
         
         /**
-         * Increment the stack level.
+         * Tracks the number of component method called
+         * in the current thread.
+         */
+        int m_componentStack = 0;
+        
+        /**
+         * Increment the stack level from the first
+         * service get.
          */
         public void inc() {
             m_stack++;
         }
         
         /**
+         * Increment the component stack level.
+         */
+        public void incComponentStack() {
+            m_componentStack++;
+        }
+        
+        /**
          * Decrement the stack level.
          * @return  true if the stack is 0 after the decrement.
          */
@@ -57,6 +71,15 @@
         }
         
         /**
+         * Decrement the component stack level.
+         * @return  true if the stack is 0 after the decrement.
+         */
+        public boolean decComponentStack() {
+            m_componentStack--;
+            return m_componentStack == 0;
+        }
+        
+        /**
          * Clear the service object array.
          */
         public void clear() {

Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/MethodMetadata.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/MethodMetadata.java?rev=893960&r1=893959&r2=893960&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/MethodMetadata.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/MethodMetadata.java Sat Dec 26 11:15:42 2009
@@ -28,6 +28,21 @@
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
  */
 public class MethodMetadata {
+    
+    /**
+     * Empty Constructor Method Id.
+     */
+    public static final String EMPTY_CONSTRUCTOR_ID = "$init";
+
+    /**
+     * Bundle Context Constructor Method Id.
+     */
+    public static final String BC_CONSTRUCTOR_ID = "$init$org_osgi_framework_BundleContext";
+    
+    /**
+     * Constructor Prefix.
+     */
+    public static final String CONSTRUCTOR_PREFIX = "$init";
 
     /**
      * The name of the method.
@@ -125,5 +140,4 @@
         }
         return identifier.toString();
     }
-
 }

Modified: felix/trunk/ipojo/core/src/main/resources/core.xsd
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/resources/core.xsd?rev=893960&r1=893959&r2=893960&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/resources/core.xsd (original)
+++ felix/trunk/ipojo/core/src/main/resources/core.xsd Sat Dec 26 11:15:42 2009
@@ -260,6 +260,13 @@
                       <xs:documentation>Specific service provider. The dependency can only be fulfilled by the component with the matching name, or by the service with a matching PID.</xs:documentation>
                     </xs:annotation>
         </xs:attribute>
+        
+        <xs:attribute name="proxy" type="xs:boolean"
+          use="optional">
+                    <xs:annotation>
+                      <xs:documentation>Enables or Disable the proxy injection (on field injection)</xs:documentation>
+                    </xs:annotation>
+        </xs:attribute>
 
         <xs:attribute name="scope" use="optional">
           <xs:simpleType>

Modified: felix/trunk/ipojo/examples/tutorial-maven/hello.client.annotation/src/main/java/ipojo/example/hello/client/HelloClient.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/examples/tutorial-maven/hello.client.annotation/src/main/java/ipojo/example/hello/client/HelloClient.java?rev=893960&r1=893959&r2=893960&view=diff
==============================================================================
--- felix/trunk/ipojo/examples/tutorial-maven/hello.client.annotation/src/main/java/ipojo/example/hello/client/HelloClient.java (original)
+++ felix/trunk/ipojo/examples/tutorial-maven/hello.client.annotation/src/main/java/ipojo/example/hello/client/HelloClient.java Sat Dec 26 11:15:42 2009
@@ -20,6 +20,8 @@
 
 import ipojo.example.hello.Hello;
 
+import java.util.Set;
+
 import org.apache.felix.ipojo.annotations.Component;
 import org.apache.felix.ipojo.annotations.Invalidate;
 import org.apache.felix.ipojo.annotations.Requires;
@@ -38,8 +40,8 @@
     /**
      * Hello services. Injected by the container.
      */
-    @Requires
-    private Hello[] m_hello;
+    @Requires(specification="ipojo.example.hello.Hello", optional=true, defaultimplementation=MyDummyHello.class)
+    private Hello m_hello;
 
     /**
      *  End flag.
@@ -65,9 +67,11 @@
      * Invoke hello services.
      */
     public void invokeHelloServices() {
-        for (int i = 0; i < m_hello.length; i++) {
-            System.out.println(i + " :" + m_hello[i].sayHello("Clement"));
-        }
+        System.out.println(m_hello);
+        Hello hello = m_hello;
+        //for (Hello hello : m_hello) {
+            System.out.println(hello.sayHello("Clement ") + hello);
+        //}
     }
 
     /**

Added: felix/trunk/ipojo/examples/tutorial-maven/hello.client.annotation/src/main/java/ipojo/example/hello/client/MyDummyHello.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/examples/tutorial-maven/hello.client.annotation/src/main/java/ipojo/example/hello/client/MyDummyHello.java?rev=893960&view=auto
==============================================================================
--- felix/trunk/ipojo/examples/tutorial-maven/hello.client.annotation/src/main/java/ipojo/example/hello/client/MyDummyHello.java (added)
+++ felix/trunk/ipojo/examples/tutorial-maven/hello.client.annotation/src/main/java/ipojo/example/hello/client/MyDummyHello.java Sat Dec 26 11:15:42 2009
@@ -0,0 +1,11 @@
+package ipojo.example.hello.client;
+
+import ipojo.example.hello.Hello;
+
+public class MyDummyHello implements Hello {
+
+    public String sayHello(String name) {
+        return "Bonjour";
+    }
+
+}

Propchange: felix/trunk/ipojo/examples/tutorial-maven/hello.client.annotation/src/main/java/ipojo/example/hello/client/MyDummyHello.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: felix/trunk/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalDependency.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalDependency.java?rev=893960&r1=893959&r2=893960&view=diff
==============================================================================
--- felix/trunk/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalDependency.java (original)
+++ felix/trunk/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalDependency.java Sat Dec 26 11:15:42 2009
@@ -125,7 +125,7 @@
         if (! proxy) { // No proxy => initialize the Thread local.
             m_usage = new ServiceUsage();
         } else if (proxy && ! agg) { // Scalar proxy => Create the proxy.
-            ProxyFactory proxyFactory = new ProxyFactory(this.getSpecification().getClassLoader(), this.getClass().getClassLoader());
+            ProxyFactory proxyFactory = new ProxyFactory(this.getClass().getClassLoader());
             m_proxyObject = proxyFactory.getProxy(getSpecification(), this);
         }
     }
@@ -495,23 +495,16 @@
     private class ProxyFactory extends ClassLoader {
         
         /**
-         * Instance classloader, used to load specification and dependent classes.
-         */
-        private ClassLoader m_instanceCL;
-        
-        /**
          * Handler classloader, used to load the temporal dependency class. 
          */
         private ClassLoader m_handlerCL;
         
         /**
          * Creates the proxy classloader.
-         * @param parent1 the instance classloader.
-         * @param parent2 the handler classloader.
+         * @param parent the handler classloader.
          */
-        public ProxyFactory(ClassLoader parent1, ClassLoader parent2) {
-            this.m_instanceCL = parent1;
-            this.m_handlerCL = parent2;
+        public ProxyFactory(ClassLoader parent) {
+            this.m_handlerCL = parent;
         }
         
         /**
@@ -554,7 +547,7 @@
          */
         public Class loadClass(String name) throws ClassNotFoundException {
             try {
-                return m_instanceCL.loadClass(name);
+                return m_handler.getInstanceManager().getContext().getBundle().loadClass(name);
             } catch (ClassNotFoundException e) {
                 return m_handlerCL.loadClass(name);
             }