站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > NetBeans API Javadoc (Current Development Version)

MIME Lookup API - NetBeans Architecture Questions - NetBeans API Javadoc (Current Development Version)

NetBeans Architecture Answers for MIME Lookup API module

WARNING: answering questions version 1.28 rather than the current 1.29.

Interfaces table

Group of java interfaces
Interface NameIn/OutStabilitySpecified in What Document?
MimeLookupAPIExportedOfficial
MimeLookupSPIExportedOfficial
FilesystemsAPIImportedOfficial .../overview-summary.html

The module is needed for compilation. The module is used during runtime. Specification version 7.1 is required.

UtilitiesAPIImportedOfficial../org-openide-util/overview-summary.html

The module is needed for compilation. The module is used during runtime. Specification version 7.3 is required.


General Information

    Question (arch-what): What is this project good for?

    Answer: Each editor provides an EditorKit which controls the policy of specific MIME content type. The policy of content type should be easily registered and found via some lookup mechanism, that will provide convenient way of using it either for kit provider or base editor infrastructure. In addition to this, the policy can be inherited, (e.g. in case of embeded kits like JSP) and the content types need to be merged in this case. MIME Lookup API should provide all mentioned requierements via easy lookup query, so content type policy user need not to solve this searching and merging on its own side.

    Question (arch-overall): Describe the overall architecture.

    Answer: It consists of

    API contains only two classes:

    1. org.netbeans.api.editor.mimelookup.MimeLookup with public methods:
    • static MimeLookup getMimeLookup(String mime) - gets mime specific lookup.
    • static Lookup getLookup(MimePath mimePath) - gets the lookup for the particular mime-path.
    • MimeLookup childLookup(String mime) - gets mime specific child (embeded) lookup. The method was deprecated in favour of static Lookup getLookup(MimePath mimePath)
    • Object lookup(Class clazz) - Look up an object matching a given interface.
    • Result lookup(Lookup.Template template) - The general lookup method. Callers can get list of all instances and classes that match the given template and attach a listener to this be notified about changes.

    2. org.netbeans.api.editor.mimelookup.MimePath with public methods:
    • static MimePath get(String mimeType) - gets root mime-path for the given mime-type.
    • static MimePath get(MimePath prefix, String mimeType) - gets mime-path corresponding to the mime-type used in the given context mime-path.
    • static MimePath parse(String path) - parses the given mime-path string e.g. "text/x-jsp/text/x-java" and get the corresponding mime-path.
    • String getPath() - gets string path represented by this mime-path.
    • int size() -gets total number of mime-types in the mime-path.
    • String getMimeType(int index) - gets mime type of this mime-path at the given index.
    • MimePath getPrefix(int size) - returns prefix mime-path with the given number of mime-type components ranging from zero till the size of this mime-path.


    MimeLookup is represented via ProxyLookup that collects registered lookups. Particular lookups, responsible for looking up their objects can be registered using interface MimeDataProvider into default lookup by META-INF/services registration. Previously used registration via interface MimeLookupInitializer was deprecated.

    In addition to this basic registration, xml layer folder registration is also available. It is provided by registering implemented interface Class2LayerFolder into default lookup via META-INF/services registration. This approach provides a mapping of class to specific subfolder. Using this mapping one can achieve the convenient way of using MimeLookup e.g.

    MimeLookup.getMimeLookup("text/x-java").lookup(FoldManagerFactory.class);

    Using this, an instance of FoldManagerFactory is retrieved from the folder with path "Editors/text/x-java/FoldManager" provided that FoldManagerFactory.class is registered to a subfolder "FoldManager" via Class2LayerFolder registration.

    There InstanceProvider can be used if there are files of various types in the layer folder that need additional handling before becoming and instance of certain class. For more details look at use case of PopupActions creation.

    The Javadoc documentation can be generated by using

        cd /cvs/editor/mimelookup
        ant javadoc
    

    Question (arch-usecases): Describe the main use cases of the new API. Who will use it under what circumstances? What kind of code would typically need to be written to use the module?

    Answer:

    Per mime-type operation

    Operation of the editor module must be parametrized by the type of the file being edited. In the past the operation was parametrized by the class of the editor kit but that did not show up as being useful enough.
    It is more practical to use a string-based parametrization concretely the mime-type. Anyone can then easily register an additional functionality for the editor because it's just enough to know the right mime-type and the type of the functionality class to be implemented and the xml layer folder where the class should be registered.

    Provide list of instances as lookup result

    On the modules' implementation side the registered functionality must be retrieved somehow. It's necessary to instantiate the registered objects and react to module enabling/disabling which can affect validity of the registered objects.
    As the most convenient solution appears to use org.openide.util.Lookup allowing to provide the registered instances as a Lookup.Result allowing to listen for changes (e.g. caused by the module enabling/disabling).
    This resulted into creation of class MimeLookup extends Lookup containing static MimeLookup getMimeLookup(String mimeType).

    Nested mime-types

    On the lexical level the document can contain nested languages.
    For example JSP document can contain pieces of java code which can further contain javadoc comment tokens with nested javadoc language.
    The nested languages should allow for special settings such as fonts and colors of nested syntax coloring but even things like actions that would be active in the nested document section.
    This resulted into creation of static Lookup getLookup(MimePath mimePath) method in MimeLookup.

    Known clients summary

    Fold Manager Factories
    The editor/fold module expects to find the registered fold manager factories (org.netbeans.spi.editor.fold.FoldManagerFactory classes).

    Completion Providers
    The editor/completion module expects to find the registered completion providers (org.netbeans.spi.editor.completion.CompletionProvider classes).

    Editor Context Menu Actions
    The editor module expects to find the registered popup menu actions (javax.swing.Action classes or names of actions (i.e. value of Action.NAME attribute) present in editor kit e.g. "goto-source").

    Side Bars
    The editor/lib module expects to find factories for components to be placed on the sides of the editor component (org.netbeans.editor.SideBarFactory classes).

    Hyperlink Providers
    The editor/lib module expects to find hyperlink providers that allow connecting an open document with some other documents (org.netbeans.lib.editor.hyperlink.spi.HyperlinkProvider classes).

    Code Template Processors
    The editor/codetemplates module expects to find factories for code template processors (org.netbeans.lib.editor.codetemplates.spi.CodeTemplateProcessorFactory classes).

    Hints Providers
    The editor/hints module expects to find editor hints providers (org.netbeans.modules.editor.hints.spi.HintsProvider classes).


    API Use Cases

    Find class instances for the given mime-type

    An API method

    MimeLookup lookup = MimeLookup.getMimeLookup("text/x-java");

    can be used for getting the mime specific lookup. Having this we can lookup class or template:

    Object obj = lookup.lookup(LookedUpClass.class);

    or

    Lookup.Result result = lookup.lookup(new Lookup.Template(LookedUpClass.class));

    Getting embeded mime-type specific Lookup

    As an example a jsp scriptlet is used. Scriptlet in fact consists of parent "text/x-jsp" mime-type and embeded "text/x-java" mime-type. To obtain a scriptlet lookup firstly we need to get a MimePath and then get appropriate lookup:

        MimePath scriptletPath = MimePath.parse("text/x-jsp/text/x-java");
        Lookup lookup = MimeLookup.getLookup(scriptletPath);
    

    SPI Use Cases

    Providing implemented MimeLookupInitializer

    It is the general way of adding mime specific object into the MimeLookup. Implementation of MimeLookupInitializer should be created and registered to default lookup via META-INF/services registration. For details, please look at the simplified TestMimeLookupInitializer in mimelookup/test/unit or LayerMimeLookupInitializer. Usage of MimeLookupInitializer is deprecated, please use MimeDataProvider instead in similar way

    Question (arch-time): What are the time estimates of the work?

    Answer: Done.

    Question (arch-quality): How will the quality of your code be tested and how are future regressions going to be prevented?

    Answer: Unit tests are available.

    There are several testing areas covered:
    • MimeLookupTest.java
      • Looking up the class that has not registered subfolder via Class2LayerFolder. It should be found in the appropriate mime-type specific folder
      • Looking up the class that has registered subfolder via Class2LayerFolder
      • Testing if the MimeLookup is not recursive (see issue #58991 for more details)
      • Testing lazy lookup object creation. Object is instantiated only if it is directly looked up
      • Testing MimeLookupInitializer creation, registration and performing a lookup
    • MimeLookupInheritanceTest.java
      • Testing the inheritance and instance provider functionality as well as sorting of merged elements
    • MimeLookupPopupItemsChangeTest.java
      • Testing the dynamic change (addition or removal of a file [looked-up object] from xml layer folder) in inheritance tree, merging, sorting
    After fixing the issue #58941 unit tests of template lookup should be added. All tests was rewritten and adjusted to newly introduced MimePath.

    Question (arch-where): Where one can find sources for your module?

    Answer: Sources can be found in editor/mimelookup module.

    The default answer to this question is:

    The sources for the module are in NetBeans CVS in editor/mimelookup directory.


Project and platform dependencies

    Question (dep-nb): What other NetBeans projects and modules does this one depend on?

    Answer: The module needs (i.e. OpenIDE-Module-Needs) the following token: org.netbeans.spi.editor.mimelookup.MimeDataProvider. The implementation of the default MimeDataProvider that serves data from the folder hierarchy underneath the Editors/ folder on the system filesystem is provided by the editor/mimelookup/impl module. This module also provides the token mentioned earlier.

    The default answer to this question is:

    These modules are required in project.xml:

    • FilesystemsAPI - The module is needed for compilation. The module is used during runtime. Specification version 7.1 is required.
    • UtilitiesAPI - The module is needed for compilation. The module is used during runtime. Specification version 7.3 is required.

    Question (dep-non-nb): What other projects outside NetBeans does this one depend on?

    Answer: No other projects.

    Question (dep-platform): On which platforms does your module run? Does it run in the same way on each?

    Answer: All platforms.

    Question (dep-jre): Which version of JRE do you need (1.2, 1.3, 1.4, etc.)?

    Answer: JDK1.4 and higher can be used.

    Question (dep-jrejdk): Do you require the JDK or is the JRE enough?

    Answer: JRE is sufficient.

Deployment

    Question (deploy-jar): Do you deploy just module JAR file(s) or other files as well?

    Answer: No additional files.

    Question (deploy-nbm): Can you deploy an NBM via the Update Center?

    Answer: Yes.

    Question (deploy-shared): Do you need to be installed in the shared location only, or in the user directory only, or can your module be installed anywhere?

    Answer: Anywhere.

    Question (deploy-packages): Are packages of your module made inaccessible by not declaring them public?

    Answer: Yes, only the API and SPI are public. The implementation is not public.

    Question (deploy-dependencies): What do other modules need to do to declare a dependency on this one, in addition to or instead of the normal module dependency declaration (e.g. tokens to require)?

    Answer: Nothing.

Compatibility with environment

    Question (compat-i18n): Is your module correctly internationalized?

    Answer: Yes.

    Question (compat-standards): Does the module implement or define any standards? Is the implementation exact or does it deviate somehow?

    Answer: Compatible with standards.

    Question (compat-version): Can your module coexist with earlier and future versions of itself? Can you correctly read all old settings? Will future versions be able to read your current settings? Can you read or politely ignore settings stored by a future version?

    Answer: No persistence is used for MimeLookup

    Question (compat-deprecation): How the introduction of your project influences functionality provided by previous version of the product?

    Answer: As the module's API/SPI has been naturaly evolving over the time the module contains several deprecated classes. All of them are still fully supported and the module remains backward compatible.

Access to resources

    Question (resources-file): Does your module use java.io.File directly?

    Answer: Only in tests.

    Question (resources-layer): Does your module provide own layer? Does it create any files or folders in it? What it is trying to communicate by that and with which components?

    Answer: No.

    Question (resources-read): Does your module read any resources from layers? For what purpose?

    Answer: No.

    Question (resources-mask): Does your module mask/hide/override any resources provided by other modules in their layers?

    Answer: No.

    Question (resources-preferences): Does your module uses preferences via Preferences API? Does your module use NbPreferences or or regular JDK Preferences ? Does it read, write or both ? Does it share preferences with other modules ? If so, then why ?

    WARNING: Question with id="resources-preferences" has not been answered!

Lookup of components

    Question (lookup-lookup): Does your module use org.openide.util.Lookup or any similar technology to find any components to communicate with? Which ones?

    Answer: Yes. MimeLookup in API extends Lookup and it searches the default lookup for instances of MimeLookupInitializer (this is already deprecated) and MimeDataProvider.

    Question (lookup-register): Do you register anything into lookup for other code to find?

    Answer: No.

    Question (lookup-remove): Do you remove entries of other modules from lookup?

    Answer: No.

Execution Environment

    Question (exec-property): Is execution of your code influenced by any environment or Java system (System.getProperty) property? On a similar note, is there something interesting that you pass to java.util.logging.Logger? Or do you observe what others log?

    Answer: No.

    Question (exec-component): Is execution of your code influenced by any (string) property of any of your components?

    Answer: No.

    Question (exec-ant-tasks): Do you define or register any ant tasks that other can use?

    Answer: No.

    Question (exec-classloader): Does your code create its own class loader(s)?

    Answer: No.

    Question (exec-reflection): Does your code use Java Reflection to execute other code?

    Answer: No.

    Question (exec-privateaccess): Are you aware of any other parts of the system calling some of your methods by reflection?

    Answer: No.

    Question (exec-process): Do you execute an external process from your module? How do you ensure that the result is the same on different platforms? Do you parse output? Do you depend on result code?

    Answer: No.

    Question (exec-introspection): Does your module use any kind of runtime type information (instanceof, work with java.lang.Class, etc.)?

    Answer: No.

    Question (exec-threading): What threading models, if any, does your module adhere to? How the project behaves with respect to threading?

    Answer: No special threading models used.

    Question (security-policy): Does your functionality require modifications to the standard policy file?

    Answer: No.

    Question (security-grant): Does your code grant additional rights to some other code?

    Answer: No.

Format of files and protocols

    Question (format-types): Which protocols and file formats (if any) does your module read or write on disk, or transmit or receive over the network? Do you generate an ant build script? Can it be edited and modified?

    Answer: No files read or written to the disk.

    Question (format-dnd): Which protocols (if any) does your code understand during Drag & Drop?

    Answer: No D&D.

    Question (format-clipboard): Which data flavors (if any) does your code read from or insert to the clipboard (by access to clipboard on means calling methods on java.awt.datatransfer.Transferable?

    Answer: No clipboard support.

Performance and Scalability

    Question (perf-startup): Does your module run any code on startup?

    Answer: No.

    Question (perf-exit): Does your module run any code on exit?

    Answer: No.

    Question (perf-scale): Which external criteria influence the performance of your program (size of file in editor, number of files in menu, in source directory, etc.) and how well your code scales?

    Answer: Number of initialized MimeLookups. Since the MimeLookup delegates to ProxyLookup performance during lookup depends on the performance of ProxyLookup. LayerMimeLookupInitializer instantiates the object found in the layer only during direct lookup of the particular class using LazyLookup (inner class defined in LayerMimeLookupInitializer).

    Question (perf-limit): Are there any hard-coded or practical limits in the number or size of elements your code can handle?

    Answer: No limits.

    Question (perf-mem): How much memory does your component consume? Estimate with a relation to the number of windows, etc.

    Answer: MimeLookup caches instances of mime sensitive MimeLookups in static Map, instances of children MimeLookups in Map, InitializerListeners and Initializers in Lists. LayerMimeLookupInitializer also caches mime sensitive LayerMimeLookupInitializers and LazyLookups.

    Question (perf-wakeup): Does any piece of your code wake up periodically and do something even when the system is otherwise idle (no user interaction)?

    Answer: No.

    Question (perf-progress): Does your module execute any long-running tasks?

    Answer: No.

    Question (perf-huge_dialogs): Does your module contain any dialogs or wizards with a large number of GUI controls such as combo boxes, lists, trees, or text areas?

    Answer: No.

    Question (perf-menus): Does your module use dynamically updated context menus, or context-sensitive actions with complicated and slow enablement logic?

    Answer: No.

    Question (perf-spi): How the performance of the plugged in code will be enforced?

    Answer: Pluggins are just clients lookups that are installed into MimeLookup. The performance should be influenced by the lookupable object gathering by clients lookups. LayerMimeLookupInitializer (client lookup provided by mimelookup module) provides a LazyLookup, it instantiates the object found in the layer only during direct lookup of the particular class. Otherwise performance should be similar as ProxyLookup.

Built on May 28 2007.  |  Portions Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.