private void checkPermission(Object object,NamespacePermissionEnum[] permissions,List<AccessDeniedException> accessDeniedExceptions){
  if (object != null) {
    if (object instanceof Collection) {
      Collection<?> collection=(Collection<?>)object;
      for (      Object element : collection) {
        checkPermission(element,permissions,accessDeniedExceptions);
      }
    }
 else     if (object instanceof String) {
      try {
        checkPermission((String)object,permissions);
      }
 catch (      AccessDeniedException accessDeniedException) {
        accessDeniedExceptions.add(accessDeniedException);
      }
    }
 else {
      throw new IllegalStateException(String.format("Object must be of type %s or %s. Actual object.class = %s",String.class,Collection.class,object.getClass()));
    }
  }
}

private void checkPermission ( Object object , NamespacePermissionEnum [ ] permissions , List < AccessDeniedException > accessDeniedExceptions ) { if ( object != null ) { if ( object instanceof Collection ) { Collection < ? > collection = ( Collection < ? > ) object ; for ( Object element : collection ) { checkPermission ( element , permissions , accessDeniedExceptions ) ; } } else if ( object instanceof String ) { try { checkPermission ( ( String ) object , permissions ) ; } catch ( AccessDeniedException accessDeniedException ) { accessDeniedExceptions . add ( accessDeniedException ) ; } } else { throw new IllegalStateException ( String . format ( "Object must be of type %s or %s. Actual object.class = %s" , String . class , Collection . class , object . getClass ( ) ) ) ; } } }
checks the current user ' s permissions against the given object which may represent a single or multiple namespaces . allowed types are string or collection of string .
