Example usage for javax.servlet Registration getName

List of usage examples for javax.servlet Registration getName

Introduction

In this page you can find the example usage for javax.servlet Registration getName.

Prototype

public String getName();

Source Link

Document

Gets the name of the Servlet or Filter that is represented by this Registration.

Usage

From source file:org.apache.struts.service.factory.FactoryService.java

/** Process bean registration. It returns false if some errors
 *  occured and true as flag of successful operation. Successful
 *  issue is after such steps as - <br>
 *  <p>//from  w  ww  .  j  a v  a 2  s  .  co m
 *  <li> search bean template
 *  <li> search factory
 *  <li> create bean with this factory from bean template
 *  <li> store bean in session or request scope</p>
 *
 *  @param beanRegistration Bean registration to be processed
 *  @param request The servlet request we are processing
 *  @param response The servlet response we are generating
 *
 *  @return boolean
 *
 *  @throws IOExceprion
 *  @throws ServletExceprion
 */
public boolean processRegistration(Registration registration, HttpServletRequest request,
        HttpServletResponse response) throws IOException, ServletException {
    String name = null;
    FactoryMapping factoryMapping = null;
    Template template = null;
    Object bean = null;

    if (getDebug() >= 1)
        log("Process Registration for name = '" + registration.getName() + "' and factory '"
                + registration.getFactory() + "'");

    factoryMapping = findFactoryMapping(registration.getFactory());
    // find bean factory or exit with error
    if (factoryMapping == null) {
        if (getDebug() >= 1)
            log(" No factory available for name " + registration.getFactory());
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Invalid factory name");
        return false;
    }
    // find bean template or exit with error
    template = findTemplate(registration.getName());
    if (template == null) {
        if (getDebug() >= 1)
            log(" No template available for name " + registration.getName());
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Invalid template name");
        return false;
    }
    try {
        bean = processCreateBean(template, factoryMapping, registration, request);
    } catch (Throwable e) {
        log("Exception at create instance process!", e);
        e.printStackTrace(System.out);
    }
    if (bean == null) {
        if (getDebug() >= 1)
            log(" Bean not created! Bean template name - " + name);
        if (registration.getNecessary()) {
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                    "Can not create internal resource");
            return false;
        }
    } else {
        String beanName = null;
        String beanScope = registration.getScope();
        if (registration.getAlias() != null)
            beanName = registration.getAlias();
        else
            beanName = registration.getName();
        if (beanScope == null)
            beanScope = defaultBeanSaveScope;
        if ("session".equals(beanScope)) {
            request.getSession().setAttribute(beanName, bean);
            if (getDebug() >= 1)
                log("Save bean in session context under name - " + beanName);
        } else if ("request".equals(beanScope)) {
            request.setAttribute(beanName, bean);
            if (getDebug() >= 1)
                log("Save bean in request context under name - " + beanName + " object saved in request - "
                        + request.getAttribute(beanName));
        } else {
            if (getDebug() >= 1)
                log("Bean is not saved in scope - " + registration.getScope());
        }
    }
    return true;
}