Search in sources :

Example 1 with ContextTransaction

use of org.apache.catalina.deploy.ContextTransaction in project tomcat70 by apache.

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.isDebugEnabled())
        log.debug("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
    ContextResourceEnvRef[] resourceEnvRefs = namingResources.findResourceEnvRefs();
    for (i = 0; i < resourceEnvRefs.length; i++) {
        addResourceEnvRef(resourceEnvRefs[i]);
    }
    // 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]);
    }
    // WebServices references
    ContextService[] services = namingResources.findServices();
    for (i = 0; i < services.length; i++) {
        addService(services[i]);
    }
    // Binding a User Transaction reference
    if (container instanceof Context) {
        try {
            Reference ref = new TransactionRef();
            compCtx.bind("UserTransaction", ref);
            ContextTransaction transaction = namingResources.getTransaction();
            if (transaction != null) {
                Iterator<String> params = transaction.listProperties();
                while (params.hasNext()) {
                    String paramName = params.next();
                    String paramValue = (String) transaction.getProperty(paramName);
                    StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
                    ref.add(refAddr);
                }
            }
        } catch (NameAlreadyBoundException e) {
        // Ignore because UserTransaction was obviously
        // added via ResourceLink
        } catch (NamingException e) {
            logger.error(sm.getString("naming.bindFailed", e));
        }
    }
    // Binding the resources directory context
    if (container instanceof Context) {
        try {
            compCtx.bind("Resources", ((Container) container).getResources());
        } catch (NamingException e) {
            logger.error(sm.getString("naming.bindFailed", e));
        }
    }
}
Also used : ContextEnvironment(org.apache.catalina.deploy.ContextEnvironment) NamingContext(org.apache.naming.NamingContext) Context(org.apache.catalina.Context) ContextService(org.apache.catalina.deploy.ContextService) Server(org.apache.catalina.Server) ContextResourceLink(org.apache.catalina.deploy.ContextResourceLink) Reference(javax.naming.Reference) NamingResources(org.apache.catalina.deploy.NamingResources) ContextTransaction(org.apache.catalina.deploy.ContextTransaction) ContextEjb(org.apache.catalina.deploy.ContextEjb) ContextResource(org.apache.catalina.deploy.ContextResource) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) StringRefAddr(javax.naming.StringRefAddr) TransactionRef(org.apache.naming.TransactionRef) NamingException(javax.naming.NamingException) ContextResourceEnvRef(org.apache.catalina.deploy.ContextResourceEnvRef)

Aggregations

NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)1 NamingException (javax.naming.NamingException)1 Reference (javax.naming.Reference)1 StringRefAddr (javax.naming.StringRefAddr)1 Context (org.apache.catalina.Context)1 Server (org.apache.catalina.Server)1 ContextEjb (org.apache.catalina.deploy.ContextEjb)1 ContextEnvironment (org.apache.catalina.deploy.ContextEnvironment)1 ContextResource (org.apache.catalina.deploy.ContextResource)1 ContextResourceEnvRef (org.apache.catalina.deploy.ContextResourceEnvRef)1 ContextResourceLink (org.apache.catalina.deploy.ContextResourceLink)1 ContextService (org.apache.catalina.deploy.ContextService)1 ContextTransaction (org.apache.catalina.deploy.ContextTransaction)1 NamingResources (org.apache.catalina.deploy.NamingResources)1 NamingContext (org.apache.naming.NamingContext)1 TransactionRef (org.apache.naming.TransactionRef)1