List of usage examples for java.lang.reflect Proxy newProxyInstance
private static Object newProxyInstance(Class<?> caller, Constructor<?> cons, InvocationHandler h)
From source file:com.mirth.connect.connectors.jms.xa.ConnectionFactoryWrapper.java
public QueueConnection createQueueConnection() throws JMSException { XAQueueConnection xaqc = ((XAQueueConnectionFactory) factory).createXAQueueConnection(); QueueConnection proxy = (QueueConnection) Proxy.newProxyInstance(Connection.class.getClassLoader(), new Class[] { QueueConnection.class }, new ConnectionInvocationHandler(xaqc)); return proxy; }
From source file:com.netflix.bluespar.amazon.security.AmazonClientProvider.java
public AmazonEC2 getAmazonEC2(AmazonCredentials amazonCredentials, String region) { AmazonEC2Client client = new AmazonEC2Client(amazonCredentials.getCredentials()); if (edda == null || edda.length() == 0) { return client; } else {/*ww w .j a v a2s . c om*/ return (AmazonEC2) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { AmazonEC2.class }, getInvocationHandler(client, region, amazonCredentials)); } }
From source file:org.apache.olingo.ext.proxy.commons.ComplexCollectionInvocationHandler.java
@Override public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { if ("filter".equals(method.getName()) || "orderBy".equals(method.getName()) || "top".equals(method.getName()) || "skip".equals(method.getName()) || "expand".equals(method.getName()) || "select".equals(method.getName()) || "nextPage".equals(method.getName()) || "execute".equals(method.getName())) { invokeSelfMethod(method, args);// w w w . j av a 2 s . c o m return proxy; } else if (isSelfMethod(method)) { return invokeSelfMethod(method, args); } else if ("operations".equals(method.getName()) && ArrayUtils.isEmpty(args)) { final Class<?> returnType = method.getReturnType(); return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { returnType }, OperationInvocationHandler.getInstance(this)); } else { throw new NoSuchMethodException(method.getName()); } }
From source file:org.mybatis.spring.asyncsynchronization.AsyncAfterCompletionHelper.java
/** * Creates proxy that performs afterCompletion call on a separate thread * /*w w w . j a v a 2s . c om*/ * @param synchronization * @return */ public TransactionSynchronization createSynchronizationWithAsyncAfterComplete( TransactionSynchronization synchronization) { if (Proxy.isProxyClass(synchronization.getClass()) && Proxy.getInvocationHandler(synchronization) instanceof AsynchAfterCompletionInvocationHandler) { // avoiding double wrapping just in case return synchronization; } Class<?>[] interfaces = { TransactionSynchronization.class }; return (TransactionSynchronization) Proxy.newProxyInstance(synchronization.getClass().getClassLoader(), interfaces, new AsynchAfterCompletionInvocationHandler(synchronization)); }
From source file:org.apache.hadoop.yarn.client.RequestHedgingRMFailoverProxyProvider.java
@Override @SuppressWarnings("unchecked") public void init(Configuration configuration, RMProxy<T> rmProxy, Class<T> protocol) { super.init(configuration, rmProxy, protocol); Map<String, ProxyInfo<T>> retriableProxies = new HashMap<>(); String originalId = HAUtil.getRMHAId(conf); for (String rmId : rmServiceIds) { conf.set(YarnConfiguration.RM_HA_ID, rmId); nonRetriableProxy.put(rmId, super.getProxyInternal()); T proxy = createRetriableProxy(); ProxyInfo<T> pInfo = new ProxyInfo<T>(proxy, rmId); retriableProxies.put(rmId, pInfo); }/* w w w .j a v a2s. co m*/ conf.set(YarnConfiguration.RM_HA_ID, originalId); T proxyInstance = (T) Proxy.newProxyInstance(RMRequestHedgingInvocationHandler.class.getClassLoader(), new Class<?>[] { protocol }, new RMRequestHedgingInvocationHandler(retriableProxies)); String combinedInfo = Arrays.toString(rmServiceIds); wrappedProxy = new ProxyInfo<T>(proxyInstance, combinedInfo); LOG.info("Created wrapped proxy for " + combinedInfo); }
From source file:org.zenoss.zep.dao.impl.EventTriggerSubscriptionDaoImpl.java
public EventTriggerSubscriptionDaoImpl(DataSource dataSource) { this.template = (SimpleJdbcOperations) Proxy.newProxyInstance(SimpleJdbcOperations.class.getClassLoader(), new Class<?>[] { SimpleJdbcOperations.class }, new SimpleJdbcTemplateProxy(dataSource)); this.insert = new SimpleJdbcInsert(dataSource).withTableName(TABLE_EVENT_TRIGGER_SUBSCRIPTION); }
From source file:net.sf.jasperreports.export.CompositeExporterConfigurationFactory.java
/** * // w ww. j a v a 2 s. c o m */ private final C getProxy(Class<?> clazz, InvocationHandler handler) { List<Class<?>> allInterfaces = new ArrayList<Class<?>>(); if (clazz.isInterface()) { allInterfaces.add(clazz); } else { @SuppressWarnings("unchecked") List<Class<?>> lcInterfaces = ClassUtils.getAllInterfaces(clazz); allInterfaces.addAll(lcInterfaces); } @SuppressWarnings("unchecked") C composite = (C) Proxy.newProxyInstance(ExporterConfiguration.class.getClassLoader(), allInterfaces.toArray(new Class<?>[allInterfaces.size()]), handler); return composite; }
From source file:com.amazonaws.hal.client.HalJsonResourceUnmarshallerTest.java
@Test public void testEmbedded() throws Exception { HalResource halResource = parseHalResourceFromClasspath("blog.resource"); Assert.assertNotNull(halResource);// ww w. j av a2 s .c o m Assert.assertNotNull(halResource.getEmbedded()); Assert.assertNotNull(halResource.getEmbedded().get("/people/alan-watts")); BlogPost proxy = (BlogPost) Proxy.newProxyInstance(BlogPost.class.getClassLoader(), new Class<?>[] { BlogPost.class }, new HalResourceInvocationHandler(halResource, halResource._getSelfHref(), null)); Assert.assertEquals("123", proxy.getId()); Assert.assertNotNull(proxy.getComments()); Assert.assertEquals(3, proxy.getComments().size()); Assert.assertEquals("Roger", proxy.getComments().get(1).getAuthor()); }
From source file:org.jboss.seam.spring.factorybean.TypeSafeCdiBeanLookup.java
@Override public T lookupBean(BeanManager beanManager) { try {/*from w ww. j a v a2 s . c o m*/ List<Annotation> qualifierAnnotations = new ArrayList<Annotation>(); for (Qualifier qualifier : qualifiers) { Class<? extends Annotation> qualifierClass = (Class<Annotation>) ClassUtils.getDefaultClassLoader() .loadClass(qualifier.getClassName()); if (!beanManager.isQualifier(qualifierClass)) { throw new BeanCreationException(qualifierClass + " is not a valid JSR-299 qualifier"); } AnnotationInvocationHandler annotationInvocationHandler = new AnnotationInvocationHandler( qualifierClass).withConversionService(conversionService) .withAttributes(qualifier.getAttributes()); qualifierAnnotations.add((Annotation) Proxy.newProxyInstance(ClassUtils.getDefaultClassLoader(), new Class[] { qualifierClass }, annotationInvocationHandler)); } Bean<?> resolvedBean = beanManager .resolve(beanManager.getBeans(expectedType, qualifierAnnotations.toArray(new Annotation[] {}))); Assert.notNull(resolvedBean, "Cannot find a CDI bean"); return (T) beanManager.getReference(resolvedBean, expectedType, beanManager.createCreationalContext(resolvedBean)); } catch (Exception e) { throw new BeanCreationException("Cannot look up bean: ", e); } }
From source file:org.zenoss.zep.dao.impl.EventSignalSpoolDaoImpl.java
public EventSignalSpoolDaoImpl(DataSource dataSource) { this.template = (SimpleJdbcOperations) Proxy.newProxyInstance(SimpleJdbcOperations.class.getClassLoader(), new Class<?>[] { SimpleJdbcOperations.class }, new SimpleJdbcTemplateProxy(dataSource)); }