All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.hutool.core.util.JNDIUtil Maven / Gradle / Ivy

Go to download

Hutool是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Java拥有函数式语言般的优雅,让Java语言也可以“甜甜的”。

There is a newer version: 5.8.34
Show newest version
package cn.hutool.core.util;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.exceptions.UtilException;
import cn.hutool.core.map.MapUtil;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import javax.naming.directory.InitialDirContext;
import java.util.Hashtable;
import java.util.Map;

/**
 * JNDI工具类
* JNDI是Java Naming and Directory Interface(JAVA命名和目录接口)的英文简写,
* 它是为JAVA应用程序提供命名和目录访问服务的API(Application Programing Interface,应用程序编程接口)。 * *

* 见:https://blog.csdn.net/u010430304/article/details/54601302 *

* * @author loolY * @since 5.7.7 */ public class JNDIUtil { /** * 创建{@link InitialDirContext} * * @param environment 环境参数,{@code null}表示无参数 * @return {@link InitialDirContext} */ public static InitialDirContext createInitialDirContext(Map environment) { try { if (MapUtil.isEmpty(environment)) { return new InitialDirContext(); } return new InitialDirContext(Convert.convert(Hashtable.class, environment)); } catch (NamingException e) { throw new UtilException(e); } } /** * 创建{@link InitialContext} * * @param environment 环境参数,{@code null}表示无参数 * @return {@link InitialContext} */ public static InitialContext createInitialContext(Map environment) { try { if (MapUtil.isEmpty(environment)) { return new InitialContext(); } return new InitialContext(Convert.convert(Hashtable.class, environment)); } catch (NamingException e) { throw new UtilException(e); } } /** * 获取指定容器环境的对象的属性
* 如获取DNS属性,则URI为类似:dns:hutool.cn * * @param uri URI字符串,格式为[scheme:][name]/[domain] * @param attrIds 需要获取的属性ID名称 * @return {@link Attributes} */ public static Attributes getAttributes(String uri, String... attrIds) { try { return createInitialDirContext(null).getAttributes(uri, attrIds); } catch (NamingException e) { throw new UtilException(e); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy