Java Code Examples for org.springframework.util.ClassUtils#getQualifiedName()

The following examples show how to use org.springframework.util.ClassUtils#getQualifiedName() . 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: SmartMessageMethodArgumentResolver.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
private Object convertPayload(Message<?> message, MethodParameter parameter,
		Class<?> targetPayloadType) {
	Object result = null;
	if (this.messageConverter instanceof SmartMessageConverter) {
		SmartMessageConverter smartConverter = (SmartMessageConverter) this.messageConverter;
		result = smartConverter.fromMessage(message, targetPayloadType, parameter);
	}
	else if (this.messageConverter != null) {
		result = this.messageConverter.fromMessage(message, targetPayloadType);
	}

	if (result == null) {
		throw new MessageConversionException(message,
				"No converter found from actual payload type '"
						+ ClassUtils.getDescriptiveType(message.getPayload())
						+ "' to expected payload type '"
						+ ClassUtils.getQualifiedName(targetPayloadType) + "'");
	}
	return result;
}
 
Example 2
Source File: TypeMismatchException.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Create a new {@code TypeMismatchException}.
 * @param propertyChangeEvent the PropertyChangeEvent that resulted in the problem
 * @param requiredType the required target type (or {@code null} if not known)
 * @param cause the root cause (may be {@code null})
 */
public TypeMismatchException(PropertyChangeEvent propertyChangeEvent, @Nullable Class<?> requiredType,
		@Nullable Throwable cause) {

	super(propertyChangeEvent,
			"Failed to convert property value of type '" +
			ClassUtils.getDescriptiveType(propertyChangeEvent.getNewValue()) + "'" +
			(requiredType != null ?
			" to required type '" + ClassUtils.getQualifiedName(requiredType) + "'" : "") +
			(propertyChangeEvent.getPropertyName() != null ?
			" for property '" + propertyChangeEvent.getPropertyName() + "'" : ""),
			cause);
	this.propertyName = propertyChangeEvent.getPropertyName();
	this.value = propertyChangeEvent.getNewValue();
	this.requiredType = requiredType;
}
 
Example 3
Source File: MessageMethodArgumentResolver.java    From java-technology-stack with MIT License 6 votes vote down vote up
private Object convertPayload(Message<?> message, MethodParameter parameter, Class<?> targetPayloadType) {
	Object result = null;
	if (this.converter instanceof SmartMessageConverter) {
		SmartMessageConverter smartConverter = (SmartMessageConverter) this.converter;
		result = smartConverter.fromMessage(message, targetPayloadType, parameter);
	}
	else if (this.converter != null) {
		result = this.converter.fromMessage(message, targetPayloadType);
	}

	if (result == null) {
		throw new MessageConversionException(message, "No converter found from actual payload type '" +
				ClassUtils.getDescriptiveType(message.getPayload()) + "' to expected payload type '" +
				ClassUtils.getQualifiedName(targetPayloadType) + "'");
	}
	return result;
}
 
Example 4
Source File: StompHeaderAccessor.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private String appendPayload(Object payload) {
	if (payload.getClass() != byte[].class) {
		throw new IllegalStateException(
				"Expected byte array payload but got: " + ClassUtils.getQualifiedName(payload.getClass()));
	}
	byte[] bytes = (byte[]) payload;
	MimeType mimeType = getContentType();
	String contentType = (mimeType != null ? " " + mimeType.toString() : "");
	if (bytes.length == 0 || mimeType == null || !isReadableContentType()) {
		return contentType;
	}
	Charset charset = mimeType.getCharset();
	charset = (charset != null ? charset : StandardCharsets.UTF_8);
	return (bytes.length < 80) ?
			contentType + " payload=" + new String(bytes, charset) :
			contentType + " payload=" + new String(Arrays.copyOf(bytes, 80), charset) + "...(truncated)";
}
 
Example 5
Source File: ClassEditor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public String getAsText() {
	Class<?> clazz = (Class<?>) getValue();
	if (clazz != null) {
		return ClassUtils.getQualifiedName(clazz);
	}
	else {
		return "";
	}
}
 
Example 6
Source File: TypeMismatchException.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new TypeMismatchException.
 * @param propertyChangeEvent the PropertyChangeEvent that resulted in the problem
 * @param requiredType the required target type (or {@code null} if not known)
 * @param cause the root cause (may be {@code null})
 */
public TypeMismatchException(PropertyChangeEvent propertyChangeEvent, Class<?> requiredType, Throwable cause) {
	super(propertyChangeEvent,
			"Failed to convert property value of type '" +
			ClassUtils.getDescriptiveType(propertyChangeEvent.getNewValue()) + "'" +
			(requiredType != null ?
			 " to required type '" + ClassUtils.getQualifiedName(requiredType) + "'" : "") +
			(propertyChangeEvent.getPropertyName() != null ?
			 " for property '" + propertyChangeEvent.getPropertyName() + "'" : ""),
			cause);
	this.value = propertyChangeEvent.getNewValue();
	this.requiredType = requiredType;
}
 
Example 7
Source File: ClassEditor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getAsText() {
	Class<?> clazz = (Class<?>) getValue();
	if (clazz != null) {
		return ClassUtils.getQualifiedName(clazz);
	}
	else {
		return "";
	}
}
 
Example 8
Source File: SmartMessageMethodArgumentResolver.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
@Override
public Object resolveArgument(MethodParameter parameter, Message<?> message)
		throws Exception {
	Class<?> targetMessageType = parameter.getParameterType();
	Class<?> targetPayloadType = getPayloadType(parameter);

	if (!targetMessageType.isAssignableFrom(message.getClass())) {
		throw new MethodArgumentTypeMismatchException(message, parameter,
				"Actual message type '" + ClassUtils.getDescriptiveType(message)
						+ "' does not match expected type '"
						+ ClassUtils.getQualifiedName(targetMessageType) + "'");
	}

	Class<?> payloadClass = message.getPayload().getClass();

	if (message instanceof ErrorMessage
			|| conversionNotRequired(payloadClass, targetPayloadType)) {
		return message;
	}
	Object payload = message.getPayload();
	if (isEmptyPayload(payload)) {
		throw new MessageConversionException(message,
				"Cannot convert from actual payload type '"
						+ ClassUtils.getDescriptiveType(payload)
						+ "' to expected payload type '"
						+ ClassUtils.getQualifiedName(targetPayloadType)
						+ "' when payload is empty");
	}

	payload = convertPayload(message, parameter, targetPayloadType);
	return MessageBuilder.createMessage(payload, message.getHeaders());
}
 
Example 9
Source File: TypeMismatchException.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Create a new {@code TypeMismatchException} without a {@code PropertyChangeEvent}.
 * @param value the offending value that couldn't be converted (may be {@code null})
 * @param requiredType the required target type (or {@code null} if not known)
 * @param cause the root cause (may be {@code null})
 * @see #initPropertyName
 */
public TypeMismatchException(@Nullable Object value, @Nullable Class<?> requiredType, @Nullable Throwable cause) {
	super("Failed to convert value of type '" + ClassUtils.getDescriptiveType(value) + "'" +
			(requiredType != null ? " to required type '" + ClassUtils.getQualifiedName(requiredType) + "'" : ""),
			cause);
	this.value = value;
	this.requiredType = requiredType;
}
 
Example 10
Source File: UnsatisfiedDependencyException.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new UnsatisfiedDependencyException.
 * @param resourceDescription description of the resource that the bean definition came from
 * @param beanName the name of the bean requested
 * @param ctorArgIndex the index of the constructor argument that couldn't be satisfied
 * @param ctorArgType the type of the constructor argument that couldn't be satisfied
 * @param msg the detail message
 */
public UnsatisfiedDependencyException(
		String resourceDescription, String beanName, int ctorArgIndex, Class<?> ctorArgType, String msg) {

	super(resourceDescription, beanName,
			"Unsatisfied dependency expressed through constructor argument with index " +
			ctorArgIndex + " of type [" + ClassUtils.getQualifiedName(ctorArgType) + "]" +
			(msg != null ? ": " + msg : ""));
}
 
Example 11
Source File: UnsatisfiedDependencyException.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new UnsatisfiedDependencyException.
 * @param resourceDescription description of the resource that the bean definition came from
 * @param beanName the name of the bean requested
 * @param ctorArgIndex the index of the constructor argument that couldn't be satisfied
 * @param ctorArgType the type of the constructor argument that couldn't be satisfied
 * @param msg the detail message
 * @deprecated in favor of {@link #UnsatisfiedDependencyException(String, String, InjectionPoint, String)}
 */
@Deprecated
public UnsatisfiedDependencyException(
		String resourceDescription, String beanName, int ctorArgIndex, Class<?> ctorArgType, String msg) {

	super(resourceDescription, beanName,
			"Unsatisfied dependency expressed through constructor argument with index " +
			ctorArgIndex + " of type [" + ClassUtils.getQualifiedName(ctorArgType) + "]" +
			(msg != null ? ": " + msg : ""));
}
 
Example 12
Source File: TypeMismatchException.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Create a new {@code TypeMismatchException} without a {@code PropertyChangeEvent}.
 * @param value the offending value that couldn't be converted (may be {@code null})
 * @param requiredType the required target type (or {@code null} if not known)
 * @param cause the root cause (may be {@code null})
 * @see #initPropertyName
 */
public TypeMismatchException(@Nullable Object value, @Nullable Class<?> requiredType, @Nullable Throwable cause) {
	super("Failed to convert value of type '" + ClassUtils.getDescriptiveType(value) + "'" +
			(requiredType != null ? " to required type '" + ClassUtils.getQualifiedName(requiredType) + "'" : ""),
			cause);
	this.value = value;
	this.requiredType = requiredType;
}
 
Example 13
Source File: TypeMismatchException.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new TypeMismatchException without PropertyChangeEvent.
 * @param value the offending value that couldn't be converted (may be {@code null})
 * @param requiredType the required target type (or {@code null} if not known)
 * @param cause the root cause (may be {@code null})
 */
public TypeMismatchException(Object value, Class<?> requiredType, Throwable cause) {
	super("Failed to convert value of type '" + ClassUtils.getDescriptiveType(value) + "'" +
			(requiredType != null ? " to required type '" + ClassUtils.getQualifiedName(requiredType) + "'" : ""),
			cause);
	this.value = value;
	this.requiredType = requiredType;
}
 
Example 14
Source File: TypeMismatchException.java    From blog_demos with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new TypeMismatchException.
 * @param propertyChangeEvent the PropertyChangeEvent that resulted in the problem
 * @param requiredType the required target type (or {@code null} if not known)
 * @param cause the root cause (may be {@code null})
 */
public TypeMismatchException(PropertyChangeEvent propertyChangeEvent, Class<?> requiredType, Throwable cause) {
	super(propertyChangeEvent,
			"Failed to convert property value of type '" +
			ClassUtils.getDescriptiveType(propertyChangeEvent.getNewValue()) + "'" +
			(requiredType != null ?
			 " to required type '" + ClassUtils.getQualifiedName(requiredType) + "'" : "") +
			(propertyChangeEvent.getPropertyName() != null ?
			 " for property '" + propertyChangeEvent.getPropertyName() + "'" : ""),
			cause);
	this.value = propertyChangeEvent.getNewValue();
	this.requiredType = requiredType;
}
 
Example 15
Source File: ClassEditor.java    From blog_demos with Apache License 2.0 5 votes vote down vote up
@Override
public String getAsText() {
	Class<?> clazz = (Class<?>) getValue();
	if (clazz != null) {
		return ClassUtils.getQualifiedName(clazz);
	}
	else {
		return "";
	}
}
 
Example 16
Source File: TypeDescriptor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return the name of this type: the fully qualified class name.
 */
public String getName() {
	return ClassUtils.getQualifiedName(getType());
}
 
Example 17
Source File: TypeDescriptor.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Return the name of this type: the fully qualified class name.
 */
public String getName() {
	return ClassUtils.getQualifiedName(getType());
}
 
Example 18
Source File: TypeDescriptor.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Return the name of this type: the fully qualified class name.
 */
public String getName() {
	return ClassUtils.getQualifiedName(getType());
}
 
Example 19
Source File: FormatHelper.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Determine a readable name for a given Class object.
 * <p>A String array will have the formatted name "java.lang.String[]".
 * @param clazz the Class whose name is to be formatted
 * @return a formatted String suitable for message inclusion
 * @see ClassUtils#getQualifiedName(Class)
 */
public static String formatClassNameForMessage(@Nullable Class<?> clazz) {
	return (clazz != null ? ClassUtils.getQualifiedName(clazz) : "null");
}
 
Example 20
Source File: FormatHelper.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Determine a readable name for a given Class object.
 * <p>A String array will have the formatted name "java.lang.String[]".
 * @param clazz the Class whose name is to be formatted
 * @return a formatted String suitable for message inclusion
 * @see ClassUtils#getQualifiedName(Class)
 */
public static String formatClassNameForMessage(@Nullable Class<?> clazz) {
	return (clazz != null ? ClassUtils.getQualifiedName(clazz) : "null");
}