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;
}
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;
}
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);
}
}
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);
}
}
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();
}
}
Aggregations