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.pivotal.gemfire.cache.GemFireBasedSerialAsyncEventQueueTest.java

protected Region<String, String> getTestRegion() {
    Assert.state(testRegion != null, "The 'TestRegion' was not properly configured and initialized!");
    return testRegion;
}

From source file:com.saysth.commons.quartz.CronTriggerBean.java

/**
 * Set the start delay in milliseconds.//w  w  w  .  j  a  va2s . c o m
 * <p>
 * The start delay is added to the current system time (when the bean
 * starts) to control the {@link #setStartTime start time} of the trigger.
 * <p>
 * If the start delay is non-zero it will <strong>always</strong> take
 * precedence over start time.
 * 
 * @param startDelay
 *            the start delay, in milliseconds.
 */
public void setStartDelay(long startDelay) {
    Assert.state(startDelay >= 0, "Start delay cannot be negative.");
    this.startDelay = startDelay;
}

From source file:admin.jmx.BatchMBeanExporter.java

@Override
public void afterPropertiesSet() {
    Assert.state(jobService != null, "A JobService must be provided");
    super.afterPropertiesSet();
}

From source file:tv.arte.resteventapi.core.presentation.decoration.RestEventApiControllerLinkBuilder.java

/**
 * Copy of {@link ServletUriComponentsBuilder#getCurrentRequest()} until SPR-10110 gets fixed.
 * //w w w  .j  a v  a  2s  .co  m
 * @return
 */
private static HttpServletRequest getCurrentRequest() {
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    Assert.state(requestAttributes != null, "Could not find current request via RequestContextHolder");
    Assert.isInstanceOf(ServletRequestAttributes.class, requestAttributes);
    HttpServletRequest servletRequest = ((ServletRequestAttributes) requestAttributes).getRequest();
    Assert.state(servletRequest != null, "Could not find current HttpServletRequest");
    return servletRequest;
}

From source file:com.siberhus.tdfl.mapping.BeanWrapLineMapper.java

/**
 * Check that precisely one of type or prototype bean name is specified.
 * /*from w w  w  . ja v a2s  .  c om*/
 * @throws IllegalStateException if neither is set or both properties are
 * set.
 * 
 * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
 */
public void afterPropertiesSet() throws Exception {
    Assert.state(name != null || type != null, "Either name or type must be provided.");
    Assert.state(name == null || type == null, "Both name and type cannot be specified together.");
}

From source file:org.opennms.ng.services.capsd.Capsd.java

/**
 * <p>onInit</p>//from   w  ww  . j a v a2s  . c o m
 */
protected void onInit() {
    BeanUtils.assertAutowiring(this);

    Assert.state(m_suspectRunner != null, "must set the suspectRunner property");
    Assert.state(m_rescanRunner != null, "must set the rescanRunner property");
    Assert.state(m_eventListener != null, "must set the eventListener property");

    if (System.getProperty("org.opennms.provisiond.enableDiscovery", "true").equalsIgnoreCase("true")) {
        throw new IllegalStateException("Provisiond is configured to handle discovery events. "
                + "Please disable Capsd in service-configuration.xml, or set "
                + "org.opennms.provisiond.enableDiscovery=false in opennms.properties!");
    }

    /*
      * First any new services are added to the services table
      * with a call to syncServices().
      *
      * Secondly the management state of interfaces and services
      * in the database is updated based on the latest configuration
      * information with a call to syncManagementState()
      *
      * Lastly the primary snmp interface state ('isSnmpPrimary')
      * of all interfaces which support SNMP is updated based on
      * the latest configuration information via a call to
      * syncSnmpPrimaryState()
      */

    LOG.debug("init: Loading services into database...");
    m_capsdDbSyncer.syncServices();

    LOG.debug("init: Syncing management state...");
    m_capsdDbSyncer.syncManagementState();

    LOG.debug("init: Syncing primary SNMP interface state...");
    m_capsdDbSyncer.syncSnmpPrimaryState();
}

From source file:org.opennms.ng.services.trapd.Trapd.java

/**
 * <p>onInit</p>/*from   ww w  .j av a  2s.com*/
 */
public synchronized void onInit() {
    BeanUtils.assertAutowiring(this);

    Assert.state(m_backlogQ != null, "backlogQ must be set");

    try {
        m_trapdIpMgr.dataSourceSync();
    } catch (final SQLException e) {
        LOG.error("init: Failed to load known IP address list", e);
        throw new UndeclaredThrowableException(e);
    }

    try {
        InetAddress address = getInetAddress();
        LOG.info("Listening on {}:{}", address == null ? "[all interfaces]" : InetAddressUtils.str(address),
                m_snmpTrapPort);
        SnmpUtils.registerForTraps(this, this, address, m_snmpTrapPort, m_snmpV3Users);
        m_registeredForTraps = true;

        LOG.debug("init: Creating the trap session");
    } catch (final IOException e) {
        if (e instanceof java.net.BindException) {
            Logging.withPrefix("OpenNMS.Manager", new Runnable() {
                @Override
                public void run() {
                    LOG.error(
                            "init: Failed to listen on SNMP trap port, perhaps something else is already listening?",
                            e);
                }
            });
            LOG.error("init: Failed to listen on SNMP trap port, perhaps something else is already listening?",
                    e);
        } else {
            LOG.error("init: Failed to initialize SNMP trap socket", e);
        }
        throw new UndeclaredThrowableException(e);
    }

    try {
        m_eventReader.open();
    } catch (final Throwable e) {
        LOG.error("init: Failed to open event reader", e);
        throw new UndeclaredThrowableException(e);
    }
}

From source file:com.frank.search.solr.core.query.FacetOptions.java

/**
 * @param fieldName//  w w w.java  2 s .c om
 * @return
 */
public final FacetOptions addFacetOnPivot(String... fieldnames) {
    Assert.state(fieldnames.length > 1, "2 or more fields required for pivot facets");
    for (String fieldname : fieldnames) {
        Assert.hasText(fieldname, "Fieldnames must not contain null/empty values");
    }

    this.facetOnPivotFields.add(new SimplePivotField(fieldnames));
    return this;
}

From source file:io.github.huherto.springyRecords.RecordMapper.java

/**
 * Extract the values for all columns in the current row.
 * <p>Utilizes public setters and result set metadata.
 * @see java.sql.ResultSetMetaData/*from  w  ww .j  a  va  2 s. c om*/
 */
@Override
public T mapRow(ResultSet rs, int rowNumber) throws SQLException {
    Assert.state(this.mappedClass != null, "Mapped class was not specified");

    T mappedObject;
    try {
        mappedObject = mappedClass.newInstance();
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    ResultSetMetaData rsmd = rs.getMetaData();
    int columnCount = rsmd.getColumnCount();

    for (int index = 1; index <= columnCount; index++) {
        String column = JdbcUtils.lookupColumnName(rsmd, index);
        Field field = this.mappedFields.get(column.replaceAll(" ", ""));
        if (field != null) {
            Object value = getColumnValue(rs, index, field);
            if (logger.isTraceEnabled() && rowNumber == 0) {
                logger.trace("Mapping column '" + column + "' to property '" + field.getName() + "' of type "
                        + field.getType());
            }
            try {
                field.set(mappedObject, value);
            } catch (IllegalArgumentException e) {
                if (value == null && primitivesDefaultedForNullValue) {
                    logger.debug("Intercepted IllegalArgumentException for row " + rowNumber + " and column '"
                            + column + "' with value " + value + " when setting property '" + field.getName()
                            + "' of type " + field.getType() + " on object: " + mappedObject);
                } else {
                    throw e;
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }

    return mappedObject;
}

From source file:org.trpr.platform.batch.impl.spring.jmx.BatchMetricsExporter.java

/**
 * Interface method implementation. Ensures that a {@link JobAdministrator} instance is set
 * @see org.springframework.jmx.export.MBeanExporter#afterPropertiesSet()
 *//*from   w w w.jav a 2  s. c o m*/
public void afterPropertiesSet() {
    Assert.state(jobAdministrator != null, "A JobAdministrator must be provided");
    super.afterPropertiesSet();
}