Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*****************************************************************************
* Copyright (C) PicoContainer Organization. All rights reserved. *
* ------------------------------------------------------------------------- *
* The software in this package is published under the terms of the BSD *
* style license a copy of which has been included with this distribution in *
* the LICENSE.txt file. *
* *
* Original code by *
*****************************************************************************/
package org.picocontainer.gems.behaviors;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Future;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.picocontainer.ComponentAdapter;
import org.picocontainer.PicoContainer;
import org.picocontainer.behaviors.AbstractBehavior;
import org.picocontainer.behaviors.Cached;
/**
* This component adapter makes it possible to hide the implementation of a real subject (behind a proxy).
* The proxy will implement all the interfaces of the
* underlying subject. If you want caching,
* use a {@link Cached} around this one.
*
* @author Paul Hammant
*/
@SuppressWarnings("serial")
public class AsmHiddenImplementation extends AbstractBehavior implements Opcodes {
public AsmHiddenImplementation(final ComponentAdapter delegate) {
super(delegate);
}
@Override
public T getComponentInstance(final PicoContainer container, final java.lang.reflect.Type into) {
T o = getDelegate().getComponentInstance(container, into);
Class[] interfaces = o.getClass().getInterfaces();
if (interfaces.length != 0) {
byte[] bytes = makeProxy("XX", interfaces, true);
AsmClassLoader cl = new AsmClassLoader(HotSwappable.Swappable.class.getClassLoader());
Class> pClazz = cl.defineClass("XX", bytes);
try {
Constructor ctor = (Constructor) pClazz.getConstructor(HotSwappable.Swappable.class);
final HotSwappable.Swappable swappable = getSwappable();
swappable.swap(o);
return ctor.newInstance(swappable);
} catch (NoSuchMethodException e) {
} catch (InstantiationException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
}
}
return o;
}
public String getDescriptor() {
return "Hidden";
}
protected HotSwappable.Swappable getSwappable() {
return new HotSwappable.Swappable();
}
public byte[] makeProxy(final String proxyName, final Class[] interfaces, final boolean setter) {
ClassWriter cw = new ClassWriter(0);
FieldVisitor fv;
Class