Search in sources :

Example 11 with UnableToProxyException

use of org.apache.aries.proxy.UnableToProxyException in project aries by apache.

the class ProxyClassLoader method createProxyClass.

public Class<?> createProxyClass(Class<?> superclass, SortedSet<Class<?>> interfaces) throws UnableToProxyException {
    LinkedHashSet<Class<?>> createSet = new LinkedHashSet<Class<?>>(interfaces);
    //Even a null superclass helps with key uniqueness
    createSet.add(superclass);
    String className = classes.get(createSet);
    if (className != null) {
        try {
            return Class.forName(className, false, this);
        } catch (ClassNotFoundException cnfe) {
            //This is odd, but we should be able to recreate the class, continue
            classes.remove(createSet);
        }
    }
    Lock wLock = ifacesLock.writeLock();
    wLock.lock();
    try {
        //We want the superclass, but only if it isn't null
        ifaces.addAll(interfaces);
        if (superclass != null)
            ifaces.add(superclass);
    } finally {
        wLock.unlock();
    }
    className = "Proxy" + AbstractWovenProxyAdapter.getSanitizedUUIDString();
    InterfaceCombiningClassAdapter icca = new InterfaceCombiningClassAdapter(className, this, superclass, interfaces);
    try {
        byte[] bytes = icca.generateBytes();
        Class<?> c = defineClass(className, bytes, 0, bytes.length, PROXY_PROTECTION_DOMAIN);
        String old = classes.putIfAbsent(createSet, className);
        if (old != null) {
            c = Class.forName(className, false, this);
        }
        return c;
    } catch (ClassFormatError cfe) {
        throw new UnableToProxyException(createSet.iterator().next(), cfe);
    } catch (ClassNotFoundException e) {
        throw new UnableToProxyException(createSet.iterator().next(), e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) UnableToProxyException(org.apache.aries.proxy.UnableToProxyException) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock)

Example 12 with UnableToProxyException

use of org.apache.aries.proxy.UnableToProxyException in project aries by apache.

the class BeanRecipe method createProxyBean.

private Object createProxyBean(ReferenceRecipe rr) {
    try {
        VoidableCallable vc = new VoidableCallable();
        rr.addVoidableChild(vc);
        return blueprintContainer.getProxyManager().createDelegatingProxy(blueprintContainer.getBundleContext().getBundle(), rr.getProxyChildBeanClasses(), vc, vc.call());
    } catch (UnableToProxyException e) {
        throw new ComponentDefinitionException(e);
    }
}
Also used : ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) UnableToProxyException(org.apache.aries.proxy.UnableToProxyException)

Aggregations

UnableToProxyException (org.apache.aries.proxy.UnableToProxyException)12 IOException (java.io.IOException)3 InputStream (java.io.InputStream)2 FinalModifierException (org.apache.aries.proxy.FinalModifierException)2 ClassReader (org.objectweb.asm.ClassReader)2 Bundle (org.osgi.framework.Bundle)2 BundleWiring (org.osgi.framework.wiring.BundleWiring)2 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Lock (java.util.concurrent.locks.Lock)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 ProxyManager (org.apache.aries.proxy.ProxyManager)1 WovenProxy (org.apache.aries.proxy.weaving.WovenProxy)1 Label (org.objectweb.asm.Label)1 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)1 Method (org.objectweb.asm.commons.Method)1 WeavingException (org.osgi.framework.hooks.weaving.WeavingException)1