samples/componentinjection/src/org/apidesign/component/InjectionViaServiceLoader.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:53:44 +0200
changeset 83 ab11b9173089
permissions -rw-r--r--
Showing use of service loader
jtulach@83
     1
package org.apidesign.component;
jtulach@83
     2
jtulach@83
     3
import java.util.Collection;
jtulach@83
     4
import java.util.ServiceLoader;
jtulach@83
     5
import org.openide.util.Lookup;
jtulach@83
     6
jtulach@83
     7
public class InjectionViaServiceLoader {
jtulach@83
     8
    private InjectionViaServiceLoader() {
jtulach@83
     9
    }
jtulach@83
    10
    
jtulach@83
    11
    // BEGIN: lookup.query.serviceloader
jtulach@83
    12
    public static InjectionSlot singleSlot() {
jtulach@83
    13
        // get one implementation
jtulach@83
    14
        return ServiceLoader.load(InjectionSlot.class).iterator().next();
jtulach@83
    15
    }
jtulach@83
    16
    
jtulach@83
    17
    public static Iterable<? extends InjectionSlot> multiSlot() {
jtulach@83
    18
        // get all registered implementations
jtulach@83
    19
        return ServiceLoader.load(InjectionSlot.class);
jtulach@83
    20
    }
jtulach@83
    21
    // END: lookup.query.serviceloader
jtulach@83
    22
}