JNDI Directory Services Objects |
Active Web |
The two objects below allow Active Web to access Java 2 Enterprise Edition (J2EE) Java Naming and Directory Services (JNDI). JNDI services are made available by J2EE application servers to allow software components to locate other services either inside or outside the application server.
The Directory Object will only function correctly when Active Web is deployed in a J2EE Application Server, any attempt to create a Directory object when Active Web is deployed in only a Servlet Container (Tomcat or Jetty for example) will result in the error property of the constructed object being set.
Note: This manual does not attempt to detail J2EE or JNDI, for further details on these topics the reader is referred to Sun Microsystems J2EE documentation. The ContextEnvironment and Directory Object documentation assume that the reader is familiar with J2EE and JNDI.
The ContextEnvironment object is used in the construction of a Directory Object. It defines the initial context used to connect with a JNDI service. It is analogous to the Java Hashtable supplied to the JNDI InitialContext object.
A ContextEnvironment object constructor does not take any parameters; if any are supplied then they have no effect on the object construction.
var myContext = new ContextEnvironment();
The ContextEnvironment object has no prototype chain.
The Context environment behaves like any other script object in that you can set properties within it. However, it has a collection of reserved properties which map to reserved properties passed to the InitialContext creation. The table below outlines the script object properties and the Context properties they map to.
Property |
Context Mapping |
initial |
java.naming.factory.initial |
objectFactories |
java.naming.factory.object |
stateFactories |
java.naming.factory.state |
urlPkgs |
java.naming.factory.url.pkgs |
providerUrl |
java.naming.provider.url |
dnsUrl |
java.naming.dns.url |
authorative |
java.naming.authorative |
batchsize |
java.naming.batchsize |
referral |
java.naming.referral |
secProtocol |
java.naming.security.protocol |
secAuthentication |
java.naming.security.authentication |
secPrincipal |
java.naming.security.principal |
secCredentials |
java.naming.security.credentials |
language |
java.naming.language |
applet |
java.naming.applet |
It is possible to set other properties of the ContextEnvironment object; these will be automatically inserted into the hashtable when the object is used as the parameter to the Directory Object constructor function.
myContext = new ContextEnvrionment();
myContext.secProtocol = "ssl";
myContext.initial = "com.xool.RefFSContextFactory";
myContext.providerUrl = "file:d:/jndi/";
myContext[“mysetting?] = "my settings value";
The Directory object provides the Active Web Script developer with the ability to perform simple searches of a JNDI service. A Directory object is created with a ContextEnvironment object which has been populated with the necessary environment settings.
When a directory object has been created it consumes system resources; when the executing page completes those resources are freed automatically by the Active Web Runtime.
The Directory object constructor takes zero or one parameter; a ContextEnvironment object. When the constructor is called without any parameters then a default directory context is created without any additional properties. When the constructor is called with a single ContextEnvironment object the Directory object is created using the configuration parameters supplied by the parameter object.
The Directory object has no prototype chain.
The Directory object has only one property, error; which is set during construction or when a directory search has resulted in an error.
The Directory object contains two functions see the table below:
Function |
Description |
lookup(name) |
Looks up an object in the directory; the Java Object returned is presented to the script developer in the same way as if the developer had created a Java object themselves.
If an error occurs during the lookup process the error field will be populated with a suitable error message. |
close() |
Closes the directory object; any further attempts to lookup objects will result in a runtime error and the page execution will terminate. |
Continuing from the example above; the code below looks up a Payroll EJB using the directory:
myDir = new Directory(myContext);
if (myDir.error == null) {
myPayroll = myDir.lookup("companyPayroll");
}
Topic ID: 150068