List of usage examples for org.springframework.util Assert isInstanceOf
public static void isInstanceOf(Class<?> type, @Nullable Object obj, Supplier<String> messageSupplier)
From source file:es.fcs.batch.integration.chunk.SerializableChunkProcessor.java
private void validate() { Assert.notNull(itemProcessor, "itemProcessor is required"); Assert.notNull(itemWriter, "itemWriter is required"); Assert.isInstanceOf(Serializable.class, itemProcessor, "itemProcessor must implement Serializable"); Assert.isInstanceOf(Serializable.class, itemWriter, "itemWriter must implement Serializable"); itemProcessorSerializable = (Serializable) itemProcessor; itemWriterSerializable = (Serializable) itemWriter; }
From source file:org.springmodules.validation.valang.functions.FunctionTests.java
public void testUpperCaseFunctionFail() { try {//from w ww . j a v a2 s .c om getUpperCaseFunction(null).getResult(null); fail("UpperCaseFunction should throw ValangException!"); } catch (ValangException e) { Assert.isInstanceOf(NullPointerException.class, e.getCause(), "Cause is not NullPointerException!"); } }
From source file:org.verinice.rest.security.VeriniceAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) { Assert.isInstanceOf(UsernamePasswordAuthenticationToken.class, authentication, messages.getMessage("AbstractUserDetailsAuthenticationProvider.onlySupports", "Only UsernamePasswordAuthenticationToken is supported")); // Determine username String username = (authentication.getPrincipal() == null) ? "NONE_PROVIDED" : authentication.getName(); boolean cacheWasUsed = true; UserDetails user = this.getUserCache().getUserFromCache(username); if (user == null) { cacheWasUsed = false;//from ww w .ja v a 2s . c o m try { user = retrieveUser(username, (UsernamePasswordAuthenticationToken) authentication); } catch (UsernameNotFoundException notFound) { logger.debug("User '" + username + "' not found"); if (hideUserNotFoundExceptions) { throw new BadCredentialsException(messages.getMessage( "AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials")); } else { throw notFound; } } catch (InternalAuthenticationServiceException e) { throw new BadCredentialsException(e.getMessage(), e); } Assert.notNull(user, "retrieveUser returned null - a violation of the interface contract"); } try { getPreAuthenticationChecks().check(user); additionalAuthenticationChecks(user, (UsernamePasswordAuthenticationToken) authentication); } catch (AuthenticationException exception) { if (cacheWasUsed) { // There was a problem, so try again after checking // we're using latest data (i.e. not from the cache) cacheWasUsed = false; user = retrieveUser(username, (UsernamePasswordAuthenticationToken) authentication); getPreAuthenticationChecks().check(user); additionalAuthenticationChecks(user, (UsernamePasswordAuthenticationToken) authentication); } else { throw exception; } } getPostAuthenticationChecks().check(user); if (!cacheWasUsed) { this.getUserCache().putUserInCache(user); } Object principalToReturn = user; if (isForcePrincipalAsString()) { principalToReturn = user.getUsername(); } return createSuccessAuthentication(principalToReturn, authentication, user); }
From source file:org.springmodules.validation.valang.functions.FunctionTests.java
public void testLowerCaseFunctionFail() { try {// ww w .ja v a2s. c o m getLowerCaseFunction(null).getResult(null); fail("LowerCaseFunction should throw ValangException!"); } catch (ValangException e) { Assert.isInstanceOf(NullPointerException.class, e.getCause(), "Cause is not NullPointerException!"); } }
From source file:grails.plugin.searchable.internal.compass.search.DefaultSuggestQueryMethod.java
public Object invoke(Object[] args) { if (!CompassMappingUtils.hasSpellCheckMapping(getCompass())) { throw new IllegalStateException( "Suggestions are only available when classes are mapped with \"spellCheck\" options, either at the class " + "or property level. The simplest way to do this is add spellCheck \"include\" to the domain class searchable mapping closure. " + "See the plugin/Compass documentation Mapping sections for details."); }//from w w w .j av a 2s . c o m if (!"true".equals(getCompass().getSettings().getSetting("compass.engine.spellcheck.enable"))) { throw new IllegalStateException( "Suggestions are only available when the Compass Spell Check feature is enabled, but currently it is not. " + "Please set Compass setting 'compass.engine.spellcheck.enable' to 'true'. " + "One way to so this is to use the SearchableConfiguration.groovy file (run \"grails install-searchable-config\") and " + "add \"'compass.engine.spellcheck.enable': 'true'\" to the compassSettings Map. " + "Also see the Spell Check section in the Compass docs for additional settings."); } Object query = SearchableMethodUtils.getQueryArgument(args); if (query instanceof Closure) { throw new UnsupportedOperationException( "Closure queries are not support for query suggestions, only String queries."); } Assert.isInstanceOf(String.class, query, "Only String queries are supported for query suggestions"); SuggestQueryCompassCallback suggestQueryCallback = new SuggestQueryCompassCallback(getCompass(), getDefaultOptions(), args); Map options = getOptions(args); suggestQueryCallback.applyOptions(options); suggestQueryCallback.setGrailsApplication(grailsApplication); suggestQueryCallback.setCompassQueryBuilder(compassQueryBuilder); return doInCompass(suggestQueryCallback); }
From source file:com.frank.search.solr.server.support.HttpSolrClientFactory.java
private boolean assertHttpClientInstance(HttpClient httpClient) { Assert.isInstanceOf(AbstractHttpClient.class, httpClient, "HttpClient has to be derivate of AbstractHttpClient in order to allow authentication."); return true;/*from w ww . ja v a2s . c o m*/ }
From source file:org.synyx.hades.dao.orm.GenericDaoSupport.java
/** * Asserts that the {@code EntityManager} implementation being used by the * dao is an instance of the given type. * /*w w w .j a v a 2s.co m*/ * @param clazz * @throws IllegalArgumentException if the entity manager is not of the * given type */ protected void assertEntityManagerClass(Class<? extends EntityManager> clazz) { Assert.isInstanceOf(clazz, entityManager, String.format( "%s can only be used with %s implementation! " + "Please check configuration or use %s instead!", getClass().getSimpleName(), clazz.getSimpleName(), GenericJpaDao.class.getSimpleName())); }
From source file:com.joshlong.examples.data.counter.CounterConfiguration.java
@Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { this.beanFactory = beanFactory; Assert.isInstanceOf(ConfigurableBeanFactory.class, beanFactory, "the context used must be an instance of " + ConfigurableBeanFactory.class.getName()); ConfigurableBeanFactory configurableBeanFactory = (ConfigurableBeanFactory) beanFactory; }
From source file:lodsve.core.condition.OnBeanCondition.java
private List<String> getMatchingBeans(ConditionContext context, BeanSearchSpec beans) { ConfigurableListableBeanFactory beanFactory = context.getBeanFactory(); if (beans.getStrategy() == SearchStrategy.PARENTS) { BeanFactory parent = beanFactory.getParentBeanFactory(); Assert.isInstanceOf(ConfigurableListableBeanFactory.class, parent, "Unable to use SearchStrategy.PARENTS"); beanFactory = (ConfigurableListableBeanFactory) parent; }/*ww w . j a v a 2 s . co m*/ if (beanFactory == null) { return Collections.emptyList(); } List<String> beanNames = new ArrayList<String>(); boolean considerHierarchy = beans.getStrategy() == SearchStrategy.ALL; for (String type : beans.getTypes()) { beanNames.addAll(getBeanNamesForType(beanFactory, type, context.getClassLoader(), considerHierarchy)); } for (String ignoredType : beans.getIgnoredTypes()) { beanNames.removeAll( getBeanNamesForType(beanFactory, ignoredType, context.getClassLoader(), considerHierarchy)); } for (String annotation : beans.getAnnotations()) { beanNames.addAll(Arrays.asList(getBeanNamesForAnnotation(beanFactory, annotation, context.getClassLoader(), considerHierarchy))); } for (String beanName : beans.getNames()) { if (containsBean(beanFactory, beanName, considerHierarchy)) { beanNames.add(beanName); } } return beanNames; }
From source file:com.github.lothar.security.acl.elasticsearch.repository.AclElasticsearchRepository.java
@Override public Page<T> search(SearchQuery query) { Assert.isInstanceOf(NativeSearchQuery.class, query, "NativeSearchQuery only are supported :("); NativeSearchQuery searchQuery = new NativeSearchQuery(and(query.getQuery(), aclFilter())); BeanUtils.copyProperties(query, searchQuery, "query"); return elasticsearchOperations.queryForPage(searchQuery, getEntityClass()); }