List of usage examples for java.lang.reflect Proxy newProxyInstance
private static Object newProxyInstance(Class<?> caller, Constructor<?> cons, InvocationHandler h)
From source file:net.sf.morph.reflect.reflectors.BaseReflector.java
/** * Implementation of {@link Reflector#getWrapper(Object)}. *///from w ww . ja v a 2 s. c o m protected Wrapper getWrapperImpl(Object object) throws Exception { WrapperInvocationHandler invocationHandler = createWrapperInvocationHandler(object); return (Wrapper) Proxy.newProxyInstance(object.getClass().getClassLoader(), invocationHandler.getInterfaces(object), invocationHandler); }
From source file:org.apache.olingo.ext.proxy.commons.EntityContainerInvocationHandler.java
@SuppressWarnings("unchecked") public <T extends EntityType<?>, NEC extends EntityCollection<T, ?, ?>> NEC newEntityCollection( final Class<NEC> ref) { return (NEC) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { ref }, new EntityCollectionInvocationHandler<T>(getService(), ref)); }
From source file:org.kuali.rice.kew.rule.web.WebRuleResponsibility.java
private void injectWebMembers() throws Exception { DelegationRulesProxy delegationRulesProxy = new DelegationRulesProxy(getDelegationRules()); Class delegationRulesClass = getDelegationRules().getClass(); //System.err.println("delegation rules class: "+ delegationRulesClass); Class[] delegationRulesInterfaces = new Class[0]; // = delegationRulesClass.getInterfaces(); List<Class> delegationRulesInterfaceList = (List<Class>) ClassUtils.getAllInterfaces(delegationRulesClass); delegationRulesInterfaces = delegationRulesInterfaceList.toArray(delegationRulesInterfaces); ClassLoader delegationRulesClassLoader = getDelegationRules().getClass().getClassLoader(); Object o = Proxy.newProxyInstance(delegationRulesClassLoader, delegationRulesInterfaces, delegationRulesProxy);/*from w ww.ja v a 2s. c om*/ //setDelegationRules((List) o); if (Integer.parseInt(CoreFrameworkServiceLocator.getParameterService().getParameterValueAsString( KewApiConstants.KEW_NAMESPACE, KRADConstants.DetailTypes.RULE_DETAIL_TYPE, KewApiConstants.RULE_DELEGATE_LIMIT)) > getDelegationRules().size() || showDelegations) { for (Iterator iterator = getDelegationRules().iterator(); iterator.hasNext();) { RuleDelegationBo ruleDelegation = (RuleDelegationBo) iterator.next(); WebRuleBaseValues webRule = new WebRuleBaseValues(); webRule.load(ruleDelegation.getDelegationRule()); webRule.edit(ruleDelegation.getDelegationRule()); ruleDelegation.setDelegationRule(webRule); } } }
From source file:com.msopentech.odatajclient.proxy.api.impl.EntitySetInvocationHandler.java
@SuppressWarnings("unchecked") private <NE> NE newEntity(final Class<NE> reference) { final ODataEntity entity = client.getObjectFactory() .newEntity(containerHandler.getSchemaName() + "." + ClassUtils.getEntityTypeName(reference)); final EntityTypeInvocationHandler handler = EntityTypeInvocationHandler.getInstance(entity, containerHandler.getEntityContainerName(), entitySetName, reference, containerHandler); EntityContainerFactory.getContext().entityContext().attachNew(handler); return (NE) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { reference }, handler); }
From source file:com.infinities.skyport.timeout.ServiceProviderTimeLimiter.java
private static <T> T newProxy(Class<T> interfaceType, InvocationHandler handler) { Object object = Proxy.newProxyInstance(interfaceType.getClassLoader(), new Class<?>[] { interfaceType }, handler);// w ww .j a v a 2 s. co m return interfaceType.cast(object); }
From source file:org.cfr.capsicum.datasource.TransactionAwareDataSourceProxy.java
/** * Wraps the given Connection with a proxy that delegates every method call to it * but delegates <code>close()</code> calls to DataSourceUtils. * @param targetDataSource DataSource that the Connection came from * @return the wrapped Connection//from w w w. j a va 2s . c o m * @see java.sql.Connection#close() * @see DataSourceUtils#doReleaseConnection */ protected Connection getTransactionAwareConnectionProxy(DataSource targetDataSource) { return (Connection) Proxy.newProxyInstance(ConnectionProxy.class.getClassLoader(), new Class[] { ConnectionProxy.class }, new TransactionAwareInvocationHandler(targetDataSource)); }
From source file:apple.dts.samplecode.osxadapter.OSXAdapter.java
public static void setHandler(OSXAdapter adapter) { try {/*ww w. ja v a 2 s .c om*/ Class<?> applicationClass = Class.forName("com.apple.eawt.Application"); if (macOSXApplication == null) { macOSXApplication = applicationClass.getConstructor((Class<?>[]) null).newInstance((Object[]) null); } Class<?> applicationListenerClass = Class.forName("com.apple.eawt.ApplicationListener"); Method addListenerMethod = applicationClass.getDeclaredMethod("addApplicationListener", new Class<?>[] { applicationListenerClass }); // Create a proxy object around this handler that can be reflectively added as an Apple ApplicationListener Object osxAdapterProxy = Proxy.newProxyInstance(OSXAdapter.class.getClassLoader(), new Class<?>[] { applicationListenerClass }, adapter); addListenerMethod.invoke(macOSXApplication, new Object[] { osxAdapterProxy }); } catch (ClassNotFoundException cnfe) { System.err.println( "This version of Mac OS X does not support the Apple EAWT. ApplicationEvent handling has been disabled (" + cnfe + ")"); } catch (Exception ex) { // Likely a NoSuchMethodException or an IllegalAccessException loading/invoking eawt.Application methods log.error("Mac OS X Adapter could not talk to EAWT:", ex); } }
From source file:org.apache.olingo.ext.proxy.commons.EntityContainerInvocationHandler.java
@SuppressWarnings("unchecked") public <NE extends ComplexType<?>> NE newComplexInstance(final Class<NE> ref) { return (NE) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { ref }, ComplexInvocationHandler.getInstance(ref, getService())); }
From source file:org.apache.lucene.gdata.storage.db4o.DB4oController.java
/** * @see org.apache.lucene.gdata.server.registry.ServerComponent#initialize() *///w w w. ja va2 s . com public void initialize() { if (LOG.isInfoEnabled()) LOG.info("Initialize " + this.toString()); Db4o.configure().objectClass(DB4oEntry.class).objectField("updated").indexed(true); Db4o.configure().objectClass(BaseEntry.class).objectField("id").indexed(true); Db4o.configure().objectClass(BaseFeed.class).objectField("id").indexed(true); Db4o.configure().objectClass(GDataAccount.class).objectField("name").indexed(true); Db4o.configure().objectClass(ServerBaseFeed.class).cascadeOnDelete(false); Db4o.configure().objectClass(ServerBaseFeed.class).maximumActivationDepth(0); Db4o.configure().objectClass(BaseFeed.class).minimumActivationDepth(1); Db4o.configure().objectClass(BaseEntry.class).minimumActivationDepth(1); Db4o.configure().objectClass(BaseFeed.class).cascadeOnDelete(true); Db4o.configure().objectClass(DB4oEntry.class).cascadeOnDelete(true); Db4o.configure().objectClass(GDataAccount.class).cascadeOnDelete(true); Db4o.configure().weakReferences(this.weakReferences); Db4o.configure().optimizeNativeQueries(false); if (this.runAsServer) { this.server = Db4o.openServer(this.filePath, this.port); if (this.server == null) throw new RuntimeException("Can't create server at confiugred destination -- " + this.filePath); this.server.grantAccess(this.user, this.password); } else { InvocationHandler handler = new ObjectServerDecorator(this.user, this.password, this.host, this.port); this.server = (ObjectServer) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[] { ObjectServer.class }, handler); } PoolObjectFactory<ObjectContainer> factory = new ObjectContinerFactory(this.server); this.containerPool = new SimpleObjectPool<ObjectContainer>(this.containerPoolSize, factory); try { createAdminAccount(); } catch (StorageException e) { LOG.error("Can not create admin account -- ", e); } }
From source file:com.msopentech.odatajclient.proxy.api.impl.EntitySetInvocationHandler.java
@SuppressWarnings("unchecked") private <NEC> NEC newEntityCollection(final Class<NEC> reference) { return (NEC) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { reference }, new EntityCollectionInvocationHandler<T>(containerHandler, new ArrayList<T>(), typeRef, containerHandler.getEntityContainerName())); }