person.java~35~

来自「JNDI课件」· JAVA~35~ 代码 · 共 71 行

JAVA~35~
71
字号
/* 曾海 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 {    myAttrs=new BasicAttributes(true); //大小写无关    type=uid;    Attribute oc = new BasicAttribute("objectclass");    oc.add("person");    oc.add("top");    Attribute ouSet = new BasicAttribute("ou");    ouSet.add("Groups");    ouSet.add(ou);    myAttrs.put(oc);    myAttrs.put(ouSet);    myAttrs.put("uid",uid);    myAttrs.put("cn",givenname+" "+sn);    myAttrs.put("sn",sn);    myAttrs.put("givenname",givenname);    myAttrs.put("mail",mail);    myAttrs.put("dc","jssvc");    myAttrs.put("dc","com");  }//cons  //总是只返回一个总的东西。  public Attributes getAttributes(String name) throws NamingException{   if (! name.equals(""))     throw new NameNotFoundException();   return myAttrs;  }  public Attributes getAttributes(Name name) throws NamingException{    return getAttributes(name.toString() );  }  public Attributes getAttributes(String name,String[] ids) throws NamingException{    if(!name.equals(""))        throw new NameNotFoundException();   Attributes answer= new BasicAttributes(true);  }  public String toString(){    return type;  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?