FileDocCategorySizeDatePackage
ResponseFacade.javaAPI DocGlassfish v2 API10076Fri May 04 22:31:54 BST 2007org.apache.catalina.connector

ResponseFacade

public class ResponseFacade extends Object implements ServletResponse
Facade class that wraps a Catalina-internal Response object. All methods are delegated to the wrapped response.
author
Remy Maucherat
version
$Revision: 1.4 $ $Date: 2007/05/05 05:31:53 $

Fields Summary
private static final org.apache.catalina.util.StringManager
sm
The string manager for this package.
protected ServletResponse
response
The wrapped response.
protected org.apache.catalina.Response
resp
The wrapped response.
Constructors Summary
public ResponseFacade(org.apache.catalina.Response response)
Construct a wrapper for the specified response.

param
response The response to be wrapped



    // ----------------------------------------------------------- Constructors


                       
       
        this.resp = response;
        this.response = (ServletResponse) response;
    
Methods Summary
public voidclear()
Clear facade.



    // --------------------------------------------------------- Public Methods


           
       
        response = null;
        resp = null;
    
public voidfinish()


        resp.setSuspended(true);

    
public voidflushBuffer()


        // Disallow operation if the object has gone out of scope
        if (response == null) {
            throw new IllegalStateException(
                sm.getString("object.invalidScope"));
        }

        if (isFinished())
            //            throw new IllegalStateException
            //                (/*sm.getString("responseFacade.finished")*/);
            return;

        resp.setAppCommitted(true);

        try {
            response.flushBuffer();
        } catch(IOException ioe) {
            // An IOException on a write is almost always due to
            // the remote client aborting the request.  Wrap this
            // so that it can be handled better by the error dispatcher.
            throw new ClientAbortException(ioe);
        }
    
public intgetBufferSize()


        // Disallow operation if the object has gone out of scope
        if (response == null) {
            throw new IllegalStateException(
                sm.getString("object.invalidScope"));
        }

        return response.getBufferSize();
    
public java.lang.StringgetCharacterEncoding()

        // Disallow operation if the object has gone out of scope
        if (response == null) {
            throw new IllegalStateException(
                sm.getString("object.invalidScope"));
        }
        return response.getCharacterEncoding();
    
public java.lang.StringgetContentType()


        // Disallow operation if the object has gone out of scope
        if (response == null) {
            throw new IllegalStateException(
                sm.getString("object.invalidScope"));
        }

        return response.getContentType();

    
public java.util.LocalegetLocale()


        // Disallow operation if the object has gone out of scope
        if (response == null) {
            throw new IllegalStateException(
                sm.getString("object.invalidScope"));
        }

        return response.getLocale();
    
public javax.servlet.ServletOutputStreamgetOutputStream()


        //        if (isFinished())
        //            throw new IllegalStateException
        //                (/*sm.getString("responseFacade.finished")*/);

        // Disallow operation if the object has gone out of scope
        if (response == null) {
            throw new IllegalStateException(
                sm.getString("object.invalidScope"));
        }

        ServletOutputStream sos = response.getOutputStream();
        if (isFinished())
            resp.setSuspended(true);
        return (sos);

    
public java.io.PrintWritergetWriter()


        //        if (isFinished())
        //            throw new IllegalStateException
        //                (/*sm.getString("responseFacade.finished")*/);

        // Disallow operation if the object has gone out of scope
        if (response == null) {
            throw new IllegalStateException(
                sm.getString("object.invalidScope"));
        }

        PrintWriter writer = response.getWriter();
        if (isFinished())
            resp.setSuspended(true);
        return (writer);

    
public booleanisCommitted()


        // Disallow operation if the object has gone out of scope
        if (response == null) {
            throw new IllegalStateException(
                sm.getString("object.invalidScope"));
        }

        return (resp.isAppCommitted());
    
public booleanisFinished()


        return resp.isSuspended();

    
public voidreset()


        // Disallow operation if the object has gone out of scope
        if (response == null) {
            throw new IllegalStateException(
                sm.getString("object.invalidScope"));
        }

        if (isCommitted())
            throw new IllegalStateException
                (/*sm.getString("responseBase.reset.ise")*/);

        response.reset();

    
public voidresetBuffer()


        // Disallow operation if the object has gone out of scope
        if (response == null) {
            throw new IllegalStateException(
                sm.getString("object.invalidScope"));
        }

        if (isCommitted())
            throw new IllegalStateException
                (/*sm.getString("responseBase.reset.ise")*/);

        response.resetBuffer();

    
public voidsetBufferSize(int size)


        // Disallow operation if the object has gone out of scope
        if (response == null) {
            throw new IllegalStateException(
                sm.getString("object.invalidScope"));
        }

        if (isCommitted())
            throw new IllegalStateException
                (/*sm.getString("responseBase.reset.ise")*/);

        response.setBufferSize(size);

    
public voidsetCharacterEncoding(java.lang.String charset)


        // Disallow operation if the object has gone out of scope
        if (response == null) {
            throw new IllegalStateException(
                sm.getString("object.invalidScope"));
        }

        if (isCommitted())
            return;

        response.setCharacterEncoding(charset);

    
public voidsetContentLength(int len)


        // Disallow operation if the object has gone out of scope
        if (response == null) {
            throw new IllegalStateException(
                sm.getString("object.invalidScope"));
        }

        if (isCommitted())
            return;

        response.setContentLength(len);

    
public voidsetContentType(java.lang.String type)


        // Disallow operation if the object has gone out of scope
        if (response == null) {
            throw new IllegalStateException(
                sm.getString("object.invalidScope"));
        }

        if (isCommitted())
            return;

        response.setContentType(type);

    
public voidsetLocale(java.util.Locale loc)


        // Disallow operation if the object has gone out of scope
        if (response == null) {
            throw new IllegalStateException(
                sm.getString("object.invalidScope"));
        }

        if (isCommitted())
            return;

        response.setLocale(loc);