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:net.yasion.common.core.bean.wrapper.impl.ExtendedBeanWrapperImpl.java

/**
 * Obtain a lazily initializted CachedIntrospectionResults instance for the wrapped object.
 *//*ww w  . j  a  va2s  . c o  m*/
private CachedIntrospectionResults getCachedIntrospectionResults() {
    Assert.state(this.object != null, "BeanWrapper does not hold a bean instance");
    if (this.cachedIntrospectionResults == null) {
        this.cachedIntrospectionResults = CachedIntrospectionResults.forClass(getWrappedClass());
    }
    return this.cachedIntrospectionResults;
}

From source file:nl.ivo2u.tiny.controller.TinyRestController.java

private static HttpServletRequest getCurrentRequest() {
    final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    Assert.state(requestAttributes != null, "Could not find current request via RequestContextHolder");
    Assert.isInstanceOf(ServletRequestAttributes.class, requestAttributes);
    final HttpServletRequest servletRequest = ((ServletRequestAttributes) requestAttributes).getRequest();
    Assert.state(servletRequest != null, "Could not find current HttpServletRequest");
    return servletRequest;
}

From source file:org.apache.nifi.controller.StandardProcessorNode.java

@Override
public void setAnnotationData(final String data) {
    Assert.state(!isRunning(), "Cannot set AnnotationData while processor is running");
    super.setAnnotationData(data);
}

From source file:org.broadleafcommerce.common.web.resource.BroadleafDefaultResourceResolverChain.java

private ResourceResolver getNext() {

    Assert.state(this.index <= this.resolvers.size(),
            "Current index exceeds the number of configured ResourceResolver's");

    if (this.index == (this.resolvers.size() - 1)) {
        return null;
    }/*from w w w.j a v  a 2 s  .c o  m*/

    this.index++;
    return this.resolvers.get(this.index);
}

From source file:org.broadleafcommerce.test.BroadleafGenericGroovyXmlWebContextLoader.java

/**
 * Configures web resources for the supplied web application context (WAC).
 *
 * <h4>Implementation Details</h4>
 *
 * <p>If the supplied WAC has no parent or its parent is not a WAC, the
 * supplied WAC will be configured as the Root WAC (see "<em>Root WAC
 * Configuration</em>" below).// ww w . ja va 2  s  . co m
 *
 * <p>Otherwise the context hierarchy of the supplied WAC will be traversed
 * to find the top-most WAC (i.e., the root); and the {@link ServletContext}
 * of the Root WAC will be set as the {@code ServletContext} for the supplied
 * WAC.
 *
 * <h4>Root WAC Configuration</h4>
 *
 * <ul>
 * <li>The resource base path is retrieved from the supplied
 * {@code WebMergedContextConfiguration}.</li>
 * <li>A {@link ResourceLoader} is instantiated for the {@link MockServletContext}:
 * if the resource base path is prefixed with "{@code classpath:/}", a
 * {@link DefaultResourceLoader} will be used; otherwise, a
 * {@link FileSystemResourceLoader} will be used.</li>
 * <li>A {@code MockServletContext} will be created using the resource base
 * path and resource loader.</li>
 * <li>The supplied {@link MergeXmlWebApplicationContext} is then stored in
 * the {@code MockServletContext} under the
 * {@link MergeXmlWebApplicationContext#ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE} key.</li>
 * <li>Finally, the {@code MockServletContext} is set in the
 * {@code MergeXmlWebApplicationContext}.</li>
 *
 * @param context the merge xml web application context for which to configure the web
 * resources
 * @param webMergedConfig the merged context configuration to use to load the
 * merge xml web application context
 */
protected void configureWebResources(MergeXmlWebApplicationContext context,
        WebMergedContextConfiguration webMergedConfig) {

    ApplicationContext parent = context.getParent();

    // if the WAC has no parent or the parent is not a WAC, set the WAC as
    // the Root WAC:
    if (parent == null || (!(parent instanceof WebApplicationContext))) {
        String resourceBasePath = webMergedConfig.getResourceBasePath();
        ResourceLoader resourceLoader = resourceBasePath.startsWith(ResourceLoader.CLASSPATH_URL_PREFIX)
                ? new DefaultResourceLoader()
                : new FileSystemResourceLoader();

        ServletContext servletContext = new MockServletContext(resourceBasePath, resourceLoader);
        servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context);
        context.setServletContext(servletContext);
    } else {
        ServletContext servletContext = null;

        // find the Root WAC
        while (parent != null) {
            if (parent instanceof WebApplicationContext
                    && !(parent.getParent() instanceof WebApplicationContext)) {
                servletContext = ((WebApplicationContext) parent).getServletContext();
                break;
            }
            parent = parent.getParent();
        }
        Assert.state(servletContext != null,
                "Failed to find Root MergeXmlWebApplicationContext in the context hierarchy");
        context.setServletContext(servletContext);
    }
}

From source file:org.cleverbus.core.common.asynch.msg.MessageServiceImpl.java

@Transactional
@Override/*w  ww .j a  v a  2 s.c  om*/
public void insertMessage(final Message message) {
    Assert.notNull(message, "the message must not be null");
    Assert.state(message.getState() == MsgStateEnum.NEW || message.getState() == MsgStateEnum.PROCESSING,
            "new message can be in NEW or PROCESSING state only");

    message.setLastUpdateTimestamp(new Date());

    messageDao.insert(message);

    Log.debug("Inserted new message " + message.toHumanString());
}

From source file:org.cloudfoundry.identity.uaa.client.ClientAdminEndpoints.java

@Override
public void afterPropertiesSet() throws Exception {
    Assert.state(clientRegistrationService != null, "A ClientRegistrationService must be provided");
    Assert.state(clientDetailsService != null, "A ClientDetailsService must be provided");
    Assert.state(clientDetailsValidator != null, "A ClientDetailsValidator must be provided");
}

From source file:org.cloudfoundry.identity.uaa.client.ClientAdminEndpoints.java

@RequestMapping(value = "/oauth/clients/{client}", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.OK)/*from   www  .  j av a 2  s  .  c o  m*/
@ResponseBody
public ClientDetails updateClientDetails(@RequestBody BaseClientDetails client,
        @PathVariable("client") String clientId) throws Exception {
    Assert.state(clientId.equals(client.getClientId()),
            String.format("The client id (%s) does not match the URL (%s)", client.getClientId(), clientId));
    ClientDetails details = client;
    try {
        ClientDetails existing = getClientDetails(clientId);
        if (existing == null) {
            //TODO - should we proceed? Previous code did by throwing a NPE and logging a warning
            logger.warn("Couldn't fetch client config, null, for client_id: " + clientId);
        } else {
            details = syncWithExisting(existing, client);
        }
    } catch (Exception e) {
        logger.warn("Couldn't fetch client config for client_id: " + clientId, e);
    }
    details = clientDetailsValidator.validate(details, Mode.MODIFY);
    clientRegistrationService.updateClientDetails(details);
    clientUpdates.incrementAndGet();
    return removeSecret(clientDetailsService.retrieve(clientId));
}

From source file:org.cloudfoundry.identity.uaa.client.ClientAdminEndpointsValidator.java

@Override
public void afterPropertiesSet() throws Exception {
    Assert.state(clientDetailsService != null, "A ClientDetailsService must be provided");
}

From source file:org.cloudfoundry.identity.uaa.config.YamlConfigurationValidator.java

@Override
@SuppressWarnings("unchecked")
public void afterPropertiesSet() throws Exception {

    Assert.state(yaml != null, "Yaml document should not be null");

    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();

    try {/*from   w  ww. j a v  a  2 s . c om*/
        logger.trace("Yaml document is\n" + yaml);
        configuration = (T) (new Yaml(constructor)).load(yaml);
        Set<ConstraintViolation<T>> errors = validator.validate(configuration);

        if (!errors.isEmpty()) {
            logger.error("YAML configuration failed validation");
            for (ConstraintViolation<?> error : errors) {
                logger.error(error.getPropertyPath() + ": " + error.getMessage());
            }
            if (exceptionIfInvalid) {
                @SuppressWarnings("rawtypes")
                ConstraintViolationException summary = new ConstraintViolationException((Set) errors);
                throw summary;
            }
        }
    } catch (YAMLException e) {
        if (exceptionIfInvalid) {
            throw e;
        }
        logger.error("Failed to load YAML validation bean. Your YAML file may be invalid.", e);
    }
}