• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using the Singleton pattern

 
Kamal Patel
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am creating a Singleton class, so that only one instance of a object can ever be created. I am however getting an error with my code where I call the below command which is in my code below:
'instance = new ldapConnection(userID, pwd);' AND 'return ctx;'
I am not sure why it is complaining about the code - I am using an IDE and am getting a red line under these two lines of code meaning there is something wrong with it! Is it because I have not initialised my variables or something???

I have given my code below.
public class ldapConnection
{

/** Creates a new instance of ldapConnection */
private static DirContext instance = null;
public static DirContext getInstance(String userID, String pwd)
{
if (instance == null){
instance = new ldapConnection(userID, pwd);}
return instance;
}
protected DirContext ldapConnection(String ID, String password){

Hashtable env = new Hashtable(5, 0.75f);
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://nyssoadmin.us.db.com:1389/dc=db,dc=com");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "uid"+ID+", ou=Directory Administrators, dc=db, dc=com");
env.put(Context.SECURITY_CREDENTIALS , password);

try {
DirContext ctx = new InitialDirContext(env);}
catch(NamingException e)
{
//System.out.println("Search failed. <br>");
e.printStackTrace();
}
return ctx;

} // end of method

} //end of class
Thanks for your help.
 
Joe Ess
Bartender
Posts: 9313
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
crosspost
[ November 25, 2003: Message edited by: Joe Ess ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic