WEBX Example-petstore Analysis 1

Source: Internet
Author: User

1. Download the source code

2. Start the container and load the component--webxcontextloaderlistener

Webxcontextloaderlistener inherits from Org.springframework.web.context.ContextLoaderListener. It overrides a method: Createcontextloader (), which returns a Contextloader object, the context loader. The implementation of the method uses the anonymous inner class method, which returns the anonymous subclass of Webxcomponentsloader, which overrides a method: Getdefaultcontextclass ().

Webxcontextloaderlistener inherits the Method Contextinitialized () in the parent class Contextloaderlistener, which internally invokes the overridden method Createcontextloader (), and call Org.springframework.web.context.ContextLoader's Initwebapplicationcontext () using the Webxcomponentsloader object returned by the method Method.

The Initwebapplicationcontext method in Webxcomponentsloader, in addition to saving the ServletContext object, invokes the same method as the parent class Contextloader after calling Init ().

The Webxcomponentscontext class is used by default as the ApplicationContext that actually launches the spring container. It derives from the Webxapplicationcontext class. Descendants of Org.springframework.web.context.support.XmlWebApplicationContext.

Webxcomponentsloader.createcomponents method code is long, but only one thing to do: Create a WEBX component

A component in WEBX is a set of related functions, essentially a webapplicationcontext.

There are two sources of components:

? automatically scans for configuration file generation under the Web-inf directory

? webx.xml specified in

The collection of component names that are obtained in both ways is the set of assembly names that will eventually be processed. Note that the name of the component specified in the Webx.xml is also the Webx-*.xml form of the configuration file and cannot be specified at random.

Automatic scanning can be turned off, this time, only by configuring the way to get the components

The Componentpath property of a component can only be set by Webx.xml

The automatic scan works like this: Scans all files in the Web-inf directory that match Webx-*.xml, where * replaces the string as the component name. For example, Web-inf has a file named Webx-home.xml, which represents a component called home.

3. Load additional configuration files

4. Configure the Service Requestcontexts service

Detailed explanations can be found in the Official guide 7th, Chapter 8. Http://openwebx.org/docs/requestcontexts.html

Upload Service

Pull Service

The Pull service is the equivalent of providing a tool class that can be defined as a Java class and can be called in a VM template

Module-loader Service

Module is a programmable, executable logic that is identified by the module interface. The module interface has only one Execute method:

 
 

Implementing a custom module simply implements the module interface and implements the custom execution logic in the Execute () method. On the caller, the Execute () method is invoked through the module interface to trigger the module's execution.

Moduleloaderservice is a service that defines and locates modules. It loads classes by scanning specific packages or specific classes, and applies the loaded classes to the executable module. Each module in the Moduleloaderservice has both moduletype and modulename , which are used to represent the module information. Depending on the two information, you can find the required module from the Moduleloaderservice using the lookup interface provided by Moduleloaderservice.

Moduleloaderservice has two important components,modulefactory and moduleadapterfactory. The former is used to scan and load the module (which can be written in a non-Java language) based on specific conditions, while the latter is used to convert the loaded module into an executable module (implementing the Module Interface). Because Modulefactory-loaded module does not necessarily implement the module interface, even if the module interface is implemented, the interface has only one parameterless method, which limits the module's flexibility. So! Moduleadapterfactory through the mechanism of the adapter will not implement module interface but meet certain conditions of the module to implement the module interface adapter, while maintaining the original processing logic unchanged.

In the WEBX system, module undertakes the receiving and processing of user submissions, the control and forwarding of requests, the presentation of results, and other important functions. The WEBX default defines three types of module:

    • action: Mainly used to process the user submitted data, as well as the request control and forwarding;
    • screen: Mainly used to process the main content of the page;
    • control: Primarily used to process portions of a page, especially reusable content.

Screen and control can be used together with the template file to complete the presentation of the page, you can also separate from the template Output page.

In addition to action, screen and Control,moduleloaderservice, it also supports the convenience of defining other types of module.

The modulefactory interface scans and loads classes based on specific conditions, and WEBX provides two implementations for that interface:classmodulefactory and scriptmodulefactory. The former is used to load the Java-written module, which is written in facilitates with dynamic languages such as groovy.

The Moduleadapterfactory interface is used to convert the loaded module into an executable module,databindingadapterfactory and Actioneventadapterfactory is the two implementations of this interface. Databindingadapterfactory is suitable for all module with a method named execute (which can not implement the module interface, and the parameters of the Execute method can be arbitrarily defined). The databindingadapter is generated, and Actioneventadapterfactory is adapted to the module of type "action" to generate a actioneventadapter. Both Databindingadapter and Actioneventadapter implement the module interface. Databindingadapter only the public method named execute for the original module, which is invoked directly at execution time, while Actioneventadapter proxies all public methods starting with do (for example, Doadd ( ), the corresponding method is called according to the value of the request parameter at execution time.

<services:module-loader> is the element defined by the Springext mechanism specifically for defining moduleloaderservice, which has two properties:

    • Cacheenabled: If the module is cached, if the cache is used, the lookup module is first looked up from the cache when it is not present in the cache, and is located directly from the Modulefactory if the cache is not used. In production, it is recommended to turn on the module cache to improve module lookup performance;
    • Includedefaultadapters: Whether to use WEBX default implementation of Moduleadapterfactory, including: Databindingadapterfactory, Actioneventadapterfactory and Webx2moduleadapterfactory, if the value of this property is set to True, The default is to load these adapterfactory in Moduleloaderservice without additional configuration;

The <services:module-loader> element can also contain child elements, whose child elements can be divided into two types: the child elements of the configuration modulefactory and the child elements of the configuration moduleadapterfactory. The child elements of the configuration modulefactory are:

    • <ml-factories:class-modules>: Configure the Classmodulefactory to find classes generation module;
    • <ml-factories:script-modules>: Configure the Scriptmodulefactory to find Script generation module;
    • <ml-factories:factory >:classmodulefactory and Scriptmodulefactory are modulefactory implementations provided by WEBX, You can also extend the custom modulefactory and then use the <ml-factories:factory > element configuration, which has the same properties as the <bean> elements provided by spring;

There are also several child elements of the configuration moduleadapterfactory:

    • <ml-adapters:data-binding-adapter/>: Configuration databindingadapterfactory;
    • <ml-adapters:action-event-adapter/>: Configuration actioneventadapterfactory;
    • <ml-adapters:adapter>: Similar to Modulefactory, Moduleadapterfactory can also be extended to implement a custom moduleadapterfactory,< The ml-adapters:adapter> is used to configure the custom moduleadapterfactory.

When set <services:module-loader> includedefaultadapters= "true", Databindingadapterfactory, actioneventadapterfactory are automatically loaded for Moduleloaderservice, so you can no longer use <ml-adapters: Data-binding-adapter/> and <ml-adapters:action-event-adapter/> are additionally configured.

Resources

http://code.taobao.org/p/webx/wiki/module_load_service/

http://www.atatech.org/articles/55937

WEBX Example-petstore Analysis 1

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.