tomcat6 jndi 四

5.DBUserInfoFactory如下:
package com.huawei.support.dao;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NamingException;
import javax.naming.Reference;
import javax.naming.spi.ObjectFactory;
import com.huawei.support.exception.ApplicationException;

/**
* DBUserInfo工厂类.
*/
public class DBUserInfoFactory implements ObjectFactory
{
    /**创建DBUserInfo实例.
     * @param aObj aObj
     * @param aName 关联上下文的名称
     * @param aNameCtx 上下文
     * @param aEnvironment aEnvironment
     * @return Object 创建的DBUserInfo实例
     * @throws ApplicationException ApplicationException
     */
    public Object getObjectInstance(Object aObj, Name aName, Context aNameCtx,
        Hashtable<?, ?> aEnvironment) throws ApplicationException
    {
        DBUserInfo info = new DBUserInfo();
        try
        {
            // 用户名
            info.setmUserName((String) ((Reference) aObj).get("userName")
                    .getContent());
            // 密码
            info.setmPassword((String) ((Reference) aObj).get("password")
                    .getContent());

            aNameCtx.addToEnvironment("dbUserInfo", info);
        }
        catch (NamingException e)
        {
            throw new ApplicationException(e);
        }
        return info;
    }
}

你可能感兴趣的:(DAO)