Annotation Type ProjectServiceProvider
Like
LookupProvider
but registers a single object into a project's lookup.
An annotated class must have one public constructor, which may take Project
and/or Lookup
parameters.
An annotated factory method must have similar parameters.
public final class TestAction implements ActionListener { public void actionPerformed(ActionEvent e) { System.err.println("===> running action"); for (Project p : OpenProjects.getDefault().getOpenProjects()) { Service s = p.getLookup().lookup(Service.class); if (s != null) { System.err.println("===> got a service: " + s.m()); } else { System.err.println("===> nothing for " + p); } } } public abstract static class Service { static { System.err.println("===> loading Service"); } public abstract String m(); } @ProjectServiceProvider(service=Service.class, projectType="org-netbeans-modules-java-j2seproject") public static class ServiceImpl extends Service { static { System.err.println("===> loading ServiceImpl"); } private final Project p; public ServiceImpl(Project p) { this.p = p; System.err.println("===> new ServiceImpl on " + p); } public String m() { return ProjectUtils.getInformation(p).getDisplayName(); } } }
To avoid deadlocks, stack overflows, and the like, an implementation
accepting a Project
in its constructor (or factory method) may not
examine that project's lookup inside the constructor. It is fine to use the
project lookup from other service methods called later, typically to find
"sister" services (such as ProjectInformation
in the example above).
It is also safe to accept a Lookup
in the constructor
and examine its contents, since this is the "base lookup" supplied to
LookupProviderSupport.createCompositeLookup(org.openide.util.Lookup, java.lang.String)
, which will not have
other declaratively registered services anyway.
- Since:
- org.netbeans.modules.projectapi/1 1.23
- See Also:
-
Required Element Summary
Required Elements -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionString[]
Token(s) denoting one or more project types, e.g.Alternate registration of project types with positions.
-
Element Details
-
service
Class<?>[] serviceService class(es) to be registered. The annotated class must be assignable to the service class(es). -
projectType
String[] projectTypeToken(s) denoting one or more project types, e.g."org-netbeans-modules-java-j2seproject"
LookupProviderSupport.createCompositeLookup(org.openide.util.Lookup, java.lang.String)
may be used with the pathProjects/TYPE/Lookup
.- Default:
{}
-
projectTypes
LookupProvider.Registration.ProjectType[] projectTypesAlternate registration of project types with positions. You must specify either this orprojectType()
(or both).- Default:
{}
-