blob: e604005da638c89038d1fa78cae29cb0cc7ba19b [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2<html>
3<head>
4<!--
5Copyright 1999-2006 Sun Microsystems, Inc. All Rights Reserved.
6DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7
8This code is free software; you can redistribute it and/or modify it
9under the terms of the GNU General Public License version 2 only, as
10published by the Free Software Foundation. Sun designates this
11particular file as subject to the "Classpath" exception as provided
12by Sun in the LICENSE file that accompanied this code.
13
14This code is distributed in the hope that it will be useful, but WITHOUT
15ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17version 2 for more details (a copy is included in the LICENSE file that
18accompanied this code).
19
20You should have received a copy of the GNU General Public License version
212 along with this work; if not, write to the Free Software Foundation,
22Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23
24Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
25CA 95054 USA or visit www.sun.com if you need additional information or
26have any questions.
27-->
28</head>
29<body bgcolor="white">
30
31Provides the classes and interfaces for accessing naming services.
32
33<p>
34This package defines the naming operations of the Java Naming and
35Directory Interface<font size=-2><sup>TM</sup></font> (JNDI). &nbsp;
36JNDI provides naming and directory functionality to applications
37written in the Java programming language. It is designed to be
38independent of any specific naming or directory service
39implementation. Thus a variety of services--new, emerging, and
40already deployed ones--can be accessed in a common way.
41
42
43<h4>Context</h4>
44<p>
45This package defines the notion of a <em>context</em>, represented
46by the <tt>Context</tt> interface.
47A context consists of a set of name-to-object <em>bindings</em>.
48<tt>Context</tt> is the core interface for looking up, binding, unbinding,
49and renaming objects, and for creating and destroying subcontexts.
50<p>
51<tt>lookup()</tt> is the most commonly used operation.
52You supply <tt>lookup()</tt>
53the name of the object you want
54to look up, and it returns the object bound to that name.
55For example, the following code fragment looks up
56a printer and sends a document to the printer object
57to be printed:
58
59<blockquote>
60<pre>
61Printer printer = (Printer)ctx.lookup("treekiller");
62printer.print(report);
63</pre>
64</blockquote>
65
66<h4>Names</h4>
67<p>
68Every naming method in the <tt>Context</tt>
69interface has two
70overloads: one that accepts a
71<tt>Name</tt> argument and one that accepts a string name.
72<tt>Name</tt> is an interface that represents a generic
73name--an ordered sequence of zero of more components.
74For these methods, <tt>Name</tt> can be used to represent a
75<em>composite name</em> (<tt>CompositeName</tt>)
76so that you can name an object using a name which spans multiple namespaces.
77<p>
78The overloads that accept <tt>Name</tt>
79are useful for applications that need to manipulate names: composing
80them, comparing components, and so on.
81The overloads that accept string names are likely to be more useful
82for simple applications, such as those that simply read in a name
83and look up the corresponding object.
84<p>
85
86<h4>Bindings</h4>
87
88The <tt>Binding</tt> class represents a name-to-object binding.
89It is a tuple containing the name of the bound object,
90the name of the object's class, and the object itself.
91<p>
92The <tt>Binding</tt> class is actually a subclass of
93<tt>NameClassPair</tt>, which consists
94simply of the object's name and the object's class name.
95The <tt>NameClassPair</tt> is useful when you only want
96information about the object's class and do not want to
97pay the extra cost of getting the object.
98
99<h4>References</h4>
100Objects are stored in naming and directory services in different ways.
101If an object store supports storing Java objects,
102it might support storing an object in its serialized form.
103However, some naming and directory services do not support the
104storing of Java objects. Furthermore, for some
105objects in the directory, Java programs are but one group of applications
106that access them. In this case, a serialized Java object might
107not be the most appropriate representation.
108JNDI defines a <em>reference</em>, represented by the <tt>Reference</tt>
109class, which contains information on how to construct a copy of the object.
110JNDI will attempt to turn references looked up from the directory
111into the Java objects they represent, so that
112JNDI clients have the illusion that what
113is stored in the directory are Java objects.
114
115
116<h4>The Initial Context</h4>
117
118In JNDI, all naming and directory operations are performed relative
119to a context. There are no absolute roots.
120Therefore JNDI defines an <em>initial context</em>,
121<tt>InitialContext</tt>,
122which provides a starting point for naming and directory operations.
123Once you have an initial context, you can use it to
124look up other contexts and objects.
125
126<h4>Exceptions</h4>
127
128JNDI defines a class hierarchy for exceptions that can be thrown in
129the course of performing naming and directory operations. The root of
130this class hierarchy is <tt>NamingException</tt>.
131Programs interested in dealing with a particular exception
132can catch the corresponding subclass of the exception.
133Otherwise, programs should catch <tt>NamingException</tt>.
134
135
136<h2>Package Specification</h2>
137
138The JNDI API Specification and related documents can be found in the
139<a href="../../../technotes/guides/jndi/index.html">JNDI documentation</a>.
140
141@since 1.3
142
143</body>
144</html>