Search in sources :

Example 1 with ContextResourceEnvRef

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

the class WebAnnotationSet method addResource.

protected static void addResource(Context context, Resource annotation, String defaultName, Class<?> defaultType) {
    String name = getName(annotation, defaultName);
    String type = getType(annotation, defaultType);
    if (type.equals("java.lang.String") || type.equals("java.lang.Character") || type.equals("java.lang.Integer") || type.equals("java.lang.Boolean") || type.equals("java.lang.Double") || type.equals("java.lang.Byte") || type.equals("java.lang.Short") || type.equals("java.lang.Long") || type.equals("java.lang.Float")) {
        // env-ref element
        ContextEnvironment resource = new ContextEnvironment();
        resource.setName(name);
        resource.setType(type);
        resource.setDescription(annotation.description());
        resource.setValue(annotation.mappedName());
        resource.setLookupName(annotation.lookup());
        context.getNamingResources().addEnvironment(resource);
    } else if (type.equals("javax.xml.rpc.Service")) {
        // service-ref element
        ContextService service = new ContextService();
        service.setName(name);
        service.setWsdlfile(annotation.mappedName());
        service.setType(type);
        service.setDescription(annotation.description());
        service.setLookupName(annotation.lookup());
        context.getNamingResources().addService(service);
    } else if (type.equals("javax.sql.DataSource") || type.equals("javax.jms.ConnectionFactory") || type.equals("javax.jms.QueueConnectionFactory") || type.equals("javax.jms.TopicConnectionFactory") || type.equals("javax.mail.Session") || type.equals("java.net.URL") || type.equals("javax.resource.cci.ConnectionFactory") || type.equals("org.omg.CORBA_2_3.ORB") || type.endsWith("ConnectionFactory")) {
        // resource-ref element
        ContextResource resource = new ContextResource();
        resource.setName(name);
        resource.setType(type);
        if (annotation.authenticationType() == Resource.AuthenticationType.CONTAINER) {
            resource.setAuth("Container");
        } else if (annotation.authenticationType() == Resource.AuthenticationType.APPLICATION) {
            resource.setAuth("Application");
        }
        resource.setScope(annotation.shareable() ? "Shareable" : "Unshareable");
        resource.setProperty("mappedName", annotation.mappedName());
        resource.setDescription(annotation.description());
        resource.setLookupName(annotation.lookup());
        context.getNamingResources().addResource(resource);
    } else if (type.equals("javax.jms.Queue") || type.equals("javax.jms.Topic")) {
        // message-destination-ref
        MessageDestinationRef resource = new MessageDestinationRef();
        resource.setName(name);
        resource.setType(type);
        resource.setUsage(annotation.mappedName());
        resource.setDescription(annotation.description());
        resource.setLookupName(annotation.lookup());
        context.getNamingResources().addMessageDestinationRef(resource);
    } else {
        /*
             * General case. Also used for:
             * - javax.resource.cci.InteractionSpec
             * - javax.transaction.UserTransaction
             */
        // resource-env-ref
        ContextResourceEnvRef resource = new ContextResourceEnvRef();
        resource.setName(name);
        resource.setType(type);
        resource.setProperty("mappedName", annotation.mappedName());
        resource.setDescription(annotation.description());
        resource.setLookupName(annotation.lookup());
        context.getNamingResources().addResourceEnvRef(resource);
    }
}
Also used : ContextEnvironment(org.apache.catalina.deploy.ContextEnvironment) MessageDestinationRef(org.apache.catalina.deploy.MessageDestinationRef) ContextService(org.apache.catalina.deploy.ContextService) ContextResourceEnvRef(org.apache.catalina.deploy.ContextResourceEnvRef) ContextResource(org.apache.catalina.deploy.ContextResource)

Example 2 with ContextResourceEnvRef

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

the class NamingContextListener method addResourceEnvRef.

/**
 * Set the specified resources in the naming context.
 */
public void addResourceEnvRef(ContextResourceEnvRef resourceEnvRef) {
    // Create a reference to the resource env.
    Reference ref = new ResourceEnvRef(resourceEnvRef.getType());
    // Adding the additional parameters, if any
    Iterator<String> params = resourceEnvRef.listProperties();
    while (params.hasNext()) {
        String paramName = params.next();
        String paramValue = (String) resourceEnvRef.getProperty(paramName);
        StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
        ref.add(refAddr);
    }
    try {
        if (logger.isDebugEnabled())
            log.debug("  Adding resource env ref " + resourceEnvRef.getName());
        createSubcontexts(envCtx, resourceEnvRef.getName());
        envCtx.bind(resourceEnvRef.getName(), ref);
    } catch (NamingException e) {
        logger.error(sm.getString("naming.bindFailed", e));
    }
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) NamingException(javax.naming.NamingException) ResourceEnvRef(org.apache.naming.ResourceEnvRef) ContextResourceEnvRef(org.apache.catalina.deploy.ContextResourceEnvRef)

Example 3 with ContextResourceEnvRef

use of org.apache.catalina.deploy.ContextResourceEnvRef 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

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