Search in sources :

Example 6 with Callback

use of net.sf.cglib.proxy.Callback in project cloudstack by apache.

the class GenericDaoBase method toEntityBean.

@SuppressWarnings("unchecked")
@DB()
protected T toEntityBean(final ResultSet result, final boolean cache) throws SQLException {
    final T entity = (T) _factory.newInstance(new Callback[] { NoOp.INSTANCE, new UpdateBuilder(this) });
    toEntityBean(result, entity);
    if (cache && _cache != null) {
        try {
            _cache.put(new Element(_idField.get(entity), entity));
        } catch (final Exception e) {
            s_logger.debug("Can't put it in the cache", e);
        }
    }
    return entity;
}
Also used : Callback(net.sf.cglib.proxy.Callback) Element(net.sf.ehcache.Element) URISyntaxException(java.net.URISyntaxException) EntityExistsException(javax.persistence.EntityExistsException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) MalformedURLException(java.net.MalformedURLException)

Example 7 with Callback

use of net.sf.cglib.proxy.Callback in project tomee by apache.

the class AxisServiceReference method createServiceInterfaceProxy.

private Object createServiceInterfaceProxy(String serviceInterfaceClassName, Map seiPortNameToFactoryMap, Map seiClassNameToFactoryMap, ClassLoader classLoader) throws NamingException {
    boolean initialize = (this.serviceConstructor == null);
    if (initialize) {
        Class serviceInterface;
        try {
            serviceInterface = classLoader.loadClass(serviceInterfaceClassName);
        } catch (ClassNotFoundException e) {
            throw (NamingException) new NamingException("Could not load service interface class " + serviceInterfaceClassName).initCause(e);
        }
        // create method interceptors
        Callback callback = new ServiceMethodInterceptor(seiPortNameToFactoryMap);
        this.methodInterceptors = new Callback[] { NoOp.INSTANCE, callback };
        // create service class
        Enhancer enhancer = new Enhancer();
        enhancer.setClassLoader(classLoader);
        enhancer.setSuperclass(ServiceImpl.class);
        enhancer.setInterfaces(new Class[] { serviceInterface });
        enhancer.setCallbackFilter(new NoOverrideCallbackFilter(Service.class));
        enhancer.setCallbackTypes(new Class[] { NoOp.class, MethodInterceptor.class });
        enhancer.setUseFactory(false);
        enhancer.setUseCache(false);
        this.enhancedServiceClass = enhancer.createClass();
        // get constructor
        this.serviceConstructor = FastClass.create(this.enhancedServiceClass).getConstructor(SERVICE_CONSTRUCTOR_TYPES);
    }
    // associate the method interceptors with the generated service class on the current thread
    Enhancer.registerCallbacks(this.enhancedServiceClass, this.methodInterceptors);
    Object[] arguments = new Object[] { seiPortNameToFactoryMap, seiClassNameToFactoryMap };
    Object serviceInstance = null;
    try {
        serviceInstance = this.serviceConstructor.newInstance(arguments);
    } catch (InvocationTargetException e) {
        throw (NamingException) new NamingException("Could not construct service instance").initCause(e.getTargetException());
    }
    if (initialize) {
        for (Iterator iterator = seiPortNameToFactoryMap.values().iterator(); iterator.hasNext(); ) {
            SeiFactoryImpl seiFactory = (SeiFactoryImpl) iterator.next();
            try {
                seiFactory.initialize(serviceInstance, classLoader);
            } catch (ClassNotFoundException e) {
                throw (NamingException) new NamingException("Could not load service interface class; " + e.getMessage()).initCause(e);
            }
        }
    }
    return serviceInstance;
}
Also used : Enhancer(net.sf.cglib.proxy.Enhancer) Service(org.apache.axis.client.Service) InvocationTargetException(java.lang.reflect.InvocationTargetException) Callback(net.sf.cglib.proxy.Callback) Iterator(java.util.Iterator) FastClass(net.sf.cglib.reflect.FastClass) NamingException(javax.naming.NamingException)

Example 8 with Callback

use of net.sf.cglib.proxy.Callback in project tomee by apache.

the class SeiFactoryImpl method createServiceEndpoint.

public Remote createServiceEndpoint() throws ServiceException {
    //TODO figure out why this can't be called in readResolve!
    //        synchronized (this) {
    //            if (!initialized) {
    //                initialize();
    //                initialized = true;
    //            }
    //        }
    Service service = ((ServiceImpl) serviceImpl).getService();
    GenericServiceEndpoint serviceEndpoint = new GenericServiceEndpoint(portQName, service, location);
    Callback callback = new ServiceEndpointMethodInterceptor(serviceEndpoint, sortedOperationInfos, credentialsName);
    Callback[] callbacks = new Callback[] { NoOp.INSTANCE, callback };
    Enhancer.registerCallbacks(serviceEndpointClass, callbacks);
    try {
        return (Remote) constructor.newInstance(new Object[] { serviceEndpoint });
    } catch (InvocationTargetException e) {
        throw (ServiceException) new ServiceException("Could not construct service instance", e.getTargetException()).initCause(e);
    }
}
Also used : Callback(net.sf.cglib.proxy.Callback) ServiceException(javax.xml.rpc.ServiceException) Service(org.apache.axis.client.Service) Remote(java.rmi.Remote) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 9 with Callback

use of net.sf.cglib.proxy.Callback in project simplejpa by appoxy.

the class CgLibTests method testToCheckEnhancedMethods.

@Test
public void testToCheckEnhancedMethods() {
    Bean bean = (Bean) BeansCglib.newInstance(Bean.class);
    for (Class<?> aClass : bean.getClass().getInterfaces()) {
        System.out.println("interface=" + aClass);
    }
    for (Method method : bean.getClass().getDeclaredMethods()) {
        System.out.println("method=" + method);
    }
    Factory factory = (Factory) bean;
    for (Callback callback : factory.getCallbacks()) {
        System.out.println("callback=" + callback);
    }
}
Also used : Callback(net.sf.cglib.proxy.Callback) Factory(net.sf.cglib.proxy.Factory) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 10 with Callback

use of net.sf.cglib.proxy.Callback in project roboguice by roboguice.

the class ProxyFactory method create.

public ConstructionProxy<T> create() throws ErrorsException {
    if (interceptors.isEmpty()) {
        return new DefaultConstructionProxyFactory<T>(injectionPoint).create();
    }
    @SuppressWarnings("unchecked") Class<? extends Callback>[] callbackTypes = new Class[callbacks.length];
    for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] == net.sf.cglib.proxy.NoOp.INSTANCE) {
            callbackTypes[i] = net.sf.cglib.proxy.NoOp.class;
        } else {
            callbackTypes[i] = net.sf.cglib.proxy.MethodInterceptor.class;
        }
    }
    // to this injector. Otherwise, the proxies for each injector will waste PermGen memory
    try {
        Enhancer enhancer = BytecodeGen.newEnhancer(declaringClass, visibility);
        enhancer.setCallbackFilter(new IndicesCallbackFilter(methods));
        enhancer.setCallbackTypes(callbackTypes);
        return new ProxyConstructor<T>(enhancer, injectionPoint, callbacks, interceptors);
    } catch (Throwable e) {
        throw new Errors().errorEnhancingClass(declaringClass, e).toException();
    }
}
Also used : Enhancer(net.sf.cglib.proxy.Enhancer) InjectionPoint(com.google.inject.spi.InjectionPoint) Callback(net.sf.cglib.proxy.Callback) BytecodeGen.newFastClass(com.google.inject.internal.BytecodeGen.newFastClass) FastClass(net.sf.cglib.reflect.FastClass)

Aggregations

Callback (net.sf.cglib.proxy.Callback)10 Enhancer (net.sf.cglib.proxy.Enhancer)6 FastClass (net.sf.cglib.reflect.FastClass)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 InjectionPoint (com.google.inject.spi.InjectionPoint)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 SQLException (java.sql.SQLException)2 ConfigurationException (javax.naming.ConfigurationException)2 EntityExistsException (javax.persistence.EntityExistsException)2 UndeclaredThrowableStrategy (net.sf.cglib.transform.impl.UndeclaredThrowableStrategy)2 Element (net.sf.ehcache.Element)2 Service (org.apache.axis.client.Service)2 BytecodeGen.newFastClass (com.google.inject.internal.BytecodeGen.newFastClass)1 Method (java.lang.reflect.Method)1 Remote (java.rmi.Remote)1 Iterator (java.util.Iterator)1