本文整理汇总了Java中org.springframework.util.StringUtils.hasLength方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtils.hasLength方法的具体用法?Java StringUtils.hasLength怎么用?Java StringUtils.hasLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.util.StringUtils
的用法示例。
在下文中一共展示了StringUtils.hasLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findAutowiringMetadata
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
private InjectionMetadata findAutowiringMetadata(String beanName, Class<?> clazz, PropertyValues pvs) {
// Fall back to class name as cache key, for backwards compatibility with custom callers.
String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
// Quick check on the concurrent map first, with minimal locking.
InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey);
if (InjectionMetadata.needsRefresh(metadata, clazz)) {
synchronized (this.injectionMetadataCache) {
metadata = this.injectionMetadataCache.get(cacheKey);
if (InjectionMetadata.needsRefresh(metadata, clazz)) {
if (metadata != null) {
clear(metadata, pvs);
}
try {
metadata = buildAutowiringMetadata(clazz);
this.injectionMetadataCache.put(cacheKey, metadata);
} catch (NoClassDefFoundError err) {
throw new IllegalStateException("Failed to introspect bean class [" + clazz.getName() +
"] for autowiring metadata: could not find class that it depends on", err);
}
}
}
}
return metadata;
}
示例2: validate
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
@Override
public void validate(Object obj, Errors errors) {
Pet pet = (Pet) obj;
String name = pet.getName();
// name validation
if (!StringUtils.hasLength(name)) {
errors.rejectValue("name", REQUIRED, REQUIRED);
}
// type validation
if (pet.isNew() && pet.getType() == null) {
errors.rejectValue("type", REQUIRED, REQUIRED);
}
// birth date validation
if (pet.getBirthDate() == null) {
errors.rejectValue("birthDate", REQUIRED, REQUIRED);
}
}
示例3: populateMetricDescriptor
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
private void populateMetricDescriptor(Descriptor desc, ManagedMetric metric) {
applyCurrencyTimeLimit(desc, metric.getCurrencyTimeLimit());
if (StringUtils.hasLength(metric.getPersistPolicy())) {
desc.setField(FIELD_PERSIST_POLICY, metric.getPersistPolicy());
}
if (metric.getPersistPeriod() >= 0) {
desc.setField(FIELD_PERSIST_PERIOD, Integer.toString(metric.getPersistPeriod()));
}
if (StringUtils.hasLength(metric.getDisplayName())) {
desc.setField(FIELD_DISPLAY_NAME, metric.getDisplayName());
}
if(StringUtils.hasLength(metric.getUnit())) {
desc.setField(FIELD_UNITS, metric.getUnit());
}
if(StringUtils.hasLength(metric.getCategory())) {
desc.setField(FIELD_METRIC_CATEGORY, metric.getCategory());
}
String metricType = (metric.getMetricType() == null) ? MetricType.GAUGE.toString() : metric.getMetricType().toString();
desc.setField(FIELD_METRIC_TYPE, metricType);
}
示例4: getHeaders
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
@Override
public HttpHeaders getHeaders() {
if (this.headers == null) {
this.headers = new HttpHeaders();
// Header field 0 is the status line for most HttpURLConnections, but not on GAE
String name = this.connection.getHeaderFieldKey(0);
if (StringUtils.hasLength(name)) {
this.headers.add(name, this.connection.getHeaderField(0));
}
int i = 1;
while (true) {
name = this.connection.getHeaderFieldKey(i);
if (!StringUtils.hasLength(name)) {
break;
}
this.headers.add(name, this.connection.getHeaderField(i));
i++;
}
}
return this.headers;
}
示例5: locateMBeanServer
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
* Attempt to find a locally running {@code MBeanServer}. Fails if no
* {@code MBeanServer} can be found. Logs a warning if more than one
* {@code MBeanServer} found, returning the first one from the list.
* @param agentId the agent identifier of the MBeanServer to retrieve.
* If this parameter is {@code null}, all registered MBeanServers are considered.
* If the empty String is given, the platform MBeanServer will be returned.
* @return the {@code MBeanServer} if found
* @throws org.springframework.jmx.MBeanServerNotFoundException
* if no {@code MBeanServer} could be found
* @see javax.management.MBeanServerFactory#findMBeanServer(String)
*/
public static MBeanServer locateMBeanServer(String agentId) throws MBeanServerNotFoundException {
MBeanServer server = null;
// null means any registered server, but "" specifically means the platform server
if (!"".equals(agentId)) {
List<MBeanServer> servers = MBeanServerFactory.findMBeanServer(agentId);
if (servers != null && servers.size() > 0) {
// Check to see if an MBeanServer is registered.
if (servers.size() > 1 && logger.isWarnEnabled()) {
logger.warn("Found more than one MBeanServer instance" +
(agentId != null ? " with agent id [" + agentId + "]" : "") +
". Returning first from list.");
}
server = servers.get(0);
}
}
if (server == null && !StringUtils.hasLength(agentId)) {
// Attempt to load the PlatformMBeanServer.
try {
server = ManagementFactory.getPlatformMBeanServer();
}
catch (SecurityException ex) {
throw new MBeanServerNotFoundException("No specific MBeanServer found, " +
"and not allowed to obtain the Java platform MBeanServer", ex);
}
}
if (server == null) {
throw new MBeanServerNotFoundException(
"Unable to locate an MBeanServer instance" +
(agentId != null ? " with agent id [" + agentId + "]" : ""));
}
if (logger.isDebugEnabled()) {
logger.debug("Found MBeanServer: " + server);
}
return server;
}
示例6: getMatchOutcome
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
String clientId = context.getEnvironment()
.getProperty("security.oauth2.client.client-id");
ConditionMessage.Builder message = ConditionMessage
.forCondition("OAuth Client ID");
if (StringUtils.hasLength(clientId)) {
return ConditionOutcome.match(message
.foundExactly("security.oauth2.client.client-id property"));
}
return ConditionOutcome.noMatch(message
.didNotFind("security.oauth2.client.client-id property").atAll());
}
开发者ID:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:15,代码来源:OAuth2RestOperationsConfiguration.java
示例7: createConnectionFactory
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
* Creates and returns a JmsConnectionFactory instance using the current
* configuration to prepare the factory for use.
*
* @param factoryClass
* The type of JmsConnectionFactory to create.
*
* @return a newly created and configured JmsConnectionFactory instance.
*/
public JmsConnectionFactory createConnectionFactory(Class<JmsConnectionFactory> factoryClass) {
try {
JmsConnectionFactory factory = new JmsConnectionFactory();
factory.setRemoteURI(getRemoteURI());
// Override the URI options with configuration values, but only if
// the value is actually set.
if (StringUtils.hasLength(properties.getUsername())) {
factory.setUsername(properties.getUsername());
}
if (StringUtils.hasLength(properties.getPassword())) {
factory.setPassword(properties.getPassword());
}
if (StringUtils.hasLength(properties.getClientId())) {
factory.setClientID(properties.getClientId());
}
if (properties.isReceiveLocalOnly() != null) {
factory.setReceiveLocalOnly(properties.isReceiveLocalOnly());
}
if (properties.isReceiveNoWaitLocalOnly() != null) {
factory.setReceiveNoWaitLocalOnly(properties.isReceiveNoWaitLocalOnly());
}
configureDeserializationPolicy(properties, factory);
return factory;
} catch (Exception ex) {
LOG.error("Exception while createing Qpid JMS Connection Factory.", ex);
throw new IllegalStateException("Failed to create the Qpid JMS ConnectionFactory, " +
"make sure the client Jar is on the Classpath.", ex);
}
}
示例8: populateMBeanDescriptor
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
* Adds descriptor fields from the {@code ManagedResource} attribute
* to the MBean descriptor. Specifically, adds the {@code currencyTimeLimit},
* {@code persistPolicy}, {@code persistPeriod}, {@code persistLocation}
* and {@code persistName} descriptor fields if they are present in the metadata.
*/
@Override
protected void populateMBeanDescriptor(Descriptor desc, Object managedBean, String beanKey) {
ManagedResource mr = this.attributeSource.getManagedResource(getClassToExpose(managedBean));
if (mr == null) {
throw new InvalidMetadataException(
"No ManagedResource attribute found for class: " + getClassToExpose(managedBean));
}
applyCurrencyTimeLimit(desc, mr.getCurrencyTimeLimit());
if (mr.isLog()) {
desc.setField(FIELD_LOG, "true");
}
if (StringUtils.hasLength(mr.getLogFile())) {
desc.setField(FIELD_LOG_FILE, mr.getLogFile());
}
if (StringUtils.hasLength(mr.getPersistPolicy())) {
desc.setField(FIELD_PERSIST_POLICY, mr.getPersistPolicy());
}
if (mr.getPersistPeriod() >= 0) {
desc.setField(FIELD_PERSIST_PERIOD, Integer.toString(mr.getPersistPeriod()));
}
if (StringUtils.hasLength(mr.getPersistName())) {
desc.setField(FIELD_PERSIST_NAME, mr.getPersistName());
}
if (StringUtils.hasLength(mr.getPersistLocation())) {
desc.setField(FIELD_PERSIST_LOCATION, mr.getPersistLocation());
}
}
示例9: setProperty
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
* Set the property to compare.
* <p>If the property was the same as the current, the sort is reversed if
* "toggleAscendingOnProperty" is activated, else simply ignored.
* @see #setToggleAscendingOnProperty
*/
public void setProperty(String property) {
if (!StringUtils.hasLength(property)) {
this.property = "";
}
else {
// Implicit toggling of ascending?
if (isToggleAscendingOnProperty()) {
this.ascending = (!property.equals(this.property) || !this.ascending);
}
this.property = property;
}
}
示例10: getDelegate
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
private Delegate<?> getDelegate() {
String serverLocation = System.getProperty(SERVER_PROPERTY);
if (StringUtils.hasLength(serverLocation) && !serverLocation.startsWith("$")) {
return new RunningServerDelegate(serverLocation);
}
return new DockerDelegate();
}
示例11: getBean
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
* 获取bean实例对象
*
* @param name bean名称
* @param <T> 泛型类
* @return Object 一个以所给名字注册的bean的实例
* @throws BeansException 获取bean失败异常
*/
public static <T> T getBean(String name) throws BeansException {
if (!StringUtils.hasLength(name)){
return null;
}
char[] chars = name.toCharArray();
chars[0] = String.valueOf(chars[0]).toLowerCase().charAt(0);
return (T) beanFactory.getBean(String.valueOf(chars));
}
示例12: initUserTransactionAndTransactionManager
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
* Initialize the UserTransaction as well as the TransactionManager handle.
* @throws TransactionSystemException if initialization failed
*/
protected void initUserTransactionAndTransactionManager() throws TransactionSystemException {
if (this.userTransaction == null) {
// Fetch JTA UserTransaction from JNDI, if necessary.
if (StringUtils.hasLength(this.userTransactionName)) {
this.userTransaction = lookupUserTransaction(this.userTransactionName);
this.userTransactionObtainedFromJndi = true;
}
else {
this.userTransaction = retrieveUserTransaction();
if (this.userTransaction == null && this.autodetectUserTransaction) {
// Autodetect UserTransaction at its default JNDI location.
this.userTransaction = findUserTransaction();
}
}
}
if (this.transactionManager == null) {
// Fetch JTA TransactionManager from JNDI, if necessary.
if (StringUtils.hasLength(this.transactionManagerName)) {
this.transactionManager = lookupTransactionManager(this.transactionManagerName);
}
else {
this.transactionManager = retrieveTransactionManager();
if (this.transactionManager == null && this.autodetectTransactionManager) {
// Autodetect UserTransaction object that implements TransactionManager,
// and check fallback JNDI locations otherwise.
this.transactionManager = findTransactionManager(this.userTransaction);
}
}
}
// If only JTA TransactionManager specified, create UserTransaction handle for it.
if (this.userTransaction == null && this.transactionManager != null) {
this.userTransaction = buildUserTransaction(this.transactionManager);
}
}
示例13: hasLength
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
public static void hasLength(String text, RuntimeException throwIfAssertFail) {
if (!StringUtils.hasLength(text)) {
throw throwIfAssertFail;
}
}
示例14: doesNotContain
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
public static void doesNotContain(String textToSearch, String substring, RuntimeException throwIfAssertFail) {
if (StringUtils.hasLength(textToSearch) && StringUtils.hasLength(substring)
&& textToSearch.indexOf(substring) != -1) {
throw throwIfAssertFail;
}
}
示例15: setAsText
import org.springframework.util.StringUtils; //导入方法依赖的package包/类
/**
* Format is PROPAGATION_NAME,ISOLATION_NAME,readOnly,timeout_NNNN,+Exception1,-Exception2.
* Null or the empty string means that the method is non transactional.
* @see java.beans.PropertyEditor#setAsText(java.lang.String)
*/
@Override
public void setAsText(String text) throws IllegalArgumentException {
if (StringUtils.hasLength(text)) {
// tokenize it with ","
String[] tokens = StringUtils.commaDelimitedListToStringArray(text);
RuleBasedTransactionAttribute attr = new RuleBasedTransactionAttribute();
for (int i = 0; i < tokens.length; i++) {
// Trim leading and trailing whitespace.
String token = StringUtils.trimWhitespace(tokens[i].trim());
// Check whether token contains illegal whitespace within text.
if (StringUtils.containsWhitespace(token)) {
throw new IllegalArgumentException(
"Transaction attribute token contains illegal whitespace: [" + token + "]");
}
// Check token type.
if (token.startsWith(RuleBasedTransactionAttribute.PREFIX_PROPAGATION)) {
attr.setPropagationBehaviorName(token);
}
else if (token.startsWith(RuleBasedTransactionAttribute.PREFIX_ISOLATION)) {
attr.setIsolationLevelName(token);
}
else if (token.startsWith(RuleBasedTransactionAttribute.PREFIX_TIMEOUT)) {
String value = token.substring(DefaultTransactionAttribute.PREFIX_TIMEOUT.length());
attr.setTimeout(Integer.parseInt(value));
}
else if (token.equals(RuleBasedTransactionAttribute.READ_ONLY_MARKER)) {
attr.setReadOnly(true);
}
else if (token.startsWith(RuleBasedTransactionAttribute.PREFIX_COMMIT_RULE)) {
attr.getRollbackRules().add(new NoRollbackRuleAttribute(token.substring(1)));
}
else if (token.startsWith(RuleBasedTransactionAttribute.PREFIX_ROLLBACK_RULE)) {
attr.getRollbackRules().add(new RollbackRuleAttribute(token.substring(1)));
}
else {
throw new IllegalArgumentException("Invalid transaction attribute token: [" + token + "]");
}
}
setValue(attr);
}
else {
setValue(null);
}
}