incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n..@apache.org
Subject svn commit: r1030761 [1/2] - in /incubator/aries/trunk: ./ blueprint/ blueprint/blueprint-api/src/main/java/org/osgi/service/blueprint/container/ blueprint/blueprint-bundle/ blueprint/blueprint-bundle/src/main/java/ blueprint/blueprint-bundle/src/main/...
Date Wed, 03 Nov 2010 23:48:49 GMT
Author: not
Date: Wed Nov  3 23:48:47 2010
New Revision: 1030761

URL: http://svn.apache.org/viewvc?rev=1030761&view=rev
Log:
ARIES-468 Create proxy service implementation and change blueprint to make use of it.

Added:
    incubator/aries/trunk/blueprint/blueprint-bundle/src/main/java/
    incubator/aries/trunk/blueprint/blueprint-bundle/src/main/java/org/
    incubator/aries/trunk/blueprint/blueprint-bundle/src/main/java/org/apache/
    incubator/aries/trunk/blueprint/blueprint-bundle/src/main/java/org/apache/aries/
    incubator/aries/trunk/blueprint/blueprint-bundle/src/main/java/org/apache/aries/blueprint/
    incubator/aries/trunk/blueprint/blueprint-bundle/src/main/java/org/apache/aries/blueprint/uberbundle/
    incubator/aries/trunk/blueprint/blueprint-bundle/src/main/java/org/apache/aries/blueprint/uberbundle/UberActivator.java
    incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/ProxyUtils.java
    incubator/aries/trunk/proxy/proxy-api/src/main/java/org/apache/aries/proxy/FinalModifierException.java
      - copied, changed from r1027453, incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/FinalModifierException.java
    incubator/aries/trunk/proxy/proxy-api/src/main/java/org/apache/aries/proxy/UnableToProxyException.java
      - copied, changed from r1027453, incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/UnableToProxyException.java
    incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/AbstractProxyManager.java
    incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/AsmProxyManager.java
    incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/DefaultWrapper.java
    incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/JdkProxyManager.java
    incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/ProxyHandler.java
    incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/ProxyManagerActivator.java
    incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/
    incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/Constants.java
    incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxyClassBytecodeGenerationException.java
      - copied, changed from r1027453, incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/ProxyClassBytecodeGenerationException.java
    incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxyClassDefinitionException.java
      - copied, changed from r1027453, incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/ProxyClassDefinitionException.java
    incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxyClassInstantiationException.java
      - copied, changed from r1027453, incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/ProxyClassInstantiationException.java
    incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassAdapter.java
      - copied, changed from r1027453, incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/ProxySubclassAdapter.java
    incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassGenerator.java
      - copied, changed from r1027453, incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/ProxySubclassGenerator.java
    incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassHierarchyAdapter.java
      - copied, changed from r1027453, incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/ProxySubclassHierarchyAdapter.java
    incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassMethodHashSet.java
      - copied, changed from r1027453, incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/ProxySubclassMethodHashSet.java
    incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/UnableToLoadProxyException.java
      - copied, changed from r1027453, incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/UnableToLoadProxyException.java
    incubator/aries/trunk/proxy/proxy-impl/src/test/java/org/
    incubator/aries/trunk/proxy/proxy-impl/src/test/java/org/apache/
    incubator/aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/
    incubator/aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/
    incubator/aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/
      - copied from r1027885, incubator/aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/proxy/
Removed:
    incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/AsmInterceptorWrapper.java
    incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/FinalModifierException.java
    incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/ProxyClassBytecodeGenerationException.java
    incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/ProxyClassDefinitionException.java
    incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/ProxyClassInstantiationException.java
    incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/ProxySubclassAdapter.java
    incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/ProxySubclassGenerator.java
    incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/ProxySubclassHierarchyAdapter.java
    incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/ProxySubclassMethodHashSet.java
    incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/UnableToLoadProxyException.java
    incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/UnableToProxyException.java
    incubator/aries/trunk/blueprint/blueprint-core/src/test/java/org/apache/aries/blueprint/proxy/
    incubator/aries/trunk/proxy/proxy-api/src/main/java/org/apache/aries/proxy/ProxyFactory.java
Modified:
    incubator/aries/trunk/blueprint/   (props changed)
    incubator/aries/trunk/blueprint/blueprint-api/src/main/java/org/osgi/service/blueprint/container/BlueprintEvent.java
    incubator/aries/trunk/blueprint/blueprint-bundle/pom.xml
    incubator/aries/trunk/blueprint/blueprint-core/   (props changed)
    incubator/aries/trunk/blueprint/blueprint-core/pom.xml
    incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/ComponentNameAlreadyInUseException.java
    incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractServiceReferenceRecipe.java
    incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java
    incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java
    incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintQuiesceParticipant.java
    incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceListRecipe.java
    incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceRecipe.java
    incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ServiceRecipe.java
    incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/Collaborator.java
    incubator/aries/trunk/blueprint/pom.xml
    incubator/aries/trunk/pom.xml
    incubator/aries/trunk/proxy/pom.xml
    incubator/aries/trunk/proxy/proxy-api/src/main/java/org/apache/aries/proxy/ProxyManager.java
    incubator/aries/trunk/proxy/proxy-bundle/pom.xml
    incubator/aries/trunk/proxy/proxy-impl/pom.xml
    incubator/aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxySubclassGeneratorTest.java

Propchange: incubator/aries/trunk/blueprint/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Wed Nov  3 23:48:47 2010
@@ -5,3 +5,5 @@ target
 .classpath
 .project
 .settings
+velocity.log
+bin

Modified: incubator/aries/trunk/blueprint/blueprint-api/src/main/java/org/osgi/service/blueprint/container/BlueprintEvent.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-api/src/main/java/org/osgi/service/blueprint/container/BlueprintEvent.java?rev=1030761&r1=1030760&r2=1030761&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-api/src/main/java/org/osgi/service/blueprint/container/BlueprintEvent.java (original)
+++ incubator/aries/trunk/blueprint/blueprint-api/src/main/java/org/osgi/service/blueprint/container/BlueprintEvent.java Wed Nov  3 23:48:47 2010
@@ -226,7 +226,7 @@ public class BlueprintEvent {
 		this.timestamp = System.currentTimeMillis();
 		this.bundle = bundle;
 		this.extenderBundle = extenderBundle;
-		this.dependencies = dependencies;
+		this.dependencies = dependencies == null ? null : dependencies.clone();
 		this.cause = cause;
 		this.replay = false;
 		if (bundle == null) {

Modified: incubator/aries/trunk/blueprint/blueprint-bundle/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-bundle/pom.xml?rev=1030761&r1=1030760&r2=1030761&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-bundle/pom.xml (original)
+++ incubator/aries/trunk/blueprint/blueprint-bundle/pom.xml Wed Nov  3 23:48:47 2010
@@ -35,7 +35,7 @@
             ${project.artifactId};blueprint.graceperiod:=false
         </aries.osgi.symbolic.name>
         <aries.osgi.activator>
-            org.apache.aries.blueprint.container.BlueprintExtender
+            org.apache.aries.blueprint.uberbundle.UberActivator
         </aries.osgi.activator>
         <aries.osgi.import>
             !org.apache.aries.blueprint*,
@@ -54,12 +54,13 @@
             org.osgi.service.blueprint.container;version="1.0.1",
             org.osgi.service.blueprint.reflect;version="1.0.1",
             !org.apache.aries.blueprint.annotation*,
-            org.apache.aries.blueprint*;version="${pom.version}"
+            org.apache.aries.blueprint*;version="${pom.version}",
+            org.apache.aries.proxy;version=0.3-incubating-SNAPSHOT
         </aries.osgi.export>
         <aries.osgi.private.pkg>
-            org.apache.aries.util.tracker,
-            org.objectweb.asm,
-            org.objectweb.asm.commons,
+            org.apache.aries.proxy*,
+            org.objectweb.asm*,
+            org.apache.aries.util*,
             OSGI-INF*
         </aries.osgi.private.pkg>
         <aries.osgi.export.service>
@@ -91,6 +92,11 @@
             <artifactId>org.apache.aries.blueprint.cm</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.apache.aries.proxy</groupId>
+            <artifactId>org.apache.aries.proxy</artifactId>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
             <groupId>asm</groupId>
             <artifactId>asm-all</artifactId>
             <optional>true</optional>

Added: incubator/aries/trunk/blueprint/blueprint-bundle/src/main/java/org/apache/aries/blueprint/uberbundle/UberActivator.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-bundle/src/main/java/org/apache/aries/blueprint/uberbundle/UberActivator.java?rev=1030761&view=auto
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-bundle/src/main/java/org/apache/aries/blueprint/uberbundle/UberActivator.java (added)
+++ incubator/aries/trunk/blueprint/blueprint-bundle/src/main/java/org/apache/aries/blueprint/uberbundle/UberActivator.java Wed Nov  3 23:48:47 2010
@@ -0,0 +1,42 @@
+/*
+ * 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.aries.blueprint.uberbundle;
+
+import org.apache.aries.blueprint.container.BlueprintExtender;
+import org.apache.aries.proxy.impl.ProxyManagerActivator;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class UberActivator implements BundleActivator 
+{
+  private BlueprintExtender blueprintActivator = new BlueprintExtender();
+  private ProxyManagerActivator proxyActivator = new ProxyManagerActivator();
+  
+  public void start(BundleContext context)
+  {
+    proxyActivator.start(context);
+    blueprintActivator.start(context);
+  }
+
+  public void stop(BundleContext arg0)
+  {
+    blueprintActivator.stop(arg0);
+    proxyActivator.start(arg0);
+  }
+}
\ No newline at end of file

Propchange: incubator/aries/trunk/blueprint/blueprint-core/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Wed Nov  3 23:48:47 2010
@@ -3,3 +3,4 @@ target
 .settings
 .classpath
 .project
+velocity.log

Modified: incubator/aries/trunk/blueprint/blueprint-core/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/pom.xml?rev=1030761&r1=1030760&r2=1030761&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-core/pom.xml (original)
+++ incubator/aries/trunk/blueprint/blueprint-core/pom.xml Wed Nov  3 23:48:47 2010
@@ -101,13 +101,16 @@
       <dependency>
       	<groupId>org.apache.aries.quiesce</groupId>
       	<artifactId>org.apache.aries.quiesce.api</artifactId>
-      	<version>0.3-incubating-SNAPSHOT</version>
       	<scope>provided</scope>
       </dependency>
       <dependency>
         <groupId>org.apache.aries.testsupport</groupId>
         <artifactId>org.apache.aries.testsupport.unit</artifactId>
       </dependency>            
+      <dependency>
+      	<groupId>org.apache.aries</groupId>
+      	<artifactId>org.apache.aries.proxy.api</artifactId>
+      </dependency>
   </dependencies>
 
     <build>

Modified: incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/ComponentNameAlreadyInUseException.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/ComponentNameAlreadyInUseException.java?rev=1030761&r1=1030760&r2=1030761&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/ComponentNameAlreadyInUseException.java (original)
+++ incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/ComponentNameAlreadyInUseException.java Wed Nov  3 23:48:47 2010
@@ -16,16 +16,21 @@
  */
 package org.apache.aries.blueprint;
 
+import org.apache.aries.util.nls.MessageUtil;
+
 public class ComponentNameAlreadyInUseException extends RuntimeException {
-    
+
     private String conflictingName;
+    private String message;
 
     public ComponentNameAlreadyInUseException(String conflictingName) {
         this.conflictingName = conflictingName;
+        message = MessageUtil.createMessageUtil(this.getClass(), "org.apache.aries.blueprint.nls.BlueprintMessages")
+                                    .getMessage("duplicate.component", conflictingName);
     }
     
     public String getMessage() {
-        return "Name '" + this.conflictingName + "' is already in use by a registered component";
+        return message;
     }
 
     public String getConflictingName() {

Modified: incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractServiceReferenceRecipe.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractServiceReferenceRecipe.java?rev=1030761&r1=1030760&r2=1030761&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractServiceReferenceRecipe.java (original)
+++ incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/AbstractServiceReferenceRecipe.java Wed Nov  3 23:48:47 2010
@@ -43,10 +43,9 @@ import org.apache.aries.blueprint.Extend
 import org.apache.aries.blueprint.di.AbstractRecipe;
 import org.apache.aries.blueprint.di.CollectionRecipe;
 import org.apache.aries.blueprint.di.Recipe;
-import org.apache.aries.blueprint.proxy.AsmInterceptorWrapper;
-import org.apache.aries.blueprint.proxy.UnableToProxyException;
 import org.apache.aries.blueprint.utils.BundleDelegatingClassLoader;
 import org.apache.aries.blueprint.utils.ReflectionUtils;
+import org.apache.aries.proxy.UnableToProxyException;
 import org.osgi.framework.Constants;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceEvent;
@@ -78,7 +77,6 @@ public abstract class AbstractServiceRef
     protected final ServiceReferenceMetadata metadata;
     protected final CollectionRecipe listenersRecipe;
     protected final List<Recipe> explicitDependencies;
-    protected final ClassLoader proxyClassLoader;
     protected final boolean optional;
     /** The OSGi filter for tracking references */
     protected final String filter;
@@ -89,7 +87,6 @@ public abstract class AbstractServiceRef
     private final AtomicBoolean started = new AtomicBoolean();
     private final AtomicBoolean satisfied = new AtomicBoolean();
     private SatisfactionListener satisfactionListener;
-    private volatile ProxyFactory proxyFactory;
 
     protected AbstractServiceReferenceRecipe(String name,
                                              ExtendedBlueprintContainer blueprintContainer,
@@ -104,57 +101,12 @@ public abstract class AbstractServiceRef
         this.explicitDependencies = explicitDependencies;
         
         
-        this.proxyClassLoader = makeProxyClassLoader(blueprintContainer, metadata);
-
         this.optional = (metadata.getAvailability() == ReferenceMetadata.AVAILABILITY_OPTIONAL);
         this.filter = createOsgiFilter(metadata);
     }
 
 
 
-    // Create a ClassLoader delegating to the bundle, but also being able to see our bundle classes
-    // so that the created proxy can access cglib classes.
-    // TODO: we should be able to get rid of this classloader when using JDK 1.4 proxies with a single interface
-    //         (the case defined by the spec) and use the interface classloader instead
-    private ClassLoader makeProxyClassLoader(
-        final ExtendedBlueprintContainer blueprintContainer,
-        ServiceReferenceMetadata metadata) {
-      
-      Class typeClass = getInterfaceClass();
-      if (typeClass == null) {
-        return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
-          public ClassLoader run() {
-            return new BundleDelegatingClassLoader(blueprintContainer.getBundleContext().getBundle(),
-                AbstractServiceReferenceRecipe.class.getClassLoader());
-          }      
-        });
-      }
-      
-      final ClassLoader interfaceClassLoader = typeClass.getClassLoader();
-      
-      return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
-        public ClassLoader run() {
-          return new DualClassloader(interfaceClassLoader);
-        }      
-      });
-    }
-
-    private static class DualClassloader extends ClassLoader {
-      DualClassloader(ClassLoader parent) {
-        super(parent);
-      }
-      
-      @Override
-      protected Class<?> findClass(String name) throws ClassNotFoundException {
-        return getClass().getClassLoader().loadClass(name);
-      }
-
-      @Override
-      protected URL findResource(String name) {
-        return getClass().getClassLoader().getResource(name);
-      }
-    }
-    
     public CollectionRecipe getListenersRecipe() {
         return listenersRecipe;
     }
@@ -252,10 +204,10 @@ public abstract class AbstractServiceRef
             }
     }
 
-    protected List<Class> loadAllClasses(Iterable<String> interfaceNames) {
-        List<Class> classes = new ArrayList<Class>();
+    protected List<Class<?>> loadAllClasses(Iterable<String> interfaceNames) {
+        List<Class<?>> classes = new ArrayList<Class<?>>();
         for (String name : interfaceNames) {
-            Class clazz = loadClass(name);
+            Class<?> clazz = loadClass(name);
             classes.add(clazz);
         }
         return classes;
@@ -277,46 +229,14 @@ public abstract class AbstractServiceRef
     }
 
 
-    protected Object createProxy(final Callable<Object> dispatcher, Set<Class> interfaces) throws Exception {
+    protected Object createProxy(final Callable<Object> dispatcher, Set<Class<?>> interfaces) throws Exception {
         if (!interfaces.iterator().hasNext()) {
             return new Object();
         } else {
-            return getProxyFactory().createProxy(proxyClassLoader, toClassArray(interfaces), dispatcher);
+            return BlueprintExtender.getProxyManager().createProxy(blueprintContainer.getBundleContext().getBundle(), interfaces, dispatcher);
         }
     }
 
-    protected synchronized ProxyFactory getProxyFactory() throws ClassNotFoundException {
-        if (proxyFactory == null) {
-            boolean proxyClass = false;
-            if (metadata instanceof ExtendedServiceReferenceMetadata) {
-                proxyClass = (((ExtendedServiceReferenceMetadata) metadata).getProxyMethod() & ExtendedServiceReferenceMetadata.PROXY_METHOD_CLASSES) != 0;
-            }
-            if (!proxyClass) {
-                Set<Class> interfaces = new HashSet<Class>();
-                Class clz = getInterfaceClass();
-                if (clz != null) interfaces.add(clz);
-                
-                for (Class cl : interfaces) {
-                    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='classes' attribute needs to be added to this service reference.");
-                    }
-                }
-            }
-            try {
-                // Try load load a asm class (to make sure it's actually available
-                // then create the asm factory
-                getClass().getClassLoader().loadClass("org.objectweb.asm.ClassVisitor");
-                proxyFactory = new AsmProxyFactory();
-            } catch (Throwable t) {
-                if (proxyClass) {
-                    throw new ComponentDefinitionException("Class proxying has been enabled but cglib can not be used", t);
-                }
-                proxyFactory = new JdkProxyFactory();
-            }
-        }
-        return proxyFactory;
-    }
-
     public void serviceChanged(ServiceEvent event) {
         int eventType = event.getType();
         ServiceReference ref = event.getServiceReference();
@@ -610,38 +530,4 @@ public abstract class AbstractServiceRef
         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 {
-                    try {
-                        return method.invoke(dispatcher.call(), args);
-                    } catch (InvocationTargetException ite) {
-                      throw ite.getTargetException();
-                    }
-                }
-            });
-        }
-
-    }
-
-    public static class AsmProxyFactory implements ProxyFactory {
-
-        public Object createProxy(final ClassLoader classLoader, final Class[] classes, final Callable<Object> dispatcher) {
-            try {
-                return AsmInterceptorWrapper.createProxyObject(classLoader, null, null, dispatcher, classes);
-            } catch (UnableToProxyException e) {
-                throw new ComponentDefinitionException("Unable to create asm proxy", e);
-            }
-        }
-
-    }
-
 }

Modified: incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java?rev=1030761&r1=1030760&r2=1030761&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java (original)
+++ incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java Wed Nov  3 23:48:47 2010
@@ -40,10 +40,11 @@ import org.apache.aries.blueprint.Extend
 import org.apache.aries.blueprint.Interceptor;
 import org.apache.aries.blueprint.di.AbstractRecipe;
 import org.apache.aries.blueprint.di.Recipe;
-import org.apache.aries.blueprint.proxy.AsmInterceptorWrapper;
-import org.apache.aries.blueprint.proxy.UnableToProxyException;
+import org.apache.aries.blueprint.proxy.Collaborator;
+import org.apache.aries.blueprint.proxy.ProxyUtils;
 import org.apache.aries.blueprint.utils.ReflectionUtils;
 import org.apache.aries.blueprint.utils.ReflectionUtils.PropertyDescriptor;
+import org.osgi.framework.FrameworkUtil;
 import org.osgi.service.blueprint.container.ComponentDefinitionException;
 import org.osgi.service.blueprint.container.ReifiedType;
 import org.osgi.service.blueprint.reflect.BeanMetadata;
@@ -669,7 +670,7 @@ public class BeanRecipe extends Abstract
         return obj;
     }    
     
-    private Object addInterceptors(Object original)
+    private Object addInterceptors(final Object original)
             throws ComponentDefinitionException {
 
         Object intercepted = null;
@@ -691,10 +692,10 @@ public class BeanRecipe extends Abstract
             // if asm is available we can proxy the original object with the
             // AsmInterceptorWrapper
             try {
-                intercepted = AsmInterceptorWrapper.createProxyObject(original
-                        .getClass().getClassLoader(), interceptorLookupKey, interceptors,
-                        AsmInterceptorWrapper.passThrough(original), original.getClass());
-            } catch (UnableToProxyException e) {
+              intercepted = BlueprintExtender.getProxyManager().createProxy(FrameworkUtil.getBundle(original.getClass()), 
+                  ProxyUtils.asList(original.getClass()), ProxyUtils.passThrough(original), 
+                  new Collaborator(interceptorLookupKey, interceptors));
+            } catch (org.apache.aries.proxy.UnableToProxyException e) {
                 throw new ComponentDefinitionException("Unable to create asm proxy", e);
             }
         } else {

Modified: incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java?rev=1030761&r1=1030760&r2=1030761&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java (original)
+++ incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java Wed Nov  3 23:48:47 2010
@@ -31,6 +31,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.aries.blueprint.BlueprintConstants;
 import org.apache.aries.blueprint.ParserService;
@@ -38,6 +39,9 @@ import org.apache.aries.blueprint.annota
 import org.apache.aries.blueprint.namespace.NamespaceHandlerRegistryImpl;
 import org.apache.aries.blueprint.utils.HeaderParser;
 import org.apache.aries.blueprint.utils.HeaderParser.PathElement;
+import org.apache.aries.proxy.ProxyManager;
+import org.apache.aries.util.SingleServiceTracker;
+import org.apache.aries.util.SingleServiceTracker.SingleServiceListener;
 import org.apache.aries.util.tracker.RecursiveBundleTracker;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleActivator;
@@ -50,6 +54,8 @@ import org.osgi.framework.SynchronousBun
 import org.osgi.service.blueprint.container.BlueprintContainer;
 import org.osgi.service.blueprint.container.BlueprintEvent;
 import org.osgi.util.tracker.BundleTrackerCustomizer;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -72,37 +78,50 @@ public class BlueprintExtender implement
     private RecursiveBundleTracker bt;
     private ServiceRegistration parserServiceReg;
     private ServiceRegistration quiesceParticipantReg;
-
-    public void start(BundleContext context) {
+    private static SingleServiceTracker<ProxyManager> proxyManager;
+    
+    public void start(BundleContext ctx) {
         LOGGER.debug("Starting blueprint extender...");
 
-        this.context = context;
-        handlers = new NamespaceHandlerRegistryImpl(context);
+        this.context = ctx;
+        handlers = new NamespaceHandlerRegistryImpl(ctx);
         executors = Executors.newScheduledThreadPool(3, new BlueprintThreadFactory("Blueprint Extender"));
-        eventDispatcher = new BlueprintEventDispatcher(context, executors);
+        eventDispatcher = new BlueprintEventDispatcher(ctx, executors);
         containers = new HashMap<Bundle, BlueprintContainerImpl>();
 
         int stateMask = Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING | Bundle.ACTIVE
         | Bundle.STOPPING;
-        bt = new RecursiveBundleTracker(context, stateMask, new BlueprintBundleTrackerCustomizer());
-        bt.open();
-
+        bt = new RecursiveBundleTracker(ctx, stateMask, new BlueprintBundleTrackerCustomizer());
+        
+        proxyManager = new SingleServiceTracker<ProxyManager>(ctx, ProxyManager.class, new SingleServiceListener() {
+          public void serviceFound() {
+            LOGGER.debug("Found ProxyManager service, starting to process blueprint bundles");
+            bt.open();
+          }
+          public void serviceLost() {
+            // TODO we should probably close here, not sure.
+          }
+          public void serviceReplaced() {
+          }
+        });
+        proxyManager.open();
+        
         // Create and publish a ParserService
-        parserServiceReg = context.registerService(ParserService.class.getName(), 
+        parserServiceReg = ctx.registerService(ParserService.class.getName(), 
             new ParserServiceImpl (handlers), 
             new Hashtable<Object, Object>()); 
 
         try{
-            context.getBundle().loadClass(QUIESCE_PARTICIPANT_CLASS);
+            ctx.getBundle().loadClass(QUIESCE_PARTICIPANT_CLASS);
             //Class was loaded, register
 
-            quiesceParticipantReg = context.registerService(QUIESCE_PARTICIPANT_CLASS, 
-              new BlueprintQuiesceParticipant(context, this), 
+            quiesceParticipantReg = ctx.registerService(QUIESCE_PARTICIPANT_CLASS, 
+              new BlueprintQuiesceParticipant(ctx, this), 
               new Hashtable<Object, Object>()); 
         } 
         catch (ClassNotFoundException e) 
         {
-            LOGGER.info("No quiesce support is available, so blueprint components will not participate in quiesce operations", e);
+            LOGGER.info("No quiesce support is available, so blueprint components will not participate in quiesce operations");
         }
         
         LOGGER.debug("Blueprint extender started");
@@ -154,6 +173,14 @@ public class BlueprintExtender implement
         executors.shutdown();
         LOGGER.debug("Blueprint extender stopped");
     }
+    
+    /**
+     * @return the proxy manager. This will return null if the blueprint is not yet managing bundles.
+     */
+    public static ProxyManager getProxyManager()
+    {
+      return proxyManager.getService();
+    }
 
     private List<Bundle> getBundlesToDestroy() {
         List<Bundle> bundlesToDestroy = new ArrayList<Bundle>();
@@ -304,7 +331,7 @@ public class BlueprintExtender implement
         boolean compatible;
         if (bundle.getState() == Bundle.ACTIVE) {
             try {
-                Class clazz = bundle.getBundleContext().getBundle().loadClass(BlueprintContainer.class.getName());
+                Class<?> clazz = bundle.getBundleContext().getBundle().loadClass(BlueprintContainer.class.getName());
                 compatible = (clazz == BlueprintContainer.class);
             } catch (ClassNotFoundException e) {
                 compatible = true;
@@ -365,7 +392,7 @@ public class BlueprintExtender implement
     }
     
     private void addEntries(Bundle bundle, String path, String filePattern, List<Object> pathList) {
-        Enumeration e = bundle.findEntries(path, filePattern, false);
+        Enumeration<?> e = bundle.findEntries(path, filePattern, false);
         while (e != null && e.hasMoreElements()) {
             URL u = (URL) e.nextElement();
             URL override = getOverrideURL(bundle, u, path);

Modified: incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintQuiesceParticipant.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintQuiesceParticipant.java?rev=1030761&r1=1030760&r2=1030761&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintQuiesceParticipant.java (original)
+++ incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintQuiesceParticipant.java Wed Nov  3 23:48:47 2010
@@ -61,6 +61,7 @@ public class BlueprintQuiesceParticipant
 	
 	public void quiesce(QuiesceCallback callback, List<Bundle> bundlesToQuiesce) 
 	{
+	    boolean shutdownMe = false;
 		for(Bundle b : bundlesToQuiesce) 
 		{
 		  try 
@@ -70,10 +71,11 @@ public class BlueprintQuiesceParticipant
 		  catch (RejectedExecutionException re) {
 		  }
 		  
-		  //If we are quiescing, then we need to quiesce this threadpool!
-		  if(b.equals(ctx.getBundle()))
-		    executor.shutdown();
+          //If we are quiescing, then we need to quiesce this threadpool!
+		  shutdownMe |= b.equals(ctx.getBundle());
 		}
+		
+		if (shutdownMe) executor.shutdown();
 	}
 
   /**

Modified: incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceListRecipe.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceListRecipe.java?rev=1030761&r1=1030760&r2=1030761&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceListRecipe.java (original)
+++ incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceListRecipe.java Wed Nov  3 23:48:47 2010
@@ -110,8 +110,8 @@ public class ReferenceListRecipe extends
                     }
                 } else {
                     dispatcher = new ServiceDispatcher(reference);
-                    Set<Class> interfaces = new HashSet<Class>();
-                    Class clz = getInterfaceClass();
+                    Set<Class<?>> interfaces = new HashSet<Class<?>>();
+                    Class<?> clz = getInterfaceClass();
                     if (clz != null) interfaces.add(clz);
                     if (metadata instanceof ExtendedReferenceListMetadata) {
                         boolean greedy = (((ExtendedReferenceListMetadata) metadata).getProxyMethod() & ExtendedReferenceListMetadata.PROXY_METHOD_GREEDY) != 0;

Modified: incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceRecipe.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceRecipe.java?rev=1030761&r1=1030760&r2=1030761&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceRecipe.java (original)
+++ incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceRecipe.java Wed Nov  3 23:48:47 2010
@@ -75,8 +75,8 @@ public class ReferenceRecipe extends Abs
                 }
             }
             // Create the proxy
-            Set<Class> interfaces = new HashSet<Class>();
-            Class clz = getInterfaceClass();
+            Set<Class<?>> interfaces = new HashSet<Class<?>>();
+            Class<?> clz = getInterfaceClass();
             if (clz != null) interfaces.add(clz);
 
             proxy = createProxy(new ServiceDispatcher(), interfaces);

Modified: incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ServiceRecipe.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ServiceRecipe.java?rev=1030761&r1=1030760&r2=1030761&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ServiceRecipe.java (original)
+++ incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ServiceRecipe.java Wed Nov  3 23:48:47 2010
@@ -17,13 +17,11 @@
 package org.apache.aries.blueprint.container;
 
 
-import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Dictionary;
 import java.util.HashSet;
 import java.util.Hashtable;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -31,18 +29,24 @@ import java.util.concurrent.Callable;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
 
-import org.apache.aries.blueprint.*;
+import org.apache.aries.blueprint.BlueprintConstants;
+import org.apache.aries.blueprint.ComponentDefinitionRegistry;
+import org.apache.aries.blueprint.ExtendedBlueprintContainer;
+import org.apache.aries.blueprint.Interceptor;
+import org.apache.aries.blueprint.ServiceProcessor;
 import org.apache.aries.blueprint.di.AbstractRecipe;
 import org.apache.aries.blueprint.di.CollectionRecipe;
 import org.apache.aries.blueprint.di.MapRecipe;
 import org.apache.aries.blueprint.di.Recipe;
 import org.apache.aries.blueprint.di.Repository;
-import org.apache.aries.blueprint.proxy.AsmInterceptorWrapper;
-import org.apache.aries.blueprint.proxy.FinalModifierException;
+import org.apache.aries.blueprint.proxy.Collaborator;
+import org.apache.aries.blueprint.proxy.ProxyUtils;
 import org.apache.aries.blueprint.utils.JavaUtils;
 import org.apache.aries.blueprint.utils.ReflectionUtils;
+import org.apache.aries.proxy.InvocationHandlerWrapper;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
+import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.ServiceFactory;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
@@ -53,8 +57,6 @@ import org.osgi.service.blueprint.reflec
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static java.lang.reflect.Modifier.isFinal;
-
 /**
  * A <code>Recipe</code> to export services into the OSGi registry.
  *
@@ -454,22 +456,20 @@ public class ServiceRecipe extends Abstr
 
             Object intercepted;
             try {
+                Bundle b = FrameworkUtil.getBundle(original.getClass());
+                Callable<Object> target = ProxyUtils.passThrough(original);
+                InvocationHandlerWrapper collaborator = new Collaborator(cm, interceptors);
                 try {
-                    // Try with subclass proxying first
-                    intercepted = AsmInterceptorWrapper.createProxyObject(
-                            original.getClass().getClassLoader(), cm,
-                            interceptors, AsmInterceptorWrapper.passThrough(original),
-                            original.getClass());
-                } catch (FinalModifierException u) {
+                    intercepted = BlueprintExtender.getProxyManager().createProxy(b, 
+                        ProxyUtils.asList(original.getClass()), target, collaborator);
+                } catch (org.apache.aries.proxy.FinalModifierException u) {
                     LOGGER.debug("Error creating asm proxy (final modifier), trying with interfaces");
-                    List<Class> classes = new ArrayList<Class>();
+                    List<Class<?>> classes = new ArrayList<Class<?>>();
                     for (String className : getClasses()) {
                         classes.add(blueprintContainer.loadClass(className));
                     }
-                    intercepted = AsmInterceptorWrapper.createProxyObject(
-                            original.getClass().getClassLoader(), cm,
-                            interceptors, AsmInterceptorWrapper.passThrough(original),
-                            classes.toArray(new Class[classes.size()]));
+                    intercepted = BlueprintExtender.getProxyManager().createProxy(b, 
+                        classes, target, collaborator);
                 }
             } catch (Throwable u) {
                 LOGGER.info("A problem occurred trying to create a proxy object. Returning the original object instead.", u);

Modified: incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/Collaborator.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/Collaborator.java?rev=1030761&r1=1030760&r2=1030761&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/Collaborator.java (original)
+++ incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/Collaborator.java Wed Nov  3 23:48:47 2010
@@ -20,14 +20,12 @@ package org.apache.aries.blueprint.proxy
 
 import java.io.Serializable;
 import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
 import java.util.List;
 import java.util.Stack;
-import java.util.concurrent.Callable;
 
 import org.apache.aries.blueprint.Interceptor;
+import org.apache.aries.proxy.InvocationHandlerWrapper;
 import org.osgi.service.blueprint.reflect.ComponentMetadata;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -36,7 +34,7 @@ import org.slf4j.LoggerFactory;
  * A collaborator which ensures preInvoke and postInvoke occur before and after
  * method invocation
  */
-class Collaborator implements InvocationHandler, Serializable {
+public class Collaborator implements InvocationHandlerWrapper, Serializable {
 
     /** Serial version UID for this class */
     private static final long serialVersionUID = -58189302118314469L;
@@ -44,45 +42,11 @@ class Collaborator implements Invocation
     private static final Logger LOGGER = LoggerFactory
             .getLogger(Collaborator.class);
 
-    /** The invocation handler to call */
-    final InvocationHandler delegate;
-    final Callable<?> object;
-
     private transient List<Interceptor> interceptors = null;
     private transient ComponentMetadata cm = null;
 
-    Collaborator(ComponentMetadata cm, List<Interceptor> interceptors,
-            final Callable<?> delegateObj) {
+    public Collaborator(ComponentMetadata cm, List<Interceptor> interceptors) {
         this.cm = cm;
-        this.object = delegateObj;
-        this.delegate = new InvocationHandler() {
-            private void onUnexpectedException(Throwable cause) {
-                throw new Error("Unreachable catch statement reached", cause);
-            }
-
-            public Object invoke(Object proxy, Method method, Object[] args)
-                    throws Throwable {
-                Object result;
-                try {
-                    result = method.invoke(object.call(), args);
-                } catch (InvocationTargetException ite) {
-                    // We are invisible, so unwrap and throw the cause as
-                    // though we called the method directly.
-                    throw ite.getCause();
-                } catch (IllegalAccessException e) {
-                    onUnexpectedException(e);
-                    return null;
-                } catch (IllegalArgumentException e) {
-                    onUnexpectedException(e);
-                    return null;
-                } catch (SecurityException e) {
-                    onUnexpectedException(e);
-                    return null;
-                }
-
-                return result;
-            }
-        };
         this.interceptors = interceptors;
     }
 
@@ -114,84 +78,67 @@ class Collaborator implements Invocation
         }
     }
 
-    public Object invoke(Object proxy, Method method, Object[] args)
+    public Object invoke(Object proxy, Method method, Object[] args, InvocationHandler target)
             throws Throwable {
         Object toReturn = null;
         
-        // Unwrap calls for equals
-        if (method.getName().equals("equals")
-                && method.getDeclaringClass() == Object.class) {
-            if (AsmInterceptorWrapper.isProxyClass(args[0].getClass())
-                    || Proxy.isProxyClass(args[0].getClass())) {
-                // unwrap in the asm case
-                args[0] = AsmInterceptorWrapper.unwrapObject(args[0]);
+        Stack<Collaborator.StackElement> calledInterceptors = new Stack<Collaborator.StackElement>();
+        boolean inInvoke = false;
+        try {
+            preCallInterceptor(interceptors, cm, method, args,
+                    calledInterceptors);
+            inInvoke = true;
+            toReturn = target.invoke(proxy, method, args);
+            inInvoke = false;
+            postCallInterceptorWithReturn(cm, method, toReturn,
+                    calledInterceptors);
+
+        } catch (Throwable e) {
+            // whether the the exception is an error is an application decision
+            LOGGER.debug("invoke", e);
+
+            // if we catch an exception we decide carefully which one to
+            // throw onwards
+            Throwable exceptionToRethrow = null;
+            // if the exception came from a precall or postcall interceptor
+            // we will rethrow it
+            // after we cycle through the rest of the interceptors using
+            // postCallInterceptorWithException
+            if (!inInvoke) {
+                exceptionToRethrow = e;
+            }
+            // if the exception didn't come from precall or postcall then it
+            // came from invoke
+            // we will rethrow this exception if it is not a runtime
+            // exception
+            else {
+                if (!(e instanceof RuntimeException)) {
+                    exceptionToRethrow = e;
+                }
             }
-            toReturn = delegate.invoke(proxy, method, args);
-        } else if (method.getName().equals("finalize") && method.getParameterTypes().length == 0) {
-            // special case finalize, don't route through to delegate because that will get its own call
-            toReturn = null;
-        } else 
-        // Proxy the call through to the delegate, wrapping call in 
-        // interceptor invocations.
-        {
-            Stack<Collaborator.StackElement> calledInterceptors = new Stack<Collaborator.StackElement>();
-            boolean inInvoke = false;
             try {
-                preCallInterceptor(interceptors, cm, method, args,
-                        calledInterceptors);
-                inInvoke = true;
-                toReturn = delegate.invoke(proxy, method, args);
-                inInvoke = false;
-                postCallInterceptorWithReturn(cm, method, toReturn,
+                postCallInterceptorWithException(cm, method, e,
                         calledInterceptors);
-
-            } catch (Throwable e) {
-                // whether the the exception is an error is an application decision
-                LOGGER.debug("invoke", e);
-
-                // if we catch an exception we decide carefully which one to
-                // throw onwards
-                Throwable exceptionToRethrow = null;
-                // if the exception came from a precall or postcall interceptor
-                // we will rethrow it
-                // after we cycle through the rest of the interceptors using
+            } catch (Exception f) {
+                // we caught an exception from
                 // postCallInterceptorWithException
-                if (!inInvoke) {
-                    exceptionToRethrow = e;
-                }
-                // if the exception didn't come from precall or postcall then it
-                // came from invoke
-                // we will rethrow this exception if it is not a runtime
-                // exception
-                else {
-                    if (!(e instanceof RuntimeException)) {
-                        exceptionToRethrow = e;
-                    }
-                }
-                try {
-                    postCallInterceptorWithException(cm, method, e,
-                            calledInterceptors);
-                } catch (Exception f) {
-                    // we caught an exception from
-                    // postCallInterceptorWithException
-                    // logger.catching("invoke", f);
-                    // if we haven't already chosen an exception to rethrow then
-                    // we will throw this exception
-                    if (exceptionToRethrow == null) {
-                        exceptionToRethrow = f;
-                    } else {
-                      LOGGER.warn("Discarding post-call with interceptor exception", f);
-                    }
-                }
-                // if we made it this far without choosing an exception we
-                // should throw e
+                // logger.catching("invoke", f);
+                // if we haven't already chosen an exception to rethrow then
+                // we will throw this exception
                 if (exceptionToRethrow == null) {
-                    exceptionToRethrow = e;
-                } else if (exceptionToRethrow != e) {
-                  LOGGER.warn("Discarding initial exception", e);
+                    exceptionToRethrow = f;
+                } else {
+                  LOGGER.warn("Discarding post-call with interceptor exception", f);
                 }
-                throw exceptionToRethrow;
             }
+            // if we made it this far without choosing an exception we
+            // should throw e
+            if (exceptionToRethrow == null) {
+                exceptionToRethrow = e;
+            } else if (exceptionToRethrow != e) {
+              LOGGER.warn("Discarding initial exception", e);
+            }
+            throw exceptionToRethrow;
         }
         return toReturn;
     }

Added: incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/ProxyUtils.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/ProxyUtils.java?rev=1030761&view=auto
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/ProxyUtils.java (added)
+++ incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/ProxyUtils.java Wed Nov  3 23:48:47 2010
@@ -0,0 +1,32 @@
+package org.apache.aries.blueprint.proxy;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+public class ProxyUtils 
+{
+  public static final Callable<Object> passThrough(final Object target)
+  {
+    return new Callable<Object>() {
+      public Object call() throws Exception {
+        return target;
+      }
+    };
+  }
+  
+  public static final List<Class<?>> asList(Class<?> ... classesArray)
+  {
+    List<Class<?>> classes = new ArrayList<Class<?>>();
+    for (Class<?> clazz : classesArray) {
+      classes.add(clazz);
+    }
+    return classes;
+  }
+  public static final List<Class<?>> asList(Class<?> clazz)
+  {
+    List<Class<?>> classes = new ArrayList<Class<?>>();
+    classes.add(clazz);
+    return classes;
+  }
+}
\ No newline at end of file

Modified: incubator/aries/trunk/blueprint/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/pom.xml?rev=1030761&r1=1030760&r2=1030761&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/pom.xml (original)
+++ incubator/aries/trunk/blueprint/pom.xml Wed Nov  3 23:48:47 2010
@@ -155,6 +155,17 @@
               <artifactId>org.apache.aries.testsupport.unit</artifactId>
               <version>0.3-incubating-SNAPSHOT</version>
             </dependency>            
+            <dependency>
+            	<groupId>org.apache.aries</groupId>
+            	<artifactId>org.apache.aries.proxy.api</artifactId>
+            	<version>0.3-incubating-SNAPSHOT</version>
+            </dependency>
+            <dependency>
+              <groupId>org.apache.aries.proxy</groupId>
+        	  <artifactId>org.apache.aries.proxy</artifactId>
+        	  <version>0.3-incubating-SNAPSHOT</version>
+        	  <scope>test</scope>
+            </dependency>
         </dependencies>
     </dependencyManagement>
 

Modified: incubator/aries/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/pom.xml?rev=1030761&r1=1030760&r2=1030761&view=diff
==============================================================================
--- incubator/aries/trunk/pom.xml (original)
+++ incubator/aries/trunk/pom.xml Wed Nov  3 23:48:47 2010
@@ -51,6 +51,7 @@
         <module>jpa</module>
         <module>spi-fly</module>
         <module>samples</module>
+        <module>proxy</module>
     </modules>
 
     <build>

Modified: incubator/aries/trunk/proxy/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/proxy/pom.xml?rev=1030761&r1=1030760&r2=1030761&view=diff
==============================================================================
--- incubator/aries/trunk/proxy/pom.xml (original)
+++ incubator/aries/trunk/proxy/pom.xml Wed Nov  3 23:48:47 2010
@@ -50,6 +50,11 @@
                 <artifactId>asm-all</artifactId>
                 <version>3.2</version>
             </dependency>
+            <dependency>
+            	<groupId>org.apache.aries</groupId>
+            	<artifactId>org.apache.aries.util</artifactId>
+            	<version>${project.version}</version>
+            </dependency>
         </dependencies>
     </dependencyManagement>
 

Copied: incubator/aries/trunk/proxy/proxy-api/src/main/java/org/apache/aries/proxy/FinalModifierException.java (from r1027453, incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/FinalModifierException.java)
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/proxy/proxy-api/src/main/java/org/apache/aries/proxy/FinalModifierException.java?p2=incubator/aries/trunk/proxy/proxy-api/src/main/java/org/apache/aries/proxy/FinalModifierException.java&p1=incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/FinalModifierException.java&r1=1027453&r2=1030761&rev=1030761&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/FinalModifierException.java (original)
+++ incubator/aries/trunk/proxy/proxy-api/src/main/java/org/apache/aries/proxy/FinalModifierException.java Wed Nov  3 23:48:47 2010
@@ -16,7 +16,8 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.aries.blueprint.proxy;
+package org.apache.aries.proxy;
+
 
 public class FinalModifierException extends UnableToProxyException
 {

Modified: incubator/aries/trunk/proxy/proxy-api/src/main/java/org/apache/aries/proxy/ProxyManager.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/proxy/proxy-api/src/main/java/org/apache/aries/proxy/ProxyManager.java?rev=1030761&r1=1030760&r2=1030761&view=diff
==============================================================================
--- incubator/aries/trunk/proxy/proxy-api/src/main/java/org/apache/aries/proxy/ProxyManager.java (original)
+++ incubator/aries/trunk/proxy/proxy-api/src/main/java/org/apache/aries/proxy/ProxyManager.java Wed Nov  3 23:48:47 2010
@@ -18,9 +18,31 @@
  */
 package org.apache.aries.proxy;
 
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+import org.osgi.framework.Bundle;
+
+/**
+ * The proxy manager service allows clients to generate and manage proxies.
+ */
 public interface ProxyManager 
 {
-  public ProxyFactory createProxyFactory();
-  public ProxyFactory createProxyFactory(boolean interfaceProxyingOnly);
-  public Object unwrap(Object proxy);
+  public Object createProxy(Bundle clientBundle, Collection<Class<?>> classes, Callable<Object> dispatcher) throws UnableToProxyException;
+  public Object createProxy(Bundle clientBundle, Collection<Class<?>> classes, Callable<Object> dispatcher, InvocationHandlerWrapper wrapper) throws UnableToProxyException;
+  /**
+   * This method unwraps the provided proxy returning the target object.
+   * 
+   * @param proxy the proxy to unwrap.
+   * @return      the target object.
+   */
+  public Callable<Object> unwrap(Object proxy);
+  /**
+   * Returns true if and only if the specified object was generated by a ProxyFactory returned by
+   * a call to {@link ProxyManager#createProxyFactory(boolean)}.
+   * @param proxy The proxy object to test
+   * @return      true if it is a proxy, false otherwise.
+   */
+  public boolean isProxy(Object proxy);
 }
\ No newline at end of file

Copied: incubator/aries/trunk/proxy/proxy-api/src/main/java/org/apache/aries/proxy/UnableToProxyException.java (from r1027453, incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/UnableToProxyException.java)
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/proxy/proxy-api/src/main/java/org/apache/aries/proxy/UnableToProxyException.java?p2=incubator/aries/trunk/proxy/proxy-api/src/main/java/org/apache/aries/proxy/UnableToProxyException.java&p1=incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/UnableToProxyException.java&r1=1027453&r2=1030761&rev=1030761&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/proxy/UnableToProxyException.java (original)
+++ incubator/aries/trunk/proxy/proxy-api/src/main/java/org/apache/aries/proxy/UnableToProxyException.java Wed Nov  3 23:48:47 2010
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.aries.blueprint.proxy;
+package org.apache.aries.proxy;
 
 public class UnableToProxyException extends Exception
 {

Modified: incubator/aries/trunk/proxy/proxy-bundle/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/proxy/proxy-bundle/pom.xml?rev=1030761&r1=1030760&r2=1030761&view=diff
==============================================================================
--- incubator/aries/trunk/proxy/proxy-bundle/pom.xml (original)
+++ incubator/aries/trunk/proxy/proxy-bundle/pom.xml Wed Nov  3 23:48:47 2010
@@ -19,8 +19,8 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
     <modelVersion>4.0.0</modelVersion>
     <parent>
-        <groupId>org.apache.aries</groupId>
-        <artifactId>java5-parent</artifactId>
+        <groupId>org.apache.aries.proxy</groupId>
+        <artifactId>proxy</artifactId>
         <version>0.3-incubating-SNAPSHOT</version>
     </parent>
 
@@ -39,14 +39,21 @@
     </scm>
 
     <properties>
+        <aries.osgi.activator>
+            org.apache.aries.proxy.impl.ProxyManagerActivator
+        </aries.osgi.activator>
         <aries.osgi.export.pkg>
             org.apache.aries.proxy;
         </aries.osgi.export.pkg>
         <aries.osgi.import.pkg>
+            org.objectweb.asm;resolution:=optional,
+            org.objectweb.asm.commons;resolution:=optional,
             *
         </aries.osgi.import.pkg>
         <aries.osgi.private.pkg>
-            org.apache.aries.proxy.impl
+            org.apache.aries.util*,
+            org.objectweb.asm*,
+            org.apache.aries.proxy.impl*
         </aries.osgi.private.pkg>
     </properties>
 
@@ -77,6 +84,16 @@
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+        	<groupId>org.apache.aries</groupId>
+        	<artifactId>org.apache.aries.proxy.api</artifactId>
+        	<version>${project.version}</version>
+        </dependency>
+        <dependency>
+        	<groupId>org.apache.aries.proxy</groupId>
+        	<artifactId>org.apache.aries.proxy.impl</artifactId>
+        	<version>${project.version}</version>
+        </dependency>
     </dependencies>
 
 </project>

Modified: incubator/aries/trunk/proxy/proxy-impl/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/proxy/proxy-impl/pom.xml?rev=1030761&r1=1030760&r2=1030761&view=diff
==============================================================================
--- incubator/aries/trunk/proxy/proxy-impl/pom.xml (original)
+++ incubator/aries/trunk/proxy/proxy-impl/pom.xml Wed Nov  3 23:48:47 2010
@@ -19,8 +19,8 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
     <modelVersion>4.0.0</modelVersion>
     <parent>
-        <groupId>org.apache.aries</groupId>
-        <artifactId>java5-parent</artifactId>
+        <groupId>org.apache.aries.proxy</groupId>
+        <artifactId>proxy</artifactId>
         <version>0.3-incubating-SNAPSHOT</version>
     </parent>
 
@@ -39,18 +39,36 @@
     </scm>
 
     <properties>
-        <aries.osgi.export.pkg>
-        </aries.osgi.export.pkg>
+        <aries.osgi.export.pkg/>
+        <aries.osgi.activator>
+            org.apache.aries.proxy.impl.ProxyManagerActivator
+        </aries.osgi.activator>
         <aries.osgi.import.pkg>
+            org.objectweb.asm;resolution:=optional,
+            org.objectweb.asm.commons;resolution:=optional,
             *
         </aries.osgi.import.pkg>
         <aries.osgi.private.pkg>
-            org.apache.aries.proxy.impl
+            org.apache.aries.proxy.impl*
         </aries.osgi.private.pkg>
     </properties>
 
     <dependencies>
         <dependency>
+            <groupId>asm</groupId>
+            <artifactId>asm-all</artifactId>
+            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
             <scope>provided</scope>
@@ -83,6 +101,11 @@
         	<type>bundle</type>
         	<scope>compile</scope>
         </dependency>
+        <dependency>
+        	<groupId>org.apache.aries</groupId>
+        	<artifactId>org.apache.aries.util</artifactId>
+        	<scope>compile</scope>
+        </dependency>
     </dependencies>
 
 </project>

Added: incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/AbstractProxyManager.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/AbstractProxyManager.java?rev=1030761&view=auto
==============================================================================
--- incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/AbstractProxyManager.java (added)
+++ incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/AbstractProxyManager.java Wed Nov  3 23:48:47 2010
@@ -0,0 +1,128 @@
+/*
+ * 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.aries.proxy.impl;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Collection;
+import java.util.concurrent.Callable;
+
+import org.apache.aries.proxy.InvocationHandlerWrapper;
+import org.apache.aries.proxy.ProxyManager;
+import org.apache.aries.proxy.UnableToProxyException;
+import org.apache.aries.util.AriesFrameworkUtil;
+import org.osgi.framework.Bundle;
+
+public abstract class AbstractProxyManager implements ProxyManager
+{
+  public final Object createProxy(Bundle clientBundle, Collection<Class<?>> classes,
+      Callable<Object> dispatcher) 
+    throws UnableToProxyException
+  {
+    return createProxy(clientBundle, classes, dispatcher, null);
+  }
+
+  public final Object createProxy(Bundle clientBundle, Collection<Class<?>> classes,
+      Callable<Object> dispatcher, InvocationHandlerWrapper wrapper)
+      throws UnableToProxyException 
+  {
+    InvocationHandler ih = new ProxyHandler(this, dispatcher, wrapper);
+    Object proxyObject = duplicateProxy(classes, ih);
+    
+    if (proxyObject == null) {
+      proxyObject = createNewProxy(clientBundle, classes, ih);
+    }
+    
+    return proxyObject;
+  }
+  
+  public final Callable<Object> unwrap(Object proxy) 
+  {
+    Callable<Object> target = null;
+    
+    if (isProxy(proxy)) {
+      InvocationHandler ih = getInvocationHandler(proxy);
+      
+      if (ih instanceof ProxyHandler) {
+        target = ((ProxyHandler)ih).getTarget();
+      }
+    }
+    
+    return target;
+  }
+  
+  public final boolean isProxy(Object proxy)
+  {
+    return (getInvocationHandler(proxy) instanceof ProxyHandler);
+  }
+  
+  protected abstract Object createNewProxy(Bundle clientBundle, Collection<Class<?>> classes,
+      InvocationHandler ih) throws UnableToProxyException;
+  protected abstract InvocationHandler getInvocationHandler(Object proxy);
+  protected abstract boolean isProxyClass(Class<?> clazz);
+
+  protected synchronized ClassLoader getClassLoader(final Bundle clientBundle, Collection<Class<?>> classes) 
+  {
+    if (clientBundle.getState() == Bundle.UNINSTALLED) {
+      throw new IllegalStateException("The bundle " + clientBundle.getBundleId() + " has been uninstalled");
+    }
+    
+    ClassLoader cl = null;
+    
+    if (classes.size() == 1) cl = classes.iterator().next().getClassLoader();
+
+    if (cl == null) {
+      // First of all see if the AriesFrameworkUtil can get the classloader, if it can we go with that.
+      cl = AriesFrameworkUtil.getClassLoaderForced(clientBundle);
+    }
+    
+    return cl;
+  }
+
+  private Object duplicateProxy(Collection<Class<?>> classes, InvocationHandler handler)
+  {
+    Object proxyObject = null;
+    
+    if (classes.size() == 1) {
+
+      Class<?> classToProxy = classes.iterator().next();
+
+      boolean isProxy = isProxyClass(classToProxy);
+
+      if (isProxy) {
+        try {
+          /*
+           * the class is already a proxy, we should just invoke
+           * the constructor to get a new instance of the proxy
+           * with a new Collaborator using the specified delegate
+           */
+          proxyObject = classToProxy.getConstructor(InvocationHandler.class).newInstance(handler);
+        } catch (InvocationTargetException e) {
+        } catch (NoSuchMethodException e) {
+        } catch (InstantiationException e) {
+        } catch (IllegalArgumentException e) {
+        } catch (SecurityException e) {
+        } catch (IllegalAccessException e) {
+        }
+      }
+    }
+    
+    return proxyObject;
+  }
+}
\ No newline at end of file

Added: incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/AsmProxyManager.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/AsmProxyManager.java?rev=1030761&view=auto
==============================================================================
--- incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/AsmProxyManager.java (added)
+++ incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/AsmProxyManager.java Wed Nov  3 23:48:47 2010
@@ -0,0 +1,110 @@
+/*
+ * 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.aries.proxy.impl;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.aries.proxy.ProxyManager;
+import org.apache.aries.proxy.UnableToProxyException;
+import org.apache.aries.proxy.impl.gen.ProxySubclassGenerator;
+import org.osgi.framework.Bundle;
+
+public final class AsmProxyManager extends AbstractProxyManager implements ProxyManager
+{
+  public Object createNewProxy(Bundle clientBundle, Collection<Class<?>> classes, InvocationHandler handler) 
+    throws UnableToProxyException
+  {
+    Object proxyObject = null;
+
+    // if we just have interfaces and no classes we default to using
+    // the interface proxy because we can't dynamically
+    // subclass more than one interface
+    // unless we have a class
+    // that implements all of them
+
+    // default to not subclass
+    boolean useSubclassProxy = false;
+
+    // loop through the classes checking if they are java interfaces
+    // if we find any class that isn't an interface we need to use
+    // the subclass proxy
+    Set<Class<?>> notInterfaces = new HashSet<Class<?>>();
+    for (Class<?> clazz : classes) {
+      if (!!!clazz.isInterface()) {
+        useSubclassProxy = true;
+        notInterfaces.add(clazz);
+      }
+    }
+
+    if (useSubclassProxy) {
+      // if we need to use the subclass proxy then we need to find
+      // the most specific class
+      Class<?> classToProxy = null;
+      int deepest = 0;
+      // for each of the classes find out how deep it is in the
+      // hierarchy
+      for (Class<?> clazz : notInterfaces) {
+        Class<?> nextHighestClass = clazz;
+        int depth = 0;
+        do {
+          nextHighestClass = nextHighestClass.getSuperclass();
+          depth++;
+        } while (nextHighestClass != null);
+        if (depth > deepest) {
+          // if we find a class deeper than the one we already
+          // had
+          // it becomes the new most specific
+          deepest = depth;
+          classToProxy = clazz;
+        }
+      }
+      proxyObject = ProxySubclassGenerator.newProxySubclassInstance(classToProxy, handler);
+    } else {
+      // TODO there are some problems here. If we get a BundleToClassLoaderAdapter back and the bundle can't see all the classes referenced by the interface bad things happen (i.e. it fails).
+      proxyObject = Proxy.newProxyInstance(getClassLoader(clientBundle, classes), classes.toArray(new Class<?>[classes.size()]), handler);
+    }
+
+    return proxyObject;
+  }
+  
+  @Override
+  protected boolean isProxyClass(Class<?> clazz)
+  {
+    return ProxySubclassGenerator.isProxySubclass(clazz) || Proxy.isProxyClass(clazz);
+  }
+
+  @Override
+  protected InvocationHandler getInvocationHandler(Object proxy) 
+  {
+    Class<?> type = proxy.getClass();
+    InvocationHandler ih = null;
+    
+    if (ProxySubclassGenerator.isProxySubclass(type)) {
+      ih = ProxySubclassGenerator.getInvocationHandler(proxy);
+    } else if (Proxy.isProxyClass(type)) {
+      ih = Proxy.getInvocationHandler(proxy);
+    }
+    
+    return ih;
+  }
+}
\ No newline at end of file

Added: incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/DefaultWrapper.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/DefaultWrapper.java?rev=1030761&view=auto
==============================================================================
--- incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/DefaultWrapper.java (added)
+++ incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/DefaultWrapper.java Wed Nov  3 23:48:47 2010
@@ -0,0 +1,34 @@
+/*
+ * 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.aries.proxy.impl;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+import org.apache.aries.proxy.InvocationHandlerWrapper;
+
+public class DefaultWrapper implements InvocationHandlerWrapper {
+
+  public Object invoke(Object proxy, Method m, Object[] args,
+      InvocationHandler delegate) throws Throwable 
+  {
+    return delegate.invoke(proxy, m, args);
+  }
+
+}

Added: incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/JdkProxyManager.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/JdkProxyManager.java?rev=1030761&view=auto
==============================================================================
--- incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/JdkProxyManager.java (added)
+++ incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/JdkProxyManager.java Wed Nov  3 23:48:47 2010
@@ -0,0 +1,60 @@
+/*
+ * 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.aries.proxy.impl;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
+import java.util.Collection;
+
+import org.apache.aries.proxy.ProxyManager;
+import org.osgi.framework.Bundle;
+
+public final class JdkProxyManager extends AbstractProxyManager implements ProxyManager
+{
+  public Object createNewProxy(Bundle clientBundle, Collection<Class<?>> classes, InvocationHandler handler) 
+  {
+    return Proxy.newProxyInstance(getClassLoader(clientBundle, classes), getInterfaces(classes), handler);
+  }
+
+  private static final Class<?>[] getInterfaces(Collection<Class<?>> classes)
+  {
+    for (Class<?> clazz : classes) {
+        if (!!!clazz.isInterface()) {
+          throw new IllegalArgumentException("ARGH " + clazz + " is not an interface and I can't deal with that");
+        } 
+    }
+    return (Class[]) classes.toArray(new Class[classes.size()]);
+  }
+
+  @Override
+  protected boolean isProxyClass(Class<?> clazz) 
+  {
+    return Proxy.isProxyClass(clazz);
+  }
+
+  @Override
+  protected InvocationHandler getInvocationHandler(Object proxy) 
+  {
+    Class<?> clazz = proxy.getClass();
+    if (isProxyClass(clazz)) {
+      return Proxy.getInvocationHandler(proxy);
+    }
+    return null;
+  }
+}
\ No newline at end of file

Added: incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/ProxyHandler.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/ProxyHandler.java?rev=1030761&view=auto
==============================================================================
--- incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/ProxyHandler.java (added)
+++ incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/ProxyHandler.java Wed Nov  3 23:48:47 2010
@@ -0,0 +1,85 @@
+/*
+ * 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.aries.proxy.impl;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.concurrent.Callable;
+
+import org.apache.aries.proxy.InvocationHandlerWrapper;
+
+public final class ProxyHandler implements InvocationHandler {
+  private final Callable<Object> target;
+  private final InvocationHandler core;
+  private final InvocationHandlerWrapper wrapper;
+  private final AbstractProxyManager proxyManager;
+
+  public ProxyHandler(AbstractProxyManager abstractProxyManager, Callable<Object> dispatcher, InvocationHandlerWrapper wrapper)
+  {
+    target = dispatcher;
+    proxyManager = abstractProxyManager;
+    if (wrapper == null) {
+      this.wrapper = new DefaultWrapper();
+    } else {
+      this.wrapper = wrapper;
+    }
+    
+    core = new InvocationHandler() {
+      public Object invoke(Object proxy, Method method, Object[] args)
+          throws Throwable 
+      {
+          Object result;
+          try {
+              result = method.invoke(target.call(), args);
+          } catch (InvocationTargetException ite) {
+              // We are invisible, so unwrap and throw the cause as
+              // though we called the method directly.
+              throw ite.getCause();
+          } catch (IllegalAccessException e) {
+              throw new IllegalAccessError(e.getMessage());
+          }
+
+          return result;
+      }
+    };
+  }
+
+  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable 
+  {
+    // Unwrap calls for equals
+    if (method.getName().equals("equals")
+            && method.getDeclaringClass() == Object.class) {
+        Object targetObject = args[0];
+        if (proxyManager.isProxy(targetObject)) {
+          args[0] = proxyManager.unwrap(proxy).call();
+        }
+    } else if (method.getName().equals("finalize") && method.getParameterTypes().length == 0) {
+        // special case finalize, don't route through to delegate because that will get its own call
+        return null;
+    }
+    
+    return wrapper.invoke(proxy, method, args, core);
+  }
+
+  public Callable<Object> getTarget() 
+  {
+    return target;
+  }
+}
\ No newline at end of file

Added: incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/ProxyManagerActivator.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/ProxyManagerActivator.java?rev=1030761&view=auto
==============================================================================
--- incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/ProxyManagerActivator.java (added)
+++ incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/ProxyManagerActivator.java Wed Nov  3 23:48:47 2010
@@ -0,0 +1,58 @@
+/*
+ * 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.aries.proxy.impl;
+
+import org.apache.aries.proxy.ProxyManager;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class ProxyManagerActivator implements BundleActivator 
+{
+  private static final boolean ASM_PROXY_SUPPORTED;
+  private AbstractProxyManager managerService;
+  
+  static
+  {
+    boolean classProxy = false;
+    try {
+      // Try load load a asm class (to make sure it's actually available
+      // then create the asm factory
+      Class.forName("org.objectweb.asm.ClassVisitor");
+      classProxy = true;
+    } catch (Throwable t) {
+    }
+    
+    ASM_PROXY_SUPPORTED = classProxy;
+  }
+  
+  public void start(BundleContext context)
+  {
+    if (ASM_PROXY_SUPPORTED) {
+      managerService = new AsmProxyManager();
+    } else {
+      managerService = new JdkProxyManager();
+    }
+    
+    context.registerService(ProxyManager.class.getName(), managerService, null);
+  }
+
+  public void stop(BundleContext context)
+  {
+  }
+}
\ No newline at end of file

Added: incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/Constants.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/Constants.java?rev=1030761&view=auto
==============================================================================
--- incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/Constants.java (added)
+++ incubator/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/Constants.java Wed Nov  3 23:48:47 2010
@@ -0,0 +1,26 @@
+/*
+ * 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.aries.proxy.impl.gen;
+
+public interface Constants 
+{
+  final static String LOG_ENTRY = "Method entry: {}, args {}";
+  final static String LOG_EXIT = "Method exit: {}, returning {}";
+  final static String LOG_EXCEPTION = "Caught exception";
+}



Mime
View raw message