List of usage examples for org.springframework.util ObjectUtils isEmpty
@SuppressWarnings("rawtypes") public static boolean isEmpty(@Nullable Object obj)
From source file:jun.learn.scene.handlerMapping.HandlerExecutionChain.java
/** * Apply afterConcurrentHandlerStarted callback on mapped AsyncHandlerInterceptors. *///from w w w. j a v a 2 s . com void applyAfterConcurrentHandlingStarted(HttpServletRequest request, HttpServletResponse response) { HandlerInterceptor[] interceptors = getInterceptors(); if (!ObjectUtils.isEmpty(interceptors)) { for (int i = interceptors.length - 1; i >= 0; i--) { if (interceptors[i] instanceof AsyncHandlerInterceptor) { try { AsyncHandlerInterceptor asyncInterceptor = (AsyncHandlerInterceptor) interceptors[i]; asyncInterceptor.afterConcurrentHandlingStarted(request, response, this.handler); } catch (Throwable ex) { logger.error( "Interceptor [" + interceptors[i] + "] failed in afterConcurrentHandlingStarted", ex); } } } } }
From source file:objective.taskboard.controller.FollowUpController.java
@RequestMapping public ResponseEntity<Object> download(@RequestParam("project") String projectKey, @RequestParam("template") String template, @RequestParam("date") Optional<LocalDate> date, @RequestParam("timezone") String zoneId) { if (ObjectUtils.isEmpty(projectKey)) return new ResponseEntity<>("You must provide the project", BAD_REQUEST); if (ObjectUtils.isEmpty(template)) return new ResponseEntity<>("Template not selected", BAD_REQUEST); Template templateFollowup = templateService.getTemplate(template); if (templateFollowup == null || !authorizer.hasAnyRoleInProjects(templateFollowup.getRoles(), asList(projectKey))) return new ResponseEntity<>("Template or project doesn't exist", HttpStatus.NOT_FOUND); ZoneId timezone = determineTimeZoneId(zoneId); try {/*w w w. j a v a 2 s . co m*/ Resource resource = followUpFacade.generateReport(template, date, timezone, projectKey); String filename = "Followup_" + template + "_" + projectKey + "_" + templateDate(date, timezone) + ".xlsm"; return ResponseEntity.ok().contentLength(resource.contentLength()) .header("Content-Disposition", "attachment; filename=\"" + filename + "\"") .header("Set-Cookie", "fileDownload=true; path=/").body(resource); } catch (InvalidTableRangeException e) {//NOSONAR return ResponseEntity.badRequest().body(format( "The selected template is invalid. The range of table %s? in sheet %s? is smaller than the available data. " + "Please increase the range to cover at least row %s.", e.getTableName(), e.getSheetName(), e.getMinRows())); } catch (ClusterNotConfiguredException e) {//NOSONAR return ResponseEntity.badRequest() .body("No cluster configuration found for project " + projectKey + "."); } catch (ProjectDatesNotConfiguredException e) {//NOSONAR return ResponseEntity.badRequest() .body("The project " + projectKey + " has no start or delivery date."); } catch (Exception e) { log.warn("Error generating followup spreadsheet", e); return ResponseEntity.status(INTERNAL_SERVER_ERROR).header("Content-Type", "text/html; charset=utf-8") .body(StringUtils.defaultIfEmpty(e.getMessage(), e.toString())); } }
From source file:org.beangle.model.persist.hibernate.internal.ClassUtils.java
/** * Returns an array of class string names for the given classes. * /*from w w w. j a va2 s . c o m*/ * @param array * @return */ public static String[] toStringArray(Class<?>[] array) { if (ObjectUtils.isEmpty(array)) return new String[0]; String[] strings = new String[array.length]; for (int i = 0; i < array.length; i++) { strings[i] = array[i].getName(); } return strings; }
From source file:org.beangle.model.persist.hibernate.internal.ClassUtils.java
/** * Determines if multiple classes(not interfaces) are specified, without any * relation to each other. Interfaces will simply be ignored. * /*from w ww. j a v a 2 s . c om*/ * @param classes * an array of classes * @return true if at least two classes unrelated to each other are found, * false otherwise */ public static boolean containsUnrelatedClasses(Class<?>[] classes) { if (ObjectUtils.isEmpty(classes)) return false; Class<?> clazz = null; // check if is more then one class specified for (int i = 0; i < classes.length; i++) { if (!classes[i].isInterface()) { if (clazz == null) clazz = classes[i]; // check relationship else { if (clazz.isAssignableFrom(classes[i])) // clazz is a parent, switch with the child clazz = classes[i]; else if (!classes[i].isAssignableFrom(clazz)) return true; } } } // everything is in order return false; }
From source file:org.beangle.model.persist.hibernate.internal.ClassUtils.java
/** * Parses the given class array and eliminate parents of existing classes. * Useful when creating proxies to minimize the number of implemented * interfaces and redundant class information. * /*from w ww. j a v a 2s. co m*/ * @see #containsUnrelatedClasses(Class[]) * @see #configureFactoryForClass(ProxyFactory, Class[]) * @param classes * array of classes * @return a new array without superclasses */ public static Class<?>[] removeParents(Class<?>[] classes) { if (ObjectUtils.isEmpty(classes)) return new Class[0]; List<Class<?>> clazz = new ArrayList<Class<?>>(classes.length); for (int i = 0; i < classes.length; i++) { clazz.add(classes[i]); } // remove null elements while (clazz.remove(null)) { } // only one class is allowed // there can be multiple interfaces // parents of classes inside the array are removed boolean dirty; do { dirty = false; for (int i = 0; i < clazz.size(); i++) { Class<?> currentClass = clazz.get(i); for (int j = 0; j < clazz.size(); j++) { if (i != j) { if (currentClass.isAssignableFrom(clazz.get(j))) { clazz.remove(i); i--; dirty = true; break; } } } } } while (dirty); return (Class[]) clazz.toArray(new Class[clazz.size()]); }
From source file:org.beangle.model.persist.hibernate.internal.ClassUtils.java
/** * Based on the given class, properly instructs the ProxyFactory proxies. * For additional sanity checks on the passed classes, check the methods * below.// w w w .j ava2 s.c o m * * @see #containsUnrelatedClasses(Class[]) * @see #removeParents(Class[]) * @param factory * @param classes */ public static void configureFactoryForClass(ProxyFactory factory, Class<?>[] classes) { if (ObjectUtils.isEmpty(classes)) return; for (int i = 0; i < classes.length; i++) { Class<?> clazz = classes[i]; if (clazz.isInterface()) { factory.addInterface(clazz); } else { factory.setTargetClass(clazz); factory.setProxyTargetClass(true); } } }
From source file:org.beangle.model.persist.hibernate.internal.ClassUtils.java
/** * Loads classes with the given name, using the given classloader. * {@link ClassNotFoundException} exceptions are being ignored. The return * class array will not contain duplicates. * //from w w w . j a v a 2s . c om * @param classNames * array of classnames to load (in FQN format) * @param classLoader * classloader used for loading the classes * @return an array of classes (can be smaller then the array of class * names) w/o duplicates */ public static Class<?>[] loadClassesIfPossible(String[] classNames, ClassLoader classLoader) { if (ObjectUtils.isEmpty(classNames)) return new Class[0]; Validate.notNull(classLoader, "classLoader is required"); Set<Class<?>> classes = new LinkedHashSet<Class<?>>(classNames.length); for (int i = 0; i < classNames.length; i++) { try { classes.add(classLoader.loadClass(classNames[i])); } catch (ClassNotFoundException ex) { // ignore } } return (Class[]) classes.toArray(new Class[classes.size()]); }
From source file:org.beangle.model.persist.hibernate.internal.ClassUtils.java
/** * Loads and returns the classes given as names, using the given class * loader. Throws IllegalArgument exception if the classes cannot be loaded. * /*from w w w .j a v a2s . c o m*/ * @param classNames * array of class names * @param classLoader * class loader for loading the classes * @return the loaded classes */ public static Class<?>[] loadClasses(String[] classNames, ClassLoader classLoader) { if (ObjectUtils.isEmpty(classNames)) return new Class[0]; Validate.notNull(classLoader, "classLoader is required"); Set<Class<?>> classes = new LinkedHashSet<Class<?>>(classNames.length); for (int i = 0; i < classNames.length; i++) { classes.add(org.springframework.util.ClassUtils.resolveClassName(classNames[i], classLoader)); } return (Class[]) classes.toArray(new Class[classes.size()]); }
From source file:org.beangle.model.persist.hibernate.internal.ClassUtils.java
/** * Excludes classes from the given array, which match the given modifier. * /*from ww w.j a va 2 s .c o m*/ * @param classes * array of classes (can be null) * @param modifier * class modifier * @return array of classes (w/o duplicates) which does not have the given * modifier */ public static Class<?>[] excludeClassesWithModifier(Class<?>[] classes, int modifier) { if (ObjectUtils.isEmpty(classes)) return new Class[0]; Set<Class<?>> clazzes = new LinkedHashSet<Class<?>>(classes.length); for (int i = 0; i < classes.length; i++) { if ((modifier & classes[i].getModifiers()) == 0) clazzes.add(classes[i]); } return (Class[]) clazzes.toArray(new Class[clazzes.size()]); }
From source file:org.beangle.model.persist.hibernate.internal.ClassUtils.java
/** * Returns the first matching class from the given array, that doens't * belong to common libraries such as the JDK or OSGi API. Useful for * filtering OSGi services by type to prevent class cast problems. * <p/>/*from w ww .ja va 2 s . com*/ * No sanity checks are done on the given array class. * * @param classes * array of classes * @return a 'particular' (non JDK/OSGi) class if one is found. Else the * first available entry is returned. */ public static Class<?> getParticularClass(Class<?>[] classes) { boolean hasSecurity = (System.getSecurityManager() != null); for (int i = 0; i < classes.length; i++) { final Class<?> clazz = classes[i]; ClassLoader loader = null; if (hasSecurity) { loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { public ClassLoader run() { return clazz.getClassLoader(); } }); } else { loader = clazz.getClassLoader(); } // quick boot/system check if (loader != null) { // consider known loaders if (!knownNonOsgiLoadersSet.contains(loader)) { return clazz; } } } return (ObjectUtils.isEmpty(classes) ? null : classes[0]); }