Eclipse书籍部分翻译(英译中)7

来源:百度知道 编辑:UC知道 时间:2024/05/12 07:51:20
The mechanism works as follows:
•Plug-ins declare that they need the help of other plug-ins to load classes.
•They also identify the kind of help they want by specifying a buddy policy. The policy defines what kinds of plug-ins are to be considered to be buddies as well as how (e.g., in what order) they are consulted.
•When a plug-in fails to find a desired class through all the normal routes as outlined in Section 26.10, "Classloading" (i.e., Import-Package, Require-Bundle, and local classes), its buddy policy is invoked.
•The invoked policy discovers a set of buddies and consults each one in turn until either the class is found or the list is exhausted.
Let's apply the built-in registered buddy policy to the log4j case and see how it helps. In the log4j scenario, there are a relatively large number of potential clients of the logging API and a small number of clients supplying appenders. For performance and simplicity, it

该机制运作如下:
•插件宣布,他们需要帮助的其他插件加载类。
•他们还确定什么样的帮助,他们希望通过指定好友政策。这一政策界定什么样的插件将被视为好友以及如何(例如,在什么顺序) ,他们的意见。
•当一个插件没有找到一个理想的类通过各种正常的路线中所概述的科26.10 , “ Classloading ” (即进口包装,需要束,和地方课程) ,其好友的政策是援引。
•援引政策的发现了一套朋友和协商每一个反过来,直到阶级或发现的名单已经耗尽。
让我们套用内置的注册好友政策的情况和log4j看看它是如何帮助。在log4j的情况下,有相当多的潜在客户的伐木API和少量的客户提供appenders 。对于性能和简单,它是合理的限制好友搜索范围,只是那些提供appenders 。最简单的办法是使这些插件明确登记为朋友的log4j 。
进行这项设定,您首先标志着log4j插件的需要classloading帮助,并确定“登记”政策的政策使用。下面一行添加到log4j的MANIFEST.MF作出声明:
Eclipse的BuddyPolicy :注册
然后在每个插件用品appenders ,添加下面一行的MANIFEST.MF注册插件作为一个好友的log4j (即org.apache.log4j ) :
Eclipse的RegisterBuddy : org.apache.log4j
在运行时,当log4j去实例一个appender使用Class.forName (字符串) ,它第一次尝试一切正常的先决条件。然后,当它未能找到appender类,每个注册好友的插件是要求加载类。如果所有的appender插件的注册, appender类是肯定会被发现。
注意:
朋友的意见,好象他们是来自一流的负载要求使用Bundle.loadClass (字符串) 。这就是说,好友的进口包裹,需要捆绑,并在事实上,自己的朋友都援引在必要时寻求理想的阶级。
内置的好友政策
Eclipse的用品了一些内置的政策,归纳于表20-1

1楼的牛