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.springframework.context.RefreshedContextAttacher.java

protected void onContextInitialized(ApplicationContext context) {
    Assert.state(context != null, "No initialized context provided");
}

From source file:org.springframework.context.support.ApplicationObjectSupport.java

/**
 * Obtain the ApplicationContext for actual use.
 * @return the ApplicationContext (never {@code null})
 * @throws IllegalStateException in case of no ApplicationContext set
 * @since 5.0/*from w  w  w  .  j  a v  a  2  s  .  co m*/
 */
protected final ApplicationContext obtainApplicationContext() {
    ApplicationContext applicationContext = getApplicationContext();
    Assert.state(applicationContext != null, "No ApplicationContext");
    return applicationContext;
}

From source file:org.springframework.context.support.DefaultLifecycleProcessor.java

private ConfigurableListableBeanFactory getBeanFactory() {
    ConfigurableListableBeanFactory beanFactory = this.beanFactory;
    Assert.state(beanFactory != null, "No BeanFactory available");
    return beanFactory;
}

From source file:org.springframework.context.weaving.DefaultContextLoadTimeWeaver.java

@Override
public void addTransformer(ClassFileTransformer transformer) {
    Assert.state(this.loadTimeWeaver != null, "Not initialized");
    this.loadTimeWeaver.addTransformer(transformer);
}

From source file:org.springframework.context.weaving.DefaultContextLoadTimeWeaver.java

@Override
public ClassLoader getInstrumentableClassLoader() {
    Assert.state(this.loadTimeWeaver != null, "Not initialized");
    return this.loadTimeWeaver.getInstrumentableClassLoader();
}

From source file:org.springframework.context.weaving.DefaultContextLoadTimeWeaver.java

@Override
public ClassLoader getThrowawayClassLoader() {
    Assert.state(this.loadTimeWeaver != null, "Not initialized");
    return this.loadTimeWeaver.getThrowawayClassLoader();
}

From source file:org.springframework.core.convert.support.StringToClassConverter.java

public StringToClassConverter(ClassLoader cl) {
    Assert.state(cl != null, "No loader provided");
    loader = cl;
}

From source file:org.springframework.data.document.couchdb.core.CouchTemplate.java

public <T> T findOne(String id, Class<T> targetClass) {
    Assert.state(defaultDocumentUrl != null, "defaultDatabaseUrl must be set to use this method");
    try {/*from   w  ww.  j a  v  a2s  .  c  om*/
        return restOperations.getForObject(defaultDocumentUrl, targetClass, id);
        //TODO check this exception translation and centralize.
    } catch (HttpClientErrorException clientError) {
        if (clientError.getStatusCode() == HttpStatus.NOT_FOUND) {
            throw new DocumentRetrievalFailureException(defaultDocumentUrl + "/" + id);
        }
        throw new CouchUsageException(clientError);
    } catch (HttpServerErrorException serverError) {
        throw new CouchServerResourceUsageException(serverError);
    } catch (RestClientException otherError) {
        throw new UncategorizedCouchDataAccessException(otherError);
    }
}

From source file:org.springframework.data.document.couchdb.core.CouchTemplate.java

public <T> T findOne(URI uri, Class<T> targetClass) {
    Assert.state(uri != null, "uri must be set to use this method");
    try {/*from  w  w  w.j av  a2s.  co  m*/
        return restOperations.getForObject(uri, targetClass);
        //TODO check this exception translation and centralize.
    } catch (HttpClientErrorException clientError) {
        if (clientError.getStatusCode() == HttpStatus.NOT_FOUND) {
            throw new DocumentRetrievalFailureException(uri.getPath());
        }
        throw new CouchUsageException(clientError);
    } catch (HttpServerErrorException serverError) {
        throw new CouchServerResourceUsageException(serverError);
    } catch (RestClientException otherError) {
        throw new UncategorizedCouchDataAccessException(otherError);
    }
}

From source file:org.springframework.data.gemfire.function.FunctionContextInjectingArgumentResolver.java

public FunctionContextInjectingArgumentResolver(Method method) {
    this.method = method;

    int regionDataAnnotationParameterPosition = GemfireFunctionUtils.getAnnotationParameterPosition(method,
            RegionData.class, new Class[] { Map.class });

    int regionTypeParameterPosition = getArgumentTypePosition(method, Region.class);

    if (regionDataAnnotationParameterPosition >= 0 && regionTypeParameterPosition >= 0) {
        Assert.isTrue(regionDataAnnotationParameterPosition == regionTypeParameterPosition, String.format(
                "Function method signature for method %s cannot contain an @RegionData parameter and a different Region type parameter",
                method.getName()));//from w  ww  . ja  va2  s  .c  o m
    }

    regionParameterPosition = (regionDataAnnotationParameterPosition >= 0
            ? regionDataAnnotationParameterPosition
            : (regionTypeParameterPosition >= 0 ? regionTypeParameterPosition : -1));

    filterParameterPosition = GemfireFunctionUtils.getAnnotationParameterPosition(method, Filter.class,
            new Class[] { Set.class });

    if (regionParameterPosition >= 0 && filterParameterPosition >= 0) {
        Assert.state(regionParameterPosition != filterParameterPosition,
                "region parameter and filter parameter must be different");
    }

    functionContextParameterPosition = getArgumentTypePosition(method, FunctionContext.class);

    resultSenderParameterPosition = getArgumentTypePosition(method, ResultSender.class);
}