class UserFunctionExecution implements InternalFunction<Object[]> {

  @SuppressWarnings("unchecked")
  Execution<Object, Object, List<Object>> buildExecution(Cache cache, String onRegion)
      throws RegionNotFoundException {
    Execution<Object, Object, List<Object>> execution;
    DistributedMember member = cache.getDistributedSystem().getDistributedMember();

    if (onRegion != null && onRegion.length() > 0) {
      Region<?, ?> region = cache.getRegion(onRegion);

      if (region == null) {
        throw new RegionNotFoundException(onRegion);
      }

      execution = FunctionService.onRegion(region);
    } else {
      execution = FunctionService.onMember(member);
    }

    return execution;
  }

}