Search in sources :

Example 36 with Reference

use of javax.naming.Reference in project Payara by payara.

the class NamingContextListener method addResourceLink.

/**
 * Set the specified resource link in the naming context.
 */
public void addResourceLink(ContextResourceLink resourceLink) {
    // Create a reference to the resource.
    Reference ref = new ResourceLinkRef(resourceLink.getType(), resourceLink.getGlobal());
    // Adding the additional parameters, if any
    addAdditionalParameters(resourceLink.getNamingResources(), ref, resourceLink.getName());
    try {
        if (debug >= 2)
            log("  Adding resource link " + resourceLink.getName());
        createSubcontexts(envCtx, resourceLink.getName());
        envCtx.bind(resourceLink.getName(), ref);
    } catch (NamingException e) {
        String msg = MessageFormat.format(rb.getString(LogFacade.BIND_OBJECT_FAILED), e);
        log(msg);
    }
}
Also used : Reference(javax.naming.Reference) NamingException(javax.naming.NamingException)

Example 37 with Reference

use of javax.naming.Reference in project Payara by payara.

the class NamingContextListener method createNamingContext.

/**
 * Create and initialize the JNDI naming context.
 */
private void createNamingContext() throws NamingException {
    // Creating the comp subcontext
    if (container instanceof Server) {
        compCtx = namingContext;
        envCtx = namingContext;
    } else {
        compCtx = namingContext.createSubcontext("comp");
        envCtx = compCtx.createSubcontext("env");
    }
    int i;
    if (log.isLoggable(Level.FINE))
        log.log(Level.FINE, "Creating JNDI naming context");
    if (namingResources == null) {
        namingResources = new NamingResources();
        namingResources.setContainer(container);
    }
    // Resource links
    ContextResourceLink[] resourceLinks = namingResources.findResourceLinks();
    for (i = 0; i < resourceLinks.length; i++) {
        addResourceLink(resourceLinks[i]);
    }
    // Resources
    ContextResource[] resources = namingResources.findResources();
    for (i = 0; i < resources.length; i++) {
        addResource(resources[i]);
    }
    // Resources Env
    String[] resourceEnvRefs = namingResources.findResourceEnvRefs();
    for (i = 0; i < resourceEnvRefs.length; i++) {
        String key = resourceEnvRefs[i];
        String type = namingResources.findResourceEnvRef(key);
        addResourceEnvRef(key, type);
    }
    // Environment entries
    ContextEnvironment[] contextEnvironments = namingResources.findEnvironments();
    for (i = 0; i < contextEnvironments.length; i++) {
        addEnvironment(contextEnvironments[i]);
    }
    // EJB references
    ContextEjb[] ejbs = namingResources.findEjbs();
    for (i = 0; i < ejbs.length; i++) {
        addEjb(ejbs[i]);
    }
    // Binding a User Transaction reference
    if (container instanceof Context) {
        try {
            Reference ref = new TransactionRef();
            compCtx.bind("UserTransaction", ref);
            addAdditionalParameters(namingResources, ref, "UserTransaction");
        } catch (NamingException e) {
            String msg = MessageFormat.format(rb.getString(LogFacade.BIND_OBJECT_FAILED), e);
            log(msg);
        }
    }
    // Binding the resources directory context
    if (container instanceof Context) {
        try {
            compCtx.bind("Resources", ((Container) container).getResources());
        } catch (NamingException e) {
            String msg = MessageFormat.format(rb.getString(LogFacade.BIND_OBJECT_FAILED), e);
            log(msg);
        }
    }
}
Also used : Reference(javax.naming.Reference) NamingException(javax.naming.NamingException)

Example 38 with Reference

use of javax.naming.Reference in project Payara by payara.

the class NamingContextListener method addResource.

/**
 * Set the specified resources in the naming context.
 */
public void addResource(ContextResource resource) {
    // Create a reference to the resource.
    Reference ref = new ResourceRef(resource.getType(), resource.getDescription(), resource.getScope(), resource.getAuth());
    // Adding the additional parameters, if any
    addAdditionalParameters(resource.getNamingResources(), ref, resource.getName());
    try {
        if (debug >= 2) {
            log("  Adding resource ref " + resource.getName());
            log("  " + ref);
        }
        createSubcontexts(envCtx, resource.getName());
        envCtx.bind(resource.getName(), ref);
    } catch (NamingException e) {
        String msg = MessageFormat.format(rb.getString(LogFacade.BIND_OBJECT_FAILED), e);
        log(msg);
    }
}
Also used : Reference(javax.naming.Reference) NamingException(javax.naming.NamingException)

Example 39 with Reference

use of javax.naming.Reference in project Payara by payara.

the class ConcurrentObjectFactory method getObjectInstance.

@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
    Reference ref = (Reference) obj;
    LOGGER.log(Level.FINE, "ConcurrentNamingObjectFactory: {0} Name:{1}", new Object[] { ref, name });
    BaseConfig config = (BaseConfig) ref.get(0).getContent();
    ResourceInfo resourceInfo = (ResourceInfo) ref.get(1).getContent();
    Object instance = null;
    switch(config.getType()) {
        case CONTEXT_SERVICE:
            instance = getContextService((ContextServiceConfig) config, resourceInfo);
            break;
        case MANAGED_EXECUTOR_SERVICE:
            instance = getManagedExecutorService((ManagedExecutorServiceConfig) config, resourceInfo);
            break;
        case MANAGED_SCHEDULED_EXECUTOR_SERVICE:
            instance = getManagedScheduledExecutorService((ManagedScheduledExecutorServiceConfig) config, resourceInfo);
            break;
        case MANAGED_THREAD_FACTORY:
            instance = getManagedThreadFactory((ManagedThreadFactoryConfig) config, resourceInfo);
            break;
        default:
            break;
    }
    return instance;
}
Also used : ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) Reference(javax.naming.Reference)

Example 40 with Reference

use of javax.naming.Reference in project Payara by payara.

the class GlassfishNamingManagerImpl method publishCosNamingObject.

@Override
public void publishCosNamingObject(String name, Object obj, boolean rebind) throws NamingException {
    Name nameObj = new CompositeName(name);
    // Create any COS naming sub-contexts in name
    // that don't already exist.
    createSubContexts(nameObj, getCosContext());
    if (rebind) {
        getCosContext().rebind(name, obj);
    } else {
        getCosContext().bind(name, obj);
    }
    // Bind a reference to it in the SerialContext using
    // the same name. This is needed to allow standalone clients
    // to lookup the object using the same JNDI name.
    // It is also used from bindObjects while populating ejb-refs in
    // the java:comp namespace.
    Object serialObj = new Reference("reference", new StringRefAddr("url", name), IIOPOBJECT_FACTORY, null);
    publishObject(name, serialObj, rebind);
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) CompositeName(javax.naming.CompositeName) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Aggregations

Reference (javax.naming.Reference)226 NamingException (javax.naming.NamingException)79 RefAddr (javax.naming.RefAddr)59 StringRefAddr (javax.naming.StringRefAddr)54 Context (javax.naming.Context)41 NameNotFoundException (javax.naming.NameNotFoundException)40 InitialContext (javax.naming.InitialContext)37 Test (org.junit.Test)33 Name (javax.naming.Name)30 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)28 Properties (java.util.Properties)26 OperationNotSupportedException (javax.naming.OperationNotSupportedException)25 NotContextException (javax.naming.NotContextException)24 ObjectFactory (javax.naming.spi.ObjectFactory)23 CompositeName (javax.naming.CompositeName)21 Referenceable (javax.naming.Referenceable)18 Binding (javax.naming.Binding)17 CompoundName (javax.naming.CompoundName)16 LinkRef (javax.naming.LinkRef)15 Hashtable (java.util.Hashtable)12