List of usage examples for org.springframework.util Assert state
public static void state(boolean expression, Supplier<String> messageSupplier)
From source file:org.springframework.data.gemfire.function.FunctionContextInjectingArgumentResolver.java
private static int getArgumentTypePosition(Method method, Class<?> requiredType) { int index = 0; int position = -1; for (Class<?> parameterType : method.getParameterTypes()) { if (requiredType.equals(parameterType)) { Assert.state(position < 0, String.format("Method %s signature cannot contain more than one parameter of type %s.", method.getName(), requiredType.getName())); position = index;/* ww w. j a v a 2s. c o m*/ } index++; } return position; }
From source file:org.springframework.data.gemfire.function.GemfireFunctionUtils.java
/** * Determine the order position of a an annotated method parameter * * @param method the {@link Method} instance * @param targetAnnotationType the annotation * @param requiredTypes an array of valid parameter types for the annotation * @return the parameter position or -1 if the annotated parameter is not found *//*from www. j a v a2 s.co m*/ public static int getAnnotationParameterPosition(Method method, Class<?> targetAnnotationType, Class<?>[] requiredTypes) { int position = -1; Annotation[][] parameterAnnotations = method.getParameterAnnotations(); if (parameterAnnotations.length > 0) { Class<?>[] parameterTypes = method.getParameterTypes(); List<Class<?>> requiredTypesList = Arrays.asList(requiredTypes); for (int index = 0; index < parameterAnnotations.length; index++) { Annotation[] annotations = parameterAnnotations[index]; if (annotations.length > 0) { for (Annotation annotation : annotations) { if (annotation.annotationType().equals(targetAnnotationType)) { Assert.state(position < 0, String.format( "Method %s signature cannot contain more than one parameter annotated with type %s", method.getName(), targetAnnotationType.getName())); boolean isRequiredType = false; for (Class<?> requiredType : requiredTypesList) { if (requiredType.isAssignableFrom(parameterTypes[index])) { isRequiredType = true; break; } } Assert.isTrue(isRequiredType, String.format( "Parameter of type %s annotated with %s must be assignable from one of type %s in method %s", parameterTypes[index], targetAnnotationType.getName(), StringUtils.arrayToCommaDelimitedString(requiredTypes), method.getName())); position = index; } } } } } return position; }
From source file:org.springframework.data.gemfire.snapshot.SnapshotServiceFactoryBean.java
/** * Gets a reference to the GemFire Cache for which the snapshot will be taken. * * @return the GemFire Cache used to create an instance of CacheSnapshotService. * @throws IllegalStateException if the Cache argument is null. * @see com.gemstone.gemfire.cache.Cache * @see #setCache(Cache)//from ww w . j a v a 2 s . c o m */ protected Cache getCache() { Assert.state(cache != null, "The GemFire Cache was not properly initialized"); return cache; }
From source file:org.springframework.data.gemfire.support.GemfireBeanFactoryLocator.java
/** * Resolves a single Spring {@link BeanFactory} from the mapping of registered bean factories. * * This class method is synchronized because it contains a "compound action", even though separate actions * are performed on a {@link ConcurrentMap}, the actions are not independent and therefore must operate * atomically./*from ww w . j av a 2 s. com*/ * * @return a single Spring {@link BeanFactory} from the registry. * @throws IllegalStateException if the registry contains more than 1, or no * Spring {@link BeanFactory bean factories}. * @see org.springframework.beans.factory.BeanFactory */ protected static synchronized BeanFactory resolveSingleBeanFactory() { if (!BEAN_FACTORIES.isEmpty()) { boolean allTheSameBeanFactory = true; BeanFactory currentBeanFactory = null; for (BeanFactory beanFactory : BEAN_FACTORIES.values()) { allTheSameBeanFactory &= nullOrEquals(currentBeanFactory, beanFactory); currentBeanFactory = beanFactory; if (!allTheSameBeanFactory) { break; } } Assert.state(allTheSameBeanFactory, String.format( "BeanFactory key must be specified when more than one BeanFactory %s is registered", new TreeSet(BEAN_FACTORIES.keySet()).toString())); return BEAN_FACTORIES.values().iterator().next(); } return null; }
From source file:org.springframework.data.gemfire.support.SpringContextBootstrappingInitializer.java
/** * Gets a reference to the Spring ApplicationContext constructed, configured and initialized inside the GemFire * Server-based JVM process.// w w w. j ava2 s. c om * * @return a reference to the Spring ApplicationContext bootstrapped by GemFire. * @see org.springframework.context.ConfigurableApplicationContext */ public static synchronized ConfigurableApplicationContext getApplicationContext() { Assert.state(applicationContext != null, "The Spring ApplicationContext was not configured and initialized properly!"); return applicationContext; }