Tuesday November 04, 2008
@org.openide.util.lookup.ServiceProvider
Read issue 150447 and then look at the code below:
public interface DemoInterface {
public String getName();
}
@org.openide.util.lookup.ServiceProvider(service=DemoInterface.class)
public class DemoServiceProvider1 implements DemoInterface {
public String getName() {
return "John";
}
}
public class Installer extends ModuleInstall {
@Override
public void restored() {
for (DemoInterface di : Lookup.getDefault().lookupAll(DemoInterface.class)) {
System.out.println("Hello " + di.getName());
}
}
}
The above works using a build I picked up today. No more META-INF/services (unless you want to continue using that approach). I especially like Jarda's comment in that issue: "This is how our future should look like". Would be nice to work with Actions and so on via annotations and to increasingly forget the layer.xml file. Seems extremely likely that will be increasingly possible. That would be the biggest revolution for the NetBeans Platform since its creation.
Nov 04 2008, 07:47:24 AM PST Permalink
You might find Jesse's original proposal interesting:
http://wiki.netbeans.org/DeclarativeRegistrationUsingAnnotations
In particular, see the part about actions towards the bottom.
Posted by Tom Wheeler on November 04, 2008 at 09:03 AM PST #
But it could be a performance problem. The manifest-files an the layer.xml files are well known files in the JARs.
For annotations you need to scan all the classes to detect the annotation @org.openide.util.lookup.ServiceProvider
The boot performance of modules is a very critical section. With annotations we need a additional register cache or we can wait a long time for booting netbeans.
best regards,
josh.
Posted by Aljoscha Rittner on November 05, 2008 at 02:20 AM PST #
Is this for Nb 7.0 or will it find it's way into the 6.5 release? I think this feature is pretty cool, especially if all of Jesse's proposal is implemented...
Posted by Thomas Wuerthinger on November 05, 2008 at 02:26 AM PST #
Definitely not in 6.5, Thomas.
Posted by Geertjan on November 05, 2008 at 04:31 AM PST #
Not usually a fan of having even more ways to do the same thing, but if this will be the de-facto then good.
What happens if no service is assigned explicitly in the annotation, will it be able to just pick up on the interface by reflective means?
Also, it starts to look a lot like next hurdle will be versioning of services. Unless we just use naive embedding in the interface name like DemoInterface14.class etc.
Posted by Casper on November 05, 2008 at 06:50 AM PST #
@Aljoscha: If I got it right all is done during module build making use of the annotation processor - generating the necessary META-INF/service files and a layer file.
Posted by Sven Reimers on November 05, 2008 at 12:09 PM PST #
Yes, I've got some information from Bruce Chapman. I've made a deeper look into the diff patch :-)
The @Service-annotation is a "syntactic sugar" to simplify the service registration at build time.
josh.
Posted by 77.177.16.104 on November 05, 2008 at 01:29 PM PST #


