目录

我的学习分享

记录精彩的程序人生

【Netbeans Platform】Lookup API

The Lookup API is a loose coupling mechanism enabling a
component to place a query for a particular interface and get back
pointers to all registered instances of that interface across all modules
of the application. Simply put, Lookup is an observable Map, with
Class objects as keys and instances of those Class objects as values,
and it allows loosely coupled communication between modules
.

NetBeans’ implementation of a MultiFileSystem is the so-called System FileSystem. It is
used to define all of the actions, menus, menu items, icons, key bindings, toolbars, and
services available in your application.
It can be viewed from the Files window under the build directory as classes/
METAINF/generated-layer.xml. In previous versions of NetBeans, the developer had
to edit a layer.xml file like the above in order to configure actions, menu and toolbar
items, key bindings, service providers, etc. Nowadays, all these should be taken care by
annotations, as we shall see in the next chapter. However, there are still some specialized
things that you can only do by editing this file. Furthermore, the layer.xml file is the
gateway to your NetBeans Platform application’s complete configuration data. The
FileSystem API handles this virtual file system in the same way (Listing 7-10).

// Listing 7-10. Accessing layer.xml with the FileSystem API
FileObject root = FileUtil.getConfigRoot();
FileObject someFolder = FileUtil.getConfigFile("someFolder");
JToolBar tb = FileUtil.getConfigObject("/path/to/fileobject", JToolBar.
class)

The System FileSystem provides another type of inter-module communication (the
other is the Lookup). Using the layer.xml file, a module can register folders and files that
another module can use.

Documents are TopComponents in the editor mode.