@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.

Comments:

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 01: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 04, 2008 at 06:20 PM 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 04, 2008 at 06:26 PM PST #

Definitely not in 6.5, Thomas.

Posted by Geertjan on November 04, 2008 at 08:31 PM 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 04, 2008 at 10:50 PM 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 04:09 AM 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 guest on November 05, 2008 at 05:29 AM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today