List of usage examples for java.lang Class getInterfaces
public Class<?>[] getInterfaces()
From source file:io.gravitee.gateway.repository.plugins.RepositoryPluginHandler.java
private void registerRepositoryDefinitions(Repository repository, ApplicationContext repoApplicationContext) { DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) ((ConfigurableApplicationContext) applicationContext) .getBeanFactory();//from w w w. j a v a2 s . com String[] beanNames = repoApplicationContext.getBeanDefinitionNames(); for (String beanName : beanNames) { Object repositoryClassInstance = repoApplicationContext.getBean(beanName); if ((beanName.endsWith("Repository") || beanName.endsWith("Manager")) && !repository.getClass().equals(repositoryClassInstance.getClass())) { Class<?> repositoryObjectClass = repositoryClassInstance.getClass(); if (repositoryObjectClass.getInterfaces().length > 0) { Class<?> repositoryItfClass = repositoryObjectClass.getInterfaces()[0]; LOGGER.debug("Register {} [{}] in gateway context", beanName, repositoryItfClass); beanFactory.registerSingleton(repositoryItfClass.getName(), repositoryClassInstance); } } } }
From source file:com.jeeframework.util.classes.ClassUtils.java
/** * Return all interfaces that the given class implements as Set, * including ones implemented by superclasses. * <p>If the class itself is an interface, it gets returned as sole interface. * @param clazz the class to analyse for interfaces * @param classLoader the ClassLoader that the interfaces need to be visible in * (may be <code>null</code> when accepting all declared interfaces) * @return all interfaces that the given object implements as Set *///w w w .ja v a2 s.c om public static Set getAllInterfacesForClassAsSet(Class clazz, ClassLoader classLoader) { Assert.notNull(clazz, "Class must not be null"); if (clazz.isInterface()) { return Collections.singleton(clazz); } Set interfaces = new LinkedHashSet(); while (clazz != null) { for (int i = 0; i < clazz.getInterfaces().length; i++) { Class ifc = clazz.getInterfaces()[i]; if (classLoader == null || isVisible(ifc, classLoader)) { interfaces.add(ifc); } } clazz = clazz.getSuperclass(); } return interfaces; }
From source file:org.apache.openjpa.meta.InterfaceImplGenerator.java
public Class<?> toManagedInterface(Class<?> cls) { Class<?>[] ifaces = cls.getInterfaces(); for (int i = 0; i < ifaces.length; i++) { if (_impls.get(ifaces[i]) == cls) return ifaces[i]; }/*from w w w . j a v a 2 s . co m*/ throw new IllegalArgumentException(cls.getName()); }
From source file:es.logongas.ix3.businessprocess.security.AuthorizationInterceptorImplBusinessProcess.java
/** * Dado un objeto que implementa un interfaz BusinessProcess o alguno que hereda de l, obtiene el que exactamente implementa. * * @param businessProcess objeto que implementa un interfaz BusinessProcess o alguno que hereda de l * @return Exactamente el interfaz que implementa *///from w w w . jav a2 s . c om private Class<? extends BusinessProcess> getInterfaceBusinessProcess(BusinessProcess businessProcess) { if (businessProcess == null) { throw new IllegalArgumentException("El objeto businessProcess no puede ser null"); } Class clazz = businessProcess.getClass(); Class[] interfaces = clazz.getInterfaces(); Class<? extends BusinessProcess> interfaceBusinessProcess = null; for (Class interfaze : interfaces) { if (BusinessProcess.class.isAssignableFrom(interfaze) == true) { if (interfaceBusinessProcess != null) { throw new RuntimeException("El objeto de la clase " + businessProcess.getClass().getName() + " no puede implementar mas de 2 interfaces BusinessProcess pero implementa al menos " + interfaceBusinessProcess.getName() + " y " + interfaze.getName()); } interfaceBusinessProcess = interfaze; } } return interfaceBusinessProcess; }
From source file:my.school.spring.beans.ProfilingBeanPostProcessor.java
@Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { Class beanClazz = profilingClasses.get(beanName); if (beanClazz != null) { Object proxyInstance = Proxy.newProxyInstance(beanClazz.getClassLoader(), beanClazz.getInterfaces(), (Object proxy, Method method, Object[] args) -> { LOG.info("Call for {}::{}", proxy.getClass().getName(), method.getName()); Object ret;/*from w ww . j a v a2 s . c o m*/ if (profilingController.isEnabled()) { long startTime = System.nanoTime(); ret = method.invoke(bean, args); long endTime = System.nanoTime(); LOG.info("PROF:8150F577C514: {}", endTime - startTime); } else { ret = method.invoke(bean, args); } ret.getClass().getName(); return ret; }); LOG.info("Creating a PROXY for {}: {} over target of class {} (Defined as: {})", beanName, proxyInstance.getClass().getName(), bean.getClass().getName(), beanClazz.getName()); return proxyInstance; } return bean; }
From source file:org.millr.slick.impl.services.OsgiServiceImpl.java
/** * Wait for service.//w ww . j a va 2 s . c om * * @param serviceImpl the service impl * @param timeout the timeout */ @SuppressWarnings({ "unused", "rawtypes" }) private void waitForService(Class serviceImpl, long timeout) { Class serviceInterface = serviceImpl.getInterfaces()[0]; BundleContext bundleContext = FrameworkUtil.getBundle(serviceInterface).getBundleContext(); ServiceReference factoryRef = bundleContext.getServiceReference(serviceInterface.getName()); ServiceTracker serviceTracker = new ServiceTracker(bundleContext, factoryRef, null); serviceTracker.open(); try { serviceTracker.waitForService(timeout); } catch (InterruptedException e) { LOGGER.error("Could not get service", e); } serviceTracker.close(); }
From source file:org.atemsource.atem.impl.common.AbstractMetaDataRepository.java
public void addServices(final AbstractEntityType entityType, Class serviceClass, Object service) { for (Class<?> serviceInterface : serviceClass.getInterfaces()) { entityType.addService(serviceInterface, service); addServices(entityType, serviceInterface, service); }// ww w. jav a2 s. c o m }
From source file:com.qpark.eip.core.spring.JAXBElementAwarePayloadTypeRouter.java
private int determineTypeDifferenceWeight(final String candidate, final Class<?> type, final int level) { if (type.getName().equals(candidate)) { return level; }//w w w . ja v a 2 s. com for (Class<?> iface : type.getInterfaces()) { if (iface.getName().equals(candidate)) { return (level % 2 == 1) ? level + 2 : level + 1; } // no match at this level, continue up the hierarchy for (Class<?> superInterface : iface.getInterfaces()) { int weight = this.determineTypeDifferenceWeight(candidate, superInterface, level + 3); if (weight < Integer.MAX_VALUE) { return weight; } } } if (type.getSuperclass() == null) { // exhausted hierarchy and found no match return Integer.MAX_VALUE; } return this.determineTypeDifferenceWeight(candidate, type.getSuperclass(), level + 2); }
From source file:de.itsvs.cwtrpc.controller.AutowiredRemoteServiceGroupConfig.java
protected Class<?> getRemoteServiceInterface(Class<?> beanType) { Class<?> foundInterface = null; for (Class<?> c : beanType.getInterfaces()) { if (RemoteService.class.isAssignableFrom(c)) { if (foundInterface != null) { /* interface must be unique */ return null; }//from w w w . j a v a 2s. com foundInterface = c; } } return foundInterface; }
From source file:ome.services.throttling.Task.java
/** * The Ice AMD-implementations are package-private and so cannot be executed * on. Instead, we have to find the public interface and use its methods. */// www .j a v a2 s. co m private Class getPublicInterface(Class c) { if (!c.getName().startsWith("AMD_")) { while (!c.equals(Object.class)) { Class[] ifaces = c.getInterfaces(); for (Class c2 : ifaces) { if (c2.getSimpleName().startsWith("AMD_")) { return c2; } } // Ok. We didn't find anything so recurse into the superclass c = c.getSuperclass(); } throw new RuntimeException("No public AMD_ interface found."); } else { return c; } }