在Apache目录服务器中存储Java对象,第2部分:(下) - 编程入门网
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-06-15
eration ne = search(user, object, initialContext); if (ne != null) processSearchResult(ne); else System.out.println ("searchFromServer... failed"); close(); }//searchFromServer private void processSearchResult (NamingEnumeration ne){ try { if (ne!=null) { while (ne.hasMore()) { SearchResult sr = (SearchResult) ne.next(); Object obj = sr.getObject(); if (obj != null) { javaObject = obj; javaObjectCN = sr.getName(); } else { userID = sr.getName(); processAttributes(sr.getAttributes()); } }//while }//if (ne != null) } catch (javax.naming.NamingException e) { e.printStackTrace(); } }//processSearchResult private void processAttributes(Attributes attrs){ try { for (Enumeration e = attrs.getAll() ; e.hasMoreElements() ;) { Attribute attr = (Attribute) e.nextElement(); if (attr.getID().equals("cn")) commonName = (String)attr.get(); else if (attr.getID().equals("sn")) surName = (String)attr.get(); } } catch (javax.naming.NamingException ne){ ne.printStackTrace(); } }//processAttributes public void setUserID(String userID) { this.userID = userID; } public String getUserID() { return userID; } public void setJavaObjectCN(String objectCN) { this.javaObjectCN = objectCN; } public String getJavaObjectCN() { return javaObjectCN; } public void setCommonName (String cn) { commonName = cn; } public void setSurName (String sn) { surName = sn; } public String getCommonName() { return commonName; } public String getSurName() { return surName; } public static void main(String[] args) { LDAP4JavaObjects javaLdapClient = new LDAP4JavaObjects(); javaLdapClient.setPassword("secret"); javaLdapClient.setUserID("Alice"); //Instantiating a Java object. MessagingPreferences msgPreferences = new MessagingPreferences (); //Setting a Java object. try { javaLdapClient.setJavaObject (msgPreferences); } catch (Exception e) { e.printStackTrace(); } javaLdapClient.setJavaObjectCN ("preferences"); javaLdapClient.writeToServer(); Sy |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于在Apache目录服务器中存储Java对象,第2部分:(下) - 编程入门网的所有评论