XML Model SPIs

The SPI defines an interface of GrammarQuery provider. Once registered (the registration methods depends on particular client) it can reply to queries that can be resolved with a grammar knowledge. It reuses DOM interfaces for context definition however their semantics can be slightly changed. Most notably the DOM is read-only and may throw DOMException.UNSUPPORTED_OPERATION from more methods than defined by DOM IDLs.

How to Register a Provider

Default GrammarQuery registration mechanism uses Lookup. Modules providing an implementation can register {@link org.netbeans.modules.xml.api.model.GrammarQueryManager} at default filesystem. Such registration can be than located by clients using {@link org.netbeans.modules.xml.api.model.GrammarQueryManager#getDefault} which returns an implementation proxing to registered ones.

XML Code Completion ("XCC") SPI Requirements

XML Phenomens to be Completed

XCC Context

All bellow can be described by read-only DOM Node context. Document content that is not described by DOM Node that must be extra handled by a client:
Entity Prolog
extra handling is easy no grammar required
DTD Stuff
what about it? exclude this support in GrammarQuery
Document DTD if any (note it is a responsibility of a binder)

XCC Interface

XCC behaviour should be pluggable, XML module should provide a default implementation for:
well formed document
document history based completion (at least pairing tags)
DTD grammar based completion
content is forced by a DTD grammar
Schema grammar based completion
must be namespace aware
Particular XCC plugins can add some well-known global attributes at element content or can provide information that is not provided by grammar (Ant task names and content) or can handle new type of grammar.

Integration with Text Editor

Text editor must provide its context as virtual read-only Node representing just edited phenomenon (therefore itself invalid).

Narrowing Context

Node context can be narrowed by knowledge of characters precending caret.
whitespace in content
complete element name, the first option is pairing end tag
<ns:prefix
complete element name starting with the prefix defined in given ns (detect that document use : for ordinary naming)
</prefix
complete pairing end tag starting with prefix
<prefix
complete element name or namespace starting with the prefix
[prefix after] whitespace in element start tag markup
complete namespace prefix of attribute name (global)
&prefix
list all declared general entities starting with prefix
pseudo attribute name in prolog
complete one of: version, standalone, encoding
pseudo attribute value in prolog
complete from list of known values (encodings)

Integration with Tree Editor

Narrowing Context

All particular text field values may be used as prefix, but in this mode all other values can be hidden. http://xml.netbeans.org/issues/show_bug.cgi?id=14296