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.kmnet.com.fw.common.date.jodatime.JdbcAdjustedJodaTimeDateFactory.java

/**
 * Reloads the adjustment value from the database.
 * <P>/*  w  w  w. j a v  a 2  s.  c om*/
 * Depending on the settings, the reloaded fresh value will also be cached.
 * </P>
 */
@Override
public void afterPropertiesSet() {
    Assert.notNull(jdbcTemplate, "namedJdbcTemplate must not be null");
    Assert.hasLength(adjustedValueQuery, "adjustedValueQuery must not be empty");
    reload();
}

From source file:org.terasoluna.gfw.common.date.jodatime.JdbcAdjustedJodaTimeDateFactory.java

/**
 * Reloads the adjustment value from the database.
 * <P>/*w  ww . j  ava  2  s . c om*/
 * Depending on the settings, the reloaded fresh value will also be cached.
 */
@Override
public void afterPropertiesSet() {
    Assert.notNull(jdbcTemplate, "jdbcTemplate must not be null");
    Assert.hasLength(adjustedValueQuery, "adjustedValueQuery must not be empty");
    reload();
}

From source file:com.baidu.cc.patch.struts2.ReloadableJsonAwareParametersInterceptor.java

/**
 * do property load here.//from  w w w .  j a va2 s  .c  o m
 */
@Override
public void init() {
    super.init();

    ccServerUrl = Constants.getServerUrl(ccServerUrl);
    ccUser = Constants.getUser(ccUser);
    ccPassword = Constants.getPassword(ccPassword);

    Assert.hasLength(ccServerUrl, "property 'ccServerUrl' can not blank");
    Assert.hasLength(ccUser, "property 'ccUser' can not blank");
    Assert.hasText(ccVersionName, "property 'ccVersionName' can not blank");

    configLoader = ConfigLoader.createConfigLoader(this);
}

From source file:org.terasoluna.gfw.common.codelist.JdbcCodeList.java

/**
 * This method is called after the codelist is initialized Checks whether the values of querySql, valueColumn, labelColumn
 * and jdbcTemplate properties are set// w  ww .jav a2 s  . c  o  m
 * @see org.terasoluna.gfw.common.codelist.AbstractReloadableCodeList#afterPropertiesSet()
 */
@Override
public void afterPropertiesSet() {
    Assert.hasLength(querySql, "querySql is empty");
    Assert.hasLength(valueColumn, "valueColumn is empty");
    Assert.hasLength(labelColumn, "labelColumn is empty");
    Assert.notNull(jdbcTemplate, "jdbcTemplate (or dataSource) is empty");
    super.afterPropertiesSet();
}

From source file:com.scf.web.context.BeforeSpringContextListener.java

/**
 * ?test/dev/demo/product//w  w w . j  a v a 2 s.  c  o m
 */
private void setCurrentSystemEnv() {
    try {
        CommonConstants.CURRENT_ENVIRONMENT = (String) RootConfigInitor.PARAMS.get("system.env", "");
        _logger.info("system.env", CommonConstants.CURRENT_ENVIRONMENT);
        Assert.hasLength(CommonConstants.CURRENT_SYSTEM, "system.name");
    } catch (Exception e) {
        _logger.error("", e);
    }
}

From source file:org.jdbcluster.JDBClusterUtil.java

/**
 * creates Class<?> from class named className
 * // www  . ja v  a 2 s .c  o  m
 * @param className
 *            name of the class
 * @return Class instance of class className
 */
static public Class<?> createClass(String className) {

    Assert.hasLength(className, "className may not be null or \"\"");

    try {
        return Class.forName(className);
    } catch (ClassNotFoundException e) {
        throw new ConfigurationException(
                "no definition for the class [" + className + "] with the specified name could be found", e);
    }
}

From source file:com.ktds.ldap.populator.AbstractEc2InstanceLaunchingFactoryBean.java

@Override
protected final Object createInstance() throws Exception {
    Assert.hasLength(imageName, "ImageName must be set");
    Assert.hasLength(awsKey, "AwsKey must be set");
    Assert.hasLength(awsSecretKey, "AwsSecretKey must be set");
    Assert.hasLength(keypairName, "KeyName must be set");
    Assert.hasLength(groupName, "GroupName must be set");

    LOG.info("Launching EC2 instance for image: " + imageName);

    Jec2 jec2 = new Jec2(awsKey, awsSecretKey);
    LaunchConfiguration launchConfiguration = new LaunchConfiguration(imageName);
    launchConfiguration.setKeyName(keypairName);
    launchConfiguration.setSecurityGroup(Collections.singletonList(groupName));

    ReservationDescription reservationDescription = jec2.runInstances(launchConfiguration);
    instance = reservationDescription.getInstances().get(0);
    while (!instance.isRunning() && !instance.isTerminated()) {
        LOG.info("Instance still starting up; sleeping " + INSTANCE_START_SLEEP_TIME + "ms");
        Thread.sleep(INSTANCE_START_SLEEP_TIME);
        reservationDescription = jec2.describeInstances(Collections.singletonList(instance.getInstanceId()))
                .get(0);//w  ww .  j av a  2  s .  co m
        instance = reservationDescription.getInstances().get(0);
    }

    if (instance.isRunning()) {
        LOG.info("EC2 instance is now running");
        if (preparationSleepTime > 0) {
            LOG.info(
                    "Sleeping " + preparationSleepTime + "ms allowing instance services to start up properly.");
            Thread.sleep(preparationSleepTime);
            LOG.info("Instance prepared - proceeding");
        }
        return doCreateInstance(instance.getDnsName());
    } else {
        throw new IllegalStateException("Failed to start a new instance");
    }

}

From source file:org.yestech.lib.ibatis.EhCacheController.java

/**
 * Configure a cache controller. Initialize the EH Cache Manager as a singleton.
 * This method will first check the file system for your ehcache config file. If not found,
 * it will then check on the classpath based on your configFile property.
 * <p>//w ww.ja v a 2s. c  o m
 * Example of configFile property:
 * /cache/ehcache.xml - If found on file system, it will load, if not the classpath will check.
 * </p>
 *
 * @param props - the properties object continaing configuration information.
 */
public void setProperties(Properties props) {
    Assert.notNull(props, "props must be set for this to work!");
    Assert.notNull(props.getProperty("configFile"), "configFile must not be null in your properties!");
    Assert.hasLength(props.getProperty("configFile"), "configFile property can not be empty!");

    String configFile = props.getProperty("configFile");
    File file = new File(configFile);
    if (file.exists()) {
        cacheManager = CacheManager.create(file.getAbsolutePath());
    } else {
        URL url = getClass().getResource(configFile);
        cacheManager = CacheManager.create(url);
    }
}

From source file:org.archone.ad.authentication.ShoadRealm.java

@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {

    UsernamePasswordToken upToken = (UsernamePasswordToken) token;
    String username = upToken.getUsername();
    Assert.notNull(username, "Null usernames are not allowed by this realm.");
    String password = new String(upToken.getPassword());
    Assert.hasLength(password, "Empty passwords are not allowed by this realm.");

    DirContext ctx = null;/*  w ww .  j  av  a2s  . c  o  m*/
    try {
        String userDn = getUserDn(username);

        ctx = contextSource.getContext(userDn, password);

        Attributes attrs = ctx.getAttributes(userDn);
        DirContextAdapter result = new DirContextAdapter(attrs, new DistinguishedName(userDn));

        return new SimpleAuthenticationInfo(result, password.toCharArray(), getName());

    } catch (javax.naming.NamingException ex) {
        throw new AuthenticationException();
    } catch (NamingException ex) {
        throw new AuthenticationException();
    }
}

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

public void createUser(IUser userToCreate) throws AlreadyExistsException, UncategorizedUserRoleDaoException {
    Assert.notNull(userToCreate,//from w  ww  .  j ava  2  s .  c o  m
            Messages.getInstance().getString("HibernateUserRoleDao.ERROR_0001_USER_CANNOT_BE_NULL")); //$NON-NLS-1$
    Assert.hasLength(userToCreate.getUsername(),
            Messages.getInstance().getString("HibernateUserRoleDao.ERROR_0002_USERNAME_CANNOT_BE_BLANK")); //$NON-NLS-1$
    Assert.notNull(userToCreate.getPassword(),
            Messages.getInstance().getString("HibernateUserRoleDao.ERROR_0003_PASSWORD_CANNOT_BE_NULL")); //$NON-NLS-1$

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