Search in sources :

Example 81 with Name

use of javax.naming.Name in project wildfly by wildfly.

the class NamingContext method lookupLink.

/** {@inheritDoc} */
public Object lookupLink(Name name) throws NamingException {
    check(name, JndiPermission.ACTION_LOOKUP);
    if (name.isEmpty()) {
        return lookup(name);
    }
    try {
        final Name absoluteName = getAbsoluteName(name);
        Object link = namingStore.lookup(absoluteName);
        if (!(link instanceof LinkRef) && link instanceof Reference) {
            link = getObjectInstance(link, name, null);
        }
        return link;
    } catch (Exception e) {
        throw namingException(NamingLogger.ROOT_LOGGER.cannotLookupLink(), e, name);
    }
}
Also used : Reference(javax.naming.Reference) NamingException(javax.naming.NamingException) NamingUtils.notAContextException(org.jboss.as.naming.util.NamingUtils.notAContextException) CannotProceedException(javax.naming.CannotProceedException) NamingUtils.namingException(org.jboss.as.naming.util.NamingUtils.namingException) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name) LinkRef(javax.naming.LinkRef)

Example 82 with Name

use of javax.naming.Name in project wildfly by wildfly.

the class NamingContext method rebind.

/** {@inheritDoc} */
public void rebind(final Name name, Object object) throws NamingException {
    check(name, JndiPermission.ACTION_REBIND);
    if (namingStore instanceof WritableNamingStore) {
        final Name absoluteName = getAbsoluteName(name);
        if (object instanceof Referenceable) {
            object = ((Referenceable) object).getReference();
        }
        getWritableNamingStore().rebind(absoluteName, object);
    } else {
        throw NamingLogger.ROOT_LOGGER.readOnlyNamingContext();
    }
}
Also used : Referenceable(javax.naming.Referenceable) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Example 83 with Name

use of javax.naming.Name in project wildfly by wildfly.

the class NamingUtils method unbind.

/**
     * 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
     * @throws NamingException for any error
     */
public static void unbind(Context ctx, Name name) throws NamingException {
    //unbind the end node in the name
    ctx.unbind(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.trace("Unable to remove context " + pname, e);
            break;
        }
    }
}
Also used : NamingException(javax.naming.NamingException) Name(javax.naming.Name)

Example 84 with Name

use of javax.naming.Name in project wildfly by wildfly.

the class NamingUtils method rebind.

/**
     * Rebind val to name in ctx, and make sure that all intermediate contexts exist
     *
     * @param ctx the parent JNDI Context under which value will be bound
     * @param name the name relative to ctx where value will be bound
     * @param value the value to bind.
     * @throws NamingException for any error
     */
public static void rebind(final Context ctx, final String name, final Object value) throws NamingException {
    final Name n = ctx.getNameParser("").parse(name);
    rebind(ctx, n, value);
}
Also used : Name(javax.naming.Name)

Example 85 with Name

use of javax.naming.Name in project wildfly by wildfly.

the class InMemoryNamingStoreTestCase method testList.

@Test
public void testList() throws Exception {
    final Name name = new CompositeName("test");
    final Object object = new Object();
    nameStore.bind(name, object, Object.class);
    final Name nameTwo = new CompositeName("testTwo");
    final Object objectTwo = new Object();
    nameStore.bind(nameTwo, objectTwo, Object.class);
    final Name nameThree = new CompositeName("testThree");
    final Object objectThree = new Object();
    nameStore.bind(nameThree, objectThree, Object.class);
    nameStore.bind(new CompositeName("testContext/test"), "test");
    final List<NameClassPair> results = nameStore.list(new CompositeName());
    assertEquals(4, results.size());
    final Set<String> expected = new HashSet<String>(Arrays.asList("test", "testTwo", "testThree", "testContext"));
    for (NameClassPair result : results) {
        final String resultName = result.getName();
        if ("test".equals(resultName) || "testTwo".equals(resultName) || "testThree".equals(resultName)) {
            assertEquals(Object.class.getName(), result.getClassName());
        } else if ("testContext".equals(resultName)) {
            assertEquals(Context.class.getName(), result.getClassName());
        } else {
            fail("Unknown result name: " + resultName);
        }
        expected.remove(resultName);
    }
    assertTrue("Not all expected results were returned", expected.isEmpty());
}
Also used : NameClassPair(javax.naming.NameClassPair) CompositeName(javax.naming.CompositeName) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Name (javax.naming.Name)107 CompositeName (javax.naming.CompositeName)48 NamingException (javax.naming.NamingException)38 Context (javax.naming.Context)37 InitialContext (javax.naming.InitialContext)36 NameNotFoundException (javax.naming.NameNotFoundException)34 Test (org.junit.Test)32 Reference (javax.naming.Reference)24 NotContextException (javax.naming.NotContextException)22 Binding (javax.naming.Binding)19 CompoundName (javax.naming.CompoundName)19 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)19 NameParser (javax.naming.NameParser)17 OperationNotSupportedException (javax.naming.OperationNotSupportedException)16 InvalidNameException (javax.naming.InvalidNameException)10 NamingContext (org.eclipse.jetty.jndi.NamingContext)10 IOException (java.io.IOException)8 LinkRef (javax.naming.LinkRef)7 ServiceName (org.jboss.msc.service.ServiceName)7 Referenceable (javax.naming.Referenceable)6