org.openide.util 7.22.1 1

org.openide.util.lookup
Annotation Type ServiceProvider


@Retention(value=SOURCE)
@Target(value=TYPE)
public @interface ServiceProvider

Declarative registration of a singleton service provider. By marking an implementation class with this annotation, you automatically register that implementation, normally in 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

Since:
org.openide.util 7.20
See Also:
Lookups.metaInfServices(ClassLoader)

Required Element Summary
 Class<?> service
          The interface (or abstract class) to register this implementation under.
 
Optional Element Summary
 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.
 

Element Detail

service

public abstract Class<?> service
The interface (or abstract class) to register this implementation under. It is an error if the implementation class is not in fact assignable to the interface.

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.

position

public abstract int position
An optional position in which to register this service relative to others. Lower-numbered services are returned in the lookup result first. Services with no specified position are returned last.

Default:
2147483647

supersedes

public abstract String[] supersedes
An optional list of implementations (given as fully-qualified class names) which this implementation supersedes. If specified, those implementations will not be loaded even if they were registered. Useful on occasion to cancel a generic implementation and replace it with a more advanced one.

Default:
{}

path

public abstract String path
An optional path to register this implementation in. For example, Projects/sometype/Nodes could be used. This style of registration would be recognized by Lookups.forPath(java.lang.String) rather than Lookup.getDefault().

Default:
""

org.openide.util 7.22.1 1

Built on September 9 2009.  |  Portions Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.