Example usage for javax.naming Context getNameParser

List of usage examples for javax.naming Context getNameParser

Introduction

In this page you can find the example usage for javax.naming Context getNameParser.

Prototype

public NameParser getNameParser(String name) throws NamingException;

Source Link

Document

Retrieves the parser associated with the named context.

Usage

From source file:org.eclipse.ecr.testlib.runner.RuntimeFeature.java

public static void rebind(Context ctx, String key, Object value) throws NamingException {
    Name name = ctx.getNameParser("").parse(key);
    int depth = name.size() - 1;
    for (int i = 0; i < depth; i++) {
        String segment = name.get(i);
        try {/*from   w  ww . j a  v  a 2  s. co  m*/
            ctx = (Context) ctx.lookup(segment);
        } catch (NameNotFoundException e) {
            ctx = ctx.createSubcontext(segment);
        }
    }
    ctx.rebind(name.get(depth), value);
}

From source file:org.jkcsoft.java.util.JndiHelper.java

public static Object lookup(Context jndi, String name) throws NamingException {
    //        String l_name = cleanName(p_name);

    Object retObj = jndi.lookup(name);

    if (log.isDebugEnabled()) {
        try {/*from   w  ww .  j  av  a  2 s . c  o m*/
            StringBuilder sbLog = new StringBuilder();

            NameParser parser = jndi.getNameParser(name);
            Name jndiName = parser.parse(name);
            List lNames = Collections.list(jndiName.getAll());
            if (lNames != null) {
                Iterator iNames = lNames.iterator();
                while (iNames.hasNext()) {
                    String elemName = (String) iNames.next();
                    Strings.appendLine(sbLog, "name [" + elemName + "]");
                }
            }
            log.debug("Jndi parse of [" + name + "] => " + sbLog);
        } catch (NamingException e) {
            log.warn("Error in getting JNDI name info", e);
        }
    }

    return retObj;
}

From source file:org.squale.jraf.bootstrap.naming.NamingHelper.java

/**
 * Bind le couple nom/valeur dans le contexte jndi.
 * @param in_context contexte jndi racine
 * @param in_name nom//from  w  ww.  j  av a 2 s.  c om
 * @param in_value valeur
 * @throws NamingException
 */
public static void bind(Context in_context, String in_name, Object in_value) throws JrafConfigException {

    if (log.isDebugEnabled()) {
        log.debug("binding : " + in_name);
    }
    String lc_name = in_name;

    try {
        in_context.rebind(lc_name, in_value);
    } catch (NamingException e) {

        try {
            Name n = in_context.getNameParser("").parse(lc_name);
            while (n.size() > 1) {
                String ctxName = n.get(0);

                Context subctx = null;
                try {
                    if (log.isDebugEnabled()) {
                        log.debug("lookup: " + ctxName);
                    }
                    subctx = (Context) in_context.lookup(ctxName);
                } catch (NameNotFoundException nfe) {
                }

                if (subctx != null) {
                    if (log.isDebugEnabled()) {
                        log.debug("Found subcontext: " + ctxName);
                    }
                    in_context = subctx;
                } else {
                    //               log.info("Creating subcontext: " + ctxName);
                    in_context = in_context.createSubcontext(ctxName);
                }
                n = n.getSuffix(1);
            }
            if (log.isDebugEnabled()) {
                log.debug("binding: " + n);
            }
            in_context.rebind(n, in_value);
        } catch (NamingException e1) {
            log.error("Impossible de recupere l'objet dans JNDI.", e);
            throw new JrafConfigException("Impossible de recupere l'objet dans JNDI.", e);
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Bound name: " + in_name);
    }
}