List of usage examples for java.lang.reflect Proxy newProxyInstance
private static Object newProxyInstance(Class<?> caller, Constructor<?> cons, InvocationHandler h)
From source file:org.zenoss.zep.dao.impl.EventTriggerDaoImpl.java
public EventTriggerDaoImpl(DataSource dataSource) { this.template = (SimpleJdbcOperations) Proxy.newProxyInstance(SimpleJdbcOperations.class.getClassLoader(), new Class<?>[] { SimpleJdbcOperations.class }, new SimpleJdbcTemplateProxy(dataSource)); }
From source file:org.romaz.spring.scripting.ext.rhino.RhinoScriptFactoryUtils.java
/** * Creates a proxy for the script, implementing all requested interfaces. * /*from w ww .ja v a 2 s . co m*/ * @param ctx * @param scope * @param result * @param interfacesToImplement * @param converter * @return */ public static Object createScriptProxy(Context ctx, Scriptable scope, Object result, Class[] interfacesToImplement, RhinoObjectConverter converter) { if (!(result instanceof Scriptable)) { throw new ScriptCompilationException( "Script execution result must be an instance of Scriptable, it was [" + result.getClass() + "]"); } final Scriptable delegate = (Scriptable) result; return Proxy.newProxyInstance(ClassUtils.getDefaultClassLoader(), interfacesToImplement, new JsObjectMethodInvocationHandler(delegate, scope, converter)); }
From source file:org.eclipse.wb.internal.rcp.model.rcp.PageInfo.java
@Override protected void applyActionBars() throws Exception { ClassLoader editorLoader = JavaInfoUtils.getClassLoader(this); Class<?> pageSiteClass = editorLoader.loadClass("org.eclipse.ui.part.IPageSite"); // create IPageSite final Object pageSite = Proxy.newProxyInstance(editorLoader, new Class<?>[] { pageSiteClass }, new InvocationHandler() { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String signature = ReflectionUtils.getMethodSignature(method); if (signature.equals("getActionBars()")) { return m_actionBars; }/*from ww w. ja v a2s. c o m*/ if (signature .equals("setSelectionProvider(org.eclipse.jface.viewers.ISelectionProvider)")) { return null; } throw new NotImplementedException(); } }); // call init(IPageSite) ReflectionUtils.invokeMethod(getObject(), "init(org.eclipse.ui.part.IPageSite)", pageSite); }
From source file:com.sourcesense.alfresco.opensso.MockAlfrescoApplicationContext.java
@Override public Object getBean(String name) throws BeansException { try {/*from ww w .ja va2s . co m*/ Class clazz = beans.get(name); Object newProxyInstance = Proxy.newProxyInstance(getClassLoader(), new Class[] { clazz }, new InvocationHandler() { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { return null; } }); return newProxyInstance; } catch (IllegalArgumentException e) { e.printStackTrace(); } return null; }
From source file:com.guang.eunormia.group.EunormiaCluster.java
@Override public void init() { if (!inited) { try {/*w w w.j a v a2s.co m*/ if (this.cm == null) { ZookeeperConfigManager zcm = new ZookeeperConfigManager(appName, version); zcm.setZkAddress(zkAddress); zcm.init(); this.cm = zcm; } node = (RedisCommands) Proxy.newProxyInstance(RedisCommands.class.getClassLoader(), new Class[] { RedisCommands.class }, new RedisGroupInvocationHandler()); } catch (Exception e) { throw new EunormiaException("init failed", e); } inited = true; } }
From source file:com.alibaba.wasp.monitoring.TaskMonitor.java
public synchronized MonitoredTask createStatus(String description) { MonitoredTask stat = new MonitoredTaskImpl(); stat.setDescription(description);/*from ww w . j a v a2s . co m*/ MonitoredTask proxy = (MonitoredTask) Proxy.newProxyInstance(stat.getClass().getClassLoader(), new Class<?>[] { MonitoredTask.class }, new PassthroughInvocationHandler<MonitoredTask>(stat)); TaskAndWeakRefPair pair = new TaskAndWeakRefPair(stat, proxy); synchronized (this) { tasks.add(pair); } return proxy; }
From source file:org.psikeds.common.config.ServletContextProxy.java
private static Object createProxy(final ServletContext ctx) { // Get runtime class of CTX which is something that implements // ServletContext final Class<? extends ServletContext> clazz = ctx.getClass(); // Get the Classloader for that runtime class final ClassLoader loader = getClassloader(clazz); // Create a new Proxy for that Class using our ServletContextProxy return Proxy.newProxyInstance(loader, clazz.getInterfaces(), new ServletContextProxy(ctx)); }
From source file:com.laxser.blitz.lama.core.LamaDaoFactoryBean.java
@SuppressWarnings("unchecked") protected T createDAO(Class<T> daoClass) { Definition definition = new Definition(daoClass); DataAccess dataAccess = dataAccessProvider.createDataAccess(daoClass); LamaDaoInvocationHandler handler = new LamaDaoInvocationHandler(dataAccess, definition); return (T) Proxy.newProxyInstance(ClassUtils.getDefaultClassLoader(), new Class[] { daoClass }, handler); }
From source file:org.bytesoft.bytejta.supports.springcloud.SpringCloudBeanRegistry.java
public RemoteCoordinator getConsumeCoordinator(String identifier) { RemoteCoordinatorRegistry registry = RemoteCoordinatorRegistry.getInstance(); if (StringUtils.isBlank(identifier)) { return null; }/*from ww w.j av a 2 s.c o m*/ RemoteCoordinator coordinator = registry.getTransactionManagerStub(identifier); if (coordinator != null) { return coordinator; } SpringCloudCoordinator handler = new SpringCloudCoordinator(); handler.setIdentifier(identifier); coordinator = (RemoteCoordinator) Proxy.newProxyInstance(SpringCloudCoordinator.class.getClassLoader(), new Class[] { RemoteCoordinator.class }, handler); registry.putTransactionManagerStub(identifier, coordinator); return coordinator; }
From source file:com.nineteendrops.tracdrops.client.core.TracInvocationObjectFactoryImpl.java
public Object newInstance(ClassLoader classLoader, final Class aClass, final String remoteName) { return Proxy.newProxyInstance(classLoader, new Class[] { aClass }, new InvocationHandler() { public Object invoke(Object pProxy, Method pMethod, Object[] pArgs) throws Throwable { String tracClassName = Utils.findTracClassName(aClass); if (tracClassName == null) { throw new TracException( MessageUtils.registerErrorLog(log, "core.no.trac.classname.found", aClass.getName())); }//w w w . j a va2 s . c o m TracClassMethod tracClassMethodMetadata = Utils.getTracClassMethodAnnotation(pMethod); String methodName = Utils.buildTracMethodNameInvocation(tracClassName, tracClassMethodMetadata); Object result = null; try { result = getClient().execute(methodName, pArgs); } catch (XmlRpcInvocationException e) { throw new TracException(MessageUtils.registerErrorLog(log, "core.invocation.factory.invocation.exception", e.getMessage()), e); } catch (XmlRpcException e) { throw new TracException(MessageUtils.registerErrorLog(log, "core.invocation.factory.xmlrpc.exception", e.getMessage()), e); } catch (Throwable e) { throw new TracException(MessageUtils.registerErrorLog(log, "core.invocation.factory.unknown.exception", e.getMessage()), e); } Class returnType = tracClassMethodMetadata.tracReturnType(); if (returnType == Object.class) { returnType = pMethod.getReturnType(); } TypeConverter typeConverter = typeConverterFactory.getTypeConverter(returnType); return typeConverter.convert(result); } }); }