/** * <p>Gets a <code>List</code> of all interfaces implemented by the given * class and its superclasses.</p> * * <p>The order is determined by looking through each interface in turn as * declared in the source file and following its hierarchy up. Then each * superclass is considered in the same way. Later duplicates are ignored, * so the order is maintained.</p> * * @param cls the class to look up, may be <code>null</code> * @return the <code>List</code> of interfaces in order, * <code>null</code> if null input */ public static List getAllInterfaces(Class cls) { if (cls == null) { return null; } List interfacesFound = new ArrayList(); getAllInterfaces(cls, interfacesFound); return interfacesFound; }
private static Class<?>[] getAllInterfaces(Class<?> baseClass) { List interfaces = ClassUtils.getAllInterfaces(baseClass); Class<?>[] result = new Class<?>[interfaces.size()]; int i = 0; for (Object o : interfaces) { result[i++] = (Class<?>)o; } return result; }
/** * Get the interfaces for the specified class. * * @param cls the class to look up, may be <code>null</code> * @param interfacesFound the <code>Set</code> of interfaces for the class */ private static void getAllInterfaces(Class cls, List interfacesFound) { while (cls != null) { Class[] interfaces = cls.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { if (!interfacesFound.contains(interfaces[i])) { interfacesFound.add(interfaces[i]); getAllInterfaces(interfaces[i], interfacesFound); } } cls = cls.getSuperclass(); } }
@SuppressWarnings( "unchecked" ) static <T> T wrapObjectWithTimeoutHandler( T objectToWrap, InvocationHandler timeoutHandler ) { List<Class<?>> objectIntrerfaces = ClassUtils.getAllInterfaces( objectToWrap.getClass() ); Class<?>[] objectIntrerfacesArray = objectIntrerfaces.toArray( new Class<?>[objectIntrerfaces.size()] ); return (T) Proxy.newProxyInstance( objectToWrap.getClass().getClassLoader(), objectIntrerfacesArray, timeoutHandler ); } }
@SuppressWarnings( "unchecked" ) public static <T> T forObject( Class<T> iface, T delegate, Display display, LogChannelInterface log, boolean asyncForVoid ) { return (T) Proxy.newProxyInstance( delegate.getClass().getClassLoader(), (Class<?>[]) ClassUtils.getAllInterfaces( delegate.getClass() ).toArray( new Class<?>[] {} ), new DisplayInvocationHandler<T>( display, delegate, log, asyncForVoid ) ); }
@SuppressWarnings( "unchecked" ) private Repository wrapWithRepositoryTimeoutHandler( ReconnectableRepository repository ) { List<Class<?>> repositoryIntrerfaces = ClassUtils.getAllInterfaces( repository.getClass() ); Class<?>[] repositoryIntrerfacesArray = repositoryIntrerfaces.toArray( new Class<?>[repositoryIntrerfaces.size()] ); return (Repository) Proxy.newProxyInstance( repository.getClass().getClassLoader(), repositoryIntrerfacesArray, new RepositorySessionTimeoutHandler( repository, this ) ); }
/** * Searches for a class annotation. All inheritance tree is analysed. * * @since 3.1 */ public static <A extends Annotation> A getAnnotation(Object objectOrClass, Class<A> annotationClass) { Class<?> initialClass = objectOrClass instanceof Class<?> ? (Class<?>) objectOrClass : objectOrClass.getClass(); for (Class<?> aClass = initialClass; aClass != null; aClass = aClass.getSuperclass()) { A result = aClass.getAnnotation(annotationClass); if (result != null) { return result; } } for (Class<?> anInterface : (List<Class<?>>) ClassUtils.getAllInterfaces(initialClass)) { A result = anInterface.getAnnotation(annotationClass); if (result != null) { return result; } } return null; }
@SuppressWarnings( "unchecked" ) public static <T> T forObject( T delegate, LoginContext loginContext, Set<Class<?>> interfacesToDelegate ) { return (T) Proxy.newProxyInstance( delegate.getClass().getClassLoader(), ( (List<Class<?>>) ClassUtils .getAllInterfaces( delegate.getClass() ) ).toArray( new Class<?>[] {} ), new LoginContextInvocationHandler<Object>( delegate, loginContext, interfacesToDelegate ) ); }
for (Object anInterface : ClassUtils.getAllInterfaces(clazz)) { Collections.addAll(result, ((Class) anInterface).getDeclaredFields());
for (Iterator intf = ClassUtils.getAllInterfaces(cls).iterator(); intf .hasNext();) { try {
candidateClasses.addAll(getAllInterfaces(cls)); candidateClasses.addAll(getAllSuperclasses(cls));
public boolean isUserQualifiedForOperationOnCeilingEntityViaDefaultPermissions(String ceilingEntityFullyQualifiedName) { //the ceiling may be an impl, which will fail because entity permission is normally specified for the interface //try the passed in ceiling first, but also try an interfaces implemented List<String> testClasses = new ArrayList<String>(); testClasses.add(ceilingEntityFullyQualifiedName); try { for (Object interfaze : ClassUtils.getAllInterfaces(Class.forName(ceilingEntityFullyQualifiedName))) { testClasses.add(((Class<?>) interfaze).getName()); } } catch (Exception e) { throw new RuntimeException(e); } for (String testClass : testClasses) { Query query = em.createNamedQuery("BC_COUNT_BY_PERMISSION_AND_CEILING_ENTITY"); query.setParameter("permissionNames", Arrays.asList(AdminSecurityService.DEFAULT_PERMISSIONS)); query.setParameter("ceilingEntity", testClass); query.setHint(QueryHints.HINT_CACHEABLE, true); query.setHint(QueryHints.HINT_CACHE_REGION, "blAdminSecurityQuery"); Long count = (Long) query.getSingleResult(); if (count > 0) { return true; } } return false; }
public boolean doesOperationExistForCeilingEntity(PermissionType permissionType, String ceilingEntityFullyQualifiedName) { //the ceiling may be an impl, which will fail because entity permission is normally specified for the interface //try the passed in ceiling first, but also try an interfaces implemented List<String> testClasses = new ArrayList<String>(); testClasses.add(ceilingEntityFullyQualifiedName); try { for (Object interfaze : ClassUtils.getAllInterfaces(Class.forName(ceilingEntityFullyQualifiedName))) { testClasses.add(((Class<?>) interfaze).getName()); } } catch (Exception e) { throw new RuntimeException(e); } for (String testClass : testClasses) { Query query = em.createNamedQuery("BC_COUNT_PERMISSIONS_BY_TYPE_AND_CEILING_ENTITY"); query.setParameter("type", permissionType.getType()); query.setParameter("ceilingEntity", testClass); query.setHint(QueryHints.HINT_CACHEABLE, true); query.setHint(QueryHints.HINT_CACHE_REGION, "blAdminSecurityQuery"); Long count = (Long) query.getSingleResult(); if (count > 0) { return true; } } return false; } }
public boolean isUserQualifiedForOperationOnCeilingEntity(AdminUser adminUser, PermissionType permissionType, String ceilingEntityFullyQualifiedName) { //the ceiling may be an impl, which will fail because entity permission is normally specified for the interface //try the passed in ceiling first, but also try an interfaces implemented List<String> testClasses = new ArrayList<String>(); testClasses.add(ceilingEntityFullyQualifiedName); try { for (Object interfaze : ClassUtils.getAllInterfaces(Class.forName(ceilingEntityFullyQualifiedName))) { testClasses.add(((Class<?>) interfaze).getName()); } } catch (Exception e) { throw new RuntimeException(e); } for (String testClass : testClasses) { Query query = em.createNamedQuery("BC_COUNT_PERMISSIONS_FOR_USER_BY_TYPE_AND_CEILING_ENTITY"); query.setParameter("adminUser", adminUser); query.setParameter("type", permissionType.getType()); query.setParameter("ceilingEntity", testClass); query.setHint(QueryHints.HINT_CACHEABLE, true); query.setHint(QueryHints.HINT_CACHE_REGION, "blAdminSecurityQuery"); Long count = (Long) query.getSingleResult(); if (count > 0) { return true; } } return false; }
@SuppressWarnings("unchecked") private List<Class<?>> getAllInterfaces(Class<? extends Object> clazz) { return ClassUtils.getAllInterfaces(clazz); }
private static Class<?>[] getAllInterfaces(Class<?> baseClass) { List interfaces = ClassUtils.getAllInterfaces(baseClass); Class<?>[] result = new Class<?>[interfaces.size()]; int i = 0; for (Object o : interfaces) { result[i++] = (Class<?>)o; } return result; }
private static Class<?>[] getAllInterfaces(Class<?> baseClass) { List interfaces = ClassUtils.getAllInterfaces(baseClass); Class<?>[] result = new Class<?>[interfaces.size()]; int i = 0; for (Object o : interfaces) { result[i++] = (Class<?>)o; } return result; }
/** * Enumerates all Provider-derived interfaces in the type hierarchy of the specified Provider class. * * @param provider the Provider class to inspect. * @return all Provider-derived interfaces implemented by the Provider. */ protected Iterable<Class<? extends Provider>> enumerateProviderInterfaces(Provider provider) { List<Class<? extends Provider>> interfaces = (List<Class<? extends Provider>>)ClassUtils.getAllInterfaces(provider.getClass()); return interfaces.stream().filter(Provider.class::isAssignableFrom).collect(Collectors.toList()); }
@SuppressWarnings("unchecked") protected static List<Class<?>> findAllParentClasses( final Class<?> sourceClass) { List<Class<?>> superClasses = new ArrayList<Class<?>>(); superClasses.add(sourceClass); superClasses.addAll(ClassUtils.getAllSuperclasses(sourceClass)); superClasses.addAll(ClassUtils.getAllInterfaces(sourceClass)); return superClasses; }
@SuppressWarnings("unchecked") protected static List<Class<?>> findAllParentClasses( final Class<?> sourceClass) { List<Class<?>> superClasses = new ArrayList<Class<?>>(); superClasses.add(sourceClass); superClasses.addAll(ClassUtils.getAllSuperclasses(sourceClass)); superClasses.addAll(ClassUtils.getAllInterfaces(sourceClass)); return superClasses; }