WEBWORK2 Source Analysis continued three

Source: Internet
Author: User
Tags final interface object object client java web
Web
Finally, I intend to analyze the input in the webwork2.x section, the school inspection data usually includes client inspection and service-side check two, in the webwork2.x have very good support, first of all to analyze the service side, the service side of the school check class are all from the Com.opensymphony.xwork.validat or package, the service side of all the school inspection work is through a validationinterceptor interceptor to intercept, so that interceptor in the webwork2.x position is equivalent to our hearts "God", he is used to save everything, a bit exaggerated, Ha ha!



Below please enjoy the code of the Validationinterceptor interceptor







public class Validationinterceptor extends Aroundinterceptor {



protected void after (Actioninvocation dispatcher, String result) throws Exception {



}



Get the action, and then call Actionvalidatormanager to do the checking work



protected void before (Actioninvocation invocation) throws Exception {



Action action = invocation.getaction ();



String context = Invocation.getproxy (). Getactionname ();



...



Actionvalidatormanager.validate (action, context);



}



}



Don't go away, then look at Actionvalidatormanager, because this class is a bit complicated, just do the main analysis, others ignore



public class Actionvalidatormanager {



Protected static final String Validation_config_suffix = "-validation.xml";







For officers transferred Guevara check information caching



private static final Map Validatorcache = Collections.synchronizedmap (New HashMap ());



private static final Map Validatorfilecache = Collections.synchronizedmap (New HashMap ());



private static Final log = Logfactory.getlog (Actionvalidatormanager.class);



...



Create a delegatingvalidatorcontext to get settings resources such as error message information, etc.



public static void Validate (Object object, String context) throws Validationexception {



Validatorcontext validatorcontext = new Delegatingvalidatorcontext (object);



Validate (object, context, Validatorcontext);



}



//



public static void Validate (Object object, String context, Validatorcontext Validatorcontext) throws Validationexception {



Set up a school check list



List validators = getvalidators (Object.getclass (), context);



Set shortcircuitedfields = null;



Traverse this list



for (Iterator iterator = Validators.iterator (); Iterator.hasnext ();) {



Validator Validator = (Validator) iterator.next ();



Validator.setvalidatorcontext (Validatorcontext);



...



Call the school check class and note that all custom check classes must be implemented from the validator interface



Validator.validate (object);



}



...



}







As for the client check, because the operation is all from the Com.opensymphony.webwork.validators package, all other school inspection classes are inherited from the Scriptvalidationaware interface, due to the relationship between time I do not do analysis here, If you are interested, go and study it yourself!







In fact, there are a lot of webwork2.x inside the details of the call, I can not describe this, if you are interested, you may wish to look at the source.







Today is here, ah, as for the webwork2.x label I do not want to see, I do not know what is the reason I just do not like the label Ah, the next Java Web application I must use webwork2.x to develop, such a good framework does not have to be too bad ah!











Email:zhuam@studyjava.com



Zhuaming@Gmail.com





Blog:http://blog.csdn.net/zhuam




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.