List of usage examples for java.lang.reflect Proxy newProxyInstance
private static Object newProxyInstance(Class<?> caller, Constructor<?> cons, InvocationHandler h)
From source file:org.bytesoft.openjtcc.supports.spring.NativeBeanFactoryImpl.java
@SuppressWarnings("unchecked") public <T> T getBean(Class<T> interfaceClass, String beanId) { Object beanInst = this.applicationContext.getBean(beanId); if (interfaceClass.isInstance(beanInst) // && Compensable.class.isInstance(beanInst)// ) {//from w w w . j a v a 2 s .c o m if (this.transactionManager == null) { throw new RuntimeException(); } try { if (this.transactionManager.getTransaction() != null) { throw new RuntimeException(); } } catch (SystemException ex) { throw new RuntimeException(ex); } NativeCompensableProxy<Serializable> proxy = new NativeCompensableProxy<Serializable>(); proxy.setBeanName(beanId); proxy.setTarget((Compensable<Serializable>) beanInst); proxy.setProxyId(atomic.incrementAndGet()); proxy.setTransactionManager(this.transactionManager); ClassLoader classLoader = beanInst.getClass().getClassLoader(); Class<?>[] interfaces = null; if (Compensable.class.equals(interfaceClass)) { interfaces = new Class[] { interfaceClass }; } else { interfaces = new Class[] { interfaceClass, Compensable.class }; } Object proxyInst = Proxy.newProxyInstance(classLoader, interfaces, proxy); proxy.setFacade((Compensable<Serializable>) proxyInst); return interfaceClass.cast(proxyInst); } throw new RuntimeException(); }
From source file:org.apache.olingo.ext.proxy.commons.EntityCollectionInvocationHandler.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()) || "refs".equals(method.getName()) || "execute".equals(method.getName())) { invokeSelfMethod(method, args);//from www. ja va 2 s .com 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.zanata.page.DswidParamChecker.java
/** * Creates a listener for the specified driver, but does not register it. See getEventListener(). * @param driver// w w w . jav a2s.c o m */ public DswidParamChecker(EventFiringWebDriver driver) { this.driver = driver; this.urlListener = (WebDriverEventListener) Proxy.newProxyInstance(DswidParamChecker.class.getClassLoader(), new Class<?>[] { WebDriverEventListener.class }, this::invoke); }
From source file:de.xwic.appkit.core.model.EntityModelFactory.java
/** * Creates a new entity model based upon the specified entity. * @param entity//w w w. j av a 2 s . c om * @return * @throws EntityModelException */ @SuppressWarnings("unchecked") public static IEntityModel createModel(IEntity entity) { // create model and InvocationHandler Set<Class<?>> interfacesSet = new HashSet<Class<?>>(); Class<? extends IEntity> clazz = entity.getClass(); interfacesSet.add(IEntityModel.class); // recursivly add all interfaces Class<?> c = clazz; while (c != null) { Class<?>[] orgInterfaces = c.getInterfaces(); for (int i = 0; i < orgInterfaces.length; i++) { interfacesSet.add(orgInterfaces[i]); } c = c.getSuperclass(); } Class[] interfaces = new Class[interfacesSet.size()]; int idx = 0; for (Iterator<Class<?>> it = interfacesSet.iterator(); it.hasNext();) { interfaces[idx++] = it.next(); } EntityModelInvocationHandler ih = new EntityModelInvocationHandler(entity); return (IEntityModel) Proxy.newProxyInstance(classLoader, interfaces, ih); }
From source file:net.sourceforge.pmd.lang.plsql.AbstractPLSQLParserTst.java
public <E> Set<E> getNodes(LanguageVersion languageVersion, Class<E> clazz, String plsqlCode) { Collector<E> coll = new Collector<>(clazz); LanguageVersionHandler languageVersionHandler = languageVersion.getLanguageVersionHandler(); ASTInput cu = (ASTInput) languageVersionHandler.getParser(languageVersionHandler.getDefaultParserOptions()) .parse(null, new StringReader(plsqlCode)); PLSQLParserVisitor jpv = (PLSQLParserVisitor) Proxy.newProxyInstance( PLSQLParserVisitor.class.getClassLoader(), new Class[] { PLSQLParserVisitor.class }, coll); jpv.visit(cu, null);//www . j ava 2 s . com return (Set<E>) coll.getCollection(); }
From source file:com.mirth.connect.connectors.jms.xa.ConnectionFactoryWrapper.java
public Connection createConnection(String username, String password) throws JMSException { XAConnection xac = ((XAConnectionFactory) factory).createXAConnection(username, password); Connection proxy = (Connection) Proxy.newProxyInstance(Connection.class.getClassLoader(), new Class[] { Connection.class }, new ConnectionInvocationHandler(xac)); return proxy; }
From source file:de.javakaffee.kryoserializers.TestClasses.java
static SomeInterface createProxy() { return (SomeInterface) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { SomeInterface.class, Serializable.class }, new MyInvocationHandler(SomeInterfaceImpl.class)); }
From source file:net.sf.jasperreports.export.PropertiesDefaultsConfigurationFactory.java
/** * /*w ww . ja 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 proxy = (C) Proxy.newProxyInstance(ExporterConfiguration.class.getClassLoader(), allInterfaces.toArray(new Class<?>[allInterfaces.size()]), handler); return proxy; }
From source file:org.apache.hadoop.metrics.spi.CompositeContext.java
@InterfaceAudience.Private @Override//from w w w . j av a2 s . c om public MetricsRecord newRecord(String recordName) { return (MetricsRecord) Proxy.newProxyInstance(MetricsRecord.class.getClassLoader(), new Class[] { MetricsRecord.class }, new MetricsRecordDelegator(recordName, subctxt)); }
From source file:com.tc.management.JMXConnectorProxy.java
private JMXConnector getConnectorProxy() { JMXConnector connector = (JMXConnector) Proxy.newProxyInstance(JMXConnector.class.getClassLoader(), new Class[] { JMXConnector.class }, new ConnectorInvocationHandler()); return connector; }