groovy.servlet
Class ServletBinding

java.lang.Object
  extended by groovy.lang.GroovyObjectSupport
      extended by groovy.lang.Binding
          extended by groovy.servlet.ServletBinding
All Implemented Interfaces:
GroovyObject

public class ServletBinding
extends Binding

Servlet-specific binding extension to lazy load the writer or the output stream from the response.

Eager variables

Lazy variables

As per specification a call to response.getWriter() should not be done if a call to response.getOutputStream() have been done already and the other way around. Lazy bound variables can be requested without side effects, since the writer and stream is wrapped. That means response.getWriter() is not directly called if 'out' or 'html' is requested. Only if a write method call is done using the variable, a write method call on 'sout' will cause a IllegalStateException. If a write method call on 'sout' has been done already any further write method call on 'out' or 'html' will cause a IllegalStateException.

If response.getWriter() is called directly (without using out), then a write method call on 'sout' will not cause the IllegalStateException, but it will still be invalid. It is the responsibility of the user of this class, to not to mix these different usage styles. The same applies to calling response.getOoutputStream() and using 'out' or 'html'.

Methods

Author:
Guillaume Laforge, Christian Stein, Jochen Theodorou

Nested Class Summary
private static class ServletBinding.InvalidOutputStream
          A OutputStream dummy that will throw a GroovyBugError for any write method call to it.
private static class ServletBinding.ServletOutput
          A class to manage the response output stream and writer.
 
Field Summary
private  boolean initialized
           
 
Constructor Summary
ServletBinding(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.ServletContext context)
          Initializes a servlet binding.
 
Method Summary
private  void excludeReservedName(java.lang.String name, java.lang.String reservedName)
           
 void forward(java.lang.String path)
           
 java.lang.Object getVariable(java.lang.String name)
           
 java.util.Map getVariables()
           
 void include(java.lang.String path)
           
private  void lazyInit()
           
 void redirect(java.lang.String location)
           
 void setVariable(java.lang.String name, java.lang.Object value)
          Sets the value of the given variable
private  void validateArgs(java.lang.String name, java.lang.String message)
           
 
Methods inherited from class groovy.lang.Binding
getProperty, setProperty
 
Methods inherited from class groovy.lang.GroovyObjectSupport
getMetaClass, invokeMethod, setMetaClass
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

initialized

private boolean initialized
Constructor Detail

ServletBinding

public ServletBinding(javax.servlet.http.HttpServletRequest request,
                      javax.servlet.http.HttpServletResponse response,
                      javax.servlet.ServletContext context)
Initializes a servlet binding.

Parameters:
request - the HttpServletRequest object
response - the HttpServletRequest object
context - the ServletContext object
Method Detail

setVariable

public void setVariable(java.lang.String name,
                        java.lang.Object value)
Description copied from class: Binding
Sets the value of the given variable

Overrides:
setVariable in class Binding
Parameters:
name - the name of the variable to set
value - the new value for the given variable

getVariables

public java.util.Map getVariables()
Overrides:
getVariables in class Binding

getVariable

public java.lang.Object getVariable(java.lang.String name)
Overrides:
getVariable in class Binding
Parameters:
name - the name of the variable to lookup
Returns:
a writer, an output stream, a markup builder or another requested object

lazyInit

private void lazyInit()

validateArgs

private void validateArgs(java.lang.String name,
                          java.lang.String message)

excludeReservedName

private void excludeReservedName(java.lang.String name,
                                 java.lang.String reservedName)

forward

public void forward(java.lang.String path)
             throws javax.servlet.ServletException,
                    java.io.IOException
Throws:
javax.servlet.ServletException
java.io.IOException

include

public void include(java.lang.String path)
             throws javax.servlet.ServletException,
                    java.io.IOException
Throws:
javax.servlet.ServletException
java.io.IOException

redirect

public void redirect(java.lang.String location)
              throws java.io.IOException
Throws:
java.io.IOException


Copyright © ${year} The Codehaus. All Rights Reserved.