Example usage for org.springframework.util Assert hasLength

List of usage examples for org.springframework.util Assert hasLength

Introduction

In this page you can find the example usage for org.springframework.util Assert hasLength.

Prototype

public static void hasLength(@Nullable String text, Supplier<String> messageSupplier) 

Source Link

Document

Assert that the given String is not empty; that is, it must not be null and not the empty String.

Usage

From source file:org.pentaho.custom.authentication.provider.userroledao.hibernate.HibernateUserRoleDao.java

public void updateUser(IUser userToUpdate) throws NotFoundException, UncategorizedUserRoleDaoException {
    Assert.notNull(userToUpdate,//from  www.  j a  va 2  s. c om
            Messages.getInstance().getString("HibernateUserRoleDao.ERROR_0001_USER_CANNOT_BE_NULL")); //$NON-NLS-1$
    Assert.hasLength(userToUpdate.getUsername(),
            Messages.getInstance().getString("HibernateUserRoleDao.ERROR_0002_USERNAME_CANNOT_BE_BLANK")); //$NON-NLS-1$
    Assert.notNull(userToUpdate.getPassword(),
            Messages.getInstance().getString("HibernateUserRoleDao.ERROR_0003_PASSWORD_CANNOT_BE_NULL")); //$NON-NLS-1$

    if (getUser(userToUpdate.getUsername()) != null) {
        try {
            getHibernateTemplate().update(getHibernateTemplate().merge(userToUpdate));
        } catch (DataAccessException e) {
            throw new UncategorizedUserRoleDaoException(
                    Messages.getInstance().getString("HibernateUserRoleDao.ERROR_0004_DATA_ACCESS_EXCEPTION"), //$NON-NLS-1$
                    e);
        }
    } else {
        throw new NotFoundException(userToUpdate.getUsername());
    }
}

From source file:org.shept.util.FileUtils.java

public static String getTomcatWebAppPath() {
    String path = System.getProperty("wtp.deploy"); // use this property while debugging
    if (!StringUtils.hasText(path)) {
        path = System.getProperty("catalina.base");
        Assert.hasLength(path, "Catalina (tomcat) installation base directory not found");
        path = path + "/webapps";
    }/*w ww. j  ava2  s .  c  o m*/
    return path;
}

From source file:org.jdbcluster.JDBClusterUtil.java

/**
 * calles a setter on instance obj. Iterates over all superclasses
 * /*from   w w  w.ja va  2s . c  om*/
 * @param propName
 *            property name
 * @param propValue
 *            value to set
 * @param obj
 *            instance with the setter
 */
static public void invokeSetPropertyMethod(String propName, Object propValue, Object obj) {

    Assert.notNull(obj, "obj may not be null");
    Assert.notNull(propValue, "propValue may not be null");
    Assert.hasLength(propName, "obj may not be null or \"\"");

    String setMethName = "set" + propName.substring(0, 1).toUpperCase() + propName.substring(1);
    Object[] args = { propValue };
    Class[] paramType = { propValue.getClass() };
    try {
        Method mSet = JDBClusterUtil.getMethod(obj, setMethName, paramType);
        mSet.invoke(obj, args);
    } catch (SecurityException e) {
        throw new ConfigurationException("cant access property [" + propName + "] with the specified name in "
                + obj.getClass().getName(), e);
    } catch (IllegalArgumentException e) {
        throw new ConfigurationException("number of actual and formal parameters differ for the property ["
                + propName + " in " + obj.getClass().getName(), e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationException("the currently executed ctor for property [" + propName
                + "] does not have access in " + obj.getClass().getName(), e);
    } catch (InvocationTargetException e) {
        throw new ConfigurationException("the underlying constructor of the property [" + propName
                + "] throws an exception in " + obj.getClass().getName(), e);
    }
}

From source file:org.pentaho.custom.authentication.provider.userroledao.hibernate.HibernateUserRoleDao.java

/**
 * This method is more complex because this is the inverse end of a bidirectional many-to-many relationship. See 
 * Hibernate documentation section 6.3.2. Bidirectional associations. Basically, this means that the users set of this
 * role must be managed manually./* www .  j  a v a2 s .c  o m*/
 */
public void createRole(IRole roleToCreate) throws AlreadyExistsException, UncategorizedUserRoleDaoException {
    Assert.notNull(roleToCreate,
            Messages.getInstance().getString("HibernateUserRoleDao.ERROR_0005_ROLE_CANNOT_BE_NULL")); //$NON-NLS-1$
    Assert.hasLength(roleToCreate.getName(),
            Messages.getInstance().getString("HibernateUserRoleDao.ERROR_0006_ROLE_NAME_CANNOT_BE_BLANK")); //$NON-NLS-1$

    if (getRole(roleToCreate.getName()) == null) {
        try {
            getHibernateTemplate().save(roleToCreate);
        } catch (DataAccessException e) {
            throw new UncategorizedUserRoleDaoException(
                    Messages.getInstance().getString("HibernateUserRoleDao.ERROR_0004_DATA_ACCESS_EXCEPTION"), //$NON-NLS-1$
                    e);
        }
    } else {
        throw new AlreadyExistsException(roleToCreate.getName());
    }

    // manually manage users set

    for (IUser user : roleToCreate.getUsers()) {
        addUser(roleToCreate, user.getUsername());
    }
}

From source file:jails.http.MediaType.java

/**
 * Create a new {@link MediaType} for the given type, subtype, and parameters.
 * @param type the primary type//w w  w  .  j a  v a 2s . co  m
 * @param subtype the subtype
 * @param parameters the parameters, may be <code>null</code>
 * @throws IllegalArgumentException if any of the parameters contain illegal characters
 */
public MediaType(String type, String subtype, Map<String, String> parameters) {
    Assert.hasLength(type, "'type' must not be empty");
    Assert.hasLength(subtype, "'subtype' must not be empty");
    checkToken(type);
    checkToken(subtype);
    this.type = type.toLowerCase(Locale.ENGLISH);
    this.subtype = subtype.toLowerCase(Locale.ENGLISH);
    if (!CollectionUtils.isEmpty(parameters)) {
        Map<String, String> m = new LinkedCaseInsensitiveMap<String>(parameters.size(), Locale.ENGLISH);
        for (Map.Entry<String, String> entry : parameters.entrySet()) {
            String attribute = entry.getKey();
            String value = entry.getValue();
            checkParameters(attribute, value);
            m.put(attribute, unquote(value));
        }
        this.parameters = Collections.unmodifiableMap(m);
    } else {
        this.parameters = Collections.emptyMap();
    }
}

From source file:org.jdbcluster.JDBClusterUtil.java

/**
 * returnes property value directly from field. Iterates over all
 * superclasses//w w  w .j ava  2  s  .c  o m
 * 
 * @param propName
 *            name of property
 * @param obj
 *            instance of object
 * @return Object the property value
 */
static public Object getProperty(String propName, Object obj) {

    Assert.notNull(obj, "obj may not be null");
    Assert.hasLength(propName, "obj may not be null or \"\"");

    try {
        Field f = JDBClusterUtil.getField(propName, obj);
        return f.get(obj);
    } catch (SecurityException e) {
        throw new ConfigurationException("cant access property [" + propName + "] with the specified name in "
                + obj.getClass().getName(), e);
    } catch (IllegalArgumentException e) {
        throw new ConfigurationException("number of actual and formal parameters differ for the property ["
                + propName + "] in " + obj.getClass().getName(), e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationException("the currently executed ctor for property [" + propName
                + "] does not have access in " + obj.getClass().getName(), e);
    }
}

From source file:com.baidu.cc.spring.ConfigCenterPropertyPlaceholderConfigurer.java

/**
 * create a new {@link ConfigServerService} instance by proxy.
 *///w  w w.  j a v  a 2s  . c  o  m
protected void createConfigServerService() {
    if (configServerService == null) {
        //create a new one
        ccServerUrl = Constants.getServerUrl(ccServerUrl);
        Assert.hasLength(ccServerUrl, "property 'ccServerUrl' is blank.");

        proxy = new OperationTimeoutMcpackRpcProxyFactoryBean();
        proxy.setServiceUrl(ccServerUrl);
        proxy.setServiceInterface(ExtConfigServerService.class);
        proxy.setConnectionTimeout(connectionTimeout);
        proxy.setSoTimeout(readTimeout);

        //do initial
        proxy.afterPropertiesSet();

        configServerService = (ExtConfigServerService) proxy.getObject();

    }
}

From source file:org.jdbcluster.privilege.PrivilegeCheckerImpl.java

/**
 * intersects required privileges against given privileges
 * //from  w ww. j  a  v  a 2s . c  o m
 * @param serviceObject service object to check
 * @param serviceMethodName method name to check
 * @param args of method parameter
 * @return true if the privileges are sufficient
 */
public boolean checkAccess(IUser user, PrivilegedService serviceObject, String serviceMethodName,
        Object... args) {

    Assert.notNull(serviceObject, "serviceObject may not be null");
    Assert.hasLength(serviceMethodName, "serviceMethodName may not be null or \"\"");

    Method calledMethod = getMethod(serviceObject, serviceMethodName, args);
    return userPrivilegeIntersect(user, serviceObject, calledMethod, args);
}

From source file:org.pentaho.custom.authentication.provider.userroledao.hibernate.HibernateUserRoleDao.java

/**
 * This method is more complex because this is the inverse end of a bidirectional many-to-many relationship. See 
 * Hibernate documentation section 6.3.2. Bidirectional associations. Basically, this means that the users set of this
 * role must be managed manually.//ww w.  ja va2 s.c  o m
 */
public void deleteRole(IRole roleToDelete) throws NotFoundException, UncategorizedUserRoleDaoException {
    Assert.notNull(roleToDelete,
            Messages.getInstance().getString("HibernateUserRoleDao.ERROR_0005_ROLE_CANNOT_BE_NULL")); //$NON-NLS-1$
    Assert.hasLength(roleToDelete.getName(),
            Messages.getInstance().getString("HibernateUserRoleDao.ERROR_0006_ROLE_NAME_CANNOT_BE_BLANK")); //$NON-NLS-1$

    IRole role = getRole(roleToDelete.getName());
    if (role != null) {
        try {
            // for each user that is a member of this role, manually remove the role assignment from the user
            for (IUser user : role.getUsers()) {
                user.removeRole(role);
                updateUser(user);
            }
            // delete the role itself now that it is no longer referenced anywhere 
            getHibernateTemplate().delete(role);
        } catch (DataAccessException e) {
            throw new UncategorizedUserRoleDaoException(
                    Messages.getInstance().getString("HibernateUserRoleDao.ERROR_0004_DATA_ACCESS_EXCEPTION"), //$NON-NLS-1$
                    e);
        }
    } else {
        throw new NotFoundException(roleToDelete.getName());
    }
}