WebWork2 source code analysis

xiaoxiao2021-03-06  17

Finally, I intend to analyze the input school inspection section in WebWork2.x. The school check data usually includes two types of client checks and server checks. It has good support in WebWork2.x. First analyze the server, the server All school inspection categories come from com.opensymphony.xwork.validator package, all school inspections of the server are intercepted by a validationinterceptor interceptor, so the status of interceptor is equivalent to our hearts in WebWork2.x. "God", he is used to save everything, it is a bit exaggerated, haha!

Please enjoy the code of the ValidationInterceptor interceptor.

Public class validationInterceptor extends aroundinterceptor {

Protected void after (ActionInvocation Dispatcher, String Result) throws Exception {

}

// Get an action, then call ActionValidatorManager to check the job

Protected void before (actioninvocation invocation) throws exception {

Action action = invocation.getAction ();

String context = infocation.getProxy (). GetActionName ();

...

ActionValidatorManager.validate (action, context);

}

}

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

Public class actionvalidatorManager {

Protected static final string validation_config_suffix = "-validation.xml";

// Used to cache the school inspection information

Private static final map validatorcache = collections.synchronizedmap (new hashmap ());

Private static final map validatorfilecache = collections.synchronizedmap (new hashmap ());

Private static final log log = logfactory.getlog (actionValidatorManager.class);

...

/ / Create a DelegatingValidatorContext, used to get set resources, such as: error prompt 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 VALIDENEXCEPTION {

/ / Establish a school inspection list

List validators = getValidators (Object.getClass (), Context); Set ShortCircuitedFields = NULL;

// Traverse this list

Iterator itrator = Validators.ITERATOR (); item.hasnext ();) {

Validator Validator = (Validator) Iterator.next ();

Validator.SetValidatorContext (ValidatorContext);

...

// Call the school check class, pay attention to all custom school inspection classes must be implemented from the Validator interface

Validator.validate (Object);

}

...

}

As for the client-side examination, because all of the operations come from com.opensymphony.webwork.validators package, all other school inspection classes inherited from the ScriptValidationAware interface, due to time, I am not analyzed here, if you are interested, Go to study!

In fact, there are still many related details in WebWork2.x, where I can't describe it, if you are interested, you may wish to see the source code.

I am here today, as for the webwork2.x tab, I don't want to see it. I don't know if I am, I don't like the label. I must use WebWork2.x to develop this next Java web application. A Framework is not a pity!

Email: zhuam@studyjava.com

Zhuaming@gmail.com

Blog: http://blog.9cbs.net/zhuam

转载请注明原文地址:https://www.9cbs.com/read-41843.html

New Post(0)