Search in sources :

Example 31 with Name

use of javax.naming.Name in project geode by apache.

the class ContextImpl method createSubcontext.

/**
   * Creates subcontext with name, relative to this Context.
   * 
   * @param name subcontext name.
   * @return new subcontext named name relative to this context.
   * @throws NoPermissionException if this context has been destroyed.
   * @throws InvalidNameException if name is empty or is CompositeName that spans more than one
   *         naming system.
   * @throws NameAlreadyBoundException if name is already bound in this Context
   * @throws NotContextException if any intermediate name from name is not bound to instance of
   *         javax.naming.Context.
   * 
   */
public Context createSubcontext(Name name) throws NamingException {
    checkIsDestroyed();
    Name parsedName = getParsedName(name);
    if (parsedName.size() == 0 || parsedName.get(0).length() == 0) {
        throw new InvalidNameException(LocalizedStrings.ContextImpl_NAME_CAN_NOT_BE_EMPTY.toLocalizedString());
    }
    String subContextName = parsedName.get(0);
    Object boundObject = ctxMaps.get(parsedName.get(0));
    if (parsedName.size() == 1) {
        // Check if name is already in use
        if (boundObject == null) {
            Context subContext = new ContextImpl(this, subContextName);
            ctxMaps.put(subContextName, subContext);
            return subContext;
        } else {
            throw new NameAlreadyBoundException(LocalizedStrings.ContextImpl_NAME_0_IS_ALREADY_BOUND.toLocalizedString(subContextName));
        }
    } else {
        if (boundObject instanceof Context) {
            // an exception will be thrown in that case.
            return ((Context) boundObject).createSubcontext(parsedName.getSuffix(1));
        } else {
            throw new NotContextException(LocalizedStrings.ContextImpl_EXPECTED_CONTEXT_BUT_FOUND_0.toLocalizedString(boundObject));
        }
    }
}
Also used : Context(javax.naming.Context) NotContextException(javax.naming.NotContextException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) InvalidNameException(javax.naming.InvalidNameException) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Example 32 with Name

use of javax.naming.Name in project geode by apache.

the class ContextImpl method composeName.

/**
   * Returns composition of prefix and name .
   * 
   * @param name name relative to this context
   * @param prefix name of this context Example: composeName("a","b") : b/a composeName("a","") : a
   * 
   */
public Name composeName(Name name, Name prefix) throws NamingException {
    checkIsDestroyed();
    // We do not want to modify any of the parameters (JNDI requirement).
    // Clone <code> prefix </code> to satisfy the requirement.
    Name parsedPrefix = getParsedName((Name) prefix.clone());
    Name parsedName = getParsedName(name);
    return parsedPrefix.addAll(parsedName);
}
Also used : CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Example 33 with Name

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

the class WritableServiceBasedNamingStoreTestCase method testUnbind.

@Test
public void testUnbind() throws Exception {
    final Name name = new CompositeName("test");
    final Object value = new Object();
    WritableServiceBasedNamingStore.pushOwner(OWNER_FOO);
    try {
        store.bind(name, value);
        store.unbind(name);
    } finally {
        WritableServiceBasedNamingStore.popOwner();
    }
    try {
        store.lookup(name);
        fail("Should have thrown name not found");
    } catch (NameNotFoundException expect) {
    }
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) CompositeName(javax.naming.CompositeName) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name) ServiceName(org.jboss.msc.service.ServiceName) Test(org.junit.Test)

Example 34 with Name

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

the class WritableServiceBasedNamingStoreTestCase method testMultipleOwnersBindingReferences.

@Test
public void testMultipleOwnersBindingReferences() throws Exception {
    final Name name = new CompositeName("test");
    final ServiceName serviceName = store.buildServiceName(name);
    final Object value = new Object();
    // ensure bind does not exists
    try {
        store.lookup(name);
        fail("Should have thrown name not found");
    } catch (NameNotFoundException expect) {
    }
    // ensure the owners RuntimeBindReleaseService have no reference to the future bind
    final RuntimeBindReleaseService.References fooDuBindingReferences = (RuntimeBindReleaseService.References) container.getService(JndiNamingDependencyProcessor.serviceName(OWNER_FOO)).getValue();
    assertFalse(fooDuBindingReferences.contains(serviceName));
    final RuntimeBindReleaseService.References barDuBindingReferences = (RuntimeBindReleaseService.References) container.getService(JndiNamingDependencyProcessor.serviceName(OWNER_BAR)).getValue();
    assertFalse(barDuBindingReferences.contains(serviceName));
    WritableServiceBasedNamingStore.pushOwner(OWNER_FOO);
    try {
        store.bind(name, value);
        // Foo's RuntimeBindReleaseService should now have a reference to the new bind
        assertTrue(fooDuBindingReferences.contains(serviceName));
        // Bar's RuntimeBindReleaseService reference to the bind should not exist
        assertFalse(barDuBindingReferences.contains(serviceName));
    } finally {
        WritableServiceBasedNamingStore.popOwner();
    }
    WritableServiceBasedNamingStore.pushOwner(OWNER_BAR);
    try {
        store.rebind(name, value);
        // after rebind, Foo's RuntimeBindReleaseService reference to the bind should still exist
        assertTrue(fooDuBindingReferences.contains(serviceName));
        // after rebind, Bar's RuntimeBindReleaseService reference to the bind should now exist
        assertTrue(barDuBindingReferences.contains(serviceName));
    } finally {
        WritableServiceBasedNamingStore.popOwner();
    }
    WritableServiceBasedNamingStore.pushOwner(OWNER_FOO);
    try {
        store.unbind(name);
    } finally {
        WritableServiceBasedNamingStore.popOwner();
    }
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) NameNotFoundException(javax.naming.NameNotFoundException) CompositeName(javax.naming.CompositeName) RuntimeBindReleaseService(org.jboss.as.naming.deployment.RuntimeBindReleaseService) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name) ServiceName(org.jboss.msc.service.ServiceName) Test(org.junit.Test)

Example 35 with Name

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

the class ServiceBasedNamingStoreTestCase method testStoredContext.

@Test
public void testStoredContext() throws Exception {
    final ServiceName bindingName = ServiceName.JBOSS.append("foo-stored").append("again");
    bindObject(bindingName, new Context() {

        @Override
        public Object lookup(Name name) throws NamingException {
            if ("blah/blah2".equals(name.toString())) {
                return new Integer(5);
            }
            return null;
        }

        @Override
        public Object lookup(String name) throws NamingException {
            return lookup(new CompositeName(name));
        }

        @Override
        public void bind(Name name, Object obj) throws NamingException {
        }

        @Override
        public void bind(String name, Object obj) throws NamingException {
        }

        @Override
        public void rebind(Name name, Object obj) throws NamingException {
        }

        @Override
        public void rebind(String name, Object obj) throws NamingException {
        }

        @Override
        public void unbind(Name name) throws NamingException {
        }

        @Override
        public void unbind(String name) throws NamingException {
        }

        @Override
        public void rename(Name oldName, Name newName) throws NamingException {
        }

        @Override
        public void rename(String oldName, String newName) throws NamingException {
        }

        @Override
        public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
            return null;
        }

        @Override
        public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
            return null;
        }

        @Override
        public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
            if (!"hi/there".equals(name.toString()))
                throw new IllegalArgumentException("Expected hi/there");
            return null;
        }

        @Override
        public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
            return null;
        }

        @Override
        public void destroySubcontext(Name name) throws NamingException {
        }

        @Override
        public void destroySubcontext(String name) throws NamingException {
        }

        @Override
        public Context createSubcontext(Name name) throws NamingException {
            return null;
        }

        @Override
        public Context createSubcontext(String name) throws NamingException {
            return null;
        }

        @Override
        public Object lookupLink(Name name) throws NamingException {
            return null;
        }

        @Override
        public Object lookupLink(String name) throws NamingException {
            return null;
        }

        @Override
        public NameParser getNameParser(Name name) throws NamingException {
            return null;
        }

        @Override
        public NameParser getNameParser(String name) throws NamingException {
            return null;
        }

        @Override
        public Name composeName(Name name, Name prefix) throws NamingException {
            return null;
        }

        @Override
        public String composeName(String name, String prefix) throws NamingException {
            return null;
        }

        @Override
        public Object addToEnvironment(String propName, Object propVal) throws NamingException {
            return null;
        }

        @Override
        public Object removeFromEnvironment(String propName) throws NamingException {
            return null;
        }

        @Override
        public Hashtable<?, ?> getEnvironment() throws NamingException {
            return null;
        }

        @Override
        public void close() throws NamingException {
        }

        @Override
        public String getNameInNamespace() throws NamingException {
            return null;
        }
    });
    final NamingContext ctx = new NamingContext(new CompositeName(), store, null);
    final Object obj = ctx.lookup(new CompositeName("foo-stored/again/blah/blah2"));
    ctx.listBindings("foo-stored/again/hi/there");
    assertNotNull(obj);
    assertEquals(new Integer(5), obj);
}
Also used : StopContext(org.jboss.msc.service.StopContext) Context(javax.naming.Context) StartContext(org.jboss.msc.service.StartContext) Hashtable(java.util.Hashtable) CompositeName(javax.naming.CompositeName) NamingEnumeration(javax.naming.NamingEnumeration) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name) ServiceName(org.jboss.msc.service.ServiceName) ServiceName(org.jboss.msc.service.ServiceName) NamingException(javax.naming.NamingException) NameParser(javax.naming.NameParser) 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