Translator in hivemind

Source: Internet
Author: User
In many cases, an attribute represented by a string needs to be converted to a specific object, such as Boolean, integer, or date. Hivemind uses translator to complete this task. You can name a translator in <attribute> or <element>.
Hivemind's support for translator is managed by a class called translatormanager. Considering the scalability of translator, it has a special structure for translator. First, it requires all translators to inherit the same interface, and the constructor is also limited. Second, it expands itself through the extension Point configuration.
In the Framework Package of hivemind, there is a configuration extension point named translators, which defines the format of configuring translator in its schema. Interestingly, the translator attribute is recursively used in this schema, which makes the entire format seem confusing. The solution to this loop call is to preset the translator in the kernel so that the request loop is not generated when the extension point is generated. When a request is sent to translatormanager to apply for a translator, translatormanager does not read the data of the configuration extension point immediately. It only reads the configuration data of translator when the necessary translator is not found. Because the four translators class, service, smart, and instance are preset, the circular dependency on the translator is not generated when reading the configuration data.
In the pre-defined Translator, there is a kind of Translator called object, which needs to be used with ObjectProvider. The role of ObjectProvider is very similar to that of Translator, and the work done is very similar. The difference is that ObjectProvider must inherit another interface. The purpose of this operation is to increase flexibility and allow objects to take values in multiple ways. Instead of writing a new Translator for each value method, you do not need to know which objectproviders are currently available. On the other hand, this write can also make the meaning of the value clearer, because the Translator attribute must use a prefix to declare the ObjectProvider to get the object. For example, if you want to obtain a bean in spring after the application integrates spring, you can use the following format <... value = "spring: beanName"/>.
Translator is a task supported by the HiveMind kernel and can be expanded by configuration. We can see this phenomenon in other work supported by HiveMind kernel. The kernel code and key configurations cannot be completely separated. At least for a higher efficiency, it cannot be completely separated.

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.