• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java ObjectUtils类的典型用法代码示例

java 11次浏览

本文整理汇总了Java中org.springframework.util.ObjectUtils的典型用法代码示例。如果您正苦于以下问题:Java ObjectUtils类的具体用法?Java ObjectUtils怎么用?Java ObjectUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

ObjectUtils类属于org.springframework.util包,在下文中一共展示了ObjectUtils类的40个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: handleError

点赞 3

import org.springframework.util.ObjectUtils; //导入依赖的package包/类
@Override
public void handleError(ClientHttpResponse response) throws IOException {
	String exceptionClazz = null;
	Map<String, String> map = new HashMap<>();
	try {
		String body = new String(getResponseBody(response));
		@SuppressWarnings("unchecked")
		Map<String, String> parsed = objectMapper.readValue(body, Map.class);
		map.putAll(parsed);
		exceptionClazz = map.get("exception");
	}
	catch (Exception e) {
		// don't want to error here
	}
	if (ObjectUtils.nullSafeEquals(exceptionClazz, ReleaseNotFoundException.class.getName())) {
		handleReleaseNotFoundException(map);
	}
	else if (ObjectUtils.nullSafeEquals(exceptionClazz, PackageDeleteException.class.getName())) {
		handlePackageDeleteException(map);
	}
	else if (ObjectUtils.nullSafeEquals(exceptionClazz, SkipperException.class.getName())) {
		handleSkipperException(map);
	}
	super.handleError(response);
}
 

开发者ID:spring-cloud,
项目名称:spring-cloud-skipper,
代码行数:26,
代码来源:SkipperClientResponseErrorHandler.java

示例2: predictBeanType

点赞 3

import org.springframework.util.ObjectUtils; //导入依赖的package包/类
@Override
protected Class<?> predictBeanType(String beanName, RootBeanDefinition mbd, Class<?>... typesToMatch) {
	Class<?> targetType = mbd.getTargetType();
	if (targetType == null) {
		targetType = (mbd.getFactoryMethodName() != null ? getTypeForFactoryMethod(beanName, mbd, typesToMatch) :
				resolveBeanClass(mbd, beanName, typesToMatch));
		if (ObjectUtils.isEmpty(typesToMatch) || getTempClassLoader() == null) {
			mbd.setTargetType(targetType);
		}
	}
	// Apply SmartInstantiationAwareBeanPostProcessors to predict the
	// eventual type after a before-instantiation shortcut.
	if (targetType != null && !mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()) {
		for (BeanPostProcessor bp : getBeanPostProcessors()) {
			if (bp instanceof SmartInstantiationAwareBeanPostProcessor) {
				SmartInstantiationAwareBeanPostProcessor ibp = (SmartInstantiationAwareBeanPostProcessor) bp;
				Class<?> predicted = ibp.predictBeanType(targetType, beanName);
				if (predicted != null && (typesToMatch.length != 1 || !FactoryBean.class.equals(typesToMatch[0]) ||
						FactoryBean.class.isAssignableFrom(predicted))) {
					return predicted;
				}
			}
		}
	}
	return targetType;
}
 

开发者ID:lamsfoundation,
项目名称:lams,
代码行数:27,
代码来源:AbstractAutowireCapableBeanFactory.java

示例3: mqttClientFactory

点赞 3

import org.springframework.util.ObjectUtils; //导入依赖的package包/类
@Bean
public MqttPahoClientFactory mqttClientFactory() {
	DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory();
	factory.setServerURIs(mqttProperties.getUrl());
	factory.setUserName(mqttProperties.getUsername());
	factory.setPassword(mqttProperties.getPassword());
	factory.setCleanSession(mqttProperties.isCleanSession());
	factory.setConnectionTimeout(mqttProperties.getConnectionTimeout());
	factory.setKeepAliveInterval(mqttProperties.getKeepAliveInterval());
	if (ObjectUtils.nullSafeEquals(mqttProperties.getPersistence(), "file")) {
		factory.setPersistence(new MqttDefaultFilePersistence(mqttProperties.getPersistenceDirectory()));
	}
	else if (ObjectUtils.nullSafeEquals(mqttProperties.getPersistence(), "memory")) {
		factory.setPersistence(new MemoryPersistence());
	}
	return factory;
}
 

开发者ID:spring-cloud-stream-app-starters,
项目名称:mqtt,
代码行数:18,
代码来源:MqttConfiguration.java

示例4: setHeader

点赞 3

import org.springframework.util.ObjectUtils; //导入依赖的package包/类
/**
 * Set a header.
 *
 * @param name Name
 * @param value Value
 */
public void setHeader(String name, Object value) {
  verifyType(name, value);
  if (value != null) {
    // Modify header if necessary
    if (!ObjectUtils.nullSafeEquals(value, getHeader(name))) {
      this.modified = true;
      this.headers.put(name, value);
    }
  } else {
    // Remove header if available
    if (this.headers.containsKey(name)) {
      this.modified = true;
      this.headers.remove(name);
    }
  }
}
 

开发者ID:netshoes,
项目名称:spring-cloud-sleuth-amqp,
代码行数:23,
代码来源:AmqpMessageHeaderAccessor.java

示例5: getParticularClass

点赞 3

import org.springframework.util.ObjectUtils; //导入依赖的package包/类
/**
 * Returns the first matching class from the given array, that doens't belong to common libraries such as the JDK or
 * OSGi API. Useful for filtering OSGi services by type to prevent class cast problems.
 * 
 * <p/> No sanity checks are done on the given array class.
 * 
 * @param classes array of classes
 * @return a 'particular' (non JDK/OSGi) class if one is found. Else the first available entry is returned.
 */
public static Class<?> getParticularClass(Class<?>[] classes) {
	boolean hasSecurity = (System.getSecurityManager() != null);
	for (int i = 0; i < classes.length; i++) {
		final Class<?> clazz = classes[i];
		ClassLoader loader = null;
		if (hasSecurity) {
			loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
				public ClassLoader run() {
					return clazz.getClassLoader();
				}
			});
		} else {
			loader = clazz.getClassLoader();
		}
		// quick boot/system check
		if (loader != null) {
			// consider known loaders
			if (!knownNonOsgiLoadersSet.contains(loader)) {
				return clazz;
			}
		}
	}

	return (ObjectUtils.isEmpty(classes) ? null : classes[0]);
}
 

开发者ID:eclipse,
项目名称:gemini.blueprint,
代码行数:35,
代码来源:ClassUtils.java

示例6: getOperationParameters

点赞 3

import org.springframework.util.ObjectUtils; //导入依赖的package包/类
/**
 * Reads {@code MBeanParameterInfo} from the {@code ManagedOperationParameter}
 * attributes attached to a method. Returns an empty array of {@code MBeanParameterInfo}
 * if no attributes are found.
 */
@Override
protected MBeanParameterInfo[] getOperationParameters(Method method, String beanKey) {
	ManagedOperationParameter[] params = this.attributeSource.getManagedOperationParameters(method);
	if (ObjectUtils.isEmpty(params)) {
		return super.getOperationParameters(method, beanKey);
	}

	MBeanParameterInfo[] parameterInfo = new MBeanParameterInfo[params.length];
	Class<?>[] methodParameters = method.getParameterTypes();
	for (int i = 0; i < params.length; i++) {
		ManagedOperationParameter param = params[i];
		parameterInfo[i] =
				new MBeanParameterInfo(param.getName(), methodParameters[i].getName(), param.getDescription());
	}
	return parameterInfo;
}
 

开发者ID:lamsfoundation,
项目名称:lams,
代码行数:22,
代码来源:MetadataMBeanInfoAssembler.java

示例7: testScopes

点赞 3

import org.springframework.util.ObjectUtils; //导入依赖的package包/类
public void testScopes() throws Exception {

		assertNull(tag);
		Object a = bf.getBean("a");
		System.out.println("got a" + a);
		assertNotNull(tag);

		((Properties) a).put("goo", "foo");

		Object b = bf.getBean("b");
		System.out.println("request b;got=" + b);
		System.out.println("b class is" + b.getClass());
		b = bf.getBean("b");
		System.out.println("request b;got=" + b);
		System.out.println("b class is" + b.getClass());

		Object scopedA = bf.getBean("a");
		System.out.println(scopedA.getClass());
		System.out.println(a);
		System.out.println(scopedA);
		System.out.println(ObjectUtils.nullSafeToString(ClassUtils.getAllInterfaces(scopedA)));
	}
 

开发者ID:eclipse,
项目名称:gemini.blueprint,
代码行数:23,
代码来源:ScopeTests.java

示例8: getConfigurations

点赞 3

import org.springframework.util.ObjectUtils; //导入依赖的package包/类
public String[] getConfigurations(Bundle bundle) {
	String[] locations = ConfigUtils.getHeaderLocations(bundle.getHeaders());

	// if no location is specified in the header, try the defaults
	if (ObjectUtils.isEmpty(locations)) {
		// check the default locations if the manifest doesn't provide any info
		Enumeration defaultConfig = bundle.findEntries(CONTEXT_DIR, CONTEXT_FILES, false);
		if (defaultConfig != null && defaultConfig.hasMoreElements()) {
			return new String[] { DEFAULT_CONFIG };
		}
		else {
			return new String[0];
		}
	}
	else {
		return locations;
	}
}
 

开发者ID:eclipse,
项目名称:gemini.blueprint,
代码行数:19,
代码来源:DefaultConfigurationScanner.java

示例9: createApplicationContext

点赞 3

import org.springframework.util.ObjectUtils; //导入依赖的package包/类
public DelegatedExecutionOsgiBundleApplicationContext createApplicationContext(BundleContext bundleContext)
		throws Exception {
	Bundle bundle = bundleContext.getBundle();
	ApplicationContextConfiguration config = new BlueprintContainerConfig(bundle);
	String bundleName = OsgiStringUtils.nullSafeNameAndSymName(bundle);
	if (log.isTraceEnabled())
		log.trace("Created configuration " + config + " for bundle " + bundleName);

	// it's not a spring bundle, ignore it
	if (!config.isSpringPoweredBundle()) {
		if (log.isDebugEnabled())
			log.debug("No blueprint configuration found in bundle " + bundleName + "; ignoring it...");
		return null;
	}

	log.info("Discovered configurations " + ObjectUtils.nullSafeToString(config.getConfigurationLocations())
			+ " in bundle [" + bundleName + "]");

	DelegatedExecutionOsgiBundleApplicationContext sdoac =
			new OsgiBundleXmlApplicationContext(config.getConfigurationLocations());
	sdoac.setBundleContext(bundleContext);
	sdoac.setPublishContextAsService(config.isPublishContextAsService());

	return sdoac;
}
 

开发者ID:eclipse,
项目名称:gemini.blueprint,
代码行数:26,
代码来源:BlueprintContainerCreator.java

示例10: callListenersUnbind

点赞 3

import org.springframework.util.ObjectUtils; //导入依赖的package包/类
public static void callListenersUnbind(Object serviceProxy, ServiceReference reference,
		OsgiServiceLifecycleListener[] listeners) {
	if (!ObjectUtils.isEmpty(listeners)) {
		boolean debug = log.isDebugEnabled();
		// get a Dictionary implementing a Map
		Dictionary properties =
				(reference != null ? OsgiServiceReferenceUtils.getServicePropertiesSnapshot(reference) : null);
		for (int i = 0; i < listeners.length; i++) {
			if (debug)
				log.debug("Calling unbind on " + listeners[i] + " w/ reference " + reference);
			try {
				listeners[i].unbind(serviceProxy, (Map) properties);
			} catch (Exception ex) {
				log.warn("Unbind method on listener " + listeners[i] + " threw exception ", ex);
			}
			if (debug)
				log.debug("Called unbind on " + listeners[i] + " w/ reference " + reference);
		}
	}
}
 

开发者ID:eclipse,
项目名称:gemini.blueprint,
代码行数:21,
代码来源:OsgiServiceBindingUtils.java

示例11: invokeCustomServiceReferenceMethod

点赞 3

import org.springframework.util.ObjectUtils; //导入依赖的package包/类
/**
 * Invoke method with signature <code>bla(ServiceReference ref)</code>.
 * 
 * @param target
 * @param method
 * @param service
 */
private void invokeCustomServiceReferenceMethod(Object target, Method method, Object service) {
	if (method != null) {
		boolean trace = log.isTraceEnabled();

		// get the service reference
		// find the compatible types (accept null service)
		if (trace)
			log.trace("invoking listener custom method " + method);

		ServiceReference ref =
				(service != null ? ((ImportedOsgiServiceProxy) service).getServiceReference() : null);

		try {
			ReflectionUtils.invokeMethod(method, target, new Object[] { ref });
		}
		// make sure to log exceptions and continue with the
		// rest of the listeners
		catch (Exception ex) {
			Exception cause = ReflectionUtils.getInvocationException(ex);
			log.warn("custom method [" + method + "] threw exception when passing service ["
					+ ObjectUtils.identityToString(service) + "]", cause);
		}
	}
}
 

开发者ID:eclipse,
项目名称:gemini.blueprint,
代码行数:32,
代码来源:OsgiServiceLifecycleListenerAdapter.java

示例12: doResolveBeanClass

点赞 3

import org.springframework.util.ObjectUtils; //导入依赖的package包/类
private Class<?> doResolveBeanClass(RootBeanDefinition mbd, Class<?>... typesToMatch) throws ClassNotFoundException {
	if (!ObjectUtils.isEmpty(typesToMatch)) {
		ClassLoader tempClassLoader = getTempClassLoader();
		if (tempClassLoader != null) {
			if (tempClassLoader instanceof DecoratingClassLoader) {
				DecoratingClassLoader dcl = (DecoratingClassLoader) tempClassLoader;
				for (Class<?> typeToMatch : typesToMatch) {
					dcl.excludeClass(typeToMatch.getName());
				}
			}
			String className = mbd.getBeanClassName();
			return (className != null ? ClassUtils.forName(className, tempClassLoader) : null);
		}
	}
	return mbd.resolveBeanClass(getBeanClassLoader());
}
 

开发者ID:lamsfoundation,
项目名称:lams,
代码行数:17,
代码来源:AbstractBeanFactory.java

示例13: initializeExecutor

点赞 3

import org.springframework.util.ObjectUtils; //导入依赖的package包/类
@Override
protected ExecutorService initializeExecutor(
		ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {

	ScheduledExecutorService executor =
			createExecutor(this.poolSize, threadFactory, rejectedExecutionHandler);

	if (executor instanceof ScheduledThreadPoolExecutor && this.removeOnCancelPolicy != null) {
		((ScheduledThreadPoolExecutor) executor).setRemoveOnCancelPolicy(this.removeOnCancelPolicy);
	}

	// Register specified ScheduledExecutorTasks, if necessary.
	if (!ObjectUtils.isEmpty(this.scheduledExecutorTasks)) {
		registerTasks(this.scheduledExecutorTasks, executor);
	}

	// Wrap executor with an unconfigurable decorator.
	this.exposedExecutor = (this.exposeUnconfigurableExecutor ?
			Executors.unconfigurableScheduledExecutorService(executor) : executor);

	return executor;
}
 

开发者ID:lamsfoundation,
项目名称:lams,
代码行数:23,
代码来源:ScheduledExecutorFactoryBean.java

示例14: addSyntheticDependsOn

点赞 3

import org.springframework.util.ObjectUtils; //导入依赖的package包/类
private void addSyntheticDependsOn(BeanDefinition definition, String beanName) {
	if (StringUtils.hasText(beanName)) {
		String[] dependsOn = definition.getDependsOn();
		if (dependsOn != null && dependsOn.length > 0) {
			for (String dependOn : dependsOn) {
				if (beanName.equals(dependOn)) {
					return;
				}
			}
		}

		// add depends on
		dependsOn = (String[]) ObjectUtils.addObjectToArray(dependsOn, beanName);
		definition.setDependsOn(dependsOn);
		Collection<String> markers = (Collection<String>) definition.getAttribute(SYNTHETIC_DEPENDS_ON);
		if (markers == null) {
			markers = new ArrayList<String>(2);
			definition.setAttribute(SYNTHETIC_DEPENDS_ON, markers);
		}
		markers.add(beanName);
	}
}
 

开发者ID:eclipse,
项目名称:gemini.blueprint,
代码行数:23,
代码来源:CycleOrderingProcessor.java

示例15: configureFactoryForClass

点赞 3

import org.springframework.util.ObjectUtils; //导入依赖的package包/类
/**
 * Based on the given class, properly instructs the ProxyFactory proxies. For additional sanity checks on the passed
 * classes, check the methods below.
 * 
 * @see #containsUnrelatedClasses(Class[])
 * @see #removeParents(Class[])
 * 
 * @param factory
 * @param classes
 */
public static void configureFactoryForClass(ProxyFactory factory, Class<?>[] classes) {
	if (ObjectUtils.isEmpty(classes))
		return;

	for (int i = 0; i < classes.length; i++) {
		Class<?> clazz = classes[i];

		if (clazz.isInterface()) {
			factory.addInterface(clazz);
		} else {
			factory.setTargetClass(clazz);
			factory.setProxyTargetClass(true);
		}
	}
}
 

开发者ID:eclipse,
项目名称:gemini.blueprint,
代码行数:26,
代码来源:ClassUtils.java

示例16: equals

点赞 2

import org.springframework.util.ObjectUtils; //导入依赖的package包/类
@Override
public boolean equals(Object obj) {
	if (this == obj) {
		return true;
	}
	if (!(obj instanceof OpaqueUriComponents)) {
		return false;
	}

	OpaqueUriComponents other = (OpaqueUriComponents) obj;
	return ObjectUtils.nullSafeEquals(getScheme(), other.getScheme()) &&
			ObjectUtils.nullSafeEquals(this.ssp, other.ssp) &&
			ObjectUtils.nullSafeEquals(getFragment(), other.getFragment());

}
 

开发者ID:lamsfoundation,
项目名称:lams,
代码行数:16,
代码来源:OpaqueUriComponents.java

示例17: sqlSessionFactory

点赞 2

import org.springframework.util.ObjectUtils; //导入依赖的package包/类
@Bean(name = "sqlSessionFactory")
@ConditionalOnMissingBean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
    SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
    factory.setDataSource(dataSource);
    factory.setVfs(SpringBootVFS.class);
    if (StringUtils.hasText(this.properties.getConfigLocation())) {
        factory.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation()));
    }
    org.apache.ibatis.session.Configuration configuration = this.properties.getConfiguration();
    if (configuration == null && !StringUtils.hasText(this.properties.getConfigLocation())) {
        configuration = new org.apache.ibatis.session.Configuration();
    }
    factory.setConfiguration(configuration);
    if (this.properties.getConfigurationProperties() != null) {
        factory.setConfigurationProperties(this.properties.getConfigurationProperties());
    }
    if (!ObjectUtils.isEmpty(this.interceptors)) {
        factory.setPlugins(this.interceptors);
    }
    if (StringUtils.hasLength(this.properties.getTypeAliasesPackage())) {
        factory.setTypeAliasesPackage(this.properties.getTypeAliasesPackage());
    }
    if (StringUtils.hasLength(this.properties.getTypeHandlersPackage())) {
        factory.setTypeHandlersPackage(this.properties.getTypeHandlersPackage());
    }
    if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) {
        factory.setMapperLocations(this.properties.resolveMapperLocations());
    }

    return factory.getObject();
}
 

开发者ID:weiwei02,
项目名称:Yoghurt,
代码行数:33,
代码来源:MybatisAutoConfiguration.java

示例18: getTreeNodeById

点赞 2

import org.springframework.util.ObjectUtils; //导入依赖的package包/类
/**
 * 根据treeNodeId获取TreeNode对象
 * @param treeNodeId
 * @param allTreeNodeList
 * @return
 */
protected T getTreeNodeById(I treeNodeId, List<T> allTreeNodeList) {
	if(CollectionUtils.isEmpty(allTreeNodeList) || ObjectUtils.isEmpty(treeNodeId)){
		return null;
	}
	for(T treeNode : allTreeNodeList){
		if(treeNode != null && treeNodeId.equals(getTreeNodeId(treeNode))){
			return treeNode;
		}
	}
	return null;
}
 

开发者ID:penggle,
项目名称:xproject,
代码行数:18,
代码来源:AbstractXTreeBuilder.java

示例19: getDirectChildNodeList

点赞 2

import org.springframework.util.ObjectUtils; //导入依赖的package包/类
/**
 * 根据parentTreeNodeId获取直接子节点
 * @param parentTreeNodeId
 * @param allTreeNodeList
 * @return
 */
public List<T> getDirectChildNodeList(I parentTreeNodeId, List<T> allTreeNodeList) {
	List<T> childList = new ArrayList<T>();
	if(CollectionUtils.isEmpty(allTreeNodeList) || ObjectUtils.isEmpty(parentTreeNodeId)){
		return childList;
	}
	for(T treeNode : allTreeNodeList){
		if(treeNode != null && parentTreeNodeId.equals(getParentTreeNodeId(treeNode))){
			childList.add(treeNode);
		}
	}
	return childList;
}
 

开发者ID:penggle,
项目名称:xproject,
代码行数:19,
代码来源:AbstractXTreeBuilder.java

示例20: getMBeanInfo

点赞 2

import org.springframework.util.ObjectUtils; //导入依赖的package包/类
/**
 * Gets the {@code ModelMBeanInfo} for the bean with the supplied key
 * and of the supplied type.
 */
private ModelMBeanInfo getMBeanInfo(Object managedBean, String beanKey) throws JMException {
	ModelMBeanInfo info = this.assembler.getMBeanInfo(managedBean, beanKey);
	if (logger.isWarnEnabled() && ObjectUtils.isEmpty(info.getAttributes()) &&
			ObjectUtils.isEmpty(info.getOperations())) {
		logger.warn("Bean with key '" + beanKey +
				"' has been registered as an MBean but has no exposed attributes or operations");
	}
	return info;
}
 

开发者ID:lamsfoundation,
项目名称:lams,
代码行数:14,
代码来源:MBeanExporter.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (2)