📄 person.java~51~
字号:
/* 曾海 2003-9-11 用于定义一个加入ldap的类对象。 要加入的话必须实现dircontext接口 作为一个整体加入,加入是用ctx的bind方法 这个类主要实现一些Attribute,比如 getAttributes的各种重载方法*/package jndi;import java.util.*;import javax.naming.*;import javax.naming.directory.*;public class Person extends InitialDirContext{ String type; Attributes myAttrs; public Person(String uid,String givenname,String sn,String ou,String mail) throws NamingException { //第一步先做死,否则模式不对劲儿 givenname="Sam"; sn="Gamgee"; uid="SGamgee"; ou="groups"; mail="sam@jssvc.com"; type=uid; myAttrs=new BasicAttributes(true); //大小写无关 Attribute ouSet = new BasicAttribute("ou"); ouSet.add("Groups"); Attribute dc = new BasicAttribute("dc"); dc.add("jssvc");; dc.add("com"); myAttrs.put(ouSet);//加入 myAttrs.put(dc); myAttrs.put("uid",uid); myAttrs.put("cn",givenname+" "+sn); myAttrs.put("sn",sn); myAttrs.put("givenname",givenname); myAttrs.put("mail",mail); }//cons //总是只返回一个总的东西。 public Attributes getAttributes(String name) throws NamingException{ if (! name.equals("")) throw new NameNotFoundException(); System.err.println("getAttributes called! by system"); return myAttrs; } public Attributes getAttributes(Name name) throws NamingException{ System.err.println("getAttributes Name version called! by system"); return getAttributes(name.toString() ); } public Attributes getAttributes(String name,String[] ids) throws NamingException{ if(!name.equals("")) throw new NameNotFoundException(); System.err.println("getAttributes ids version called! by system"); Attributes answer= new BasicAttributes(true); Attribute target; for(int i=0;i<ids.length ;i++){ target = myAttrs.get(ids[i]); if(target!=null) answer.put(target); } return answer;} public Attributes getAttributes(Name name,String[] ids) throws NamingException{ System.err.println("getAttributes ids version 2 called! by system"); return getAttributes(name.toString() ,ids); } public String toString(){ return type; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -