dcsimg
How do you create an object in JNDI
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Tuesday, April 23, 2002 09:43 AM

I am unsure of what it means to create a object in JNDI, could anyone tell me if you have to create a class to instantiate the object or is this done automatically some where? My code is as follows but I am getting "Operation failed: javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]; remaining name 'cn=Button'"

			
DirContext ctx = new InitialDirContext(env);
Button b=new Button("Push me");
ctx.bind("cn=Button", b);
Button b2=(Button)ctx.lookup("cn=Button");
System.out.println(b2);
ctx.close();

Re: How do you create an object in JNDI

Posted By:   Bozidar_Dangubic  
Posted On:   Tuesday, April 23, 2002 10:41 AM

simple example. createName() binds a String to JNDI, getName() reads it from JNDI.

import javax.naming.*;

public void createName() throws NamingException {
Context context = new InitialContext();
context.bind("/config/applicationName", "MyApp");
}

public String getName() throws NamingException {
Context context = new InitialContext();
return (String) context.lookup("/config/applicationName");
}
About | Sitemap | Contact