Search in sources :

Example 46 with Name

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

the class InMemoryNamingStoreTestCase method testBindAndLookupResolveResult.

@Test
public void testBindAndLookupResolveResult() throws Exception {
    final Name name = new CompositeName("test");
    final Reference reference = new Reference(Context.class.getName());
    nameStore.bind(name, reference, Context.class);
    final Object result = nameStore.lookup(new CompositeName("test/value"));
    assertTrue(result instanceof ResolveResult);
}
Also used : Context(javax.naming.Context) Reference(javax.naming.Reference) CompositeName(javax.naming.CompositeName) ResolveResult(javax.naming.spi.ResolveResult) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name) Test(org.junit.Test)

Example 47 with Name

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

the class NamingContext method bind.

/** {@inheritDoc} */
public void bind(final Name name, final Object object) throws NamingException {
    check(name, JndiPermission.ACTION_BIND);
    if (namingStore instanceof WritableNamingStore) {
        final Name absoluteName = getAbsoluteName(name);
        final Object value;
        if (object instanceof Referenceable) {
            value = ((Referenceable) object).getReference();
        } else {
            value = object;
        }
        if (System.getSecurityManager() == null) {
            getWritableNamingStore().bind(absoluteName, value);
        } else {
            // The permissions check has already happened for the binding further permissions should be allowed
            final NamingException e = AccessController.doPrivileged(new PrivilegedAction<NamingException>() {

                @Override
                public NamingException run() {
                    try {
                        getWritableNamingStore().bind(absoluteName, value);
                    } catch (NamingException e) {
                        return e;
                    }
                    return null;
                }
            });
            // Check that a NamingException wasn't thrown during the bind
            if (e != null) {
                throw e;
            }
        }
    } else {
        throw NamingLogger.ROOT_LOGGER.readOnlyNamingContext();
    }
}
Also used : Referenceable(javax.naming.Referenceable) NamingException(javax.naming.NamingException) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Example 48 with Name

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

the class NamingEventCoordinator method fireEvent.

/**
     * Fire a naming event.  An event will be created with the provided information and sent to each listener that matches
     * the target and scope information.
     *
     * @param context The event context generating the event.
     * @param name The target name the event represents
     * @param existingBinding The existing binding at the provided name
     * @param newBinding The new binding at the provided name
     * @param type The event type
     * @param changeInfo The change info for the event
     * @param scopes The scopes this event should be fired against
     */
void fireEvent(final EventContext context, final Name name, final Binding existingBinding, final Binding newBinding, int type, final String changeInfo, final Integer... scopes) {
    final String target = name.toString();
    final Set<Integer> scopeSet = new HashSet<Integer>(Arrays.asList(scopes));
    final NamingEvent event = new NamingEvent(context, type, newBinding, existingBinding, changeInfo);
    final Set<ListenerHolder> holdersToFire = new HashSet<ListenerHolder>();
    // Check for OBJECT_SCOPE based listeners
    if (scopeSet.contains(EventContext.OBJECT_SCOPE)) {
        final TargetScope targetScope = new TargetScope(target, EventContext.OBJECT_SCOPE);
        final List<ListenerHolder> holders = holdersByTarget.get(targetScope);
        if (holders != null) {
            for (ListenerHolder holder : holders) {
                holdersToFire.add(holder);
            }
        }
    }
    // Check for ONELEVEL_SCOPE based listeners
    if (scopeSet.contains(EventContext.ONELEVEL_SCOPE) && !name.isEmpty()) {
        final TargetScope targetScope = new TargetScope(name.getPrefix(name.size() - 1).toString(), EventContext.ONELEVEL_SCOPE);
        final List<ListenerHolder> holders = holdersByTarget.get(targetScope);
        if (holders != null) {
            for (ListenerHolder holder : holders) {
                holdersToFire.add(holder);
            }
        }
    }
    // Check for SUBTREE_SCOPE based listeners
    if (scopeSet.contains(EventContext.SUBTREE_SCOPE) && !name.isEmpty()) {
        for (int i = 1; i < name.size(); i++) {
            final Name parentName = name.getPrefix(i);
            final TargetScope targetScope = new TargetScope(parentName.toString(), EventContext.SUBTREE_SCOPE);
            final List<ListenerHolder> holders = holdersByTarget.get(targetScope);
            if (holders != null) {
                for (ListenerHolder holder : holders) {
                    holdersToFire.add(holder);
                }
            }
        }
    }
    executor.execute(new FireEventTask(holdersToFire, event));
}
Also used : NamingEvent(javax.naming.event.NamingEvent) HashSet(java.util.HashSet) Name(javax.naming.Name)

Example 49 with Name

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

the class NamingContext method unbind.

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

Example 50 with Name

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

the class CNBindingEnumeration method mapBinding.

/**
     * Constructs a JNDI Binding object from the COS Naming binding
     * object.
     *
     * @throws org.omg.CosNaming.NamingContextPackage.CannotProceed   Unable to obtain a continuation context
     * @throws org.omg.CosNaming.NamingContextPackage.InvalidNameCNCtx     Name not understood.
     * @throws NamingException One of the above.
     */
private javax.naming.Binding mapBinding(org.omg.CosNaming.Binding bndg) throws NamingException {
    java.lang.Object obj = _ctx.callResolve(bndg.binding_name);
    Name cname = org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.cosNameToName(bndg.binding_name);
    try {
        obj = NamingManager.getObjectInstance(obj, cname, _ctx, _env);
    } catch (NamingException e) {
        throw e;
    } catch (Exception e) {
        NamingException ne = IIOPLogger.ROOT_LOGGER.errorGeneratingObjectViaFactory();
        ne.setRootCause(e);
        throw ne;
    }
    // Use cname.toString() instead of bindingName because the name
    // in the binding should be a composite name
    String cnameStr = cname.toString();
    javax.naming.Binding jbndg = new javax.naming.Binding(cnameStr, obj);
    NameComponent[] comps = _ctx.makeFullName(bndg.binding_name);
    String fullName = org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.cosNameToInsString(comps);
    jbndg.setNameInNamespace(fullName);
    return jbndg;
}
Also used : NameComponent(org.omg.CosNaming.NameComponent) NamingException(javax.naming.NamingException) NamingException(javax.naming.NamingException) NoSuchElementException(java.util.NoSuchElementException) Name(javax.naming.Name)

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