List of usage examples for org.springframework.util Assert hasLength
public static void hasLength(@Nullable String text, Supplier<String> messageSupplier)
From source file:org.jdbcluster.JDBClusterUtil.java
/** * calculates method object. Iterates over all superclasses Find a method * with the given method name and the given parameter types, declared on the * given class or one of its superclasses. Prefers public methods, but will * return a protected, package access, or private method too. * <p>/* ww w . jav a 2 s . c om*/ * Checks <code>Class.getMethod</code> first, falling back to * <code>getDeclaredMethod</code>. * * @param clazz * Class of Object * @param methodName * method name * @param parameterTypes * parameter types of method * @return */ static public Method getMethod(Class clazz, String methodName, Class... parameterTypes) { Assert.notNull(clazz, "clazz may not be null"); Assert.hasLength(methodName, "methodName may not be null or \"\""); Method m = null; try { m = clazz.getMethod(methodName, parameterTypes); } catch (SecurityException e) { throw new ConfigurationException( "cant get Method for method [" + methodName + "] with the specified name", e); } catch (NoSuchMethodException e) { return JDBClusterUtil.getDeclaredMethod(clazz, methodName, parameterTypes); } return m; }
From source file:org.pentaho.custom.authentication.provider.userroledao.hibernate.HibernateUserRoleDao.java
/** * This method is necessary because this is the inverse end of a bidirectional many-to-many relationship. See * Hibernate documentation section 6.3.2. Bidirectional associations. *//* w w w . j a v a 2 s.co m*/ protected void addUser(IRole roleToUpdate, String username) throws NotFoundException, UncategorizedUserRoleDaoException { Assert.notNull(roleToUpdate, Messages.getInstance().getString("HibernateUserRoleDao.ERROR_0005_ROLE_CANNOT_BE_NULL")); //$NON-NLS-1$ Assert.hasLength(roleToUpdate.getName(), Messages.getInstance().getString("HibernateUserRoleDao.ERROR_0006_ROLE_NAME_CANNOT_BE_BLANK")); //$NON-NLS-1$ Assert.hasLength(username, Messages.getInstance().getString("HibernateUserRoleDao.ERROR_0002_USERNAME_CANNOT_BE_BLANK")); //$NON-NLS-1$ IUser user = getUser(username); if (user != null) { user.addRole(roleToUpdate); updateUser(user); } else { throw new NotFoundException(username); } }
From source file:org.codhaus.groovy.grails.validation.ext.ConstrainedPropertyGunn.java
public static void registerNewConstraint(String name, Class<?> constraintClass) { Assert.hasLength(name, "Argument [name] cannot be null"); if (constraintClass == null || !Constraint.class.isAssignableFrom(constraintClass)) { throw new IllegalArgumentException( "Argument [constraintClass] with value [" + constraintClass + "] is not a valid constraint"); }// w w w. j a va2s . co m List<Object> objects = getOrInitializeConstraint(name); objects.add(constraintClass); }
From source file:org.codhaus.groovy.grails.validation.ext.ConstrainedPropertyGunn.java
public static void registerNewConstraint(String name, ConstraintFactory factory) { Assert.hasLength(name, "Argument [name] cannot be null or blank"); Assert.notNull(factory, "Argument [factory] cannot be null"); List<Object> objects = getOrInitializeConstraint(name); objects.add(factory);/*from www. ja va2 s . c o m*/ }
From source file:org.pentaho.custom.authentication.provider.userroledao.hibernate.HibernateUserRoleDao.java
/** * This method is necessary because this is the inverse end of a bidirectional many-to-many relationship. See * Hibernate documentation section 6.3.2. Bidirectional associations. *//* w w w . j a v a 2 s. c o m*/ protected void removeUser(IRole roleToUpdate, String username) throws NotFoundException, UncategorizedUserRoleDaoException { Assert.notNull(roleToUpdate, Messages.getInstance().getString("HibernateUserRoleDao.ERROR_0005_ROLE_CANNOT_BE_NULL")); //$NON-NLS-1$ Assert.hasLength(roleToUpdate.getName(), Messages.getInstance().getString("HibernateUserRoleDao.ERROR_0006_ROLE_NAME_CANNOT_BE_BLANK")); //$NON-NLS-1$ Assert.hasLength(username, Messages.getInstance().getString("HibernateUserRoleDao.ERROR_0002_USERNAME_CANNOT_BE_BLANK")); //$NON-NLS-1$ IUser user = getUser(username); if (user != null) { user.removeRole(roleToUpdate); updateUser(user); } else { throw new NotFoundException(username); } }
From source file:org.jdbcluster.JDBClusterUtil.java
/** * calculates method object. Iterates over all superclasses. Find a method * with the given method name and the given parameter types, declared on the * given class or one of its superclasses. Will return a public, protected, * package access, or private method.//from w w w .ja v a 2 s . c o m * <p> * Checks <code>Class.getDeclaredMethod</code>, cascading upwards to all * superclasses. * * @param clazz * Class of Object * @param methodName * method name * @param parameterTypes * parameter types of method * @return */ static public Method getDeclaredMethod(Class clazz, String methodName, Class... parameterTypes) { Assert.notNull(clazz, "clazz may not be null"); Assert.hasLength(methodName, "methodName may not be null or \"\""); Method m = null; try { m = clazz.getDeclaredMethod(methodName, parameterTypes); } catch (SecurityException e) { throw new ConfigurationException( "cant get Method for method [" + methodName + "] with the specified name", e); } catch (NoSuchMethodException e) { if (clazz.getSuperclass() != null) { return JDBClusterUtil.getDeclaredMethod(clazz.getSuperclass(), methodName, parameterTypes); } throw new ConfigurationException( "cant get Method for method [" + methodName + "] with the specified name", e); } return m; }
From source file:org.pentaho.custom.authentication.provider.userroledao.hibernate.HibernateUserRoleDao.java
public void setAllUsersQuery(String allUsersQuery) { Assert.hasLength(allUsersQuery, Messages.getInstance() .getString("HibernateUserRoleDao.ERROR_0007_ALL_USERS_QUERY_CANNOT_BE_BLANK")); //$NON-NLS-1$ this.allUsersQuery = allUsersQuery; }
From source file:org.pentaho.custom.authentication.provider.userroledao.hibernate.HibernateUserRoleDao.java
public void setAllRolesQuery(String allRolesQuery) { Assert.hasLength(allUsersQuery, Messages.getInstance() .getString("HibernateUserRoleDao.ERROR_0008_ALL_ROLES_QUERY_CANNOT_BE_BLANK")); //$NON-NLS-1$ this.allRolesQuery = allRolesQuery; }
From source file:demo.tomcat.SciTomcatEmbeddedServletContainerFactory.java
/** * The Tomcat protocol to use when create the {@link Connector}. * @param protocol the protocol//from ww w. ja va 2 s. c o m * @see Connector#Connector(String) */ public void setProtocol(String protocol) { Assert.hasLength(protocol, "Protocol must not be empty"); this.protocol = protocol; }
From source file:jails.http.MediaType.java
/** * Parse the given String into a single {@link MediaType}. * @param mediaType the string to parse/* ww w .j a v a2 s.c o m*/ * @return the media type * @throws IllegalArgumentException if the string cannot be parsed */ public static MediaType parseMediaType(String mediaType) { Assert.hasLength(mediaType, "'mediaType' must not be empty"); String[] parts = StringUtils.tokenizeToStringArray(mediaType, ";"); String fullType = parts[0].trim(); // java.net.HttpURLConnection returns a *; q=.2 Accept header if (WILDCARD_TYPE.equals(fullType)) { fullType = "*/*"; } int subIndex = fullType.indexOf('/'); if (subIndex == -1) { throw new IllegalArgumentException("\"" + mediaType + "\" does not contain '/'"); } if (subIndex == fullType.length() - 1) { throw new IllegalArgumentException("\"" + mediaType + "\" does not contain subtype after '/'"); } String type = fullType.substring(0, subIndex); String subtype = fullType.substring(subIndex + 1, fullType.length()); Map<String, String> parameters = null; if (parts.length > 1) { parameters = new LinkedHashMap<String, String>(parts.length - 1); for (int i = 1; i < parts.length; i++) { String parameter = parts[i]; int eqIndex = parameter.indexOf('='); if (eqIndex != -1) { String attribute = parameter.substring(0, eqIndex); String value = parameter.substring(eqIndex + 1, parameter.length()); parameters.put(attribute, value); } } } return new MediaType(type, subtype, parameters); }