List of usage examples for org.apache.commons.lang ClassUtils getAllInterfaces
public static List<Class<?>> getAllInterfaces(Class<?> cls)
Gets a List
of all interfaces implemented by the given class and its superclasses.
The order is determined by looking through each interface in turn as declared in the source file and following its hierarchy up.
From source file:com.liferay.portal.search.internal.IndexerRegistryImpl.java
protected <T> Indexer<T> proxyIndexer(Indexer<T> indexer) { if (indexer == null) { return null; }/*w w w .j a v a2 s .co m*/ IndexerRequestBuffer indexerRequestBuffer = IndexerRequestBuffer.get(); if ((indexerRequestBuffer == null) || !_indexerRegistryConfiguration.buffered()) { return indexer; } Indexer<?> proxiedIndexer = _proxiedIndexers.get(indexer.getClassName()); if (proxiedIndexer == null) { List<?> interfaces = ClassUtils.getAllInterfaces(indexer.getClass()); BufferedIndexerInvocationHandler bufferedIndexerInvocationHandler = new BufferedIndexerInvocationHandler( indexer, _indexStatusManager, _indexerRegistryConfiguration, _persistedModelLocalServiceRegistry); if (_indexerRequestBufferOverflowHandler == null) { bufferedIndexerInvocationHandler .setIndexerRequestBufferOverflowHandler(_defaultIndexerRequestBufferOverflowHandler); } else { bufferedIndexerInvocationHandler .setIndexerRequestBufferOverflowHandler(_indexerRequestBufferOverflowHandler); } _bufferedInvocationHandlers.put(indexer.getClassName(), bufferedIndexerInvocationHandler); proxiedIndexer = (Indexer<?>) ProxyUtil.newProxyInstance(PortalClassLoaderUtil.getClassLoader(), interfaces.toArray(new Class<?>[interfaces.size()]), bufferedIndexerInvocationHandler); _proxiedIndexers.put(indexer.getClassName(), proxiedIndexer); } return (Indexer<T>) proxiedIndexer; }
From source file:jenkins.scm.api.SCMHeadMixinEqualityGenerator.java
/** * Creates the {@link SCMHeadMixin.Equality} instance. * * @param type the {@link SCMHead} type to create the instance for. * @return the {@link SCMHeadMixin.Equality} instance. */// w w w .jav a2s . co m @NonNull private SCMHeadMixin.Equality create(@NonNull Class<? extends SCMHead> type) { Map<String, Method> properties = new TreeMap<String, Method>(); for (Class clazz : (List<Class>) ClassUtils.getAllInterfaces(type)) { if (!SCMHeadMixin.class.isAssignableFrom(clazz)) { // not a mix-in continue; } if (SCMHeadMixin.class == clazz) { // no need to check this by reflection continue; } if (!Modifier.isPublic(clazz.getModifiers())) { // not public continue; } // this is a mixin interface, only look at declared properties; for (Method method : clazz.getDeclaredMethods()) { if (method.getReturnType() == Void.class) { // nothing to do with us continue; } if (!Modifier.isPublic(method.getModifiers())) { // should never get here continue; } if (Modifier.isStatic(method.getModifiers())) { // might get here with Java 8 continue; } if (method.getParameterTypes().length != 0) { // not a property continue; } String name = method.getName(); if (!name.matches("^((is[A-Z0-9_].*)|(get[A-Z0-9_].*))$")) { // not a property continue; } if (name.startsWith("is")) { name = "" + Character.toLowerCase(name.charAt(2)) + (name.length() > 3 ? name.substring(3) : ""); } else { name = "" + Character.toLowerCase(name.charAt(3)) + (name.length() > 4 ? name.substring(4) : ""); } if (properties.containsKey(name)) { // a higher priority interface already defined the method continue; } properties.put(name, method); } } if (properties.isEmpty()) { // no properties to consider return new ConstantEquality(); } if (forceReflection) { return new ReflectiveEquality(properties.values().toArray(new Method[properties.size()])); } // now we define the class ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); String name = SCMHeadMixin.class.getPackage().getName() + ".internal." + type.getName(); // TODO Move to 1.7 opcodes once baseline 1.612+ cw.visit(Opcodes.V1_6, ACC_PUBLIC, name.replace('.', '/'), null, Type.getInternalName(Object.class), new String[] { Type.getInternalName(SCMHeadMixin.Equality.class) }); generateDefaultConstructor(cw); generateEquals(cw, properties.values()); byte[] image = cw.toByteArray(); Class<? extends SCMHeadMixin.Equality> c = defineClass(name, image, 0, image.length) .asSubclass(SCMHeadMixin.Equality.class); try { return c.newInstance(); } catch (InstantiationException e) { // fallback to reflection } catch (IllegalAccessException e) { // fallback to reflection } return new ReflectiveEquality(properties.values().toArray(new Method[properties.size()])); }
From source file:edu.brown.utils.ClassUtil.java
/** * Get a set of all of the interfaces that the element_class implements * /*from w w w.java 2 s . c om*/ * @param element_class * @return */ @SuppressWarnings("unchecked") public static Collection<Class<?>> getInterfaces(Class<?> element_class) { Set<Class<?>> ret = ClassUtil.CACHE_getInterfaceClasses.get(element_class); if (ret == null) { // ret = new HashSet<Class<?>>(); // Queue<Class<?>> queue = new LinkedList<Class<?>>(); // queue.add(element_class); // while (!queue.isEmpty()) { // Class<?> current = queue.poll(); // for (Class<?> i : current.getInterfaces()) { // ret.add(i); // queue.add(i); // } // FOR // } // WHILE ret = new HashSet<Class<?>>(ClassUtils.getAllInterfaces(element_class)); if (element_class.isInterface()) ret.add(element_class); ret = Collections.unmodifiableSet(ret); ClassUtil.CACHE_getInterfaceClasses.put(element_class, ret); } return (ret); }
From source file:com.haulmont.cuba.core.sys.listener.EntityListenerManager.java
protected List<?> findListener(Class<? extends Entity> entityClass, EntityListenerType type) { log.trace("get listener " + type + " for class " + entityClass.getName()); List<String> names = getDeclaredListeners(entityClass); if (names.isEmpty()) { log.trace("no annotations, exiting"); return Collections.emptyList(); }//from www . jav a 2s . c om List<Object> result = new ArrayList<>(); for (String name : names) { if (AppBeans.containsBean(name)) { Object bean = AppBeans.get(name); log.trace("listener bean found: " + bean); List<Class> interfaces = ClassUtils.getAllInterfaces(bean.getClass()); for (Class intf : interfaces) { if (intf.equals(type.getListenerInterface())) { log.trace("listener implements " + type.getListenerInterface()); result.add(bean); } } } else { try { Class aClass = Thread.currentThread().getContextClassLoader().loadClass(name); log.trace("listener class found: " + aClass); List<Class> interfaces = ClassUtils.getAllInterfaces(aClass); for (Class intf : interfaces) { if (intf.equals(type.getListenerInterface())) { log.trace("listener implements " + type.getListenerInterface()); result.add(aClass.newInstance()); } } } catch (ClassNotFoundException e) { throw new RuntimeException("Unable to create entity listener " + name + " for " + entityClass.getName() + " because there is no bean or class with such name"); } catch (IllegalAccessException | InstantiationException e) { throw new RuntimeException("Unable to instantiate an Entity Listener", e); } } } return result; }
From source file:nl.strohalm.cyclos.spring.ServiceSecurityProxyInvocationHandler.java
@SuppressWarnings("unchecked") public ServiceSecurityProxyInvocationHandler(final Object bean) { this.bean = bean; Class<? extends Object> clazz = bean.getClass(); List<Class<?>> interfaces = ClassUtils.getAllInterfaces(clazz); Collection<Class<?>> serviceInterfaces = new HashSet<Class<?>>(); for (Class<?> iface : interfaces) { if (Service.class.isAssignableFrom(clazz)) { serviceInterfaces.add(iface); }//ww w. j av a 2 s . c o m } this.serviceInterfaces = serviceInterfaces.toArray(new Class<?>[serviceInterfaces.size()]); }
From source file:org.amplafi.hivemind.factory.mock.MockBuilderFactoryImpl.java
/** * Because of MockSwitcher the object that external tests have is not actually a mock in some cases. * @param mock an EasyMock or a Proxy with a MockSwitcher as the Proxy handler. * @return actual mock object/*from w w w .ja v a2 s . c o m*/ */ @SuppressWarnings("unchecked") public Object getMock(final Object mock) { try { // check to see if this is a hivemind proxy. @SuppressWarnings("unused") final Field f = mock.getClass().getDeclaredField("_inner"); // TODO note it would be best to get the value of _inner List<Class<?>> interfaces = ClassUtils.getAllInterfaces(mock.getClass()); Map<Class<?>, Object> mockMap = getMockMap(); for (Class interfaceClass : interfaces) { Object threadMock = mockMap.get(interfaceClass); if (threadMock != null) { return threadMock; } } } catch (NoSuchFieldException e) { // ignore -- mock was not a hivemind proxy } return mock; }
From source file:org.apache.hadoop.hbase.master.MasterCoprocessorHost.java
@Override public MasterEnvironment createEnvironment(final Class<?> implClass, final Coprocessor instance, final int priority, final int seq, final Configuration conf) { for (Object itf : ClassUtils.getAllInterfaces(implClass)) { Class<?> c = (Class<?>) itf; if (CoprocessorService.class.isAssignableFrom(c)) { masterServices.registerService(((CoprocessorService) instance).getService()); }/*from w w w. j a v a2s . c o m*/ } return new MasterEnvironment(implClass, instance, priority, seq, conf, masterServices); }
From source file:org.apache.hadoop.hdfs.TestHDFSPolicyProvider.java
@Test public void testPolicyProviderForServer() { List<?> ifaces = ClassUtils.getAllInterfaces(rpcServerClass); Set<Class<?>> serverProtocols = new HashSet<>(ifaces.size()); for (Object obj : ifaces) { Class<?> iface = (Class<?>) obj; if (iface.getSimpleName().endsWith("Protocol")) { serverProtocols.add(iface);/* ww w . jav a2 s. c om*/ } } LOG.info( "Running test {} for RPC server {}. Found server protocols {} " + "and policy provider protocols {}.", testName.getMethodName(), rpcServerClass.getName(), serverProtocols, policyProviderProtocols); assertFalse("Expected to find at least one protocol in server.", serverProtocols.isEmpty()); final Set<Class<?>> differenceSet = Sets.difference(serverProtocols, policyProviderProtocols); assertTrue(String.format("Following protocols for server %s are not defined in " + "%s: %s", rpcServerClass.getName(), HDFSPolicyProvider.class.getName(), Arrays.toString(differenceSet.toArray())), differenceSet.isEmpty()); }
From source file:org.apache.hadoop.hive.metastore.RawStoreProxy.java
private static Class<?>[] getAllInterfaces(Class<?> baseClass) { List interfaces = ClassUtils.getAllInterfaces(baseClass); Class<?>[] result = new Class<?>[interfaces.size()]; int i = 0;/*from ww w . j a v a 2 s. c o m*/ for (Object o : interfaces) { result[i++] = (Class<?>) o; } return result; }
From source file:org.apache.jena.security.impl.CachedSecurityEvaluator.java
/** * Create an instance./*from w w w . j av a 2 s . c o m*/ * @param evaluator The security evaluator we are caching. * @param runAs The principal that we want to use when checking the permissions. * @return The proxied SecurityEvaluator. */ public static SecurityEvaluator getInstance(final SecurityEvaluator evaluator, final Principal runAs) { final Set<Class<?>> ifac = new LinkedHashSet<Class<?>>(); if (evaluator.getClass().isInterface()) { ifac.add(evaluator.getClass()); } ifac.addAll(ClassUtils.getAllInterfaces(evaluator.getClass())); return (SecurityEvaluator) Proxy.newProxyInstance(SecuredItemImpl.class.getClassLoader(), ifac.toArray(new Class<?>[ifac.size()]), new CachedSecurityEvaluator(evaluator, runAs)); }