List of usage examples for org.springframework.util Assert state
public static void state(boolean expression, Supplier<String> messageSupplier)
From source file:com.payu.ratel.client.ContextAnnotationAutowireCandidateResolver.java
protected Object buildLazyResolutionProxy(final DependencyDescriptor descriptor, final String beanName) { Assert.state(getBeanFactory() instanceof DefaultListableBeanFactory, "BeanFactory needs to be a DefaultListableBeanFactory"); final DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) getBeanFactory(); TargetSource ts = new TargetSource() { @Override/*from w w w . j a v a 2s . c o m*/ public Class<?> getTargetClass() { return descriptor.getDependencyType(); } @Override public boolean isStatic() { return false; } @Override public Object getTarget() { return beanFactory.doResolveDependency(descriptor, beanName, null, null); } @Override public void releaseTarget(Object target) { } }; ProxyFactory pf = new ProxyFactory(); pf.setTargetSource(ts); Class<?> dependencyType = descriptor.getDependencyType(); if (dependencyType.isInterface()) { pf.addInterface(dependencyType); } return pf.getProxy(beanFactory.getBeanClassLoader()); }
From source file:net.community.chest.gitcloud.facade.backend.git.BackendReceivePackFactory.java
@Inject public BackendReceivePackFactory(@Value(RECEIVE_TIMEOUT_SEC_INJECTION_VALUE) int timeoutValue) { Assert.state(timeoutValue > 0, "Bad timeout value: " + timeoutValue); receiveTimeoutValue = timeoutValue;//from w w w.j av a 2 s .c o m synchronized (holder) { Assert.state(holder.get() == null, "Double registered factory"); holder.set(this); } }
From source file:org.opencredo.couchdb.core.CouchDbDocumentTemplate.java
public <T> T readDocument(String id, Class<T> documentType) throws CouchDbOperationException { Assert.state(defaultDocumentUrl != null, "defaultDatabaseUrl must be set to use this method"); try {/*from www . ja va 2 s. c om*/ return restOperations.getForObject(defaultDocumentUrl, documentType, id); } catch (RestClientException e) { throw new CouchDbOperationException("Unable to communicate with CouchDB", e); } }
From source file:com.snowstore.mercury.indicator.DataSourceHealthIndicator.java
@Override public void afterPropertiesSet() throws Exception { try {//from w ww .jav a2 s. co m Assert.state(this.dataSource != null, "DataSource for DataSourceHealthIndicator must be specified"); this.jdbcTemplate = new JdbcTemplate(dataSource); } catch (Exception e) { valid = false; } }
From source file:org.cleverbus.core.alerts.EmailAlertListenerSupport.java
/** * Default implementation is to send email notification. * If you need to implement whatever else then override {@link #onAlert(AlertInfo)} with custom actions. * * @param alert the activated alert/*from w ww . ja va 2 s . co m*/ * @param actualCount the actual count of items */ @Override public final void onAlert(AlertInfo alert, long actualCount) { Log.debug("onAlert (" + alert.toHumanString() + ")"); // use default subject or body if not defined specific one String subject = StringUtils.isNotEmpty(alert.getNotificationSubject()) ? formatSubject(alert) : String.format(DEFAULT_ALERT_SUBJECT, alert.getId()); String body = StringUtils.isNotEmpty(alert.getNotificationBody()) ? formatBody(alert, actualCount) : String.format(DEFAULT_ALERT_BODY, actualCount, alert.getId(), alert.getLimit()); Assert.state(StringUtils.isNotEmpty(subject), "subject can't be empty"); Assert.state(StringUtils.isNotEmpty(body), "body can't be empty"); // send email try { sendEmail(subject, body); } catch (Exception ex) { Log.error("Error occurred during email sending for alert id=" + alert.getId(), ex); } // do whatever else try { onAlert(alert); } catch (Exception ex) { Log.error("Error occurred during final action for alert id=" + alert.getId(), ex); } }
From source file:org.wallride.autoconfigure.WebAdminComponentScanRegistrar.java
private Set<String> getPackagesToScan(AnnotationMetadata metadata) { AnnotationAttributes attributes = AnnotationAttributes .fromMap(metadata.getAnnotationAttributes(WebAdminComponentScan.class.getName())); String[] value = attributes.getStringArray("value"); String[] basePackages = attributes.getStringArray("basePackages"); Class<?>[] basePackageClasses = attributes.getClassArray("basePackageClasses"); if (!ObjectUtils.isEmpty(value)) { Assert.state(ObjectUtils.isEmpty(basePackages), "@WebAdminComponentScan basePackages and value attributes are mutually exclusive"); }/*from w ww .j ava 2 s. c om*/ Set<String> packagesToScan = new LinkedHashSet<String>(); packagesToScan.addAll(Arrays.asList(value)); packagesToScan.addAll(Arrays.asList(basePackages)); for (Class<?> basePackageClass : basePackageClasses) { packagesToScan.add(ClassUtils.getPackageName(basePackageClass)); } if (packagesToScan.isEmpty()) { return Collections.singleton(ClassUtils.getPackageName(metadata.getClassName())); } return packagesToScan; }
From source file:org.mvnsearch.spring.boot.mybatis.MybatisAutoConfiguration.java
@PostConstruct public void checkConfigFileExists() { Assert.state(properties.getConfig() != null, "Cannot find config location: (please add config file or check your Mybatis configuration)"); if (this.properties.getConfig() != null) { Resource resource = this.resourceLoader.getResource(this.properties.getConfig()); Assert.state(resource.exists(), "Cannot find config location: " + resource + " (please add config file or check your Mybatis configuration)"); }// w w w . j a v a 2s . co m }
From source file:org.cloudfoundry.identity.uaa.client.SocialClientUserDetailsSource.java
@Override public void afterPropertiesSet() { Assert.state(userInfoUrl != null, "User info URL must be provided"); Assert.state(restTemplate != null, "RestTemplate URL must be provided"); }
From source file:org.cleverbus.core.common.extension.AbstractExtensionConfigurationLoader.java
/** * Loads Spring configuration files.//from w w w .j ava 2 s .c om * Each config represents root configuration file for one extension and new child Spring context will be * created for each extension. * * @param extConfigLocations Extension configuration locations */ protected final void loadExtensions(String... extConfigLocations) { Assert.state(parentContext != null, "parent context is not defined"); Assert.state(camelContext != null, "camel context is not defined"); if (extConfigLocations == null) { return; } int count = 0; for (String extConfigLocation : extConfigLocations) { try { loadExtension(extConfigLocation, ++count); } catch (Exception ex) { String msg = "error during extension configuration '" + extConfigLocation + "' loading"; Log.error(msg, ex); throw new ExtensionConfigurationException(msg, ex); } } }