List of usage examples for org.springframework.util Assert notNull
public static void notNull(@Nullable Object object, Supplier<String> messageSupplier)
From source file:com.trenako.utility.Slug.java
/** * Encodes the provided String as {@code slug}. * * @param input the String to be encoded * @return the slug/*from w w w . j a v a 2 s . c om*/ */ public static String encode(String input) { Assert.notNull(input, "The input string must be not null"); String nowhitespace = WHITESPACE.matcher(input).replaceAll("-"); String normalized = Normalizer.normalize(nowhitespace, Form.NFD); String slug = NONLATIN.matcher(normalized).replaceAll(""); return slug.toLowerCase(Locale.ENGLISH); }
From source file:de.itsvs.cwtrpc.core.pattern.PatternFactory.java
public static Pattern compile(String patternType, MatcherType matcherType, String pattern) throws IllegalArgumentException { final PatternType convertedPatternType; Assert.notNull(patternType, "'patternType' must not be null"); try {//w w w .j av a2 s .com convertedPatternType = PatternType.valueOf(patternType.toUpperCase()); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Pattern type '" + patternType + "' is unsupported"); } return compile(convertedPatternType, matcherType, pattern); }
From source file:com.changeme.security.SecurityUtils.java
/** * Configures the Spring Security {@link SecurityContext} to be authenticated as the user with the given username and * password as well as the given granted authorities. * /*from w w w.j a v a 2s . c o m*/ * @param username must not be {@literal null} or empty. * @param password must not be {@literal null} or empty. * @param roles */ public static void runAs(String username, String password, String... roles) { Assert.notNull(username, "Username must not be null!"); Assert.notNull(password, "Password must not be null!"); SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(username, password, AuthorityUtils.createAuthorityList(roles))); }
From source file:com.nec.crud.hibernate.HibernateSessionManager.java
/** * Retrieves the Hibernate SessionFactory that will be used to create new * sessions./* w ww . ja v a2s. co m*/ * * @return Returns the SessionFactory from which Hibernate sessions are * created. */ public static SessionFactory getSessionFactory() { Assert.notNull(sessionFactory, "No SessionFactory specified"); return sessionFactory; }
From source file:com.github.javarch.persistence.orm.hibernate.BeanValidator.java
/** * Realiza a validao de um objeto atravs da JSR 303. * /*from w ww . j a v a2 s. c o m*/ * @param objeto Entidade que contm anotaes da JSR 303 * * @return BindingResult Objeto que encapsula as mensagens de erros encontradas * nas validaes do objeto atravs das anotaes da JSR 303 */ public static <T> BindingResult validate(T objeto) { Assert.notNull(objeto, "No possivel aplicar regras de validao JSR-303 em um objeto nulo."); BindingResult bindingResult = new BeanPropertyBindingResult(objeto, objeto.getClass().getSimpleName()); javax.validation.Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); Set<ConstraintViolation<T>> constraintViolations = validator.validate(objeto); for (ConstraintViolation<T> constraint : constraintViolations) { bindingResult.rejectValue(constraint.getPropertyPath().toString(), "", constraint.getMessage()); } return bindingResult; }
From source file:org.arrow.util.DelegateUtil.java
/** * Creates a new {@link JavaDelegate} instance of the class with the given * name. Throws an IllegalArgumentException if the class could not be * instantiated.//w w w. ja v a 2 s .c o m * * @param className the java delegate class name * @return JavaDelegate */ public static JavaDelegate getJavaDelegate(String className) { Assert.notNull(className, "className must not be null"); try { if (cache.containsKey(className)) { return (JavaDelegate) cache.get(className); } Class<?> clazz = Class.forName(className); JavaDelegate delegate = (JavaDelegate) clazz.newInstance(); cache.put(className, delegate); return delegate; } catch (Exception e) { throw new IllegalArgumentException("Java delegation error", e); } }
From source file:com.devnexus.ting.model.CfpSubmissionStatusType.java
public static CfpSubmissionStatusType fromKey(String cfpSubmissionStatusTypeId) { Assert.notNull(cfpSubmissionStatusTypeId, "Parameter scheduleItemType must not be null."); for (CfpSubmissionStatusType cfpSubmissionStatusType : CfpSubmissionStatusType.values()) { if (cfpSubmissionStatusType.getKey().equals(cfpSubmissionStatusTypeId)) { return cfpSubmissionStatusType; }/*w w w .j a v a2 s . c o m*/ } return null; }
From source file:org.jdbcluster.clustertype.ClusterTypeFactory.java
/** * creates ClusterType objects depending on the ClusterType name which is passed as * an argument// ww w . ja v a2s .c om * @param <T> is a template which extends the interface ClusterType * @param clusterTypeName the ClusterType's name as a String * @return clusterType the ClusterType object * @throws ClusterTypeException */ @SuppressWarnings("unchecked") static public <T extends ClusterType> T newInstance(String clusterTypeName) throws ClusterTypeException { Assert.notNull(clusterTypeName, "clusterTypeName may not be null"); Assert.hasLength(clusterTypeName, "clusterTypeName may not have zero length"); //get the classname of the object String className = ClusterTypeBase.getClusterTypeConfig().getClusterClassName(clusterTypeName); //if no name was defined, throw an exception if (className == null) { throw new ClusterTypeException("No ClusterType of type " + clusterTypeName + " found!", new Throwable()); } ClusterTypeBase clusterType = new ClusterTypeImpl(); //save the name clusterType.setName(clusterTypeName); return (T) clusterType; }
From source file:com.frank.search.solr.core.query.DefaultValueFunction.java
/** * Creates new {@link DefaultValueFunction} representing {@code def(fieldname, defaultValue))} * * @param fieldName must not be empty/* w w w . j a va 2 s . c om*/ * @param defaultValue must not be null * @return */ public static DefaultValueFunction defaultValue(String fieldName, Object defaultValue) { Assert.hasText(fieldName, "Fieldname must not be 'empty' for default value operation."); Assert.notNull(defaultValue, "DefaultValue must not be 'null'."); return new DefaultValueFunction(fieldName, defaultValue); }
From source file:curly.commons.web.hateoas.PageProcessor.java
public static <T> Page<T> toPage(PagedResources<T> res) { Assert.notNull(res, "Resources content must be not null"); PageMetadata metadata = res.getMetadata(); if (res.getContent().isEmpty()) return new PageImpl<T>(Collections.emptyList()); return new PageImpl<>(new ArrayList<>(res.getContent()), new PageRequest((int) metadata.getNumber(), (int) metadata.getSize()), metadata.getTotalElements()); }