Example usage for org.springframework.util Assert state

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

Introduction

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

Prototype

public static void state(boolean expression, Supplier<String> messageSupplier) 

Source Link

Document

Assert a boolean expression, throwing an IllegalStateException if the expression evaluates to false .

Usage

From source file:org.spring.data.gemfire.app.service.UserService.java

protected UserDao getUserDao() {
    Assert.state(userDao != null, "A reference to the UserDao was not properly configured!");
    return userDao;
}

From source file:net.sf.gazpachoquest.services.user.impl.GroupServiceImpl.java

@Transactional(readOnly = false)
@Override/*from w w w . j a va  2s.  c  o m*/
public void addUserToGroup(User user, Integer groupId) {
    Group group = repository.findOne(groupId);
    Assert.notNull(group, "Group not found");
    Assert.state(!user.isNew(), "Persist user before adding to groups");

    user = respondentRepository.findOne(user.getId());
    Assert.notNull(user, "User not found");
    group.assignUser(user);
}

From source file:org.opennms.ng.dao.support.ResourceTreeWalker.java

/**
 * <p>afterPropertiesSet</p>
 *///ww  w.  j  a va  2  s .c om
@Override
public void afterPropertiesSet() {
    Assert.state(m_resourceDao != null, "property resourceDao must be set to a non-null value");
    Assert.state(m_visitor != null, "property visitor must be set to a non-null value");
}

From source file:org.spring.data.gemfire.cache.asyncqueue.QueueAsyncEventListener.java

public AsyncEventQueue getQueue() {
    Assert.state(queue != null, String.format(
            "A reference to the Async Event Queue on which this listener (%1$s) has been registered was not properly configured!",
            this));
    return queue;
}

From source file:biz.c24.io.spring.integration.config.XPathSelectorParser.java

@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {

    String evaluationType = element.getAttribute("evaluation-result-type");

    String expression = element.getAttribute("xpath-statement");
    String expressionRef = element.getAttribute("xpath-statement-ref");

    boolean hasRef = StringUtils.hasText(expressionRef);
    Assert.isTrue(hasRef ^ StringUtils.hasText(expression),
            "Exactly one of the 'xpath-statement' or 'xpath-statement-ref' attributes is required.");
    if (hasRef) {
        builder.addConstructorArgReference(expressionRef);
    } else {//from w  w  w  . j  a v  a2s .co m
        builder.addConstructorArgValue(expression);
    }

    String stringTestValue = element.getAttribute("string-test-value");

    if (evaluationType.equals("boolean")) {
        builder.getBeanDefinition()
                .setBeanClass(biz.c24.io.spring.integration.selector.C24BooleanTestXPathMessageSelector.class);
        Assert.state(!StringUtils.hasText(stringTestValue),
                "'string-test-value' should not be specified when 'evaluation-result-type' is boolean");
    } else if (evaluationType.equals("string")) {
        Assert.hasText(stringTestValue,
                "'string-test-value' must be specified when 'evaluation-result-type' is string");
        builder.addPropertyValue("valueToTestFor", stringTestValue);
        builder.getBeanDefinition().setBeanClass(
                biz.c24.io.spring.integration.selector.C24StringValueTestXPathMessageSelector.class);
    } else {
        throw new IllegalArgumentException("Unsupported value [" + evaluationType
                + "] for 'evaluation-result-type', expected boolean or string.");
    }
}

From source file:org.opennms.ng.dao.support.AttributeMatchingResourceVisitor.java

/**
 * <p>afterPropertiesSet</p>
 *
 * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
 *//*from   w ww. j ava 2s .c o  m*/
@Override
public void afterPropertiesSet() {
    Assert.state(m_attributeVisitor != null, "property attributeVisitor must be set to a non-null value");
    Assert.state(m_attributeMatch != null, "property attributeMatch must be set to a non-null value");
}

From source file:example.app.service.ContactsService.java

protected example.app.repo.jpa.ContactRepository getJpaContactRepository() {
    Assert.state(jpaContactRepository != null, "JPA ContactRepository was not properly initialized");
    return jpaContactRepository;
}

From source file:org.opennms.ng.dao.support.FilterWalker.java

/**
 * <p>afterPropertiesSet</p>
 *//*from   www .j a v a2s  .co  m*/
@Override
public void afterPropertiesSet() {
    Assert.state(m_visitor != null, "property visitor must be set to a non-null value");
    Assert.state(m_filterDao != null, "property filterDao must be set to a non-null value");
    Assert.state(m_nodeDao != null, "property nodeDao must be set to a non-null value");
    Assert.state(m_filter != null, "property filter must be set to a non-null value");
}

From source file:com.apress.prospringintegration.customadapters.inbound.eventdriven.fsmon.LinuxInotifyDirectoryMonitor.java

protected boolean exists(File dir) {
    boolean goodDirToMonitor = (dir.isDirectory() && dir.exists());

    Assert.notNull(dir, "the 'dir' parameter must not be null");

    if (!goodDirToMonitor) {
        if (!dir.exists()) {
            if (this.autoCreateDirectory) {
                if (!dir.mkdirs()) {
                    logger.debug(String.format("couldn't create directory %s", dir.getAbsolutePath()));
                }//from w w w  .j  av a 2 s.co  m
            }
        }
    }

    Assert.state(dir.exists(), "the directory " + dir.getAbsolutePath() + " doesn't exist");

    return dir.exists();
}