1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
3
* Copyright � 2006 Sun Microsystems, Inc. All rights reserved.
4
* Use is subject to license terms.
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">
15
<h2>About Service Providers</h2>
17
<a href="#seealso">See Also</a>
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
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>.
46
The <tt>DocumentBuilderFactory.newInstance</tt> method then searches
47
for all <tt>META-INF/services/javax.xml.parsers.DocumentBuilderFactory</tt>
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>
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>
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>
72
<small><a href="../credits.html">Legal Notices</a></small>
73
<table cellpadding="20" border="0">
74
<tr><td> </td></tr>
75
<tr><td> </td></tr>
76
<tr><td> </td></tr>