m.c.m.proxyma.resource
Class ProxymaResponseDataBean

java.lang.Object
  extended by m.c.m.proxyma.resource.ProxymaResponseDataBean
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class ProxymaResponseDataBean
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

This class rappresents all the data that can be sent to a Client as Response.
It is designed to be "rewritable" in any part allowing plugins to manipulate it without any restriction.
This class makes Proxyma able to transparently handle "Servlet" (and "Portlet"?) data in the same way.

NOTE: this software is released under GPL License. See the LICENSE of this distribution for more informations.

Version:
$Id: ProxymaResponseDataBean.java 138 2010-06-20 13:53:32Z marcolinuz $
Author:
Marco Casavecchia Morganti (marcolinuz) [marcolinuz-at-gmail.com]
See Also:
Serialized Form

Constructor Summary
ProxymaResponseDataBean()
           
 
Method Summary
 void addCookie(javax.servlet.http.Cookie aCookie)
          Adds a Cookie to the response.
 void addHeader(java.lang.String headerName, int headerValue)
          Adds an header to the response headers using the given name and value to create it.
 void addHeader(java.lang.String headerName, long headerValue)
          Adds an header to the response headers using the given name and value to create it.
 void addHeader(java.lang.String headerName, java.lang.String headerValue)
          Adds an header to the response headers using the given name and value to create it.
 java.lang.Object clone()
          This method clone the current response data into a new separated object.
 boolean containsCookie(java.lang.String aCookieName)
          Checks whether the response has already a Cookie with the specified name.
 boolean containsHeader(java.lang.String headerName)
          Checks whether the response has already an header with the specified name.
 void deleteCookie(java.lang.String cookieName)
          Removes the Cookie with the given name.
 void deleteHeader(java.lang.String headerName)
          Removes an header from the response data.
 long getContentLenght()
          Returns the size in bytes of the raw binary data stored into the response
..or in other words, the value to set for the Content-Length header.
 javax.servlet.http.Cookie getCookie(java.lang.String cookieName)
          Returns the specified cookie.
 java.util.Collection<javax.servlet.http.Cookie> getCookies()
          Returns a collection of all of the Cookie objects of the response.
 ByteBuffer getData()
          Get the raw binary data of the response
 ProxymaHttpHeader getHeader(java.lang.String headerName)
          Returns the specified response http header.
 java.util.Collection<java.lang.String> getHeaderNames()
          Returns a Collection of all the header names of the response.
 java.util.Collection<ProxymaHttpHeader> getMultivalueHeader(java.lang.String headerName)
          This method is done to get values from a multiple values header (like Cache-Control).
 int getStatus()
          Get the current value of the status code of the response
 boolean isMultipleHeader(java.lang.String headerName)
          Checks whether the specified header has multiple values.
 void setData(ByteBuffer aBuffer)
          Set the raw binary data of the response
 void setStatus(int value)
          Sets the status code for this response.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProxymaResponseDataBean

public ProxymaResponseDataBean()
Method Detail

getHeaderNames

public java.util.Collection<java.lang.String> getHeaderNames()
Returns a Collection of all the header names of the response. If the response has no headers, this method returns an empty collection.

Returns:
a collection of header names.

getMultivalueHeader

public java.util.Collection<ProxymaHttpHeader> getMultivalueHeader(java.lang.String headerName)
This method is done to get values from a multiple values header (like Cache-Control). It returns a Collection of the specified response http headers.
If the wanted header is not found, this method returns null.
The header name is case insensitive.
You can use this method with any response header indeed, if the header has a single value this method will return a collection with only one element into it.

Returns:
the wanted header or null if the header doesn't exists
See Also:
ProxymaHttpHeader

getHeader

public ProxymaHttpHeader getHeader(java.lang.String headerName)
Returns the specified response http header.
If the wanted header is not found, this method returns null.
The header name is case insensitive.
You can use this method with any respose http header.
NOTE: if the header has multiple values this method will return only the first.

Returns:
the wanted header or null if the header doesn't exists
See Also:
ProxymaHttpHeader

addHeader

public void addHeader(java.lang.String headerName,
                      int headerValue)
Adds an header to the response headers using the given name and value to create it.
This method allows to set multiple values for the same headerName.
You can use the containsHeader method if you want to test for the presence of a an existing header before setting its value.

Throws:
org.apache.commons.lang.NullArgumentException - is raised if the header name is null
See Also:
ProxymaHttpHeader

addHeader

public void addHeader(java.lang.String headerName,
                      long headerValue)
Adds an header to the response headers using the given name and value to create it.
This method allows to set multiple values for the same headerName.
You can use the containsHeader method if you want to test for the presence of a an existing header before setting its value.

Throws:
org.apache.commons.lang.NullArgumentException - is raised if the header name is null
See Also:
ProxymaHttpHeader

addHeader

public void addHeader(java.lang.String headerName,
                      java.lang.String headerValue)
               throws org.apache.commons.lang.NullArgumentException
Adds an header to the response headers using the given name and value to create it.
This method allows to set multiple values for the same headerName.
You can use the containsHeader method if you want to test for the presence of a an existing header before setting its value.

Throws:
org.apache.commons.lang.NullArgumentException - is raised if the header name is null
See Also:
ProxymaHttpHeader

containsHeader

public boolean containsHeader(java.lang.String headerName)
Checks whether the response has already an header with the specified name.

Parameters:
headerName - The name of the header to check
Returns:
true if the header is found

isMultipleHeader

public boolean isMultipleHeader(java.lang.String headerName)
                         throws java.lang.NullPointerException
Checks whether the specified header has multiple values.

Parameters:
headerName - The name of the header to check
Returns:
true if the header has multiple values
Throws:
java.lang.NullPointerException - if the header doesn't exists at all.

deleteHeader

public void deleteHeader(java.lang.String headerName)
Removes an header from the response data.
The header name is case insensitive
If the specifyed header is not found, nothing will be done.
Please use the containsHeader method to check for the presence of an header before remove it.
Note: this method will remove any instnance of the specified header, so all the values of a multiple-values header will be removed.

Parameters:
headerName - The name of the header to remove

getCookies

public java.util.Collection<javax.servlet.http.Cookie> getCookies()
Returns a collection of all of the Cookie objects of the response. This method returns an empty collecion if there are no cookies.

Returns:
a Collection of cookies

getCookie

public javax.servlet.http.Cookie getCookie(java.lang.String cookieName)
Returns the specified cookie. If the cookie is not found, this method returns null.

Returns:
the header value

addCookie

public void addCookie(javax.servlet.http.Cookie aCookie)
               throws org.apache.commons.lang.NullArgumentException
Adds a Cookie to the response. If the Cookie has been already set, the new value overwrites the previous one. The containsCookie method can be used to test for the presence of a Cookie before setting its value.

Throws:
org.apache.commons.lang.NullArgumentException - if the passed argument is null

containsCookie

public boolean containsCookie(java.lang.String aCookieName)
Checks whether the response has already a Cookie with the specified name.

Parameters:
cookieName - The name of the Cookie to check
Returns:
true if the cookie was found

deleteCookie

public void deleteCookie(java.lang.String cookieName)
                  throws org.apache.commons.lang.NullArgumentException
Removes the Cookie with the given name.
If the Cookie is not found, nothing is done.
You can always use the containsCookie method to test for the presence of a Cookie before remove it.

Parameters:
cookieName - The name of the cookie to remove
Throws:
org.apache.commons.lang.NullArgumentException - if the passed parameter is null

getData

public ByteBuffer getData()
Get the raw binary data of the response

Returns:
a ByteBuffer containing the raw data of the resource

setData

public void setData(ByteBuffer aBuffer)
Set the raw binary data of the response

Parameters:
aBuffer - the ByteBuffer containing the binary data

getStatus

public int getStatus()
Get the current value of the status code of the response

Returns:
the current status

setStatus

public void setStatus(int value)
Sets the status code for this response. This method is used to set the return status code when there is no error (for example, for the status codes SC_OK or SC_MOVED_TEMPORARILY).

Parameters:
value - the new status value
See Also:
serializeToClient

getContentLenght

public long getContentLenght()
Returns the size in bytes of the raw binary data stored into the response
..or in other words, the value to set for the Content-Length header.

Returns:
the size of the response binary data.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
This method clone the current response data into a new separated object.

Overrides:
clone in class java.lang.Object
Returns:
a new and separate instance of the object.
Throws:
java.lang.CloneNotSupportedException - if the clone operation is not supported


Copyright © 2010. All Rights Reserved.