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:com.joshlong.esb.springintegration.modules.nativefs.NativeFileSystemMonitor.java

public void init() {
    additions = new LinkedBlockingQueue<String>(this.maxQueueValue);

    boolean goodDirToMonitor = (directoryToMonitor.isDirectory() && directoryToMonitor.exists());

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

    if (this.executor == null) {
        this.executor = new SimpleAsyncTaskExecutor();
    }

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

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

/**
 * <p>afterPropertiesSet</p>
 *//*from   w  ww. j  a va 2 s  . c o m*/
@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");
    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");

    m_resourceWalker.setResourceDao(getResourceDao());
    m_resourceWalker.setVisitor(getVisitor());
    m_resourceWalker.afterPropertiesSet();
}

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

@Transactional
public Customer createAccount(Customer customer) {
    Assert.state(!customer.hasAccount(), String.format("Customer [%s] already has an account", customer));

    return getCustomerRepository().save(setId(customer.with(newAccountNumber())));
}

From source file:org.openscada.da.server.spring.tools.csv.CSVLoader.java

@Override
public void afterPropertiesSet() throws Exception {
    Assert.notNull(this.hive, "'hive' must not be null");
    Assert.state(this.resource != null || this.data != null,
            "'resource' and 'data' are both unset. One must be set!");
    Assert.notNull(this.storages, "'storages' must not be null");

    load();//  w w  w .  ja va2  s  .c om
}

From source file:com.autentia.wuija.widget.UploadFile.java

public File getFile() {
    Assert.state(isSavedFile(), "There is no saved file.");
    return savedFileInfo.getFile();
}

From source file:admin.service.JdbcSearchableJobExecutionDao.java

/**
 * @see JdbcJobExecutionDao#afterPropertiesSet()
 *///w  w w . jav a  2s  .c  o  m
@Override
public void afterPropertiesSet() throws Exception {

    Assert.state(dataSource != null, "DataSource must be provided");

    if (getJdbcTemplate() == null) {
        setJdbcTemplate(new JdbcTemplate(dataSource));
    }
    setJobExecutionIncrementer(new AbstractDataFieldMaxValueIncrementer() {
        @Override
        protected long getNextKey() {
            return 0;
        }
    });

    allExecutionsPagingQueryProvider = getPagingQueryProvider();
    byJobNamePagingQueryProvider = getPagingQueryProvider("I.JOB_NAME=?");

    super.afterPropertiesSet();

}

From source file:com.autentia.wuija.view.ApplicationBreadcrumb.java

public void backward() {
    Assert.state(viewsStack.size() > 1, "You cannot go backward from the firs view. There is nothing more !!!");

    final View currentView = viewsStack.removeFirst();

    viewsStack.peekFirst().setVisible(true);

    currentView.setVisible(false);/*from  ww  w . jav a2 s . c om*/
}

From source file:com.netflix.spinnaker.fiat.roles.google.GoogleDirectoryUserRolesProvider.java

@Override
public void afterPropertiesSet() throws Exception {
    Assert.state(config.getDomain() != null, "Supply a domain");
    Assert.state(config.getAdminUsername() != null, "Supply an admin username");
}

From source file:org.cleverbus.api.event.EventNotifierBase.java

/**
 * Gets {@link ProducerTemplate} default instance from Camel Context.
 *
 * @return ProducerTemplate/*from  ww  w. j  a v  a2 s.c om*/
 * @throws IllegalStateException when there is no ProducerTemplate
 */
public ProducerTemplate getProducerTemplate() {
    if (!isStarted() && !isStarting()) {
        throw new IllegalStateException(getClass().getName() + " is not started so far!");
    }

    Set<ProducerTemplate> templates = camelContext.getRegistry().findByType(ProducerTemplate.class);
    Assert.state(templates.size() >= 1, "ProducerTemplate must be at least one.");

    return templates.iterator().next();
}

From source file:com.autentia.wuija.persistence.impl.hibernate.HibernateTestUtils.java

/**
 * Mtodo pensado para usar en los test, de forma que para la ejecucin tengamos una nica sesin. Sera similar a
 * clases como <code>penSessionInViewFilter</code>. La idea es invocar este mtodo en un <code>@After</code>.
 * <p>//from   w w  w.  j  a  va  2  s  .c o  m
 * Este mtodo se debera invocar una nica vez.
 * <p>
 * Este mtodo se encarga de cerra la sessin que est "attacha" al contexto, y que se abri con el mtodo
 * {@link #openSessionAndAttachToContext()}.
 */
public void closeSessionFromContext() {
    Assert.state(sessionAlreadyOpened != null,
            "There is not opened session. You have to call openSessionAndAttachToContext() method before this one");

    if (log.isTraceEnabled()) {
        log.trace("Closing session with SessionFactory: " + ObjectUtils.identityToString(sessionFactory));
    }

    final SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager
            .unbindResource(sessionFactory);
    final Session session = sessionHolder.getSession();

    Assert.state(sessionAlreadyOpened == session, "You are trying to close session: "
            + ObjectUtils.identityToString(session) + ", but this is not de actual opened session");
    sessionAlreadyOpened = null;

    SessionFactoryUtils.closeSession(session);

    if (log.isDebugEnabled()) {
        log.debug("Closed Session: " + ObjectUtils.identityToString(session));
    }
}