Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

ru.gammalabs.ice.utils.http
Class DefaultRequestProcessor  view DefaultRequestProcessor download DefaultRequestProcessor.java

java.lang.Object
  extended byru.gammalabs.ice.utils.http.DefaultRequestProcessor
All Implemented Interfaces:
java.lang.Cloneable, RequestProcessor

public class DefaultRequestProcessor
extends java.lang.Object
implements RequestProcessor

Default implementation of RequestProcessor for use with HTTP GET/POST request strings.

Version:
$Revision: 1.1 $

Field Summary
protected  java.util.Map cache
          Parsed objects cache.
(package private)  java.lang.String FINE_GRAIN_SEPARATOR
          Separator between complex property values (like different array values).
(package private)  java.lang.String NAME_VALUE_SEPARATOR
          Separator between object property name and value.
(package private)  java.lang.String OBJECT_PROPERTIES_SEPARATOR
          Separator between object identifier and serialized object data.
(package private)  java.lang.String OBJECTS_SEPARATOR
          Separator between two objects in request string.
(package private)  java.lang.String PROPERTIES_SEPARATOR
          Separator between two serialized properties.
protected  java.lang.String request
          Request string.
(package private)  java.lang.String SCRIBBLE_METHOD_PREFIX
           
(package private)  java.lang.String UNSCRIBBLE_METHOD_PREFIX
           
protected  java.util.Map values
          String values map.
 
Constructor Summary
DefaultRequestProcessor()
          Creates new RequestProcessor instance.
 
Method Summary
private  void assembleRequestString()
          Assembles stored request string from current values Map.
 void clear()
          Clear all request data that is currently stored in the RequestProcessor.
 java.lang.Object clone()
          This method may be called to create a new copy of the Object.
 java.lang.Object decode(java.lang.String s, java.lang.String id, java.lang.Object object)
          Fills individual object from part of request string, corresponding to this object values.
 java.lang.Object[] decode(java.lang.String s, java.lang.String id, java.lang.Object[] object)
          Fills individual object array from part of request string, corresponding to this objects array values.
 java.lang.String encode(java.lang.String id, java.lang.Object object)
          Encodes any supported Object descendant into id=value string.
 java.lang.String encode(java.lang.String id, java.lang.Object[] object)
          Encodes individual objects array to be stored in request string.
 java.lang.Object get(java.lang.String id, java.lang.Object object)
          Returns object stored in the RequestProcessor with specified identifier.
 java.lang.Object[] get(java.lang.String id, java.lang.Object[] object)
          Returns objects array stored in the RequestProcessor with specified identifier.
 java.lang.String getRequestString()
          Returns request string containing currenly stored objects in serialized form.
private  boolean isRequestable(java.lang.Class c)
          Replacement for instanceof for situations where we cannot use it.
 void put(java.lang.String id, java.lang.Object object)
          Puts object into RequestProcessor internal storage.
 void put(java.lang.String id, java.lang.Object[] object)
          Puts array of objects into RequestProcessor internal storage.
 void remove(java.lang.String id)
          Removes specified object from the RequestProcessor internal storage.
 java.lang.String scribbleboolean(boolean b)
          Method for encoding boolean value.
 java.lang.String scribbleBoolean(java.lang.Boolean b)
          Method for encoding Boolean value.
 java.lang.String scribbleClass(java.lang.Class c)
          Method for encoding Class value.
 java.lang.String scribbleDate(java.util.Date d)
          Method for encoding Date value.
 java.lang.String scribbleint(int i)
          Method for encoding int value.
 java.lang.String scribbleInteger(java.lang.Integer i)
          Method for decoding Integer value.
 java.lang.String scribbleLocale(java.util.Locale l)
          Method for encoding Locale value.
 java.lang.String scribblelong(long l)
          Method for encoding long value.
 java.lang.String scribbleLong(java.lang.Long l)
          Method for encoding Long value.
 java.lang.String scribbleObject(java.lang.Object o)
          Method for encoding Object value.
 java.lang.String scribbleObject(java.lang.Object[] o)
           
 java.lang.String scribbleRequestable(Requestable r)
          Method for encoding Requestable value.
 java.lang.String scribbleString(java.lang.String s)
          Method for encoding String value.
 void setRequestString(java.lang.String s)
          Passes request string containing serialized objects data.
private  void splitRequestString()
          Splits passed request string into internal data structures.
 boolean unscribbleboolean(java.lang.String s)
          Method for decoding encoded boolean value.
 java.lang.Boolean unscribbleBoolean(java.lang.String s)
          Method for decoding encoded Boolean value.
 java.lang.Class unscribbleClass(java.lang.String s)
          Method for decoding encoded Class value.
 java.util.Date unscribbleDate(java.lang.String s)
          Method for decoding encoded Date value.
 int unscribbleint(java.lang.String s)
          Method for decoding encoded int value.
 java.lang.Integer unscribbleInteger(java.lang.String s)
          Method for decoding encoded Integer value.
 java.util.Locale unscribbleLocale(java.lang.String s)
          Method for decoding encoded Locale value.
 long unscribblelong(java.lang.String s)
          Method for decoding encoded long value.
 java.lang.Long unscribbleLong(java.lang.String s)
          Method for decoding encoded Long value.
 java.lang.Object unscribbleObject(java.lang.String s, java.lang.Object o)
          Method for decoding string containing any Object descendand encoded value.
 java.lang.Object[] unscribbleObject(java.lang.String s, java.lang.Object[] o)
           
 Requestable unscribbleRequestable(java.lang.String s, Requestable r)
          Method for decoding string containing encoded Requestable object value.
 java.lang.String unscribbleString(java.lang.String s)
          Method for decoding encoded String value.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OBJECTS_SEPARATOR

final java.lang.String OBJECTS_SEPARATOR
Separator between two objects in request string.

See Also:
Constant Field Values

OBJECT_PROPERTIES_SEPARATOR

final java.lang.String OBJECT_PROPERTIES_SEPARATOR
Separator between object identifier and serialized object data.

See Also:
Constant Field Values

NAME_VALUE_SEPARATOR

final java.lang.String NAME_VALUE_SEPARATOR
Separator between object property name and value.

See Also:
Constant Field Values

PROPERTIES_SEPARATOR

final java.lang.String PROPERTIES_SEPARATOR
Separator between two serialized properties.

See Also:
Constant Field Values

FINE_GRAIN_SEPARATOR

final java.lang.String FINE_GRAIN_SEPARATOR
Separator between complex property values (like different array values).

See Also:
Constant Field Values

SCRIBBLE_METHOD_PREFIX

final java.lang.String SCRIBBLE_METHOD_PREFIX
See Also:
Constant Field Values

UNSCRIBBLE_METHOD_PREFIX

final java.lang.String UNSCRIBBLE_METHOD_PREFIX
See Also:
Constant Field Values

request

protected java.lang.String request
Request string.


cache

protected java.util.Map cache
Parsed objects cache. Key is object identifier String, value is Object.


values

protected java.util.Map values
String values map. Key is object identifier String, value is serialized properties String.

Constructor Detail

DefaultRequestProcessor

public DefaultRequestProcessor()
Creates new RequestProcessor instance.

Method Detail

clear

public void clear()
Description copied from interface: RequestProcessor
Clear all request data that is currently stored in the RequestProcessor.

Specified by:
clear in interface RequestProcessor

remove

public void remove(java.lang.String id)
Description copied from interface: RequestProcessor
Removes specified object from the RequestProcessor internal storage.

Specified by:
remove in interface RequestProcessor

put

public void put(java.lang.String id,
                java.lang.Object object)
Description copied from interface: RequestProcessor
Puts object into RequestProcessor internal storage.

Specified by:
put in interface RequestProcessor

put

public void put(java.lang.String id,
                java.lang.Object[] object)
Description copied from interface: RequestProcessor
Puts array of objects into RequestProcessor internal storage.

Specified by:
put in interface RequestProcessor

get

public java.lang.Object get(java.lang.String id,
                            java.lang.Object object)
Description copied from interface: RequestProcessor
Returns object stored in the RequestProcessor with specified identifier.

Specified by:
get in interface RequestProcessor

get

public java.lang.Object[] get(java.lang.String id,
                              java.lang.Object[] object)
Description copied from interface: RequestProcessor
Returns objects array stored in the RequestProcessor with specified identifier.

Specified by:
get in interface RequestProcessor

setRequestString

public void setRequestString(java.lang.String s)
Description copied from interface: RequestProcessor
Passes request string containing serialized objects data. All previously stored objects are eliminated by this call.

Specified by:
setRequestString in interface RequestProcessor

getRequestString

public java.lang.String getRequestString()
Description copied from interface: RequestProcessor
Returns request string containing currenly stored objects in serialized form.

Specified by:
getRequestString in interface RequestProcessor

clone

public java.lang.Object clone()
Description copied from class: java.lang.Object
This method may be called to create a new copy of the Object. The typical behavior is as follows:
  • o == o.clone() is false
  • o.getClass() == o.clone().getClass() is true
  • o.equals(o) is true

However, these are not strict requirements, and may be violated if necessary. Of the three requirements, the last is the most commonly violated, particularly if the subclass does not override Object.equals(Object)>Object.equals(Object) 55 .

If the Object you call clone() on does not implement java.lang.Cloneable (which is a placeholder interface), then a CloneNotSupportedException is thrown. Notice that Object does not implement Cloneable; this method exists as a convenience for subclasses that do.

Object's implementation of clone allocates space for the new Object using the correct class, without calling any constructors, and then fills in all of the new field values with the old field values. Thus, it is a shallow copy. However, subclasses are permitted to make a deep copy.

All array types implement Cloneable, and override this method as follows (it should never fail):

 public Object clone()
 {
   try
     {
       super.clone();
     }
   catch (CloneNotSupportedException e)
     {
       throw new InternalError(e.getMessage());
     }
 }
 


encode

public java.lang.String encode(java.lang.String id,
                               java.lang.Object object)
Encodes any supported Object descendant into id=value string. In case passed object implements Requestable special encode method for compaund objects is called. Otherwise we lookup encode<passed object class name> method and use it to encode passed value into string.

Specified by:
encode in interface RequestProcessor

decode

public java.lang.Object decode(java.lang.String s,
                               java.lang.String id,
                               java.lang.Object object)
Description copied from interface: RequestProcessor
Fills individual object from part of request string, corresponding to this object values.

Specified by:
decode in interface RequestProcessor

encode

public java.lang.String encode(java.lang.String id,
                               java.lang.Object[] object)
Description copied from interface: RequestProcessor
Encodes individual objects array to be stored in request string.

Specified by:
encode in interface RequestProcessor

decode

public java.lang.Object[] decode(java.lang.String s,
                                 java.lang.String id,
                                 java.lang.Object[] object)
Description copied from interface: RequestProcessor
Fills individual object array from part of request string, corresponding to this objects array values.

Specified by:
decode in interface RequestProcessor

scribbleRequestable

public java.lang.String scribbleRequestable(Requestable r)
Method for encoding Requestable value.


unscribbleRequestable

public Requestable unscribbleRequestable(java.lang.String s,
                                         Requestable r)
Method for decoding string containing encoded Requestable object value. Note: Unlike other unscribble... methods takes initialized Requestable object as the second parameter. This is done because otherwise we had to pass type information with every encoded request which adds overhead and potentially insecure. Passed object is filled with decoded values. Also decoded object is returned.


scribbleObject

public java.lang.String scribbleObject(java.lang.Object o)
Method for encoding Object value. In general it will take any Object descendant and find appropriate method to encode it. For objects implementing Requestable interface scribbleRequestable always will be called instead.


unscribbleObject

public java.lang.Object unscribbleObject(java.lang.String s,
                                         java.lang.Object o)
Method for decoding string containing any Object descendand encoded value. Note: Unlike other unscribble... methods takes initialized object as the second parameter. This is done because otherwise we had to pass type information with every encoded request which adds overhead and potentially insecure. Passed object is not modified except it implements Requestable interface. Decoded object is returned.


scribbleObject

public java.lang.String scribbleObject(java.lang.Object[] o)

unscribbleObject

public java.lang.Object[] unscribbleObject(java.lang.String s,
                                           java.lang.Object[] o)

scribbleString

public java.lang.String scribbleString(java.lang.String s)
Method for encoding String value.


unscribbleString

public java.lang.String unscribbleString(java.lang.String s)
Method for decoding encoded String value.


scribbleint

public java.lang.String scribbleint(int i)
Method for encoding int value.


unscribbleint

public int unscribbleint(java.lang.String s)
Method for decoding encoded int value.


scribbleInteger

public java.lang.String scribbleInteger(java.lang.Integer i)
Method for decoding Integer value.


unscribbleInteger

public java.lang.Integer unscribbleInteger(java.lang.String s)
Method for decoding encoded Integer value.


scribblelong

public java.lang.String scribblelong(long l)
Method for encoding long value.


unscribblelong

public long unscribblelong(java.lang.String s)
Method for decoding encoded long value.


scribbleLong

public java.lang.String scribbleLong(java.lang.Long l)
Method for encoding Long value.


unscribbleLong

public java.lang.Long unscribbleLong(java.lang.String s)
Method for decoding encoded Long value.


scribbleClass

public java.lang.String scribbleClass(java.lang.Class c)
Method for encoding Class value.


unscribbleClass

public java.lang.Class unscribbleClass(java.lang.String s)
Method for decoding encoded Class value.


scribbleDate

public java.lang.String scribbleDate(java.util.Date d)
Method for encoding Date value.


unscribbleDate

public java.util.Date unscribbleDate(java.lang.String s)
Method for decoding encoded Date value.


scribbleBoolean

public java.lang.String scribbleBoolean(java.lang.Boolean b)
Method for encoding Boolean value.


unscribbleBoolean

public java.lang.Boolean unscribbleBoolean(java.lang.String s)
Method for decoding encoded Boolean value.


scribbleboolean

public java.lang.String scribbleboolean(boolean b)
Method for encoding boolean value.


unscribbleboolean

public boolean unscribbleboolean(java.lang.String s)
Method for decoding encoded boolean value.


scribbleLocale

public java.lang.String scribbleLocale(java.util.Locale l)
Method for encoding Locale value.


unscribbleLocale

public java.util.Locale unscribbleLocale(java.lang.String s)
Method for decoding encoded Locale value.


assembleRequestString

private void assembleRequestString()
Assembles stored request string from current values Map.


splitRequestString

private void splitRequestString()
Splits passed request string into internal data structures.


isRequestable

private boolean isRequestable(java.lang.Class c)
Replacement for instanceof for situations where we cannot use it. Checks if passed class or one of it ancestors implement Requestable interface.