Web Technologies
|
|
JNDI
JNDI
1. Introduction:
JNDI stands for: Java Naming and Directory Interface. It operates
within a Java platform software (JDK). JNDI is a set of class
enclosed in files.jar; especialy jundi.jar. The JNDI 1.1.2
Class Libraries version can be dowloaded at:
java.sun.com
Once unzipped, copy the jundi.jar file to JAVA_HOME/jre/lib/ext
directory (here in C:\Program Files\Java\jre1.5.0_14\lib\ext)
JNDI contains three major components: the naming model,
the directory model, and the service provider model.
2. Definitions:
When using a system with programs, we deal with objects such as
directory, file, email address, ... To acces these objects, we give
them names. A naming service allows us to look up an object given
its name. Objects are named and we find them by their names.
To set names, we fallow some rules called naming conventions such
as LDAP (Lightweight Directory Access Protocol).The Internet
Domain Name System (DNS), is an example of the naming service.
If we consider the name scientificsentence.net, we can see that it contains,
from right to left,: net first and followed by scientificsentence.
We call bindings the link between the name and the object.
Some objects can not be stored in the naming
service, they are registered by reference, that is
information about how to access the object. We
use also the Context term that means the set of (name/object)
bindings. The naming system is a set of contexts operating
with the same conventions ans provide the same set of
operations. A naming system provides a naming service.
A name space is the set of names in the name system.
3. Examples:
Set the classpath as:
set classpath = C:\Program Files\Java\jdk1.5.0_14\jre\lib\ext\jndi.jar;
C:\Program Files\Java\jdk1.5.0_14\jre\lib\ext\fscontext.jar;
C:\Program Files\Java\jdk1.5.0_14\jre\lib\ext\providerutil.jar
Example 1:
Resolve.java
Compile with:
C:\J2EE\JNDI>javac Resolve.java
3.1 Context 1:
If we have in C:\ directory two subdirectories \bea and \beanJava, and
the AUTOEXEC.BAT file, the context1 gives:
C:\J2EE\JNDI>java Resolve /
The name AUTOEXEC.BAT is bound to the object: C:\AUTOEXEC.BAT
The name bea is bound to the object: com.sun.jndi.fscontext.FSContext@16a55fa
The name beanJava is bound to the object: com.sun.jndi.fscontext.FSContext@32c41a
C:\J2EE\JNDI>
(the argument is file:/ or file:// or file:/// or / or // ...)
3.2 Context 1 and 2:
If we have in C:\beanJava directory the files: beanJava.java, beanJava.class,
beanJava.xml, beanJava.html, and beanJava.txt; the JNDI program Resolve.java
will bind the objects to each file inside the directory as folows:
C:\J2EE\JNDI>java Resolve file:///beanJava
The name beanJava.class is bound to the object: C:\beanJava\beanJava.class
The name beanJava.html is bound to the object: C:\beanJava\beanJava.html
The name beanJava.java is bound to the object: C:\beanJava\beanJava.java
The name beanJava.txt is bound to the object: C:\beanJava\beanJava.txt
The name beanjava.xml is bound to the object: C:\beanJava\beanjava.xml
C:\J2EE\JNDI>
(In fact here, the object is just the file with its complete related directory)
The argument "file:." shows the completes directories and files in th working directory.
|
|
|