Java Code Examples for org.springframework.util.ObjectUtils#nullSafeClassName()

The following examples show how to use org.springframework.util.ObjectUtils#nullSafeClassName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleMessageConverter.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * This implementation creates a TextMessage for a String, a
 * BytesMessage for a byte array, a MapMessage for a Map,
 * and an ObjectMessage for a Serializable object.
 * @see #createMessageForString
 * @see #createMessageForByteArray
 * @see #createMessageForMap
 * @see #createMessageForSerializable
 */
@Override
public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException {
	if (object instanceof Message) {
		return (Message) object;
	}
	else if (object instanceof String) {
		return createMessageForString((String) object, session);
	}
	else if (object instanceof byte[]) {
		return createMessageForByteArray((byte[]) object, session);
	}
	else if (object instanceof Map) {
		return createMessageForMap((Map<? ,?>) object, session);
	}
	else if (object instanceof Serializable) {
		return createMessageForSerializable(((Serializable) object), session);
	}
	else {
		throw new MessageConversionException("Cannot convert object of type [" +
				ObjectUtils.nullSafeClassName(object) + "] to JMS message. Supported message " +
				"payloads are: String, byte array, Map<String,?>, Serializable object.");
	}
}
 
Example 2
Source File: SimpleMessageConverter.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * This implementation creates a TextMessage for a String, a
 * BytesMessage for a byte array, a MapMessage for a Map,
 * and an ObjectMessage for a Serializable object.
 * @see #createMessageForString
 * @see #createMessageForByteArray
 * @see #createMessageForMap
 * @see #createMessageForSerializable
 */
@Override
public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException {
	if (object instanceof Message) {
		return (Message) object;
	}
	else if (object instanceof String) {
		return createMessageForString((String) object, session);
	}
	else if (object instanceof byte[]) {
		return createMessageForByteArray((byte[]) object, session);
	}
	else if (object instanceof Map) {
		return createMessageForMap((Map<? ,?>) object, session);
	}
	else if (object instanceof Serializable) {
		return createMessageForSerializable(((Serializable) object), session);
	}
	else {
		throw new MessageConversionException("Cannot convert object of type [" +
				ObjectUtils.nullSafeClassName(object) + "] to JMS message. Supported message " +
				"payloads are: String, byte array, Map<String,?>, Serializable object.");
	}
}
 
Example 3
Source File: SimpleMessageConverter.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * This implementation creates a TextMessage for a String, a
 * BytesMessage for a byte array, a MapMessage for a Map,
 * and an ObjectMessage for a Serializable object.
 * @see #createMessageForString
 * @see #createMessageForByteArray
 * @see #createMessageForMap
 * @see #createMessageForSerializable
 */
@Override
public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException {
	if (object instanceof Message) {
		return (Message) object;
	}
	else if (object instanceof String) {
		return createMessageForString((String) object, session);
	}
	else if (object instanceof byte[]) {
		return createMessageForByteArray((byte[]) object, session);
	}
	else if (object instanceof Map) {
		return createMessageForMap((Map<? ,?>) object, session);
	}
	else if (object instanceof Serializable) {
		return createMessageForSerializable(((Serializable) object), session);
	}
	else {
		throw new MessageConversionException("Cannot convert object of type [" +
				ObjectUtils.nullSafeClassName(object) + "] to JMS message. Supported message " +
				"payloads are: String, byte array, Map<String,?>, Serializable object.");
	}
}
 
Example 4
Source File: SimpleMessageConverter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Create a JMS MapMessage for the given Map.
 * @param map the Map to convert
 * @param session current JMS session
 * @return the resulting message
 * @throws JMSException if thrown by JMS methods
 * @see javax.jms.Session#createMapMessage
 */
protected MapMessage createMessageForMap(Map<?, ?> map, Session session) throws JMSException {
	MapMessage message = session.createMapMessage();
	for (Map.Entry<?, ?> entry : map.entrySet()) {
		Object key = entry.getKey();
		if (!(key instanceof String)) {
			throw new MessageConversionException("Cannot convert non-String key of type [" +
					ObjectUtils.nullSafeClassName(key) + "] to JMS MapMessage entry");
		}
		message.setObject((String) key, entry.getValue());
	}
	return message;
}
 
Example 5
Source File: ConstructorResolver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Resolve the prepared arguments stored in the given bean definition.
 */
private Object[] resolvePreparedArguments(String beanName, RootBeanDefinition mbd, BeanWrapper bw,
		Executable executable, Object[] argsToResolve, boolean fallback) {

	TypeConverter customConverter = this.beanFactory.getCustomTypeConverter();
	TypeConverter converter = (customConverter != null ? customConverter : bw);
	BeanDefinitionValueResolver valueResolver =
			new BeanDefinitionValueResolver(this.beanFactory, beanName, mbd, converter);
	Class<?>[] paramTypes = executable.getParameterTypes();

	Object[] resolvedArgs = new Object[argsToResolve.length];
	for (int argIndex = 0; argIndex < argsToResolve.length; argIndex++) {
		Object argValue = argsToResolve[argIndex];
		MethodParameter methodParam = MethodParameter.forExecutable(executable, argIndex);
		GenericTypeResolver.resolveParameterType(methodParam, executable.getDeclaringClass());
		if (argValue instanceof AutowiredArgumentMarker) {
			argValue = resolveAutowiredArgument(methodParam, beanName, null, converter, fallback);
		}
		else if (argValue instanceof BeanMetadataElement) {
			argValue = valueResolver.resolveValueIfNecessary("constructor argument", argValue);
		}
		else if (argValue instanceof String) {
			argValue = this.beanFactory.evaluateBeanDefinitionString((String) argValue, mbd);
		}
		Class<?> paramType = paramTypes[argIndex];
		try {
			resolvedArgs[argIndex] = converter.convertIfNecessary(argValue, paramType, methodParam);
		}
		catch (TypeMismatchException ex) {
			throw new UnsatisfiedDependencyException(
					mbd.getResourceDescription(), beanName, new InjectionPoint(methodParam),
					"Could not convert argument value of type [" + ObjectUtils.nullSafeClassName(argValue) +
					"] to required type [" + paramType.getName() + "]: " + ex.getMessage());
		}
	}
	return resolvedArgs;
}
 
Example 6
Source File: SimpleMessageConverter.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Create a JMS MapMessage for the given Map.
 * @param map the Map to convert
 * @param session current JMS session
 * @return the resulting message
 * @throws JMSException if thrown by JMS methods
 * @see javax.jms.Session#createMapMessage
 */
protected MapMessage createMessageForMap(Map<?, ?> map, Session session) throws JMSException {
	MapMessage message = session.createMapMessage();
	for (Map.Entry<?, ?> entry : map.entrySet()) {
		Object key = entry.getKey();
		if (!(key instanceof String)) {
			throw new MessageConversionException("Cannot convert non-String key of type [" +
					ObjectUtils.nullSafeClassName(key) + "] to JMS MapMessage entry");
		}
		message.setObject((String) key, entry.getValue());
	}
	return message;
}
 
Example 7
Source File: ConstructorResolver.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Resolve the prepared arguments stored in the given bean definition.
 */
private Object[] resolvePreparedArguments(String beanName, RootBeanDefinition mbd, BeanWrapper bw,
		Executable executable, Object[] argsToResolve, boolean fallback) {

	TypeConverter customConverter = this.beanFactory.getCustomTypeConverter();
	TypeConverter converter = (customConverter != null ? customConverter : bw);
	BeanDefinitionValueResolver valueResolver =
			new BeanDefinitionValueResolver(this.beanFactory, beanName, mbd, converter);
	Class<?>[] paramTypes = executable.getParameterTypes();

	Object[] resolvedArgs = new Object[argsToResolve.length];
	for (int argIndex = 0; argIndex < argsToResolve.length; argIndex++) {
		Object argValue = argsToResolve[argIndex];
		MethodParameter methodParam = MethodParameter.forExecutable(executable, argIndex);
		GenericTypeResolver.resolveParameterType(methodParam, executable.getDeclaringClass());
		if (argValue instanceof AutowiredArgumentMarker) {
			argValue = resolveAutowiredArgument(methodParam, beanName, null, converter, fallback);
		}
		else if (argValue instanceof BeanMetadataElement) {
			argValue = valueResolver.resolveValueIfNecessary("constructor argument", argValue);
		}
		else if (argValue instanceof String) {
			argValue = this.beanFactory.evaluateBeanDefinitionString((String) argValue, mbd);
		}
		Class<?> paramType = paramTypes[argIndex];
		try {
			resolvedArgs[argIndex] = converter.convertIfNecessary(argValue, paramType, methodParam);
		}
		catch (TypeMismatchException ex) {
			throw new UnsatisfiedDependencyException(
					mbd.getResourceDescription(), beanName, new InjectionPoint(methodParam),
					"Could not convert argument value of type [" + ObjectUtils.nullSafeClassName(argValue) +
					"] to required type [" + paramType.getName() + "]: " + ex.getMessage());
		}
	}
	return resolvedArgs;
}
 
Example 8
Source File: ConstructorResolver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Resolve the prepared arguments stored in the given bean definition.
 */
private Object[] resolvePreparedArguments(
		String beanName, RootBeanDefinition mbd, BeanWrapper bw, Member methodOrCtor, Object[] argsToResolve) {

	TypeConverter customConverter = this.beanFactory.getCustomTypeConverter();
	TypeConverter converter = (customConverter != null ? customConverter : bw);
	BeanDefinitionValueResolver valueResolver =
			new BeanDefinitionValueResolver(this.beanFactory, beanName, mbd, converter);
	Class<?>[] paramTypes = (methodOrCtor instanceof Method ?
			((Method) methodOrCtor).getParameterTypes() : ((Constructor<?>) methodOrCtor).getParameterTypes());

	Object[] resolvedArgs = new Object[argsToResolve.length];
	for (int argIndex = 0; argIndex < argsToResolve.length; argIndex++) {
		Object argValue = argsToResolve[argIndex];
		MethodParameter methodParam = MethodParameter.forMethodOrConstructor(methodOrCtor, argIndex);
		GenericTypeResolver.resolveParameterType(methodParam, methodOrCtor.getDeclaringClass());
		if (argValue instanceof AutowiredArgumentMarker) {
			argValue = resolveAutowiredArgument(methodParam, beanName, null, converter);
		}
		else if (argValue instanceof BeanMetadataElement) {
			argValue = valueResolver.resolveValueIfNecessary("constructor argument", argValue);
		}
		else if (argValue instanceof String) {
			argValue = this.beanFactory.evaluateBeanDefinitionString((String) argValue, mbd);
		}
		Class<?> paramType = paramTypes[argIndex];
		try {
			resolvedArgs[argIndex] = converter.convertIfNecessary(argValue, paramType, methodParam);
		}
		catch (TypeMismatchException ex) {
			throw new UnsatisfiedDependencyException(
					mbd.getResourceDescription(), beanName, new InjectionPoint(methodParam),
					"Could not convert argument value of type [" + ObjectUtils.nullSafeClassName(argValue) +
					"] to required type [" + paramType.getName() + "]: " + ex.getMessage());
		}
	}
	return resolvedArgs;
}
 
Example 9
Source File: ConstructorResolver.java    From blog_demos with Apache License 2.0 5 votes vote down vote up
/**
 * Resolve the prepared arguments stored in the given bean definition.
 */
private Object[] resolvePreparedArguments(
		String beanName, RootBeanDefinition mbd, BeanWrapper bw, Member methodOrCtor, Object[] argsToResolve) {

	Class<?>[] paramTypes = (methodOrCtor instanceof Method ?
			((Method) methodOrCtor).getParameterTypes() : ((Constructor<?>) methodOrCtor).getParameterTypes());
	TypeConverter converter = (this.beanFactory.getCustomTypeConverter() != null ?
			this.beanFactory.getCustomTypeConverter() : bw);
	BeanDefinitionValueResolver valueResolver =
			new BeanDefinitionValueResolver(this.beanFactory, beanName, mbd, converter);
	Object[] resolvedArgs = new Object[argsToResolve.length];
	for (int argIndex = 0; argIndex < argsToResolve.length; argIndex++) {
		Object argValue = argsToResolve[argIndex];
		MethodParameter methodParam = MethodParameter.forMethodOrConstructor(methodOrCtor, argIndex);
		GenericTypeResolver.resolveParameterType(methodParam, methodOrCtor.getDeclaringClass());
		if (argValue instanceof AutowiredArgumentMarker) {
			argValue = resolveAutowiredArgument(methodParam, beanName, null, converter);
		}
		else if (argValue instanceof BeanMetadataElement) {
			argValue = valueResolver.resolveValueIfNecessary("constructor argument", argValue);
		}
		else if (argValue instanceof String) {
			argValue = this.beanFactory.evaluateBeanDefinitionString((String) argValue, mbd);
		}
		Class<?> paramType = paramTypes[argIndex];
		try {
			resolvedArgs[argIndex] = converter.convertIfNecessary(argValue, paramType, methodParam);
		}
		catch (TypeMismatchException ex) {
			String methodType = (methodOrCtor instanceof Constructor ? "constructor" : "factory method");
			throw new UnsatisfiedDependencyException(
					mbd.getResourceDescription(), beanName, argIndex, paramType,
					"Could not convert " + methodType + " argument value of type [" +
					ObjectUtils.nullSafeClassName(argValue) +
					"] to required type [" + paramType.getName() + "]: " + ex.getMessage());
		}
	}
	return resolvedArgs;
}
 
Example 10
Source File: SimpleMessageConverter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Create a JMS MapMessage for the given Map.
 * @param map the Map to convert
 * @param session current JMS session
 * @return the resulting message
 * @throws JMSException if thrown by JMS methods
 * @see javax.jms.Session#createMapMessage
 */
protected MapMessage createMessageForMap(Map<?, ?> map, Session session) throws JMSException {
	MapMessage message = session.createMapMessage();
	for (Map.Entry<?, ?> entry : map.entrySet()) {
		if (!(entry.getKey() instanceof String)) {
			throw new MessageConversionException("Cannot convert non-String key of type [" +
					ObjectUtils.nullSafeClassName(entry.getKey()) + "] to JMS MapMessage entry");
		}
		message.setObject((String) entry.getKey(), entry.getValue());
	}
	return message;
}
 
Example 11
Source File: ConstructorResolver.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Resolve the prepared arguments stored in the given bean definition.
 */
private Object[] resolvePreparedArguments(
		String beanName, RootBeanDefinition mbd, BeanWrapper bw, Member methodOrCtor, Object[] argsToResolve) {

	Class<?>[] paramTypes = (methodOrCtor instanceof Method ?
			((Method) methodOrCtor).getParameterTypes() : ((Constructor<?>) methodOrCtor).getParameterTypes());
	TypeConverter converter = (this.beanFactory.getCustomTypeConverter() != null ?
			this.beanFactory.getCustomTypeConverter() : bw);
	BeanDefinitionValueResolver valueResolver =
			new BeanDefinitionValueResolver(this.beanFactory, beanName, mbd, converter);
	Object[] resolvedArgs = new Object[argsToResolve.length];
	for (int argIndex = 0; argIndex < argsToResolve.length; argIndex++) {
		Object argValue = argsToResolve[argIndex];
		MethodParameter methodParam = MethodParameter.forMethodOrConstructor(methodOrCtor, argIndex);
		GenericTypeResolver.resolveParameterType(methodParam, methodOrCtor.getDeclaringClass());
		if (argValue instanceof AutowiredArgumentMarker) {
			argValue = resolveAutowiredArgument(methodParam, beanName, null, converter);
		}
		else if (argValue instanceof BeanMetadataElement) {
			argValue = valueResolver.resolveValueIfNecessary("constructor argument", argValue);
		}
		else if (argValue instanceof String) {
			argValue = this.beanFactory.evaluateBeanDefinitionString((String) argValue, mbd);
		}
		Class<?> paramType = paramTypes[argIndex];
		try {
			resolvedArgs[argIndex] = converter.convertIfNecessary(argValue, paramType, methodParam);
		}
		catch (TypeMismatchException ex) {
			String methodType = (methodOrCtor instanceof Constructor ? "constructor" : "factory method");
			throw new UnsatisfiedDependencyException(
					mbd.getResourceDescription(), beanName, argIndex, paramType,
					"Could not convert " + methodType + " argument value of type [" +
					ObjectUtils.nullSafeClassName(argValue) +
					"] to required type [" + paramType.getName() + "]: " + ex.getMessage());
		}
	}
	return resolvedArgs;
}