当前位置: 首页>>代码示例>>Java>>正文


Java ObjectUtils类代码示例

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


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

示例1: handleError

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


注:本文中的org.springframework.util.ObjectUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。