Java對象驗證框架 - iScreen

fmms 12年前發布 | 51K 次閱讀 Java Ruby開發

iScreen是一個Java對象驗證框架。它的思想與Apache Jakarta的commons-validator項目相似,驗證規則使用XML進行配置但也支持其它配置類型。它比commons-validator更強大,靈活,易于使用。
Java Object Validation

Validation is done via Java objects. Typically, these will be JavaBeans, but this is not required. OGNL (see www.ognl.org) is used to access object fields, which gives considerable flexibility in what is eventually validated.

Internationalization

Though currently somewhat weak (meaning, it needs a lot more work before it's done), basic internationalization support exists via resource bundles.

Multiple Fields

Fundamental support for pulling multiple fields from a Java object and validating them together is supported. The capability, unlike most validation frameworks, is not tacked on, but is supported as a natural configuration capability.

XML Configuration

Though the underlying engine supports configuration by other means, the primary configuration format is XML. In the future, additional formats will become available.

Configuration Reuse

The feature is tied to the XML configuration capability. This re-use allows validations to be referenced by other validations via delegation. This is interesting because it simplifies and minimizes the configuration.

Dynamic Failure Messages

Failure messages that are generated during validation are dynamically generated. Not only that, but each "validator" is configured with the message it will use (so, it's never hard-coded). These "validators" can also use multiple messages for different reasons (for example, imagine a validator that checks string lengths: it can use a different message for an invalid minimum length from the one it uses for maximum length).

Failures and Warnings

There are two types of errors that a validator can report: a failure and a warning. A warning is a failure that can be ignored (depending upon how the application wants to handle it).

Configuration-Based

Definitions of validations are done via configuration in order to minimize the required amount of code. In fact, the amount of code necessary is fairly minimal. It's recommended that an inversion of control container be used to further minimize the necessary code.

OGNL Access

OGNL (see www.ognl.org) is used for basic mapping and Java object access. This object navigation library is extremely powerful, providing considerable flexibility in what data is being validated and how messages are generated.


項目主頁:http://www.baiduhome.net/lib/view/home/1326987082983

 本文由用戶 fmms 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!