org.springframework.util.ClassUtils#getQualifiedName ( )源码实例Demo

下面列出了org.springframework.util.ClassUtils#getQualifiedName ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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)";
}
 
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;
}
 
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;
}
 
/**
 * 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;
}
 
源代码5 项目: blog_demos   文件: ClassEditor.java
@Override
public String getAsText() {
	Class<?> clazz = (Class<?>) getValue();
	if (clazz != null) {
		return ClassUtils.getQualifiedName(clazz);
	}
	else {
		return "";
	}
}
 
源代码6 项目: blog_demos   文件: TypeMismatchException.java
/**
 * 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;
}
 
源代码7 项目: lams   文件: TypeMismatchException.java
/**
 * 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;
}
 
/**
 * 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;
}
 
源代码9 项目: lams   文件: UnsatisfiedDependencyException.java
/**
 * 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 : ""));
}
 
源代码10 项目: spring4-understanding   文件: ClassEditor.java
@Override
public String getAsText() {
	Class<?> clazz = (Class<?>) getValue();
	if (clazz != null) {
		return ClassUtils.getQualifiedName(clazz);
	}
	else {
		return "";
	}
}
 
/**
 * 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 : ""));
}
 
/**
 * 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;
}
 
@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());
}
 
源代码14 项目: lams   文件: ClassEditor.java
@Override
public String getAsText() {
	Class<?> clazz = (Class<?>) getValue();
	if (clazz != null) {
		return ClassUtils.getQualifiedName(clazz);
	}
	else {
		return "";
	}
}
 
源代码15 项目: lams   文件: TypeMismatchException.java
/**
 * 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;
}
 
源代码16 项目: spring-analysis-note   文件: TypeDescriptor.java
/**
 * Return the name of this type: the fully qualified class name.
 */
public String getName() {
	return ClassUtils.getQualifiedName(getType());
}
 
源代码17 项目: lams   文件: TypeDescriptor.java
/**
 * Return the name of this type: the fully qualified class name.
 */
public String getName() {
	return ClassUtils.getQualifiedName(getType());
}
 
源代码18 项目: java-technology-stack   文件: TypeDescriptor.java
/**
 * Return the name of this type: the fully qualified class name.
 */
public String getName() {
	return ClassUtils.getQualifiedName(getType());
}
 
源代码19 项目: spring-analysis-note   文件: FormatHelper.java
/**
 * 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");
}
 
源代码20 项目: java-technology-stack   文件: FormatHelper.java
/**
 * 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");
}