List of usage examples for org.springframework.util ClassUtils getAllInterfacesForClass
public static Class<?>[] getAllInterfacesForClass(Class<?> clazz)
From source file:org.spring.guice.module.SpringModule.java
@Override public void configure(Binder binder) { for (String name : beanFactory.getBeanDefinitionNames()) { BeanDefinition definition = beanFactory.getBeanDefinition(name); if (definition.isAutowireCandidate() && definition.getRole() == AbstractBeanDefinition.ROLE_APPLICATION) { Class<?> type = beanFactory.getType(name); @SuppressWarnings("unchecked") final Class<Object> cls = (Class<Object>) type; final String beanName = name; Provider<Object> provider = new BeanFactoryProvider(beanFactory, beanName, type); if (!cls.isInterface() && !ClassUtils.isCglibProxyClass(cls)) { bindConditionally(binder, name, cls, provider); }/*from w ww . j a v a 2 s .c o m*/ for (Class<?> iface : ClassUtils.getAllInterfacesForClass(cls)) { @SuppressWarnings("unchecked") Class<Object> unchecked = (Class<Object>) iface; bindConditionally(binder, name, unchecked, provider); } } } }
From source file:im.tym.wraop.impl.SpiBasedWrapperFactory.java
@Override public WrapperFactory<I> withAllInterfacesOf(Object object) { setInterfaces(ClassUtils.getAllInterfacesForClass(object.getClass())); return this; }
From source file:im.tym.wraop.impl.SpiBasedWrapperFactory.java
@Override public WrapperFactory<I> withAllInterfacesOfClass(Class clazz) { setInterfaces(ClassUtils.getAllInterfacesForClass(clazz)); return this; }
From source file:org.sakaiproject.genericdao.springutil.CurrentClassLoaderBeanNameAutoProxyCreator.java
@SuppressWarnings("unchecked") @Override//from ww w. ja v a2 s .com protected Object createProxy(Class beanClass, String beanName, Object[] specificInterceptors, TargetSource targetSource) { if (spring12x) { ProxyFactory proxyFactory = new ProxyFactory(); // Copy our properties (proxyTargetClass etc) inherited from ProxyConfig. proxyFactory.copyFrom(this); if (!shouldProxyTargetClass(beanClass, beanName)) { // Must allow for introductions; can't just set interfaces to // the target's interfaces only. Class[] targetInterfaces = ClassUtils.getAllInterfacesForClass(beanClass); for (int i = 0; i < targetInterfaces.length; i++) { proxyFactory.addInterface(targetInterfaces[i]); } } Advisor[] advisors = buildAdvisors(beanName, specificInterceptors); for (int i = 0; i < advisors.length; i++) { proxyFactory.addAdvisor(advisors[i]); } proxyFactory.setTargetSource(targetSource); customizeProxyFactory(proxyFactory); proxyFactory.setFrozen(this.freezeProxy); return proxyFactory.getProxy(myClassLoader); } else { return super.createProxy(beanClass, beanName, specificInterceptors, targetSource); } }
From source file:org.codehaus.grepo.query.jpa.repository.DefaultJpaRepository.java
/** * Create a close-suppressing proxy for the given JPA EntityManager. * * @param em The JPA EntityManager to create a proxy for. * @return The EntityManager proxy, implementing all interfaces implemented by the passed-in EntityManager object * (that is, also implementing all provider-specific extension interfaces). *//*from w ww. ja v a 2s. c o m*/ protected EntityManager createEntityManagerProxy(EntityManager em) { Class<?>[] ifcs = null; EntityManagerFactory emf = getEntityManagerFactory(); if (emf instanceof EntityManagerFactoryInfo) { Class<?> entityManagerInterface = ((EntityManagerFactoryInfo) emf).getEntityManagerInterface(); if (entityManagerInterface != null) { ifcs = new Class[] { entityManagerInterface }; } } if (ifcs == null) { ifcs = ClassUtils.getAllInterfacesForClass(em.getClass()); } return (EntityManager) Proxy.newProxyInstance(em.getClass().getClassLoader(), ifcs, new CloseSuppressingInvocationHandler(em)); }
From source file:com.quancheng.saluki.boot.runner.GrpcServiceRunner.java
@Override public void run(String... arg0) throws Exception { System.out.println("Starting GRPC Server ..."); RpcServiceConfig rpcSerivceConfig = new RpcServiceConfig(); this.addRegistyAddress(rpcSerivceConfig); rpcSerivceConfig.setApplication(applicationName); this.addHostAndPort(rpcSerivceConfig); rpcSerivceConfig.setMonitorinterval(thrallProperties.getMonitorinterval()); Collection<Object> instances = getTypedBeansWithAnnotation(SalukiService.class); if (instances.size() > 0) { try {//from w ww.j a v a 2 s.co m for (Object instance : instances) { SalukiService serviceAnnotation = instance.getClass().getAnnotation(SalukiService.class); String serviceName = serviceAnnotation.service(); Set<String> serviceNames = Sets.newHashSet(); Object target = instance; if (StringUtils.isBlank(serviceName)) { if (this.isGrpcServer(instance)) { throw new java.lang.IllegalArgumentException( "you use grpc stub service,must set service name,service instance is" + instance); } else { target = GrpcAopUtils.getTarget(target); Class<?>[] interfaces = ClassUtils.getAllInterfacesForClass(target.getClass()); for (Class<?> interfaceClass : interfaces) { String interfaceName = interfaceClass.getName(); if (StringUtils.startsWith(interfaceName, "com.quancheng")) { serviceNames.add(interfaceName); } } } } else { serviceNames.add(serviceName); } for (String realServiceName : serviceNames) { rpcSerivceConfig.addServiceDefinition(realServiceName, getGroup(serviceAnnotation), getVersion(serviceAnnotation), instance); } } } finally { Object healthInstance = new HealthImpl(applicationContext); BeanDefinitionRegistry beanDefinitonRegistry = (BeanDefinitionRegistry) applicationContext .getBeanFactory(); BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder .genericBeanDefinition(Health.class); beanDefinitonRegistry.registerBeanDefinition(Health.class.getName(), beanDefinitionBuilder.getRawBeanDefinition()); applicationContext.getBeanFactory().registerSingleton(Health.class.getName(), healthInstance); String group = thrallProperties.getGroup() != null ? thrallProperties.getGroup() : "default"; String version = thrallProperties.getVersion() != null ? thrallProperties.getVersion() : "1.0.0"; rpcSerivceConfig.addServiceDefinition(Health.class.getName(), group, version, healthInstance); } } this.rpcService = rpcSerivceConfig; rpcSerivceConfig.export(); System.out.println(String.format("GRPC server has started!You can do test by %s \n %s", "http://localhost:" + httpPort + "/doc", "http://saluki.dev.quancheng-ec.com")); }
From source file:org.broadleafcommerce.common.cache.AbstractCacheMissAware.java
/** * Retrieve a null representation of the cache item. This representation is the same for * all cache misses and is used as the object representation to store in the cache for a * cache miss./*from w w w . j av a2s . c om*/ * * @param responseClass the class representing the type of the cache item * @param <T> the type of the cache item * @return the null representation for the cache item */ protected synchronized <T> T getNullObject(final Class<T> responseClass) { if (nullObject == null) { Class<?>[] interfaces = (Class<?>[]) ArrayUtils.add(ClassUtils.getAllInterfacesForClass(responseClass), Serializable.class); nullObject = Proxy.newProxyInstance(getClass().getClassLoader(), interfaces, new InvocationHandler() { @Override public Object invoke(Object o, Method method, Object[] objects) throws Throwable { if (method.getName().equals("equals")) { return !(objects[0] == null) && objects[0].hashCode() == 31; } else if (method.getName().equals("hashCode")) { return 31; } else if (method.getName().equals("toString")) { return "Null_" + responseClass.getSimpleName(); } throw new IllegalAccessException("Not a real object"); } }); } return (T) nullObject; }
From source file:org.broadleafcommerce.common.util.BLCCollectionUtils.java
/** * Create a collection proxy that will perform some piece of work whenever modification methods are called on the * proxy. This includes the add, allAll, remove, removeAll, clear methods. Additionally, calling remove on an iterator * created from this collection is also covered. * * @param work the work to perform on collection modification * @param original the original collection to make change aware * @param <T> the collection type (e.g. List, Set, etc...) * @return the proxied collection// w ww. j av a 2 s . c o m */ public static <T extends Collection> T createChangeAwareCollection(final WorkOnChange work, final Collection original) { T proxy = (T) Proxy.newProxyInstance(BLCCollectionUtils.class.getClassLoader(), ClassUtils.getAllInterfacesForClass(original.getClass()), new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (method.getName().startsWith("add") || method.getName().startsWith("remove") || method.getName().startsWith("clear")) { work.doWork(original); } if (method.getName().equals("iterator")) { final Iterator itr = (Iterator) method.invoke(original, args); Iterator proxyItr = (Iterator) Proxy.newProxyInstance(getClass().getClassLoader(), ClassUtils.getAllInterfacesForClass(itr.getClass()), new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (method.getName().equals("remove")) { work.doWork(original); } return method.invoke(itr, args); } }); return proxyItr; } return method.invoke(original, args); } }); return proxy; }
From source file:org.broadleafcommerce.core.catalog.domain.SkuImpl.java
@Override public Money getSalePrice() { Money returnPrice = null;//w w w. j a v a 2s . c om Money optionValueAdjustments = null; if (SkuPricingConsiderationContext.hasDynamicPricing()) { // We have dynamic pricing, so we will pull the sale price from there if (dynamicPrices == null) { DefaultDynamicSkuPricingInvocationHandler handler = new DefaultDynamicSkuPricingInvocationHandler( this); Sku proxy = (Sku) Proxy.newProxyInstance(getClass().getClassLoader(), ClassUtils.getAllInterfacesForClass(getClass()), handler); dynamicPrices = SkuPricingConsiderationContext.getSkuPricingService().getSkuPrices(proxy, SkuPricingConsiderationContext.getSkuPricingConsiderationContext()); } returnPrice = dynamicPrices.getSalePrice(); optionValueAdjustments = dynamicPrices.getPriceAdjustment(); } else if (salePrice != null) { // We have an explicitly set sale price directly on this entity. We will not apply any adjustments returnPrice = new Money(salePrice, getCurrency()); } if (returnPrice == null && hasDefaultSku()) { returnPrice = lookupDefaultSku().getSalePrice(); optionValueAdjustments = getProductOptionValueAdjustments(); } if (returnPrice == null) { return null; } if (optionValueAdjustments != null) { returnPrice = returnPrice.add(optionValueAdjustments); } return returnPrice; }
From source file:org.broadleafcommerce.core.catalog.domain.SkuImpl.java
protected Money getRetailPriceInternal() { Money returnPrice = null;// w ww . ja v a 2 s . c o m Money optionValueAdjustments = null; if (SkuPricingConsiderationContext.hasDynamicPricing()) { // We have dynamic pricing, so we will pull the retail price from there if (dynamicPrices == null) { DefaultDynamicSkuPricingInvocationHandler handler = new DefaultDynamicSkuPricingInvocationHandler( this); Sku proxy = (Sku) Proxy.newProxyInstance(getClass().getClassLoader(), ClassUtils.getAllInterfacesForClass(getClass()), handler); dynamicPrices = SkuPricingConsiderationContext.getSkuPricingService().getSkuPrices(proxy, SkuPricingConsiderationContext.getSkuPricingConsiderationContext()); } returnPrice = dynamicPrices.getRetailPrice(); optionValueAdjustments = dynamicPrices.getPriceAdjustment(); } else if (retailPrice != null) { returnPrice = new Money(retailPrice, getCurrency()); } if (returnPrice == null && hasDefaultSku()) { // Otherwise, we'll pull the retail price from the default sku returnPrice = lookupDefaultSku().getRetailPrice(); optionValueAdjustments = getProductOptionValueAdjustments(); } if (returnPrice != null && optionValueAdjustments != null) { returnPrice = returnPrice.add(optionValueAdjustments); } return returnPrice; }