Develop and Download Open Source Software

Browse CVS Repository

Diff of /mdc/BetaProject/src/org/jent/checksmtp/LDAPSearch.java

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1 by takuya-o, Sun Feb 20 23:44:03 2005 UTC revision 1.2 by takuya-o, Mon Feb 21 16:11:06 2005 UTC
# Line 21  public class LDAPSearch { Line 21  public class LDAPSearch {
21    private LDAPSearch() {    private LDAPSearch() {
22    }    }
23    
24    static private void init() {    static synchronized private void init() {
25      if ( !ApplicationProperties.getLdap() ) {      if ( ApplicationProperties.getLdap() ) {
26        //InitialDirContext        //not initialized ctx or LDAP Provider URL was changed.
27        lastProviderUrl = ApplicationProperties.getLdapProviderURL();        if ( ctx==null
28        Properties env = new Properties();        || (!lastProviderUrl.equals(ApplicationProperties.getLdapProviderURL())) ) {
29        env.setProperty(Context.INITIAL_CONTEXT_FACTORY,          try {
30                        "com.sun.jndi.ldap.LdapCtxFactory");            if ( ctx != null ) { ctx.close(); }
31        env.put(Context.PROVIDER_URL, lastProviderUrl);             //InitialDirContext
32                lastProviderUrl = ApplicationProperties.getLdapProviderURL();
33        try {            Properties env = new Properties();
34          ctx = new InitialDirContext(env);            env.setProperty(Context.INITIAL_CONTEXT_FACTORY,
35        } catch (NamingException e) {                            "com.sun.jndi.ldap.LdapCtxFactory");
36          System.err.println("LDAPSearch init error.");            env.put(Context.PROVIDER_URL, lastProviderUrl);
37          e.printStackTrace();      
38              ctx = new InitialDirContext(env);
39            } catch (NamingException e) {
40              System.err.println("LDAPSearch init error.");
41              e.printStackTrace();
42            }
43        }        }
44      }      }
45    }    }
# Line 45  public class LDAPSearch { Line 50  public class LDAPSearch {
50      if (!ApplicationProperties.getLdap()) {      if (!ApplicationProperties.getLdap()) {
51          return ans;          return ans;
52      }      }
53      synchronized (LDAPSearch.class ) {      if ( ctx==null
54        //not initialized ctx or LDAP Provider URL was changed.      || (!lastProviderUrl.equals(ApplicationProperties.getLdapProviderURL())) ) {
55        if ( ctx==null           init();
       || (!lastProviderUrl.equals(ApplicationProperties.getLdapProviderURL())) ) {  
         init();  
       }  
56      }      }
57            
58      Pattern pattern = Pattern.compile("[ \t]+"); //Attributes separate by space.      Pattern pattern = Pattern.compile("[ \t]+"); //Attributes separate by space.
# Line 95  public class LDAPSearch { Line 97  public class LDAPSearch {
97      } catch (NamingException e) {      } catch (NamingException e) {
98        System.err.println("LDAP Search Error.");        System.err.println("LDAP Search Error.");
99        e.printStackTrace();        e.printStackTrace();
100          //ctx reflesh
101          try {
102            ctx.close();
103          } catch (NamingException nEx) {
104            //IGNORE Exception
105          }
106          ctx = null;
107      } catch (UnsupportedEncodingException ueEx) {      } catch (UnsupportedEncodingException ueEx) {
108        UnsupportedEncodingException e = ueEx;        UnsupportedEncodingException e = ueEx;
109        System.err.println("LDAP SJIS Error.");        System.err.println("LDAP SJIS Error.");
110        e.printStackTrace();        e.printStackTrace();
111      }      } catch (NullPointerException npEx) { //for failsafe.
112          NullPointerException e = npEx;
113          System.err.println("LDAP Unexpected Error.");
114          e.printStackTrace();
115        }
116    
117      return ans;      return ans;
118    }    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26