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 2010/07/12 19:47:01 UTC

svn commit: r963398 - in /felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency: DependencyHandler.java ProxyGenerator.java

Author: clement
Date: Mon Jul 12 17:47:01 2010
New Revision: 963398

URL: http://svn.apache.org/viewvc?rev=963398&view=rev
Log:
Start working on FELIX-2472 [iPOJO] Proxies should throw the OSGi service exception
Adapt the dependency handler to throw a runtime exception when there is no services in proxy mode with disabled nullables.
Also fix a bunch of typo.

Modified:
    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/ProxyGenerator.java

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=963398&r1=963397&r2=963398&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 Mon Jul 12 17:47:01 2010
@@ -256,7 +256,7 @@ public class DependencyHandler extends P
             String type = meta.getFieldType();
             if (type.endsWith("[]")) {
                 if (dep.isProxy()) {
-                    info("Arrays cannot be used for proxied dependencies - Disable the proxy mode");
+                    info("Arrays cannot be used for proxied dependencies - Disabling the proxy mode");
                     dep.setProxy(false);
                 }
                 // Set the dependency to multiple
@@ -268,7 +268,7 @@ public class DependencyHandler extends P
             } 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");
+                    warn("Vectors cannot be used for proxied dependencies - Disabling the proxy mode");
                     dep.setProxy(false);
                 }
                 type = null;
@@ -286,10 +286,10 @@ public class DependencyHandler extends P
         }
         
         // 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");
-        }
+//        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;
@@ -403,7 +403,7 @@ public class DependencyHandler extends P
                     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");
+                        warn("The configuration of a service dependency overrides the proxy mode");
                     }
                     isProxy = true;
                 }   

Modified: 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=963398&r1=963397&r2=963398&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ProxyGenerator.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ProxyGenerator.java Mon Jul 12 17:47:01 2010
@@ -23,6 +23,7 @@ import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 
 import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.Label;
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.Opcodes;
 import org.objectweb.asm.Type;
@@ -124,6 +125,22 @@ public class ProxyGenerator implements O
         freeRoom = freeRoom + 1; // Object Reference.
         mv.visitVarInsn(ASTORE, varSvc); // Store the service object.
         
+        Label notNull = new Label();
+        Label isNull = new Label();
+        mv.visitVarInsn(ALOAD, varSvc); // Load the service
+        mv.visitJumpInsn(IFNONNULL, notNull); // If not null go to not null
+        // Null branch - throw the exception
+        mv.visitLabel(isNull);
+        mv.visitTypeInsn(NEW, "java/lang/RuntimeException");
+        mv.visitInsn(DUP);
+        mv.visitLdcInsn("No service available");
+        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/RuntimeException", "<init>", "(Ljava/lang/String;)V");
+        mv.visitInsn(ATHROW);
+        // End of the null branch
+        
+        // Not null, go one the execution
+        mv.visitLabel(notNull);
+                
         // Invoke the method on the service object.
         mv.visitVarInsn(ALOAD, varSvc);
         // Push argument on the stack.