亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? typeconverterdelegate.java

?? spring framework 2.5.4源代碼
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
/*
 * Copyright 2002-2008 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.beans;

import java.beans.PropertyDescriptor;
import java.beans.PropertyEditor;
import java.beans.PropertyEditorManager;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.WeakHashMap;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.core.CollectionFactory;
import org.springframework.core.GenericCollectionTypeResolver;
import org.springframework.core.JdkVersion;
import org.springframework.core.MethodParameter;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;

/**
 * Internal helper class for converting property values to target types.
 *
 * <p>Works on a given {@link PropertyEditorRegistrySupport} instance.
 * Used as a delegate by {@link BeanWrapperImpl} and {@link SimpleTypeConverter}.
 *
 * @author Juergen Hoeller
 * @author Rob Harrop
 * @since 2.0
 * @see BeanWrapperImpl
 * @see SimpleTypeConverter
 */
class TypeConverterDelegate {

	private static final Log logger = LogFactory.getLog(TypeConverterDelegate.class);

	private static final Map unknownEditorTypes = Collections.synchronizedMap(new WeakHashMap());

	private final PropertyEditorRegistrySupport propertyEditorRegistry;

	private final Object targetObject;


	/**
	 * Create a new TypeConverterDelegate for the given editor registry.
	 * @param propertyEditorRegistry the editor registry to use
	 */
	public TypeConverterDelegate(PropertyEditorRegistrySupport propertyEditorRegistry) {
		this(propertyEditorRegistry, null);
	}

	/**
	 * Create a new TypeConverterDelegate for the given editor registry and bean instance.
	 * @param propertyEditorRegistry the editor registry to use
	 * @param targetObject the target object to work on (as context that can be passed to editors)
	 */
	public TypeConverterDelegate(PropertyEditorRegistrySupport propertyEditorRegistry, Object targetObject) {
		this.propertyEditorRegistry = propertyEditorRegistry;
		this.targetObject = targetObject;
	}


	/**
	 * Convert the value to the specified required type.
	 * @param newValue the proposed new value
	 * @param requiredType the type we must convert to
	 * (or <code>null</code> if not known, for example in case of a collection element)
	 * @return the new value, possibly the result of type conversion
	 * @throws IllegalArgumentException if type conversion failed
	 */
	public Object convertIfNecessary(Object newValue, Class requiredType) throws IllegalArgumentException {
		return convertIfNecessary(null, null, newValue, requiredType, null, null);
	}

	/**
	 * Convert the value to the specified required type.
	 * @param newValue the proposed new value
	 * @param requiredType the type we must convert to
	 * (or <code>null</code> if not known, for example in case of a collection element)
	 * @param methodParam the method parameter that is the target of the conversion
	 * (may be <code>null</code>)
	 * @return the new value, possibly the result of type conversion
	 * @throws IllegalArgumentException if type conversion failed
	 */
	public Object convertIfNecessary(Object newValue, Class requiredType, MethodParameter methodParam)
			throws IllegalArgumentException {

		return convertIfNecessary(null, null, newValue, requiredType, null, methodParam);
	}

	/**
	 * Convert the value to the required type for the specified property.
	 * @param propertyName name of the property
	 * @param oldValue the previous value, if available (may be <code>null</code>)
	 * @param newValue the proposed new value
	 * @param requiredType the type we must convert to
	 * (or <code>null</code> if not known, for example in case of a collection element)
	 * @return the new value, possibly the result of type conversion
	 * @throws IllegalArgumentException if type conversion failed
	 */
	public Object convertIfNecessary(
			String propertyName, Object oldValue, Object newValue, Class requiredType)
			throws IllegalArgumentException {

		return convertIfNecessary(propertyName, oldValue, newValue, requiredType, null, null);
	}

	/**
	 * Convert the value to the required type for the specified property.
	 * @param oldValue the previous value, if available (may be <code>null</code>)
	 * @param newValue the proposed new value
	 * @param descriptor the JavaBeans descriptor for the property
	 * @return the new value, possibly the result of type conversion
	 * @throws IllegalArgumentException if type conversion failed
	 */
	public Object convertIfNecessary(Object oldValue, Object newValue, PropertyDescriptor descriptor)
			throws IllegalArgumentException {

		return convertIfNecessary(
				descriptor.getName(), oldValue, newValue, descriptor.getPropertyType(), descriptor,
				BeanUtils.getWriteMethodParameter(descriptor));
	}


	/**
	 * Convert the value to the required type (if necessary from a String),
	 * for the specified property.
	 * @param propertyName name of the property
	 * @param oldValue the previous value, if available (may be <code>null</code>)
	 * @param newValue the proposed new value
	 * @param requiredType the type we must convert to
	 * (or <code>null</code> if not known, for example in case of a collection element)
	 * @param descriptor the JavaBeans descriptor for the property
	 * @param methodParam the method parameter that is the target of the conversion
	 * (may be <code>null</code>)
	 * @return the new value, possibly the result of type conversion
	 * @throws IllegalArgumentException if type conversion failed
	 */
	protected Object convertIfNecessary(
			String propertyName, Object oldValue, Object newValue, Class requiredType,
			PropertyDescriptor descriptor, MethodParameter methodParam)
			throws IllegalArgumentException {

		Object convertedValue = newValue;

		// Custom editor for this type?
		PropertyEditor editor = this.propertyEditorRegistry.findCustomEditor(requiredType, propertyName);

		// Value not of required type?
		if (editor != null || (requiredType != null && !ClassUtils.isAssignableValue(requiredType, convertedValue))) {
			if (editor == null) {
				editor = findDefaultEditor(requiredType, descriptor);
			}
			convertedValue = doConvertValue(oldValue, convertedValue, requiredType, editor);
		}

		if (requiredType != null) {
			// Try to apply some standard type conversion rules if appropriate.

			if (convertedValue != null) {
				if (String.class.equals(requiredType) && ClassUtils.isPrimitiveOrWrapper(convertedValue.getClass())) {
					// We can stringify any primitive value...
					return convertedValue.toString();
				}
				else if (requiredType.isArray()) {
					// Array required -> apply appropriate conversion of elements.
					return convertToTypedArray(convertedValue, propertyName, requiredType.getComponentType());
				}
				else if (convertedValue instanceof Collection && CollectionFactory.isApproximableCollectionType(requiredType)) {
					// Convert elements to target type, if determined.
					convertedValue = convertToTypedCollection((Collection) convertedValue, propertyName, methodParam);
				}
				else if (convertedValue instanceof Map && CollectionFactory.isApproximableMapType(requiredType)) {
					// Convert keys and values to respective target type, if determined.
					convertedValue = convertToTypedMap((Map) convertedValue, propertyName, methodParam);
				}
				else if (convertedValue instanceof String && !requiredType.isInstance(convertedValue)) {
					String strValue = ((String) convertedValue).trim();
					if (JdkVersion.isAtLeastJava15() && requiredType.isEnum() && "".equals(strValue)) {
						// It's an empty enum identifier: reset the enum value to null.
						return null;
					}
					// Try field lookup as fallback: for JDK 1.5 enum or custom enum
					// with values defined as static fields. Resulting value still needs
					// to be checked, hence we don't return it right away.
					try {
						Field enumField = requiredType.getField(strValue);
						convertedValue = enumField.get(null);
					}
					catch (Throwable ex) {
						if (logger.isTraceEnabled()) {
							logger.trace("Field [" + convertedValue + "] isn't an enum value", ex);
						}
					}
				}
			}

			if (!ClassUtils.isAssignableValue(requiredType, convertedValue)) {
				// Definitely doesn't match: throw IllegalArgumentException.
				throw new IllegalArgumentException("Cannot convert value of type [" +
						(newValue != null ? ClassUtils.getQualifiedName(newValue.getClass()) : null) +
						"] to required type [" + ClassUtils.getQualifiedName(requiredType) + "]" +
						(propertyName != null ? " for property '" + propertyName + "'" : "") +
						": no matching editors or conversion strategy found");
			}
		}

		return convertedValue;
	}

	/**
	 * Find a default editor for the given type.
	 * @param requiredType the type to find an editor for
	 * @param descriptor the JavaBeans descriptor for the property
	 * @return the corresponding editor, or <code>null</code> if none
	 */
	protected PropertyEditor findDefaultEditor(Class requiredType, PropertyDescriptor descriptor) {
		PropertyEditor editor = null;
		if (descriptor != null) {
			if (JdkVersion.isAtLeastJava15()) {
				editor = descriptor.createPropertyEditor(this.targetObject);
			}
			else {
				Class editorClass = descriptor.getPropertyEditorClass();
				if (editorClass != null) {
					editor = (PropertyEditor) BeanUtils.instantiateClass(editorClass);
				}
			}
		}
		if (editor == null && requiredType != null) {
			// No custom editor -> check BeanWrapperImpl's default editors.
			editor = (PropertyEditor) this.propertyEditorRegistry.getDefaultEditor(requiredType);
			if (editor == null && !String.class.equals(requiredType)) {
				// No BeanWrapper default editor -> check standard JavaBean editor.
				editor = BeanUtils.findEditorByConvention(requiredType);
				if (editor == null && !unknownEditorTypes.containsKey(requiredType)) {
					// Deprecated global PropertyEditorManager fallback...
					editor = PropertyEditorManager.findEditor(requiredType);
					if (editor == null) {
						// Regular case as of Spring 2.5
						unknownEditorTypes.put(requiredType, Boolean.TRUE);
					}
					else {
						logger.warn("PropertyEditor [" + editor.getClass().getName() +
								"] found through deprecated global PropertyEditorManager fallback - " +
								"consider using a more isolated form of registration, e.g. on the BeanWrapper/BeanFactory!");
					}
				}
			}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美韩国日本综合| 日韩一级成人av| 国产精品卡一卡二| 高清不卡在线观看| 国产精品久久久久影院| 成人国产精品免费观看| 亚洲少妇中出一区| 欧美亚洲动漫精品| 日韩福利视频网| 欧美精品一区二区三区视频| 激情亚洲综合在线| 国产精品无人区| 欧美亚洲一区二区在线观看| 天堂在线亚洲视频| 精品va天堂亚洲国产| 成人午夜看片网址| 亚洲午夜国产一区99re久久| 在线播放/欧美激情| 国产一区二区主播在线| 国产精品不卡视频| 91.com在线观看| 国产91在线观看丝袜| 亚洲最色的网站| 精品国产乱码久久久久久1区2区| 成人午夜免费视频| 天天av天天翘天天综合网| 精品国产1区二区| 色先锋aa成人| 久久福利视频一区二区| 国产精品成人在线观看| 日韩你懂的电影在线观看| 成人福利视频在线看| 婷婷国产在线综合| 亚洲国产欧美日韩另类综合| 精品国产乱码久久久久久久久| 97精品视频在线观看自产线路二| 日日夜夜精品视频天天综合网| 精品少妇一区二区三区视频免付费| av一区二区三区四区| 日本va欧美va精品发布| 亚洲欧洲一区二区在线播放| 精品久久久久一区| 欧美在线观看一区二区| 粉嫩一区二区三区在线看| 首页综合国产亚洲丝袜| ●精品国产综合乱码久久久久| 欧美一区中文字幕| 色av成人天堂桃色av| 国产白丝网站精品污在线入口 | 国产精品免费观看视频| 在线观看91精品国产麻豆| 成人一级视频在线观看| 蜜桃视频免费观看一区| 亚洲猫色日本管| 欧美国产精品一区二区三区| 日韩一区二区三区高清免费看看 | 亚洲1区2区3区4区| 亚洲天堂2014| 国产精品夫妻自拍| 国产人久久人人人人爽| 精品国产免费一区二区三区四区| 欧美欧美午夜aⅴ在线观看| 91网上在线视频| 国产suv精品一区二区883| 精品一区二区三区免费播放 | 免费欧美高清视频| 亚洲成人免费影院| 亚洲一二三区不卡| 亚洲综合一区在线| 尤物av一区二区| 亚洲精品免费在线观看| 自拍偷拍亚洲欧美日韩| 国产欧美精品区一区二区三区| 亚洲精品一线二线三线| 精品三级av在线| 久久日韩粉嫩一区二区三区 | 成人97人人超碰人人99| 国产乱码精品1区2区3区| 麻豆成人91精品二区三区| 日韩精品五月天| 三级欧美在线一区| 奇米888四色在线精品| 日日夜夜免费精品| 蜜臀91精品一区二区三区| 日本午夜一区二区| 蜜臀久久99精品久久久久久9| 日韩激情视频网站| 久久成人免费网| 国产精品一品二品| 国产成人精品在线看| 成人午夜激情视频| 91久久精品一区二区三| 欧美视频一区二| 欧美一区二区三区日韩视频| 精品国产乱码久久久久久浪潮| 国产亚洲欧美中文| 精品一区二区精品| 国产精品一二三区在线| 成人小视频在线观看| 色综合一区二区| 日本道精品一区二区三区| 欧美精品 国产精品| 日韩欧美国产综合一区| 久久久久久久久久看片| 中文字幕av免费专区久久| 日韩理论片一区二区| 亚洲成人动漫在线免费观看| 久久黄色级2电影| 99在线精品一区二区三区| 在线观看三级视频欧美| 日韩欧美一区二区三区在线| 国产日本一区二区| 亚洲精品福利视频网站| 奇米888四色在线精品| va亚洲va日韩不卡在线观看| 精品视频1区2区3区| 久久婷婷成人综合色| 一区二区三区不卡视频| 激情欧美日韩一区二区| 91视频免费观看| 欧美videofree性高清杂交| 18涩涩午夜精品.www| 久久精品国产一区二区三 | 韩国欧美一区二区| 色哟哟国产精品免费观看| 欧美变态凌虐bdsm| 亚洲精品日韩专区silk| 激情综合网最新| 色婷婷av一区二区三区软件| 精品国产成人系列| 亚洲国产一区二区三区| 国产成人小视频| 91精品国产综合久久福利| 中文字幕一区二区三区蜜月 | 久久伊人蜜桃av一区二区| 亚洲制服欧美中文字幕中文字幕| 国产主播一区二区| 欧美精品在线一区二区三区| 国产精品每日更新| 免费一区二区视频| 欧美性色欧美a在线播放| 国产精品欧美久久久久一区二区 | 一区二区免费在线播放| 国产高清精品在线| 精品少妇一区二区三区在线视频| 亚洲一区二区三区四区不卡| 成人国产精品免费观看| 久久新电视剧免费观看| 麻豆91精品视频| 欧美一区二区在线视频| 夜夜亚洲天天久久| 色婷婷久久久综合中文字幕| 国产日韩精品一区| 国产精品99久久久| 日韩美女视频一区二区在线观看| 亚洲线精品一区二区三区八戒| 91麻豆免费观看| 亚洲人成精品久久久久久 | 一本久久综合亚洲鲁鲁五月天| 国产色爱av资源综合区| 久久精品国产一区二区三| 日韩一区二区电影网| 亚洲成人免费影院| 欧美午夜精品久久久久久孕妇 | 青草国产精品久久久久久| 欧美网站大全在线观看| 亚洲色图一区二区| 91婷婷韩国欧美一区二区| 国产精品嫩草影院com| gogogo免费视频观看亚洲一| 中文字幕第一页久久| 成人综合在线网站| 国产精品免费视频一区| 国产成人av一区二区三区在线观看| 精品成人私密视频| 岛国精品在线播放| 自拍偷拍亚洲综合| 日本电影亚洲天堂一区| 亚洲线精品一区二区三区| 欧美电影一区二区三区| 激情综合色综合久久| 久久久久久久久久久电影| 国产成人在线视频免费播放| 国产精品美女视频| 欧美做爰猛烈大尺度电影无法无天| 亚洲一区二区在线观看视频| 欧美熟乱第一页| 日本强好片久久久久久aaa| 精品成人a区在线观看| 国产成人精品www牛牛影视| 综合网在线视频| 欧美日韩免费观看一区三区| 蜜臀av性久久久久蜜臀aⅴ流畅| 精品福利二区三区| 成人av免费观看| 午夜久久久久久电影| 精品国产123| 欧美综合一区二区| 另类成人小视频在线| 国产精品日韩成人|