List of usage examples for org.springframework.aop.framework ProxyFactory setTarget
public void setTarget(Object target)
From source file:org.LexGrid.LexBIG.caCore.client.proxy.LexEVSProxyHelperImpl.java
@Override protected Object convertObjectToProxy(ApplicationService as, Object obj) { if (null == obj) return null; //Check to see if the returned object is an EVSRemoteExecutionResults. //If so, unwrap it and update the proxy target if (obj instanceof RemoteExecutionResults) { RemoteExecutionResults results = (RemoteExecutionResults) obj; //if the returned results are null, return null if (results.getReturnValue() == null) return null; //Get the current proxy target and update it with the retuned value //from the server Advised advised = (Advised) AopContext.currentProxy(); advised.setTargetSource(new SingletonTargetSource(results.getObj())); obj = results.getReturnValue();//from w ww . j a v a 2s. c o m } if (obj instanceof RemoteShell) { Class<?>[] targetInterfaces = ((RemoteShell) obj).getTargetInterfaces(); Class<?> targetClass = ((RemoteShell) obj).getTargetClass(); ProxyFactory pf = new ProxyFactory(targetInterfaces); pf.addAdvice(new LexEVSBeanProxy(as, this)); pf.setProxyTargetClass(true); pf.setTargetClass(targetClass); pf.setTarget(obj); return pf.getProxy(); } if (obj instanceof Integer || obj instanceof Float || obj instanceof Double || obj instanceof Character || obj instanceof Long || obj instanceof Boolean || obj instanceof String || obj instanceof Date || obj instanceof LexEVSBeanProxy || obj instanceof BeanProxy) return obj; if (!LexEVSCaCoreUtils.isLexBigClass(obj.getClass())) { return obj; } // Don't proxy client-safe LexBig objects if (isClientSafe(obj.getClass())) { return obj; } else { return LexEVSCaCoreUtils.createProxy(obj, as, this); } }
From source file:com.sinosoft.one.data.jpa.repository.support.OneRepositoryFactorySupport.java
/** * Returns a repository instance for the given interface backed by an instance providing implementation logic for * custom logic./* w ww. j a v a2 s.co m*/ * * @param <T> * @param repositoryInterface * @param customImplementation * @return */ @SuppressWarnings({ "unchecked" }) public <T> T getRepository(Class<T> repositoryInterface, Object customImplementation) { RepositoryMetadata metadata = getRepositoryMetadata(repositoryInterface); Class<?> customImplementationClass = null == customImplementation ? null : customImplementation.getClass(); RepositoryInformation information = getRepositoryInformation(metadata, customImplementationClass); validate(information, customImplementation); Object target = getTargetRepository(information); // Create proxy ProxyFactory result = new ProxyFactory(); result.setTarget(target); result.setInterfaces(new Class[] { repositoryInterface, Repository.class }); for (RepositoryProxyPostProcessor processor : postProcessors) { processor.postProcess(result); } result.addAdvice(new OneQueryExecutorMethodInterceptor(information, customImplementation, target)); return (T) result.getProxy(); }
From source file:org.synyx.hades.dao.orm.GenericDaoFactory.java
/** * Returns a DAO instance for the given interface backed by an instance * providing implementation logic for custom logic. * //from w w w .j av a 2 s . c om * @param <T> * @param daoInterface * @param customDaoImplementation * @return */ @SuppressWarnings("unchecked") public <T extends GenericDao<?, ?>> T getDao(Class<T> daoInterface, Object customDaoImplementation) { validate(daoInterface, customDaoImplementation); try { // Instantiate generic dao @SuppressWarnings("rawtypes") GenericDaoSupport genericJpaDao = getDaoClass().newInstance(); genericJpaDao.setEntityManager(entityManager); genericJpaDao.setDomainClass(ClassUtils.getDomainClass(daoInterface)); genericJpaDao.validate(); // Create proxy ProxyFactory result = new ProxyFactory(); result.setTarget(genericJpaDao); result.setInterfaces(new Class[] { daoInterface }); for (DaoProxyPostProcessor processor : postProcessors) { processor.postProcess(result); } result.addAdvice( new QueryExecuterMethodInterceptor(daoInterface, customDaoImplementation, genericJpaDao)); return (T) result.getProxy(); } catch (InstantiationException e) { throw new IllegalStateException(e); } catch (IllegalAccessException e) { throw new IllegalStateException(e); } }
From source file:org.nabucco.alfresco.enhScriptEnv.common.script.converter.rhino.ScriptableFacadeMapConverter.java
/** * {@inheritDoc}//from ww w.j a v a2s . c o m */ @Override public Object convertValueForScript(final Object value, final ValueConverter globalDelegate, final Class<?> expectedClass) { if (!(value instanceof Map<?, ?>)) { throw new IllegalArgumentException("value must be a Map"); } final Object result; final ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.addAdvice(new AdapterObjectInterceptor()); proxyFactory.addAdvice(new ScriptableBaseAdapterInterceptor()); proxyFactory.addAdvice(new ScriptableListLikeMapAdapterInterceptor()); proxyFactory.addAdvice(new ScriptableMapListAdapterInterceptor()); proxyFactory.addAdvice(new MapLengthFacadeInterceptor(Undefined.instance, false)); // proxyFactory.addAdvice(new ListLikeMapAdapterInterceptor()); // some existing scripts in Alfresco expect Map-contained strings not to be converted proxyFactory.addAdvice(new ValueConvertingMapInterceptor(globalDelegate, true)); // this somehow worked in Java 8 Nashorn PoC, but return types of remove(Object) differ between Map and List // proxyFactory.setInterfaces(ClassUtils.collectInterfaces(value, Arrays.<Class<?>> asList(Scriptable.class, List.class, AdapterObject.class))); proxyFactory.setInterfaces(ClassUtils.collectInterfaces(value, Arrays.<Class<?>>asList(Scriptable.class, AdapterObject.class))); proxyFactory.setTarget(value); result = proxyFactory.getProxy(); return result; }
From source file:ome.services.blitz.impl.AbstractAmdServant.java
/** * Applies the hard-wired intercepting to this instance. It is not possible * to configure hard-wired interceptors in Spring, instead they must be * passed in at runtime from a properly compiled class. *///from www .ja va 2 s .c o m public final void applyHardWiredInterceptors(List<HardWiredInterceptor> cptors, AopContextInitializer initializer) { if (service != null) { ProxyFactory wiredService = new ProxyFactory(); wiredService.setInterfaces(service.getClass().getInterfaces()); wiredService.setTarget(service); List<HardWiredInterceptor> reversed = new ArrayList<HardWiredInterceptor>(cptors); Collections.reverse(reversed); for (HardWiredInterceptor hwi : reversed) { wiredService.addAdvice(0, hwi); } wiredService.addAdvice(0, initializer); service = (ServiceInterface) wiredService.getProxy(); } }
From source file:org.impalaframework.service.proxy.ProxyHelper.java
/** * Possibly wraps bean with proxy. Based on following rules: * <ul>//w ww. j av a2 s . com * <li>if proxyEntries is false, then does not wrap * <li>if the bean does not implement any interface, then does not wrap * <li>if proxyInterfaces is not empty, but bean does not implement any of the specified interface, then does not wrap * <li>if proxyInterfaces is not empty, then wraps with proxy, exposing with interfaces which are both are in proxyInterfaces and implemented by bean * <li>if proxyInterfaces is null or empty, then wraps with proxy, exposing with all interfaces implemented by bean * </ul> */ public Object maybeGetProxy(ServiceRegistryEntry entry) { Object bean = entry.getServiceBeanReference().getService(); if (!proxyEntries) { return bean; } final List<Class<?>> interfaces = ReflectionUtils.findInterfaceList(bean); if (interfaces.size() == 0) { logger.warn("Bean of instance " + bean.getClass().getName() + " could not be backed by a proxy as it does not implement an interface"); return bean; } final Class<?>[] proxyInterfaces = this.proxyInterfaces; final List<Class<?>> filteredInterfaces = filterInterfaces(interfaces, proxyInterfaces); if (filteredInterfaces.size() == 0) { logger.warn("Bean of instance " + bean.getClass().getName() + " does not implement any of the specified interfaces: " + proxyInterfaces); return bean; } ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.setInterfaces(filteredInterfaces.toArray(new Class[0])); proxyFactory.setTarget(bean); final Object proxyObject = proxyFactory.getProxy(); return proxyObject; }
From source file:org.openengsb.core.services.internal.ConnectorRegistrationManager.java
private Connector proxyForSecurity(String id, ConnectorDescription description, Connector serviceInstance, Class<?>[] clazzes) { if (INTERCEPTOR_BLACKLIST.contains(description.getDomainType())) { LOGGER.info("not proxying service because domain is blacklisted: {} ", serviceInstance); return serviceInstance; }//from w w w .j a va2 s .c om if (securityInterceptor == null) { LOGGER.warn("security interceptor is not available yet"); return serviceInstance; } // @extract-start register-secure-service-code ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.setInterfaces(clazzes); proxyFactory.addAdvice(securityInterceptor); proxyFactory.setTarget(serviceInstance); Connector result = (Connector) proxyFactory.getProxy(this.getClass().getClassLoader()); // @extract-end attributeStore.replaceAttributes(serviceInstance, new SecurityAttributeEntry("name", id)); return result; }
From source file:org.openlegacy.utils.ProxyUtil.java
public static Object createPojoProxy(Class<?> entityClass, Class<?> entityInterface, Interceptor interceptor) { Object entity = ReflectionUtil.newInstance(entityClass); ProxyFactory proxyFactory = new ProxyFactory(entityInterface, interceptor); proxyFactory.setTarget(entity); proxyFactory.setProxyTargetClass(true); Object entityProxy = proxyFactory.getProxy(); return entityProxy; }
From source file:org.openmrs.api.context.ServiceContext.java
/** * Allow other services to be added to our service layer * * @param cls Interface to proxy/*from w w w .ja v a 2 s . com*/ * @param classInstance the actual instance of the <code>cls</code> interface */ @SuppressWarnings("unchecked") public void setService(Class cls, Object classInstance) { log.debug("Setting service: " + cls); if (cls != null && classInstance != null) { try { Advised cachedService = (Advised) services.get(cls); boolean noExistingService = cachedService == null; boolean replacingService = cachedService != null && cachedService != classInstance; boolean serviceAdvised = classInstance instanceof Advised; if (noExistingService || replacingService) { Advised advisedService; if (!serviceAdvised) { // Adding a bare service, wrap with AOP proxy Class[] interfaces = { cls }; ProxyFactory factory = new ProxyFactory(interfaces); factory.setTarget(classInstance); advisedService = (Advised) factory.getProxy(OpenmrsClassLoader.getInstance()); } else { advisedService = (Advised) classInstance; } if (replacingService) { moveAddedAOP(cachedService, advisedService); } services.put(cls, advisedService); } log.debug("Service: " + cls + " set successfully"); } catch (Exception e) { throw new APIException("service.unable.create.proxy.factory", new Object[] { classInstance.getClass().getName() }, e); } } }