Search in sources :

Example 1 with Link

use of org.eclipse.jetty.plus.jndi.Link in project jetty.project by eclipse.

the class PlusDescriptorProcessor method bindEntry.

/**
     * Bind a resource with the given name from web.xml of the given type
     * with a jndi resource from either the server or the webapp's naming
     * environment.
     * <p>
     * As the servlet spec does not cover the mapping of names in web.xml with
     * names from the execution environment, jetty uses the concept of a Link, which is
     * a subclass of the NamingEntry class. A Link defines a mapping of a name
     * from web.xml with a name from the execution environment (ie either the server or the
     * webapp's naming environment).
     * 
     * @param context the context
     * @param name name of the resource from web.xml
     * @param typeClass the type class
     * @throws Exception the exception
     */
protected void bindEntry(WebAppContext context, String name, Class<?> typeClass) throws Exception {
    String nameInEnvironment = name;
    boolean bound = false;
    //check if the name in web.xml has been mapped to something else
    //check a context-specific naming environment first
    Object scope = context;
    NamingEntry ne = NamingEntryUtil.lookupNamingEntry(scope, name);
    if (ne != null && (ne instanceof Link)) {
        //if we found a mapping, get out name it is mapped to in the environment
        nameInEnvironment = ((Link) ne).getLink();
    }
    //try finding that mapped name in the webapp's environment first
    scope = context;
    bound = NamingEntryUtil.bindToENC(scope, name, nameInEnvironment);
    if (bound)
        return;
    //try the server's environment
    scope = context.getServer();
    bound = NamingEntryUtil.bindToENC(scope, name, nameInEnvironment);
    if (bound)
        return;
    //try the jvm environment
    bound = NamingEntryUtil.bindToENC(null, name, nameInEnvironment);
    if (bound)
        return;
    //There is no matching resource so try a default name.
    //The default name syntax is: the [res-type]/default
    //eg       javax.sql.DataSource/default
    nameInEnvironment = typeClass.getName() + "/default";
    //First try the server scope
    NamingEntry defaultNE = NamingEntryUtil.lookupNamingEntry(context.getServer(), nameInEnvironment);
    if (defaultNE == null)
        defaultNE = NamingEntryUtil.lookupNamingEntry(null, nameInEnvironment);
    if (defaultNE != null)
        defaultNE.bindToENC(name);
    else
        throw new IllegalStateException("Nothing to bind for name " + name);
}
Also used : NamingEntry(org.eclipse.jetty.plus.jndi.NamingEntry) Link(org.eclipse.jetty.plus.jndi.Link)

Aggregations

Link (org.eclipse.jetty.plus.jndi.Link)1 NamingEntry (org.eclipse.jetty.plus.jndi.NamingEntry)1