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.jdbcluster.domain.DomainCheckerImpl.java

public boolean check(ICluster cluster, String propSlavePath, Object propValue) {

    Assert.notNull(cluster, "Cluster may not be null");
    Assert.hasLength(propSlavePath, "propSlavePath may not be null");

    if (propValue instanceof String) {
        String slaveValue = (String) propValue;
        Field fSlave = JDBClusterUtil.getField(propSlavePath, cluster);
        DomainDependancy ddSlave = fSlave.getAnnotation(DomainDependancy.class);

        if (logger.isDebugEnabled())
            logger.debug("check for cluster [" + cluster.getClass().getName() + "] and Property Slave Path ["
                    + propSlavePath + "] and Slave Value [" + slaveValue + "] and Domain Dependancy Domain Id ["
                    + ddSlave.domainId() + "]");

        return check(cluster, fSlave, slaveValue, ddSlave);
    }/*from   ww w . j  a v a2  s .c  o  m*/
    throw new DomainException("while checking property [" + propSlavePath + "] and value [" + propValue + "]"
            + " at Cluster [" + cluster + "]." + " Property is not of type " + String.class.getName());
}

From source file:pt.webdetails.browserid.spring.BrowserIdProcessingFilter.java

@Override
public void afterPropertiesSet() throws Exception {
    super.afterPropertiesSet();
    //request parameters
    Assert.hasLength(getAssertionParameterName(), "assertionParameterName cannot be empty.");
    //    Assert.hasLength(getAudienceParameterName(), "audienceParameterName cannot be empty.");

    //check URL/*from  w  w  w .ja  v a  2s  . c o m*/
    Assert.hasLength(getVerificationServiceUrl());
    try {
        HttpHost host = new HttpHost(new URI(getVerificationServiceUrl(), false));
        Assert.isTrue(host.getProtocol().isSecure(), "verificationServiceUrl does not use a secure protocol");
    } catch (URIException e) {
        throw new IllegalArgumentException("verificationServiceUrl is not a valid URI", e);
    }
}

From source file:org.springmodules.validation.valang.ValangValidator.java

public void afterPropertiesSet() throws Exception {
    Assert.hasLength(getValang(), "'valang' property must be set!");
    ValangParser parser = createValangParser(getValang());
    rules = parser.parseValidation();//from w w w.  j  av a 2 s. c o m
}

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

public IUser getUser(String username) throws UncategorizedUserRoleDaoException {
    Assert.hasLength(username,
            Messages.getInstance().getString("HibernateUserRoleDao.ERROR_0002_USERNAME_CANNOT_BE_BLANK")); //$NON-NLS-1$

    try {//from  w  ww  .j  av  a 2s . c o  m
        return (CustomUser) getHibernateTemplate().get(CustomUser.class, username);
    } catch (DataAccessException e) {
        throw new UncategorizedUserRoleDaoException(
                Messages.getInstance().getString("HibernateUserRoleDao.ERROR_0004_DATA_ACCESS_EXCEPTION"), e); //$NON-NLS-1$
    }
}

From source file:com.baidu.cc.ConfigLoader.java

/**
 * do initialize operation./*from   w ww  . ja va 2 s .  c  o  m*/
 */
public void init() {
    //here need to check parameters
    Assert.hasLength(ccUser, "property 'ccUser' is blank.");
    Assert.notNull(configServerService, "property 'configServerService' is null");

    if (ccVersion != null && ccVersion > 0) {
        printUseVersionLog();
        return;
    }

    //if set ccVersionName
    Long vId = configServerService.getVersionId(ccUser, ccPassword, ccVersionName);

    if (vId != null) {
        ccVersion = vId;
        printUseVersionLog();
        return;
    }

    if (StringUtils.isNotBlank(projectName) && StringUtils.isNotBlank(envName)) {
        long time = System.currentTimeMillis();
        ccVersion = configServerService.getLastestConfigVersion(ccUser, ccPassword, projectName, envName);
        long timetook = System.currentTimeMillis() - time;
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Get configuration version id by projectName[" + projectName + "] and envName["
                    + envName + "] and get version is:" + ccVersion + " time took(ms):" + timetook);

        }
        printUseVersionLog();
        return;
    }

    //check ccVersionName
    //if ccEnvId is not null should check ccVersion 
    if (ccEnvId != null && ccEnvId > 0) {
        //if ccVersion is not null then ccEnvId will be ignore
        if (ccVersion != null && ccVersion > 0) {
            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("Found configuration version id[" + ccVersion + "] ccEnvId[" + ccEnvId
                        + "] will be ignored.");

            }

        } else {
            long time = System.currentTimeMillis();
            //should get ccVersion id by ccEnvId
            ccVersion = configServerService.getLastestConfigVersion(ccUser, ccPassword, ccEnvId);
            if (LOGGER.isInfoEnabled()) {
                long timetook = System.currentTimeMillis() - time;
                LOGGER.info("Get configuration version id by envId[" + ccEnvId + "] and get version is:"
                        + ccVersion + " time took(ms):" + timetook);

            }
        }

    }

    Assert.notNull(ccVersion, "property 'ccVersion' is null");

}

From source file:org.jdbcluster.JDBClusterUtil.java

/**
 * calles a getter method on instance obj. Iterates over all superclasses
 * //  w w w  .jav a  2 s.  c  o m
 * @param propName
 *            name of the property
 * @param obj
 *            instance of property
 * @return Object property value
 */
static public Object invokeGetPropertyMethod(String propName, Object obj) {

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

    String getMethName = "get" + propName.substring(0, 1).toUpperCase() + propName.substring(1);
    try {
        Method mGet = JDBClusterUtil.getMethod(obj, getMethName, (Class[]) null);
        return mGet.invoke(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);
    } 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.jdbcluster.privilege.PrivilegeCheckerImpl.java

/**
 * intersects required privileges against given privileges
 * //from   w  w  w .  jav  a2s .co m
 * @param clusterObject
 * @param methodName method name to check
 * @param args of method parameter
 * @return true if the privileges are sufficient
 */
public boolean checkAccess(IUser user, PrivilegedCluster clusterObject, String methodName, Object... args) {

    Assert.notNull(clusterObject, "clusterObject may not be null");
    Assert.hasLength(methodName, "methodName may not be null or \"\"");

    Method calledMethod = getMethod(clusterObject, methodName, args);
    return userPrivilegeIntersect(user, clusterObject, calledMethod, args);
}

From source file:com.erudika.para.security.CachedCsrfTokenRepository.java

/**
 * Sets the header name that the {@link CsrfToken} is expected to appear on
 * and the header that the response will contain the {@link CsrfToken}.
 *
 * @param parameterName the new parameter name to use
 *///w ww  .ja v  a 2s . c om
public void setHeaderName(String parameterName) {
    Assert.hasLength(parameterName, "parameterName cannot be null or empty");
    this.parameterName = parameterName;
}

From source file:com.erudika.para.security.CachedCsrfTokenRepository.java

/**
 * Sets the {@link HttpServletRequest} parameter name that the {@link CsrfToken} is expected to appear on
 * @param parameterName the new parameter name to use
 *//*from w  w w. java 2  s.  c om*/
public void setParameterName(String parameterName) {
    Assert.hasLength(parameterName, "parameterName cannot be null or empty");
    this.parameterName = parameterName;
}

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

/**
 * intersects required privileges against given privileges
 * /*from  ww w .j  a v  a 2  s.  c o m*/
 * @param clusterObject cluster object instance
 * @param methodName method name to check
 * @param args array of parameter
 * @param argTypes array of parameter class objects
 * @return true if the privileges are sufficient
 */
public boolean checkAccess(IUser user, PrivilegedCluster clusterObject, String methodName, Object[] args,
        Class[] argTypes) {

    Assert.notNull(clusterObject, "clusterObject may not be null");
    Assert.hasLength(methodName, "methodName may not be null or \"\"");

    Method calledMethod = JDBClusterUtil.getMethod(clusterObject.getClass(), methodName, argTypes);
    return userPrivilegeIntersect(user, clusterObject, calledMethod, args);
}