~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to apisupport/project/javahelp/org/netbeans/modules/apisupport/project/docs/communicate_plugin/about_service_providers.html

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
Import upstream version 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 
2
<!--
 
3
 *        Copyright � 2006 Sun Microsystems, Inc. All rights reserved. 
 
4
 *        Use is subject to license terms.
 
5
> -->
 
6
<html>
 
7
<head>
 
8
 
 
9
    <title>About Service Providers</title>
 
10
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
 
11
    <link rel="StyleSheet" href="nbdocs://org.netbeans.modules.usersguide/org/netbeans/modules/usersguide/ide.css" type="text/css">
 
12
</head>
 
13
 
 
14
<body>
 
15
    <h2>About Service Providers</h2>
 
16
    <p><small> 
 
17
        <a href="#seealso">See Also</a> 
 
18
    </small></p>
 
19
 
 
20
     <p>
 
21
        In version 1.3, the JDK started to use a concept called <i>service providers</i>.
 
22
        This concept introduces a completely declarative style of registration, which
 
23
        is based just on the current classpath of a Java virtual machine
 
24
        and nothing else. This has an important advantage greatly 
 
25
        contributing to the ease of use of this registration style: in order
 
26
        to change the set of registered providers, just pick up a JAR file
 
27
        that offers such a provider and include it in application classpath. 
 
28
        Immediately its provider will be accessible to all code that searches
 
29
        for it.
 
30
        </p>
 
31
        
 
32
        <p>
 
33
        The basic idea is that each JAR file (in NetBeans terminology, each module)
 
34
        that wishes to provide an implementation of some interface, for 
 
35
        example <tt>javax.xml.parsers.DocumentBuilderFactory</tt>,
 
36
        can create its own implementation of the interface, say 
 
37
        <tt>org.sakson.MyFactory</tt>, and expose it to the system as 
 
38
        a <i>service</i> by creating a 
 
39
        <tt>META-INF/services/javax.xml.parsers.DocumentBuilderFactory</tt>
 
40
        file inside of its own JAR file. The file then contains a name
 
41
        of the implementation class per line. In this example it would contain
 
42
        one line registering the sakson factory: <tt>org.sakson.MyFactory</tt>.
 
43
        </p>
 
44
        
 
45
        <p>
 
46
        The <tt>DocumentBuilderFactory.newInstance</tt> method then searches
 
47
        for all <tt>META-INF/services/javax.xml.parsers.DocumentBuilderFactory</tt>
 
48
        files by using 
 
49
        <tt>ClassLoader.getResources("META-INF/services/javax.xml.parsers.DocumentBuilderFactory")</tt>,
 
50
        reads their content, and instantiates the class(es) found there by
 
51
        calling their default constructors. The first implementation of the 
 
52
        <tt>DocumentBuilderFactory</tt> is then returned from the <tt>newInstance</tt>
 
53
        method.
 
54
        </p>
 
55
        
 
56
        <p>
 
57
        As already mentioned, this style has been in place since JDK 1.3 and is a 
 
58
        standard way to deal with service providers. Not only has NetBeans adopted this style, 
 
59
        it is also gaining in popularity among other Java developers. As a result, 
 
60
        JDK 1.6 has introduced the new utility class 
 
61
    <classname>java.util.ServiceLoader</classname>.</p>
 
62
        
 
63
        
 
64
<dl>
 
65
    <dt><a name="seealso">See Also</a></dt>
 
66
    <dd><a href="../about/nbmodule-about.html">About NetBeans Platform and Module Development</a></dd>
 
67
    <dd><a href="about_communicate.html">About Communicating Between Modules</a></dd>
 
68
    <dd><a href="using_service_provider_browser.html">Using the Service Provider Browser</a></dd>
 
69
</dl> 
 
70
 
 
71
    <hr>
 
72
    <small><a href="../credits.html">Legal Notices</a></small> 
 
73
    <table cellpadding="20" border="0"> 
 
74
        <tr><td>&nbsp;</td></tr> 
 
75
        <tr><td>&nbsp;</td></tr> 
 
76
        <tr><td>&nbsp;</td></tr> 
 
77
    </table> 
 
78
</body></html>