@Retention(value=SOURCE) @Target(value=TYPE) public @interface ServiceProvider
Lookup.getDefault()
.
The class must be public and have a public no-argument constructor.
Example of usage:
package my.module; import org.netbeans.spi.whatever.Thing; import org.openide.util.lookup.ServiceProvider; @ServiceProvider(service=Thing.class) public class MyThing implements Thing {...}
would result in a resource file META-INF/services/org.netbeans.spi.whatever.Thing
containing the single line of text: my.module.MyThing
Lookups.metaInfServices(ClassLoader)
Modifier and Type | Required Element and Description |
---|---|
Class<?> |
service
The interface (or abstract class) to register this implementation under.
|
Modifier and Type | Optional Element and Description |
---|---|
String |
path
An optional path to register this implementation in.
|
int |
position
An optional position in which to register this service relative to others.
|
String[] |
supersedes
An optional list of implementations (given as fully-qualified class names) which this implementation supersedes.
|
public abstract Class<?> service
If you need to register one class under multiple interfaces, use ServiceProviders
.
Requests to look up the specified interface should result in this implementation. Requests for any other types may or may not result in this implementation even if the implementation is assignable to those types.
public abstract int position
public abstract String[] supersedes
Note: Dollar sign ($) is used in inner class names. For example
org.netbeans.modules.openfile.FileChooser$JavaFilesFilter
.
public abstract String path
Projects/sometype/Nodes
could be used.
This style of registration would be recognized by Lookups.forPath(java.lang.String)
rather than Lookup.getDefault()
.
The providers of a registration slot are advised to have
a look at NamedServiceDefinition
and consider using it since
version 8.14.
The NamedServiceDefinition
offers various benefits over
plain ServiceProvider.path()
usage including type checking and lower
possibility of typos.