Example usage for javax.naming Name size

List of usage examples for javax.naming Name size

Introduction

In this page you can find the example usage for javax.naming Name size.

Prototype

public int size();

Source Link

Document

Returns the number of components in this name.

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.nuxeo.runtime.binding.ServiceBindings.java

public static void createAlias(InitialContext ctx, String existingName, String aliasName)
        throws NamingException {
    LinkRef link = new LinkRef(existingName);
    Context aliasCtx = ctx;/*from   w  ww  .  j a  v a 2  s .c om*/
    Name name = ctx.getNameParser("").parse(aliasName);
    int len = name.size() - 1;
    String atom = name.get(len);
    for (int i = 0; i < len; i++) {
        String comp = name.get(i);
        try {
            aliasCtx = (Context) aliasCtx.lookup(comp);
        } catch (NameNotFoundException e) {
            aliasCtx = aliasCtx.createSubcontext(comp);
        }
    }

    aliasCtx.rebind(atom, link);

    if (log.isDebugEnabled()) {
        log.debug("Created JNDI link [" + aliasName + "] pointing to [" + existingName + "]");
    }
}

From source file:org.nuxeo.runtime.datasource.DataSourceComponent.java

@Override
public void applicationStarted(ComponentContext context) {
    if (namingContext != null) {
        return;/*from   ww  w.  j  a  v  a 2s  . c o  m*/
    }
    namingContext = NuxeoContainer.getRootContext();
    // allocate datasource sub-contexts
    Name comp;
    try {
        comp = new CompositeName(DataSourceHelper.getDataSourceJNDIPrefix());
    } catch (NamingException e) {
        throw new RuntimeException(e);
    }
    Context ctx = namingContext;
    for (int i = 0; i < comp.size(); i++) {
        try {
            ctx = (Context) ctx.lookup(comp.get(i));
        } catch (NamingException e) {
            try {
                ctx = ctx.createSubcontext(comp.get(i));
            } catch (NamingException e1) {
                throw new RuntimeException(e1);
            }
        }
    }
    // bind datasources
    for (DataSourceDescriptor datasourceDesc : datasources.values()) {
        bindDataSource(datasourceDesc);
    }
    // bind links
    for (DataSourceLinkDescriptor linkDesc : links.values()) {
        bindDataSourceLink(linkDesc);
    }
}

From source file:org.nuxeo.runtime.jtajca.NuxeoConnectionManagerFactory.java

@Override
public Object getObjectInstance(Object obj, Name objName, Context nameCtx, Hashtable<?, ?> env) {
    Reference ref = (Reference) obj;
    if (!ConnectionManager.class.getName().equals(ref.getClassName())) {
        return null;
    }//  w ww  .  j  av  a 2 s .co  m
    String name;
    int size = objName.size();
    if (size == 1) {
        name = "default";
    } else {
        name = objName.get(size - 1);
    }

    final ConnectionManager cm = NuxeoContainer.connectionManagers.get(name);
    if (cm != null) {
        return cm;
    }

    NuxeoConnectionManagerConfiguration config = new NuxeoConnectionManagerConfiguration();
    for (RefAddr addr : Collections.list(ref.getAll())) {
        String type = addr.getType();
        String content = (String) addr.getContent();
        try {
            BeanUtils.setProperty(config, type, content);
        } catch (ReflectiveOperationException e) {
            log.error(String.format("NuxeoConnectionManagerFactory cannot set %s = %s", type, content));
        }
    }
    return NuxeoContainer.initConnectionManager(config);
}

From source file:org.nuxeo.runtime.test.runner.JndiHelper.java

/**
 * Unbinds a name from ctx, and removes parents if they are empty
 *
 * @param ctx the parent JNDI Context under which the name will be unbound
 * @param name The name to unbind/*  w w w  .  j  a  va2  s.c  om*/
 * @throws NamingException for any error
 */
public static void unbind(Context ctx, Name name) throws NamingException {
    ctx.unbind(name); // unbind the end node in the name
    int sz = name.size();
    // walk the tree backwards, stopping at the domain
    while (--sz > 0) {
        Name pname = name.getPrefix(sz);
        try {
            ctx.destroySubcontext(pname);
        } catch (NamingException e) {
            log.error(e, e);
            break;
        }
    }
}

From source file:org.sonar.server.database.JndiDatabaseConnector.java

private void createJNDISubContexts(Context ctx, String jndiBinding) throws NamingException {
    Name name = new CompositeName(jndiBinding);
    for (int i = 0; i < name.size() - 1; i++) {
        String namingContext = name.get(i);
        try {/*from w  ww .j  a  v  a 2 s .c  om*/
            Object obj = ctx.lookup(namingContext);
            if (!(obj instanceof Context)) {
                throw new NamingException(namingContext + " is not a JNDI Context");
            }
        } catch (NameNotFoundException ex) {
            ctx = ctx.createSubcontext(namingContext);
        }
    }
}

From source file:org.springframework.ldap.core.DistinguishedName.java

/**
 * Construct a new <code>DistinguishedName</code> from the supplied
 * {@link Name}. The parts of the supplied {@link Name} must be
 * syntactically correct {@link LdapRdn}s.
 * //from ww  w  .j av a  2 s.c  o m
 * @param name the {@link Name} to construct a new
 * <code>DistinguishedName</code> from.
 */
public DistinguishedName(Name name) {
    Assert.notNull(name, "name cannot be null");
    if (name instanceof CompositeName) {
        parse(LdapUtils.convertCompositeNameToString((CompositeName) name));
        return;
    }
    names = new LinkedList();
    for (int i = 0; i < name.size(); i++) {
        names.add(new LdapRdn(name.get(i)));
    }
}

From source file:org.springframework.ldap.core.DistinguishedName.java

/**
 * Remove the supplied path from the beginning of this
 * <code>DistinguishedName</code> if this instance starts with
 * <code>path</code>. Useful for stripping base path suffix from a
 * <code>DistinguishedName</code>.
 * /*from   ww w.j a  v a 2  s . c  om*/
 * @param path the path to remove from the beginning of this instance.
 */
public void removeFirst(Name path) {
    if (path != null && this.startsWith(path)) {
        for (int i = 0; i < path.size(); i++)
            this.removeFirst();
    }
}

From source file:org.springframework.ldap.core.DistinguishedName.java

public boolean startsWith(Name name) {
    if (name.size() == 0) {
        return false;
    }/*from   w w w.  jav a2  s . c om*/

    DistinguishedName start = null;
    if (name instanceof DistinguishedName) {
        start = (DistinguishedName) name;
    } else {
        return false;
    }

    if (start.size() > this.size()) {
        return false;
    }

    Iterator longiter = names.iterator();
    Iterator shortiter = start.getNames().iterator();

    while (shortiter.hasNext()) {
        Object longname = longiter.next();
        Object shortname = shortiter.next();

        if (!longname.equals(shortname)) {
            return false;
        }
    }

    // All names in shortiter matched.
    return true;
}

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  w  w .j  ava  2s .com
 * @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);
    }
}