You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by gn...@apache.org on 2009/05/29 11:32:45 UTC

svn commit: r779901 - in /geronimo/sandbox/blueprint: ./ blueprint-bundle/ blueprint-core/ blueprint-core/src/main/java/org/apache/geronimo/blueprint/ blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ blueprint-core/src/main/java/or...

Author: gnodet
Date: Fri May 29 09:32:43 2009
New Revision: 779901

URL: http://svn.apache.org/viewvc?rev=779901&view=rev
Log:
Add support for optionally proxying classes and collection greedy proxying through the ext namespace, remove cglib from blueprint-bundle by default

Added:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ExtendedRefCollectionMetadata.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ExtendedServiceReferenceMetadata.java
Modified:
    geronimo/sandbox/blueprint/blueprint-bundle/pom.xml
    geronimo/sandbox/blueprint/blueprint-core/pom.xml
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AbstractServiceReferenceRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/Parser.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RefCollectionRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceRecipe.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/ExtNamespaceHandler.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/mutable/MutableRefCollectionMetadata.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/mutable/MutableServiceReferenceMetadata.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/ServiceReferenceMetadataImpl.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/resources/org/apache/geronimo/blueprint/ext/blueprint-ext.xsd
    geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/BlueprintContainerTest.java
    geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestReferences.java
    geronimo/sandbox/blueprint/pom.xml

Modified: geronimo/sandbox/blueprint/blueprint-bundle/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-bundle/pom.xml?rev=779901&r1=779900&r2=779901&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-bundle/pom.xml (original)
+++ geronimo/sandbox/blueprint/blueprint-bundle/pom.xml Fri May 29 09:32:43 2009
@@ -50,6 +50,7 @@
                         <Import-Package>
                             org.apache.geronimo.blueprint*;version="${pom.version}",
                             org.osgi.service.blueprint*;version="1.0",
+                            net.sf.cglib*;resolution:=optional,
                             *
                         </Import-Package>
                         <Export-Package>
@@ -67,6 +68,7 @@
                             org.apache.geronimo.blueprint.namespace,
                             org.apache.geronimo.blueprint.reflect,
                             org.apache.geronimo.blueprint.utils,
+                            <!--
                             org.objectweb.asm,
                             org.objectweb.asm.commons,
                             org.objectweb.asm.signature,
@@ -75,6 +77,7 @@
                             net.sf.cglib.core,
                             net.sf.cglib.proxy,
                             net.sf.cglib.reflect,
+                            -->
                         </Private-Package>
                         <_versionpolicy>[$(version;==;$(@)),$(version;+;$(@)))</_versionpolicy>
                         <_failok>true</_failok>
@@ -94,14 +97,17 @@
                         <configuration>
                             <artifactSet>
                                 <includes>
+                                    <!--
                                     <include>asm:asm-all</include>
                                     <include>cglib:cglib</include>
+                                    -->
                                     <include>org.apache.geronimo:blueprint-api</include>
                                     <include>org.apache.geronimo:blueprint-core</include>
                                     <include>org.apache.geronimo:blueprint-cm</include>
                                 </includes>
                             </artifactSet>
                             <filters>
+                                <!--
                                 <filter>
                                     <artifact>asm:asm-all</artifact>
                                     <excludes>
@@ -114,6 +120,7 @@
                                         <exclude>net/**</exclude>
                                     </excludes>
                                 </filter>
+                                -->
                                 <filter>
                                     <artifact>org.apache.geronimo:blueprint-api</artifact>
                                     <excludes>

Modified: geronimo/sandbox/blueprint/blueprint-core/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/pom.xml?rev=779901&r1=779900&r2=779901&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/pom.xml (original)
+++ geronimo/sandbox/blueprint/blueprint-core/pom.xml Fri May 29 09:32:43 2009
@@ -42,12 +42,9 @@
           <artifactId>org.osgi.compendium</artifactId>
       </dependency>
       <dependency>
-          <groupId>cglib</groupId>
-          <artifactId>cglib</artifactId>
-      </dependency>
-      <dependency>
-          <groupId>asm</groupId>
-          <artifactId>asm-all</artifactId>
+          <groupId>org.apache.servicemix.bundles</groupId>
+          <artifactId>org.apache.servicemix.bundles.cglib</artifactId>
+          <optional>true</optional>
       </dependency>
       <dependency>
           <groupId>org.slf4j</groupId>

Added: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ExtendedRefCollectionMetadata.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ExtendedRefCollectionMetadata.java?rev=779901&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ExtendedRefCollectionMetadata.java (added)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ExtendedRefCollectionMetadata.java Fri May 29 09:32:43 2009
@@ -0,0 +1,31 @@
+/**
+ *  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.geronimo.blueprint;
+
+import org.osgi.service.blueprint.reflect.RefCollectionMetadata;
+
+/**
+ * TODO: javadoc
+ *
+ * @author <a href="mailto:dev@geronimo.apache.org">Apache Geronimo Project</a>
+ * @version $Rev: 766508 $, $Date: 2009-04-19 22:09:27 +0200 (Sun, 19 Apr 2009) $
+ */
+public interface ExtendedRefCollectionMetadata extends RefCollectionMetadata, ExtendedServiceReferenceMetadata {
+
+    int PROXY_METHOD_GREEDY = 2;
+
+}

Added: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ExtendedServiceReferenceMetadata.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ExtendedServiceReferenceMetadata.java?rev=779901&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ExtendedServiceReferenceMetadata.java (added)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ExtendedServiceReferenceMetadata.java Fri May 29 09:32:43 2009
@@ -0,0 +1,35 @@
+/**
+ *  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.geronimo.blueprint;
+
+import org.osgi.service.blueprint.reflect.ServiceReferenceMetadata;
+
+/**
+ * TODO: javadoc
+ *
+ * @author <a href="mailto:dev@geronimo.apache.org">Apache Geronimo Project</a>
+ * @version $Rev: 766508 $, $Date: 2009-04-19 22:09:27 +0200 (Sun, 19 Apr 2009) $
+ */
+public interface ExtendedServiceReferenceMetadata extends ServiceReferenceMetadata {
+
+    int PROXY_METHOD_DEFAULT = 0;
+
+    int PROXY_METHOD_CLASSES = 1;
+
+    int getProxyMethod();
+
+}

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AbstractServiceReferenceRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AbstractServiceReferenceRecipe.java?rev=779901&r1=779900&r2=779901&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AbstractServiceReferenceRecipe.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/AbstractServiceReferenceRecipe.java Fri May 29 09:32:43 2009
@@ -19,6 +19,8 @@
 package org.apache.geronimo.blueprint.container;
 
 import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.lang.reflect.InvocationHandler;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -28,11 +30,13 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.Callable;
 
 import net.sf.cglib.proxy.Dispatcher;
 import net.sf.cglib.proxy.Enhancer;
 import org.apache.geronimo.blueprint.BlueprintConstants;
 import org.apache.geronimo.blueprint.ExtendedBlueprintContainer;
+import org.apache.geronimo.blueprint.ExtendedServiceReferenceMetadata;
 import org.apache.geronimo.blueprint.di.AbstractRecipe;
 import org.apache.geronimo.blueprint.di.Recipe;
 import org.apache.geronimo.blueprint.utils.BundleDelegatingClassLoader;
@@ -72,6 +76,7 @@
     private final AtomicBoolean started = new AtomicBoolean();
     private final AtomicBoolean satisfied = new AtomicBoolean();
     private SatisfactionListener satisfactionListener;
+    private ProxyFactory proxyFactory;
 
     protected AbstractServiceReferenceRecipe(String name,
                                              ExtendedBlueprintContainer blueprintContainer,
@@ -150,7 +155,7 @@
             if (listenersRecipe != null) {
                 listeners = (List<Listener>) listenersRecipe.create();
                 for (Listener listener : listeners) {
-                    listener.init(getAllClasses(metadata.getInterfaceNames()));
+                    listener.init(loadAllClasses(metadata.getInterfaceNames()));
                 }
             } else {
                 listeners = Collections.emptyList();
@@ -160,7 +165,7 @@
         }
     }
 
-    protected List<Class> getAllClasses(Iterable<String> interfaceNames) throws ClassNotFoundException {
+    protected List<Class> loadAllClasses(Iterable<String> interfaceNames) throws ClassNotFoundException {
         List<Class> classes = new ArrayList<Class>();
         for (String name : interfaceNames) {
             Class clazz = proxyClassLoader.loadClass(name);
@@ -169,67 +174,38 @@
         return classes;
     }
 
-    protected List<Class> getInterfaces(Iterable<String> interfaceNames) throws ClassNotFoundException {
-        List<Class> interfaces = new ArrayList<Class>();
-        for (String name : interfaceNames) {
-            Class clazz = proxyClassLoader.loadClass(name);
-            if (clazz.isInterface()) {
-                interfaces.add(clazz);
-            }
-        }
-        return interfaces;
+    protected Object createProxy(final Callable<Object> dispatcher, Iterable<String> interfaces) throws Exception {
+        return getProxyFactory().createProxy(proxyClassLoader, toClassArray(loadAllClasses(interfaces)), dispatcher);
     }
 
-    protected static Class[] toClassArray(List<Class> classes) {
-        return classes.toArray(new Class [classes.size()]);
-    }
-    
-    protected Class getTargetClass(Iterable<String> interfaceNames) throws ClassNotFoundException {
-        Class root = Object.class;
-        for (String name : interfaceNames) {
-            Class clazz = proxyClassLoader.loadClass(name);
-            if (!clazz.isInterface()) {
-                if (root == Object.class) {
-                    root = clazz;
-                    continue;
-                }
-                // Check that all classes are in the same hierarchy
-                for (Class p = clazz; p != Object.class; p = p.getSuperclass()) {
-                    if (p == root) {
-                        root = clazz;
-                        continue;
+    protected ProxyFactory getProxyFactory() throws ClassNotFoundException {
+        if (proxyFactory == null) {
+            synchronized (this) {
+                if (proxyFactory == null) {
+                    boolean proxyClass = false;
+                    if (metadata instanceof ExtendedServiceReferenceMetadata) {
+                        proxyClass = (((ExtendedServiceReferenceMetadata) metadata).getProxyMethod() & ExtendedServiceReferenceMetadata.PROXY_METHOD_CLASSES) != 0;
                     }
-                }
-                for (Class p = root; p != Object.class; p = p.getSuperclass()) {
-                    if (p == clazz) {
-                        continue;
+                    List<Class> classes = loadAllClasses(this.metadata.getInterfaceNames());
+                    if (!proxyClass) {
+                        for (Class cl : classes) {
+                            if (!cl.isInterface()) {
+                                throw new ComponentDefinitionException("A class " + cl.getName() + " was found in the interfaces list, but class proxying is not allowed by default. The ext:proxy-method='class' attribute needs to be added to this service reference.");
+                            }
+                        }
+                    }
+                    try {
+                        proxyFactory = new CgLibProxyFactory();
+                    } catch (Throwable t) {
+                        if (proxyClass) {
+                            throw new ComponentDefinitionException("Class proxying has been enabled but cglib can not be used", t);
+                        }
+                        proxyFactory = new JdkProxyFactory();
                     }
                 }
-                throw new ComponentDefinitionException("Classes " + root.getClass().getName() + " and " + clazz.getName() + " are not in the same hierarchy");
             }
         }
-        return root;
-    }
-
-    protected Object createProxy(Dispatcher dispatcher, Iterable<String> interfaces) throws Exception {
-        // TODO: we only use cglib for this small piece of code, we might want to use asm directly to
-        //       lower the number of dependencies / reduce size of jars
-        //       or have an optional import an asm / cglib and use JDK proxies if not present
-        //       also, check what the spec will say about that (optional imports could be fine if
-        //       the spec does not mandate support for classes proxying
-        // TODO: the spec mandates interfaces now, which means JDK proxies can be used
-        //       proxying non final classes is an implementation specific enhancement and should be triggered
-        //       by a custom attribute on the xml
-        // TODO: cglib is faster, but it should now be optional
-        // TODO: do we need to proxy equals/toString/hashCode ?
-        Enhancer e = new Enhancer();
-        e.setClassLoader(proxyClassLoader);
-        e.setSuperclass(getTargetClass(interfaces));
-        e.setInterfaces(toClassArray(getInterfaces(interfaces)));
-        e.setInterceptDuringConstruction(false);
-        e.setCallback(dispatcher);
-        e.setUseFactory(false);
-        return e.create();
+        return proxyFactory;
     }
 
     public void serviceChanged(ServiceEvent event) {
@@ -474,4 +450,82 @@
         return sb.toString();
     }
 
+    private static Class[] getInterfaces(Class[] classes) {
+        List<Class> interfaces = new ArrayList<Class>();
+        for (Class clazz : classes) {
+            if (clazz.isInterface()) {
+                interfaces.add(clazz);
+            }
+        }
+        return toClassArray(interfaces);
+    }
+
+    private static Class[] toClassArray(List<Class> classes) {
+        return classes.toArray(new Class [classes.size()]);
+    }
+
+    public static interface ProxyFactory {
+
+        public Object createProxy(ClassLoader classLoader, Class[] classes, Callable<Object> dispatcher);
+
+    }
+
+    public static class JdkProxyFactory implements ProxyFactory {
+
+        public Object createProxy(final ClassLoader classLoader, final Class[] classes, final Callable<Object> dispatcher) {
+            return Proxy.newProxyInstance(classLoader, getInterfaces(classes), new InvocationHandler() {
+                public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+                    return method.invoke(dispatcher.call(), args);
+                }
+            });
+        }
+
+    }
+
+    public static class CgLibProxyFactory implements ProxyFactory {
+
+        public Object createProxy(final ClassLoader classLoader, final Class[] classes, final Callable<Object> dispatcher) {
+            Enhancer e = new Enhancer();
+            e.setClassLoader(classLoader);
+            e.setSuperclass(getTargetClass(classes));
+            e.setInterfaces(getInterfaces(classes));
+            e.setInterceptDuringConstruction(false);
+            e.setCallback(new Dispatcher() {
+                public Object loadObject() throws Exception {
+                    return dispatcher.call();
+                }
+            });
+            e.setUseFactory(false);
+            return e.create();
+        }
+
+        protected Class getTargetClass(Class[] interfaceNames) {
+            // Only allow class proxying if specifically asked to
+            Class root = Object.class;
+            for (Class clazz : interfaceNames) {
+                if (!clazz.isInterface()) {
+                    if (root == Object.class) {
+                        root = clazz;
+                        continue;
+                    }
+                    // Check that all classes are in the same hierarchy
+                    for (Class p = clazz; p != Object.class; p = p.getSuperclass()) {
+                        if (p == root) {
+                            root = clazz;
+                            continue;
+                        }
+                    }
+                    for (Class p = root; p != Object.class; p = p.getSuperclass()) {
+                        if (p == clazz) {
+                            continue;
+                        }
+                    }
+                    throw new ComponentDefinitionException("Classes " + root.getClass().getName() + " and " + clazz.getName() + " are not in the same hierarchy");
+                }
+            }
+            return root;
+        }
+
+    }
+
 }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/Parser.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/Parser.java?rev=779901&r1=779900&r2=779901&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/Parser.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/Parser.java Fri May 29 09:32:43 2009
@@ -920,6 +920,9 @@
         
         ComponentMetadata r = references;
         
+        // Parse custom attributes
+        r = handleCustomAttributes(element.getAttributes(), r);
+
         // Parse custom elements;
         r = handleCustomElements(element, r);
         

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RefCollectionRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RefCollectionRecipe.java?rev=779901&r1=779900&r2=779901&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RefCollectionRecipe.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/RefCollectionRecipe.java Fri May 29 09:32:43 2009
@@ -30,9 +30,11 @@
 import java.util.ListIterator;
 import java.util.RandomAccess;
 import java.util.Set;
+import java.util.concurrent.Callable;
 
 import net.sf.cglib.proxy.Dispatcher;
 import org.apache.geronimo.blueprint.ExtendedBlueprintContainer;
+import org.apache.geronimo.blueprint.ExtendedRefCollectionMetadata;
 import org.apache.geronimo.blueprint.di.Recipe;
 import org.apache.geronimo.blueprint.utils.ConversionUtils;
 import org.apache.geronimo.blueprint.utils.DynamicCollection;
@@ -154,9 +156,14 @@
                     }
                 } else {
                     dispatcher = new ServiceDispatcher(reference);
-                    // TODO: it seems we need to make this greedy-proxying stuff an implementation specific
-                    // TODO: feature which could be activated by a custom attribute on the xml
-                    dispatcher.proxy = createProxy(dispatcher, Arrays.asList((String[]) reference.getProperty(Constants.OBJECTCLASS)));
+                    List<String> interfaces = metadata.getInterfaceNames(); 
+                    if (metadata instanceof ExtendedRefCollectionMetadata) {
+                        boolean greedy = (((ExtendedRefCollectionMetadata) metadata).getProxyMethod() & ExtendedRefCollectionMetadata.PROXY_METHOD_GREEDY) != 0;
+                        if (greedy) {
+                            interfaces = Arrays.asList((String[]) reference.getProperty(Constants.OBJECTCLASS));
+                        }
+                    }
+                    dispatcher.proxy = createProxy(dispatcher, interfaces);
                     synchronized (collection) {
                         collection.addDispatcher(dispatcher);
                     }
@@ -199,7 +206,7 @@
      * The ServiceDispatcher is used when creating the cglib proxy.
      * Thic class is responsible for getting the actual service that will be used.
      */
-    public class ServiceDispatcher implements Dispatcher {
+    public class ServiceDispatcher implements Callable<Object> {
 
         public ServiceReference reference;
         public Object service;
@@ -226,7 +233,7 @@
             }
         }
 
-        public synchronized Object loadObject() throws Exception {
+        public synchronized Object call() throws Exception {
             if (reference == null) {
                 throw new ServiceUnavailableException("Service is unavailable", null, null);
             }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceRecipe.java?rev=779901&r1=779900&r2=779901&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceRecipe.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/ReferenceRecipe.java Fri May 29 09:32:43 2009
@@ -19,6 +19,7 @@
 package org.apache.geronimo.blueprint.container;
 
 import java.lang.reflect.Type;
+import java.util.concurrent.Callable;
 
 import net.sf.cglib.proxy.Dispatcher;
 import org.apache.geronimo.blueprint.ExtendedBlueprintContainer;
@@ -169,9 +170,9 @@
         }
     }
 
-    public class ServiceDispatcher implements Dispatcher {
+    public class ServiceDispatcher implements Callable<Object> {
 
-        public Object loadObject() throws Exception {
+        public Object call() throws Exception {
             return getService();
         }
 

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/ExtNamespaceHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/ExtNamespaceHandler.java?rev=779901&r1=779900&r2=779901&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/ExtNamespaceHandler.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/ext/ExtNamespaceHandler.java Fri May 29 09:32:43 2009
@@ -24,6 +24,7 @@
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
+import org.w3c.dom.Attr;
 
 import org.osgi.service.blueprint.reflect.Metadata;
 import org.osgi.service.blueprint.reflect.ComponentMetadata;
@@ -33,9 +34,12 @@
 import org.osgi.service.blueprint.reflect.IdRefMetadata;
 import org.osgi.service.blueprint.reflect.CollectionMetadata;
 import org.osgi.service.blueprint.reflect.BeanProperty;
+import org.osgi.service.blueprint.reflect.ServiceReferenceMetadata;
+import org.osgi.service.blueprint.reflect.RefCollectionMetadata;
 import org.osgi.service.blueprint.container.ComponentDefinitionException;
 import org.apache.geronimo.blueprint.ParserContext;
 import org.apache.geronimo.blueprint.ComponentDefinitionRegistry;
+import org.apache.geronimo.blueprint.ExtendedRefCollectionMetadata;
 import org.apache.geronimo.blueprint.mutable.MutableBeanMetadata;
 import org.apache.geronimo.blueprint.mutable.MutableComponentMetadata;
 import org.apache.geronimo.blueprint.mutable.MutableValueMetadata;
@@ -43,6 +47,7 @@
 import org.apache.geronimo.blueprint.mutable.MutableIdRefMetadata;
 import org.apache.geronimo.blueprint.mutable.MutableCollectionMetadata;
 import org.apache.geronimo.blueprint.mutable.MutableMapMetadata;
+import org.apache.geronimo.blueprint.mutable.MutableServiceReferenceMetadata;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -67,6 +72,11 @@
     public static final String PLACEHOLDER_SUFFIX_ATTRIBUTE = "placeholder-suffix";
     public static final String DEFAULTS_REF_ATTRIBUTE = "defaults-ref";
 
+    public static final String PROXY_METHOD_ATTRIBUTE = "proxy-method";
+    public static final String PROXY_METHOD_DEFAULT = "default";
+    public static final String PROXY_METHOD_CLASSES = "classes";
+    public static final String PROXY_METHOD_GREEDY = "greedy";
+
     private static final Logger LOGGER = LoggerFactory.getLogger(ExtNamespaceHandler.class);
 
     private int idCounter;
@@ -77,7 +87,6 @@
 
     public Metadata parse(Element element, ParserContext context) {
         LOGGER.debug("Parsing element {" + element.getNamespaceURI() + "}" + element.getLocalName());
-        ComponentDefinitionRegistry registry = context.getComponentDefinitionRegistry();
         if (nodeNameEquals(element, SYSTEM_PROPERTY_PLACEHOLDER_ELEMENT)) {
             return parseSystemPropertyPlaceholder(context, element);
         } else {
@@ -86,7 +95,39 @@
     }
 
     public ComponentMetadata decorate(Node node, ComponentMetadata component, ParserContext context) {
-        throw new ComponentDefinitionException("Illegal use of blueprint ext namespace");
+        if (node instanceof Attr && nodeNameEquals(node, PROXY_METHOD_ATTRIBUTE)) {
+            return decorateProxyMethod(node, component, context);
+        } else {
+            throw new ComponentDefinitionException("Unsupported node: " + node.getNodeName());
+        }
+    }
+
+    private ComponentMetadata decorateProxyMethod(Node node, ComponentMetadata component, ParserContext context) {
+        if (!(component instanceof ServiceReferenceMetadata)) {
+            throw new ComponentDefinitionException("Attribute " + node.getNodeName() + " can only be used on a <reference>, <ref-list> or <ref-set> element");
+        }
+        if (!(component instanceof MutableServiceReferenceMetadata)) {
+            throw new ComponentDefinitionException("Expected an instance of MutableServiceReferenceMetadata");
+        }
+        int method = 0;
+        String value = ((Attr) node).getValue();
+        String[] flags = value.trim().split(" ");
+        for (String flag : flags) {
+            if (PROXY_METHOD_DEFAULT.equals(flag)) {
+                method += ExtendedRefCollectionMetadata.PROXY_METHOD_DEFAULT;
+            } else if (PROXY_METHOD_CLASSES.equals(flag)) {
+                method += ExtendedRefCollectionMetadata.PROXY_METHOD_CLASSES;
+            } else if (PROXY_METHOD_GREEDY.equals(flag)) {
+                method += ExtendedRefCollectionMetadata.PROXY_METHOD_GREEDY;
+            } else {
+                throw new ComponentDefinitionException("Unknown proxy method: " + flag);
+            }
+        }
+        if ((method & ExtendedRefCollectionMetadata.PROXY_METHOD_GREEDY) != 0 && !(component instanceof RefCollectionMetadata)) {
+            throw new ComponentDefinitionException("Greedy proxying is only available for <ref-list> and <ref-set> elements");
+        }
+        ((MutableServiceReferenceMetadata) component).setProxyMethod(method);
+        return component;
     }
 
     private Metadata parseSystemPropertyPlaceholder(ParserContext context, Element element) {

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/mutable/MutableRefCollectionMetadata.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/mutable/MutableRefCollectionMetadata.java?rev=779901&r1=779900&r2=779901&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/mutable/MutableRefCollectionMetadata.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/mutable/MutableRefCollectionMetadata.java Fri May 29 09:32:43 2009
@@ -20,6 +20,7 @@
 
 import org.osgi.service.blueprint.reflect.RefCollectionMetadata;
 import org.osgi.service.blueprint.reflect.Target;
+import org.apache.geronimo.blueprint.ExtendedRefCollectionMetadata;
 
 /**
  * A mutable version of the <code>RefCollectionMetadata</code> that allows modifications.
@@ -27,7 +28,7 @@
  * @author <a href="mailto:dev@geronimo.apache.org">Apache Geronimo Project</a>
  * @version $Rev: 766508 $, $Date: 2009-04-19 22:09:27 +0200 (Sun, 19 Apr 2009) $
  */
-public interface MutableRefCollectionMetadata extends RefCollectionMetadata, MutableServiceReferenceMetadata {
+public interface MutableRefCollectionMetadata extends ExtendedRefCollectionMetadata, MutableServiceReferenceMetadata {
 
     void setCollectionType(Class collectionType);
 

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/mutable/MutableServiceReferenceMetadata.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/mutable/MutableServiceReferenceMetadata.java?rev=779901&r1=779900&r2=779901&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/mutable/MutableServiceReferenceMetadata.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/mutable/MutableServiceReferenceMetadata.java Fri May 29 09:32:43 2009
@@ -21,6 +21,7 @@
 import org.osgi.service.blueprint.reflect.Listener;
 import org.osgi.service.blueprint.reflect.ServiceReferenceMetadata;
 import org.osgi.service.blueprint.reflect.Target;
+import org.apache.geronimo.blueprint.ExtendedServiceReferenceMetadata;
 
 /**
  * A mutable version of the <code>ServiceReferenceMetadata</code> that allows modifications.
@@ -28,7 +29,7 @@
  * @author <a href="mailto:dev@geronimo.apache.org">Apache Geronimo Project</a>
  * @version $Rev: 766508 $, $Date: 2009-04-19 22:09:27 +0200 (Sun, 19 Apr 2009) $
  */
-public interface MutableServiceReferenceMetadata extends ServiceReferenceMetadata, MutableComponentMetadata {
+public interface MutableServiceReferenceMetadata extends ExtendedServiceReferenceMetadata, MutableComponentMetadata {
 
     void setAvailability(int availability);
 
@@ -46,4 +47,6 @@
 
     void removeServiceListener(Listener listener);
 
+    void setProxyMethod(int proxyMethod);
+
 }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/ServiceReferenceMetadataImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/ServiceReferenceMetadataImpl.java?rev=779901&r1=779900&r2=779901&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/ServiceReferenceMetadataImpl.java (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/ServiceReferenceMetadataImpl.java Fri May 29 09:32:43 2009
@@ -41,6 +41,7 @@
     protected String componentName;
     protected String filter;
     protected Collection<Listener> serviceListeners;
+    protected int proxyMethod;
 
     public ServiceReferenceMetadataImpl() {
     }
@@ -131,4 +132,13 @@
             this.serviceListeners.remove(listener);
         }
     }
+
+    public int getProxyMethod() {
+        return proxyMethod;
+    }
+
+    public void setProxyMethod(int proxyMethod) {
+        this.proxyMethod = proxyMethod;
+    }
+
 }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/resources/org/apache/geronimo/blueprint/ext/blueprint-ext.xsd
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/resources/org/apache/geronimo/blueprint/ext/blueprint-ext.xsd?rev=779901&r1=779900&r2=779901&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/resources/org/apache/geronimo/blueprint/ext/blueprint-ext.xsd (original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/resources/org/apache/geronimo/blueprint/ext/blueprint-ext.xsd Fri May 29 09:32:43 2009
@@ -45,15 +45,31 @@
         </xsd:complexContent>
     </xsd:complexType>
 
-
-    <!-- #### is this the correct type here?  This is defining placeholder properties,
-         so should this be a restricted set of value types or should this be expanded to
-         all of the elements you can inject into a bean property? -->
     <xsd:complexType name="TdefaultProperties">
         <xsd:sequence minOccurs="0" maxOccurs="unbounded">
             <xsd:element name="property" type="bp:Tproperty"/>
         </xsd:sequence>
     </xsd:complexType>
 
+    <!-- proxy method -->
+
+    <xsd:attribute name="proxy-method" default="default">
+        <xsd:simpleType>
+            <xsd:restriction>
+                <xsd:simpleType>
+                    <xsd:list>
+                        <xsd:simpleType>
+                            <xsd:restriction base="xsd:NMTOKEN">
+                                <xsd:enumeration value="default"/>
+                                <xsd:enumeration value="classes"/>
+                                <xsd:enumeration value="greedy"/>
+                            </xsd:restriction>
+                        </xsd:simpleType>
+                    </xsd:list>
+                </xsd:simpleType>
+                <xsd:minLength value="1"/>
+            </xsd:restriction>
+        </xsd:simpleType>
+    </xsd:attribute>
 
 </xsd:schema>

Modified: geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/BlueprintContainerTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/BlueprintContainerTest.java?rev=779901&r1=779900&r2=779901&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/BlueprintContainerTest.java (original)
+++ geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/BlueprintContainerTest.java Fri May 29 09:32:43 2009
@@ -128,8 +128,7 @@
             mavenBundle("org.apache.geronimo", "blueprint-bundle"),
             mavenBundle("org.apache.geronimo", "blueprint-sample").noStart(),
 
-            //vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
-
+//            org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
 
             felix(), equinox() //, knopflerfish()
         );

Modified: geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestReferences.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestReferences.java?rev=779901&r1=779900&r2=779901&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestReferences.java (original)
+++ geronimo/sandbox/blueprint/blueprint-itests/src/test/java/org/apache/geronimo/blueprint/itests/TestReferences.java Fri May 29 09:32:43 2009
@@ -145,7 +145,7 @@
             mavenBundle("org.apache.geronimo", "blueprint-bundle"),
             mavenBundle("org.apache.geronimo", "blueprint-sample"),
 
-//            vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
+            org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
 
             felix() //, equinox(), knopflerfish()
         );

Modified: geronimo/sandbox/blueprint/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/pom.xml?rev=779901&r1=779900&r2=779901&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/pom.xml (original)
+++ geronimo/sandbox/blueprint/pom.xml Fri May 29 09:32:43 2009
@@ -78,15 +78,12 @@
                 <artifactId>junit</artifactId>
                 <version>4.5</version>
             </dependency>
+            <!-- Use an OSGi enabled cglib version, so that BND can find the version information
+                 and we can use it in integration tests -->
             <dependency>
-                <groupId>cglib</groupId>
-                <artifactId>cglib</artifactId>
-                <version>2.2</version>
-            </dependency>
-            <dependency>
-                <groupId>asm</groupId>
-                <artifactId>asm-all</artifactId>
-                <version>3.1</version>
+                <groupId>org.apache.servicemix.bundles</groupId>
+                <artifactId>org.apache.servicemix.bundles.cglib</artifactId>
+                <version>2.1_3_2</version>
             </dependency>
             <dependency>
                 <groupId>org.slf4j</groupId>