开发工具:
文件大小: 1mb
下载次数: 0
上传时间: 2019-08-10
详细说明:NULL
博文链接:https://zzc1684.iteye.com/blog/2210510Ia Property Editor
ui t addProperty ChangeListener(Property ChangeListener):void
o getAs Texto: string
ubn get Custom Editoro: Component
w)a getlavalnitializ ationStringo: String
w)a getTagso: Stringll
wDa getvalueo: Object
u is Paintable: boolean
w)a paintvalue(Graphics, Rectangle):void
wD h remove Property ChangeListener(Property Change Listener): void
ui o setAs Text(String): void
G setvalue(object) void
G supportscustom Editor: boolean
我们使用属性编辑器一般都是将 String对象转换成我们需要的java对象而使用的。
有个方法 setastext很重要。比如 String对象"1"要使用属性编绀器转换成 Integer对象,通过 metatext里Iη teger. parserηt(text)
得到 Integer对象,然后将 Intege对象保存到属性中
它的棊本实现类是 Proper lyEdilor Support,一般我们要编写自定义的属性编辑器只需要继承这个类即可。
Spring中有很多自定义的属性编辑器,都在 spring- beans jar包下的org. springframework. beans. propertyeditors包里
v Eli Maven: org. springframework spring-beans: 4.0.2.RELEASE
I spring-beans-4.0.2. RELEASEJjar (library home)
META-INF
v Ed org. springframework beans
annotatIon
v ad property
ao ByteArray Property Editor
7 Charact er Edito
C a CharArray PropertyEditor
Ca CharsetEdite
ao ClassEr
O Class Edito
C Currency Editor
Ct Custom BooleanEdito
Ca Custom CollectionEdito
t Custom DateEditor
G Custom Map Editor
C3 Custom NumberEditor
C a FileEditor
Ca InputSource Editor
C. Input Stream Editor
Locale Editor
St PatternEditor
C 3 Pro
Ca ResourceBundleEditor
Cb StringArray Property Editor
a3 StringTrimmerEdit
C% Timezone Edito
CtURIEditor
C% URLEdit or
CtUUIDEdit
Ca ZoneldEditor
Custombooleaneditor继承 Property editor Support并重写 metatext方法。
99
ublic void setAsText(String text) throws ILlega LArgumentException
传递5ng参数
10e
String input =(text != null text trim(): null)
101
f (this. allowEmpty && I Stringutils, hasLength(input))[
// Treat empty string-as null value
setvalue(nuLl)
是否允许为空
CustomBooleanEditort的属性
else if (this, truestring != null & input, equa lsIgnore Case (this, truestring))t
trusting和 alsestnng,可在构造函数中设
setvalue(Boolean, TRUE)
108
else if (this, falsestring != null & input, equalsIgnore Case(this false String))i
109
setvalue(Boolean FALSE)
else if (this, trueString = null 65
triesting没设置的话,如果参数的x是
input: qua siGnore Case.11 input. equalsIgnore Case(VALUE0M)1tue.on、yes.1写死了, CustomBooleant
setvalue(Boolean, TRUE:
的活那么设置属性 value为 Boolean,Tne
116
else if(this, falseString = null &5
alsestring设置的话,如果参数toxt是
(input. equalsIgnore Case(VALUE_FALSE)II input. equalsIgnore Case(VALUE_OFF)I false, off, no. 0(EstT, Custom Boolean
input.equalsIgnore Case(VALUE_NO)II inputequals(VALUE_0)))t
的活那么设置属性vae为 Boolean.Fase
setvalue(Boolean FALSE);
else i
throw new ILlega LArgumentException("Invalid boolean value [" text +I"):
重要接口和类介绍
刚刚分析了sun设计的属性编辑器。下面我们来看下 Spring对这方面的设计。
1. PropertyEditorRegistry接口
封装方法来给 Javabean注册对应的属性编辑器
public interface Prope
ol void registercustomEditor(Class> requiredType, PropertyEditor propertyEditor)
void registerCustom Editor(Class> requiredType, String property Path, Property Editor property Editor):
o. Property Editor find Custom Editor[Class> requiredType, String propertyPath)
2 PropertyEditorRegistrySupport: PropertyEditorRegistry接口的基础实现类
pubLic class Property Edi torRegistry Support imp Lements PropertyEditorRe gistry
private static Class> zoneIdcLass
9由 static{..
private Conversion Service conversidnservice:
private boolean de faultEditorsActive= false;是否启用默认编目器
private boo Lean configva lueEditorsActive= false;是否启用 String,int,ong,shor数组属性编辑器
private Map , PropertyEditor> overriddenDefaulteditors:重与默认属性编辑器集合
private Map < class>, PropertyEditor> customEditors:自定义属性生编辑器集合
private Map< String, CustomEd lder> customEditors ForPath;自定义路径属性编辑器集合
private Map cLasss?>, PropertyEditors customEditorcache;自定义属性编辑器缓存集合
PropertyEditorRegistrySupport类有个 createDefaulteditors方法,会创建默认的属性编辑器。
te void create DefaultEditorsoi
260
this, defaultEditors new HashMap, PropertyEditor>(64):
/ SimpLe editors, without parameterization capabilities
/ The Dk does not contain a default editor for any of these target types
this, defaultEditors. put( Charset class, new CharsetEditor()
this defaultEditors put(Class, class, new ClassEditor
this, defaultEditors put(Class[l class, new CLassArray Editor())
2222
this, defaultEditors put(Currency. cLass, new Currency Editor(
this defaultEditors put (File class, new FileEditor()
this, defaultEditors, put(Inputstream. class, new InputstreamEditor()):
this, defaultEditors, put(Inputsource, class, new Input SourceEditor());
this, defaultEditors put (Locale, class, new LocaleEditor():
this, defaultEditors, put(Pattern, class, new PatternEditor(
this, defaultEditors, put(Properties, class, new PropertiesEditor()
this, defaultEditors, put(Re[l, class, new Resource Array PropertyEditor();
this, defaultEditors put(Time Zone. class, new Time ZoneEditor(
this, defaultEditors put (URI, class, new URIEditori
this, defaultEditors, put (URL, class, new URLEditort
218
this,defaultEditors put(UUID class, new UUIDEditor()):
if (zoneIdCLass ! nulL)i
this, defaultEditors put (zoneIdclass, new ZoneIdEditor()):
}
/ Default instances of collection editors
/ Can be overridden by registering custom instances of those as custom editors
this, defaul tEditors put(Collection c Lass, new Custom Co llectionEditor(Collection, class)):
this, defaultEditors put(Set class, new CustomCollectionEditor(Set class))
this, defaultEditors put(SortedSet, class, new CustomCollectionEditor (Sorted Set class))
this detaultEditors put (List, class, new CustomCollectionEdi tor (List. class)
this, defaultEditors put(SortedMap, class, new CustomMapEditor(SortedMap class)):
/ Default editors for primitive arrays
232
this, defaultEditors put (byte [l class, new ByteArray Property Editor()
itors, put(cha
ass, new CharArray Property Editor());
// The JDK does not contain
a default editor for cha
this. defaultEditors, put(char class, new CharacterEditor(false));
this, defaul tEditors, put( Character, class, new CharacterEditor(true))
//Spring's CustomBooleanEditor accepts more flag values than the JDK's default editor
this,, defaultEditors put (boolean, class, new CustomBooleanEditor(false))
241
this, defaultEditors, put (Boolean, class, new CustomBooleanEditor(true))
243
/ The Dk does not contain default editors for number wrapper types
bean属性编辑器
244合
/ Override JDK primitive number editors with our own CustomNumberEditor
Boolean类型的参数允许为空
this. defaultEditors. put(byte. class, new Custom NumberEditor(Byte. class, false):ban类型的不允许为空
this defaultEditors put(Byte class, new Custom NumberEditor(Byte class, true
247
this, defaultEditors put (short class, new Custom NumberEditor(Short, class, false))
this, defaultEditors, put(Short class, new CustomNumberEditor(Short, class, true)
this defaultEditors put (int class, new CustomNumberEditor(Integer. class, false)):
this, defaultEditors put (Integer, class, new CustomNumberEditor(Integer. class, true)):
this, defaultEditors put (long, class, new Cus tom NumberEditor(Long Class, false)
this, defaultEditors, put(Long, class, new Custom NumberEditor(Long, class, true
this defaul tEditors, put(float c Lass, new Custom NumberEditor[Float, class, false))
this defaultEditors put(Float, class, new Custom NumberEditor (Float, class, true)):
this, detaultEditors, put(double, cLass, new Custom NumberEditor(Doub le, cLass, false))
this, defaultEditors put(Double, class, new Custom NumberEditor(Double class, true)
this,defaultEditors put (Bi gDecimal class, new CustomNumberEditor(BigDecimal class, true))
this, defaultEditors put(BigInteger. class, new CustomNumberEditor(BigInteger. class, true)
/ OnLy register config value editors if explicitly requested
261
if (this, configvalueEditorsActive
stringArrayPropertyEditor sae= new StringArray PropertyEditor(:
this, defaultEditors, put (String ll, class, sae);
this, defau ltEdi tors. put[short[l class, sae)
this.defaultEditors put (int [l class, sae
this, defaultEditors put (long[l, class, sae):
268
3. Type Converter接口
类型转换接口。通过该接口,可以将 value转换为 requiredType类型的对象
6 e pub lic interface Type converter
52创
T> T convertIfNecessary (Object value, Class requiredType) throws TypeMismatchException:
创
>T convertIfNecessary (Object value, Class requiredType, MethodParameter methodParam)
throws TypeMismatchException:
<> T convertIfNecessary (object value, Class requiredType, Field field)
throws Type MismatchExceptior
4 Type Converter Support: Type Converter基础实现类,并继承了 PropertyEditorRegistrySupport
有个属性 type ConverterDelegate,类型为 Type ConverterDelegate, Type Support.将类型转换委托给
type ConverterDelegate操作。
5. Type ConverterDelegate
类型转换委托类。具体的类型转换操作由此类完成。
6. Simple Converter
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.