<!-- <questionid="arch-what"when="init"> Whatisthisprojectgoodfor? <hint> Pleaseprovidehereafewlinesdescribingtheproject, whatproblemitshouldsolve,providelinkstodocumentation, specifications,etc. </hint> </question>
-->
<answer id="arch-what">
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.
</answer>
It consists of
<ul>
<li><api name="MimeLookupAPI" group="java"type="export" category="official"/> in <code>org.netbeans.api.editor.mimelookup</code></li>
<li><api name="MimeLookupSPI" group="java"type="export" category="official"/> in <code>org.netbeans.spi.editor.mimelookup</code></li>
</ul>
<p>API contains only two classes:</p>
1. org.netbeans.api.editor.mimelookup.MimeLookup with public methods:
<ul>
<li> <code> static MimeLookup getMimeLookup(String mime) </code> - gets mime specific lookup. </li>
<li> <code> static Lookup getLookup(MimePath mimePath) </code> - gets the lookup for the particular mime-path.</li>
<li> <code> MimeLookup childLookup(String mime) </code> - gets mime specific child (embeded) lookup. The method was deprecated in favour of
static Lookup getLookup(MimePath mimePath) </li>
<li> <code> Object lookup(Class clazz) </code> - Look up an object matching a given interface. </li>
<li> <code> Result lookup(Lookup.Template template) </code> - The general lookup method. Callers can get list of all instances and classes
that match the given <code>template</code> and attach a listener to
this be notified about changes. </li>
</ul>
<br/> 2. org.netbeans.api.editor.mimelookup.MimePath with public methods:
<ul>
<li> <code> static MimePath get(String mimeType) </code> - gets root mime-path for the given mime-type. </li>
<li> <code> static MimePath get(MimePath prefix, String mimeType) </code> - gets mime-path corresponding to the mime-type used in the given context
mime-path.</li>
<li> <code> static MimePath parse(String path) </code> - parses the given mime-path string
e.g. "text/x-jsp/text/x-java" and get the corresponding mime-path. </li>
<li> <code> String getPath() </code> - gets string path represented by this mime-path. </li>
<li> <code> int size() </code> -gets total number of mime-types in the mime-path. </li>
<li> <code> String getMimeType(int index) </code> - gets mime type of this mime-path at the given index. </li>
<li> <code> MimePath getPrefix(int size) </code> - returns prefix mime-path with the given number of mime-type components
ranging from zero till the size of this mime-path. </li>
</ul>
<br/>
<br/>
<code>MimeLookup</code> is represented via ProxyLookup that collects registered lookups. Particular lookups,
responsible for looking up their objects can be registered using interface <code>MimeDataProvider</code> into default lookup
by META-INF/services registration. Previously used registration via interface <code> MimeLookupInitializer</code> was deprecated.
<br/>
In addition to this basic registration, xml layer folder registration is also available.
It is provided by registering implemented interface <code>Class2LayerFolder</code> 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 <code>MimeLookup</code> e.g.
<p>
<code>
MimeLookup.getMimeLookup("text/x-java").lookup(FoldManagerFactory.class);
</code>
</p>
<p>
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 <code>Class2LayerFolder</code> registration.
</p>
<br/>
There <code>InstanceProvider</code> 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.
<p>
The Javadoc documentation can be generated by using
</p>
<pre>
cd /cvs/editor/mimelookup
ant javadoc
</pre>
</answer>
<!-- <questionid="arch-quality"when="init"> Howwillthe<ahref="http://www.netbeans.org/community/guidelines/q-evangelism.html">quality</a> ofyourcodebetestedand howarefutureregressionsgoingtobeprevented? <hint> Whatkindoftestingdo youwanttouse?Howmuchfunctionality,inwhichareas, shouldbecoveredbythetests? </hint> </question>
-->
<answer id="arch-quality">
Unit tests are available.
<br/>
There are several testing areas covered:
<ul>
<li> <code>MimeLookupTest.java</code>
<ul>
<li> Looking up the class that has not registered subfolder via <code>Class2LayerFolder</code>.
It should be found in the appropriate mime-type specific folder</li>
<li> Looking up the class that has registered subfolder via <code>Class2LayerFolder</code></li>
<li> Testing if the <code>MimeLookup</code> is not recursive (see issue #58991 for more details)</li>
<li> Testing lazy lookup object creation. Object is instantiated only if it is directly looked up</li>
<li> Testing <code>MimeLookupInitializer</code> creation, registration and performing a lookup</li>
</ul>
</li>
<li> <code>MimeLookupInheritanceTest.java</code>
<ul>
<li> Testing the inheritance and instance provider functionality as well as
sorting of merged elements</li>
</ul>
</li>
<li> <code>MimeLookupPopupItemsChangeTest.java</code>
<ul>
<li> Testing the dynamic change (addition or removal of a file [looked-up object]
from xml layer folder) in inheritance tree, merging, sorting</li>
</ul>
</li>
</ul>
After fixing the <a href="https://bz.apache.org/netbeans/show_bug.cgi?id=58941"> issue #58941 </a>
unit tests of template lookup should be added. All tests was rewritten and adjusted to newly introduced
MimePath.
</answer>
<usecase id="per-mime-type-operation" name="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.
<br/>
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.
</usecase>
<usecase id="provide-lookup-result" name="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.
<br/>
As the most convenient solution appears to use
<code>org.openide.util.Lookup</code> allowing to provide
the registered instances as a <code>Lookup.Result</code>
allowing to listen for changes (e.g. caused by the module enabling/disabling).
<br/>
This resulted into creation of <code>class MimeLookup extends Lookup</code> containing
<code>static MimeLookup getMimeLookup(String mimeType)</code>.
</usecase>
<usecase id="nested-mime-types" name="Nested mime-types">
On the lexical level the document can contain nested languages.
<br/>
For example JSP document can contain pieces of java code which can further contain
javadoc comment tokens with nested javadoc language.
<br/>
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.
<br/>
This resulted into creation of
<code>static Lookup getLookup(MimePath mimePath)</code> method in <code>MimeLookup</code>.
</usecase>
<usecase id="known-clients-summary" name="Known clients summary">
<b>Fold Manager Factories</b>
<br/>
The editor/fold module expects to find the registered
fold manager factories (<code>org.netbeans.spi.editor.fold.FoldManagerFactory</code> classes).
<br/>
<br/>
<b>Completion Providers</b>
<br/>
The editor/completion module expects to find the registered
completion providers (<code>org.netbeans.spi.editor.completion.CompletionProvider</code> classes).
<br/>
<br/>
<b>Editor Context Menu Actions</b>
<br/>
The editor module expects to find the registered
popup menu actions (<code>javax.swing.Action</code> classes or names of actions
(i.e. value of Action.NAME attribute) present in editor kit e.g. "goto-source").
<br/>
<br/>
<b>Side Bars</b>
<br/>
The editor/lib module expects to find factories for components to be placed on the
sides of the editor component (<code>org.netbeans.editor.SideBarFactory</code> classes).
<br/>
<br/>
<b>Hyperlink Providers</b>
<br/>
The editor/lib module expects to find hyperlink providers that allow connecting
an open document with some other documents (<code>org.netbeans.lib.editor.hyperlink.spi.HyperlinkProvider</code> classes).
<br/>
<br/>
<b>Code Template Processors</b>
<br/>
The editor/codetemplates module expects to find factories for code template processors
(<code>org.netbeans.lib.editor.codetemplates.spi.CodeTemplateProcessorFactory</code> classes).
<br/>
<br/>
<b>Hints Providers</b>
<br/>
The editor/hints module expects to find editor hints providers
(<code>org.netbeans.modules.editor.hints.spi.HintsProvider</code> classes).
</usecase>
<br/>
<br/>
<br/>
<b>
API Use Cases
</b>
<hr/>
<usecase id="find-class-instances-for-mime-type" name="Find class instances for the given mime-type">
An API method
<br/>
<code>
MimeLookup lookup = MimeLookup.getMimeLookup("text/x-java");
</code>
<br/>
can be used for getting the mime specific lookup. Having this we can lookup class
or template:
<br/>
<code>
Object obj = lookup.lookup(LookedUpClass.class);
</code>
<br/>
or
<br/>
<code>
Lookup.Result result = lookup.lookup(new Lookup.Template(LookedUpClass.class));
</code>
</usecase>
<usecase id="find-embedded-lookup" name="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:
<usecase id="mime-lookup-initializer" name="Providing implemented MimeLookupInitializer">
It is the general way of adding mime specific object into the <code>MimeLookup</code>. Implementation of <code>MimeLookupInitializer</code> should be created and
registered to default lookup via <code>META-INF/services</code> registration.
For details, please look at the simplified
<code>TestMimeLookupInitializer</code>
in <code>mimelookup/test/unit</code> or <code>LayerMimeLookupInitializer</code>.
<b> Usage of MimeLookupInitializer is deprecated, please use MimeDataProvider instead in similar way </b>
</usecase>
<!-- <questionid="dep-nb"when="init"> WhatotherNetBeansprojectsandmodulesdoesthisonedependon? <hint> Ifyouwant,describesuchprojectsasimportedAPIsusing the<code><apiname="identification"type="importorexport"category="stable"url="whereisthedescription"/></code> </hint> </question>
-->
<answer id="dep-nb">
The module needs (i.e. OpenIDE-Module-Needs) the following token: org.netbeans.spi.editor.mimelookup.MimeDataProvider.
The implementation of the default <code>MimeDataProvider</code> 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.
</answer>
<!-- <questionid="dep-non-nb"when="init"> WhatotherprojectsoutsideNetBeansdoesthisonedependon? <hint> Somenon-NetBeansprojectsarepackagedasNetBeansmodules (see<ahref="http://libs.netbeans.org/">libraries</a>)and itispreferredtousethisapproachwhenmoremodulesmay dependonsuchthird-partylibrary. </hint> </question>
-->
<answer id="dep-non-nb">
No other projects.
</answer>
<!-- <questionid="deploy-packages"when="init"> Arepackagesofyourmodulemadeinaccessiblebynotdeclaringthem public? <hint> NetBeansmodulesystemallowsrestrictionofaccessrightsto publicclassesofyourmodulefromothermodules.Thisprevents unwanteddependenciesofothersonyourcodeandshouldbeused wheneverpossible(<ahref="http://www.netbeans.org/download/javadoc/OpenAPIs/org/openide/doc-files/upgrade.html#3.4-public-packages"> publicpackages </a>).Ifyoudonotrestrictaccesstoyourclassesyouare makingittooeasyforotherpeopletomisuseyourimplementation details,thatiswhyyoushouldhavegoodreasonfornot restrictingpackageaccess. </hint> </question>
-->
<answer id="deploy-packages">
Yes, only the API and SPI are public. The implementation is not public.
</answer>
<!-- <questionid="exec-property"when="impl"> Isexecutionofyourcodeinfluencedbyanyenvironmentor Javasystem(<code>System.getProperty</code>)property? <hint> Ifthereisapropertythatcanchangethebehaviorofyour code,somebodywilllikelyuseit.Youshoulddescribewhatitdoes andthe<ahref="http://openide.netbeans.org/tutorial/api-design.html#life">stabilitycategory</a> ofthisAPI.Youmayuse <pre> <apitype="export"group="property"name="id"category="private"url="http://..."> descriptionoftheproperty,whereitisused,whatitinfluence,etc. </api> </pre> </hint> </question>
-->
<answer id="exec-property">
<ul><li>
<api name="org.openide.awt.ActionReference.completion" category="devel" group="systemproperty"type="import">
The annotation processor for <a href="@TOP@/org/netbeans/api/editor/mimelookup/MimeRegistration.html">MimeRegistration</a>
annotation reuses API defined by <a href="@org-openide-awt@/overview-summary.html">UI Utilities API</a>
and reads <a href="@JDK@@JDKMODULE_JAVA_BASE@/java/lang/System.html">System.getProperty("org.openide.awt.ActionReference.completion")</a>
property. If it
is specified, then the processor
tries to load such class, casts it to
<a href="@JDK@@JDKMODULE_JAVA_COMPILER@/javax/annotation/processing/Processor.html">Processor</a>
and asks it for additional completion items for annotation's
<code>mimeType</code> attribute. By default, when running inside NetBeans IDE,
<code>apisupport.project</code> registers such class and provides
items representing valid paths in current project.
</api>
</li>
</ul>
</answer>
<!-- <questionid="format-types"when="impl"> Whichprotocolsandfileformats(ifany)doesyourmodulereadorwriteondisk, ortransmitorreceiveoverthenetwork? </question>
-->
<answer id="format-types">
No files read or written to the disk.
</answer>
<!-- <questionid="lookup-lookup"when="init"> Doesyourmoduleuse<code>org.openide.util.Lookup</code> oranysimilartechnologytofindanycomponentstocommunicatewith?Whichones? <hint> Pleasedescribetheinterfacesyouaresearchingfor,where aredefined,whetheryouaresearchingforjustoneormoreofthem, iftheorderisimportant,etc.Alsoclassifythestabilityofsuch APIcontract. </hint> </question>
-->
<answer id="lookup-lookup">
Yes.
MimeLookup in API extends Lookup and it searches the default lookup for instances of
<code>MimeLookupInitializer</code> (this is already deprecated) and <code>MimeDataProvider</code>.
</answer>
<!-- <questionid="perf-mem"when="final"> Howmuchmemorydoesyourcomponentconsume?Estimate witharelationtothenumberofwindows,etc. </question>
-->
<answer id="perf-mem">
<code>MimeLookup</code> caches instances of mime sensitive MimeLookups in static Map, instances of children
MimeLookups in Map, InitializerListeners and Initializers in Lists.
<code>LayerMimeLookupInitializer</code> also caches mime sensitive LayerMimeLookupInitializers and LazyLookups.
</answer>
<!-- <questionid="perf-scale"when="init"> Whichexternalcriteriainfluencetheperformanceofyour program(sizeoffileineditor,numberoffilesinmenu, insourcedirectory,etc.)andhowwellyourcodescales? <hint> Pleaseincludesomeestimates,thereareothermoredetailed questionstoanswerinlaterphasesofimplementation. </hint> </question>
-->
<answer id="perf-scale">
Number of initialized MimeLookups. Since the <code>MimeLookup</code> delegates to ProxyLookup performance
during lookup depends on the performance of ProxyLookup. <code>LayerMimeLookupInitializer</code> instantiates
the object found in the layer only during direct lookup of the particular class using LazyLookup (inner class defined in <code>LayerMimeLookupInitializer</code>).
</answer>
<!-- <questionid="perf-spi"when="init"> Howtheperformanceofthepluggedincodewillbeenforced? <hint> Ifyouallowforeigncodetobepluggedintoyourownmodule,how doyouenforcethatitwillbehavecorrectlyandquicklyandwillnot negativelyinfluencetheperformanceofyourownmodule? </hint> </question>
-->
<answer id="perf-spi">
Pluggins are just clients lookups that are installed into <code>MimeLookup</code>. The performance
should be influenced by the lookupable object gathering by clients lookups. <code>LayerMimeLookupInitializer</code>
(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.
</answer>
<!-- <questionid="arch-where"when="init"> Whereonecanfindsourcesforyourmodule? <hint> PleaseprovidelinktotheCVSwebclientat http://www.netbeans.org/download/source_browse.html orjustusetagdefaultanswergenerate='here' </hint> </question>
-->
<answer id="arch-where">
Sources can be found in editor/mimelookup module.
</answer>
<!-- <questionid="compat-deprecation"when="init"> Howtheintroductionofyourprojectinfluencesfunctionality providedbypreviousversionoftheproduct? <hint> Ifyouareplanningtodeprecate/remove/changeanyexistingAPIs, listthemhereaccompaniedwiththereasonexplainingwhyyou aredoingso. </hint> </question>
-->
<answer id="compat-deprecation">
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.
</answer>
</api-answers>
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.27Bemerkung:
(vorverarbeitet am 2026-09-27)
¤