當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。