pl.bristleback.server.bristle.utils
Class BristleTokenFactory

java.lang.Object
  extended by pl.bristleback.server.bristle.utils.BristleTokenFactory

public final class BristleTokenFactory
extends java.lang.Object

This utility class contains a huge amount of factory methods, used to create various types of token.

Created on: 2010-11-28 13:51:16

Author:
Wojciech Niemiec

Field Summary
static java.lang.String EXCEPTION_TYPE_PARAMETER
           
static java.lang.String EXCEPTION_VALUE_PARAMETER
           
static java.lang.String VALIDATION_EXCEPTION_ERROR_TYPE
           
static java.lang.String VALIDATION_EXCEPTION_ERRORS
           
static java.lang.String VALIDATION_EXCEPTION_FIELD_NAME
           
static java.lang.String VALIDATION_EXCEPTION_TYPE
           
 
Method Summary
static org.jwebsocket.token.Token createExceptionToken(org.jwebsocket.token.Token request, java.lang.String exceptionType)
          Creates a response token with filled exception type field, this token will be processed by client's callback onFailure() method.
static org.jwebsocket.token.JSONToken createJsonExceptionToken(org.jwebsocket.token.Token request, java.lang.String exceptionType)
          Creates a json exception response token with filled exception type field, this token will be processed by client's callback onFailure() method.
static org.jwebsocket.token.JSONToken createJsonExceptionToken(org.jwebsocket.token.Token request, java.lang.String exceptionType, org.json.JSONObject exceptionValue)
          Creates a json exception response token with filled exception type and value field, this token will be processed by client's callback onFailure() method.
static org.jwebsocket.token.JSONToken createJsonResponseToken(org.jwebsocket.token.Token request)
          Creates a response JSONToken token, copying action name and request identification.
static org.jwebsocket.token.JSONToken createJsonResponseToken(org.jwebsocket.token.Token request, org.json.JSONArray json, java.lang.String arrayFieldName)
          Creates a response json token with content given in JSONArray parameter, copying action name and request identification.
static org.jwebsocket.token.JSONToken createJsonResponseToken(org.jwebsocket.token.Token request, org.json.JSONObject json)
          Creates a response json token with content given in JSONObject parameter, copying action name and request identification.
static org.jwebsocket.token.JSONToken createJsonToken(java.lang.String actionName)
          Creates a JSONToken token with filled action name field.
static org.jwebsocket.token.JSONToken createJsonToken(java.lang.String actionName, org.json.JSONArray jsonArray, java.lang.String arrayFieldName)
          Creates a Json token using given json array.
static org.jwebsocket.token.JSONToken createJsonToken(java.lang.String actionName, org.json.JSONObject json)
          Creates a json token with given json object inside and filled action name field.
static org.jwebsocket.token.Token createResponseToken(org.jwebsocket.token.Token request)
          Creates a response MapToken token, copying action name and request identification.
static org.jwebsocket.token.Token createToken(java.lang.String actionName)
          Creates a MapToken token with filled action name field.
static org.jwebsocket.token.Token createValidationExceptionToken(org.jwebsocket.token.Token request, BindingResult<?> result)
          Creates a json response token with exception type "ValidationException".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VALIDATION_EXCEPTION_TYPE

public static final java.lang.String VALIDATION_EXCEPTION_TYPE
See Also:
Constant Field Values

VALIDATION_EXCEPTION_ERRORS

public static final java.lang.String VALIDATION_EXCEPTION_ERRORS
See Also:
Constant Field Values

VALIDATION_EXCEPTION_FIELD_NAME

public static final java.lang.String VALIDATION_EXCEPTION_FIELD_NAME
See Also:
Constant Field Values

VALIDATION_EXCEPTION_ERROR_TYPE

public static final java.lang.String VALIDATION_EXCEPTION_ERROR_TYPE
See Also:
Constant Field Values

EXCEPTION_TYPE_PARAMETER

public static final java.lang.String EXCEPTION_TYPE_PARAMETER
See Also:
Constant Field Values

EXCEPTION_VALUE_PARAMETER

public static final java.lang.String EXCEPTION_VALUE_PARAMETER
See Also:
Constant Field Values
Method Detail

createJsonToken

public static org.jwebsocket.token.JSONToken createJsonToken(java.lang.String actionName,
                                                             org.json.JSONObject json)
Creates a json token with given json object inside and filled action name field.

Parameters:
actionName - action name
json - json object
Returns:
json token.

createJsonToken

public static org.jwebsocket.token.JSONToken createJsonToken(java.lang.String actionName,
                                                             org.json.JSONArray jsonArray,
                                                             java.lang.String arrayFieldName)
Creates a Json token using given json array. Because of Json token specification, array must be an element of parent json object. Name of array is specified by user.

Parameters:
actionName - action name
jsonArray - json array
arrayFieldName - name of json array inside parent json object.
Returns:
json token with given json array inside.

createToken

public static org.jwebsocket.token.Token createToken(java.lang.String actionName)
Creates a MapToken token with filled action name field.

Parameters:
actionName - action name.
Returns:
token with filled namespace and action name field.

createJsonToken

public static org.jwebsocket.token.JSONToken createJsonToken(java.lang.String actionName)
Creates a JSONToken token with filled action name field.

Parameters:
actionName - action name.
Returns:
json token with filled namespace and action name field.

createResponseToken

public static org.jwebsocket.token.Token createResponseToken(org.jwebsocket.token.Token request)
Creates a response MapToken token, copying action name and request identification.

Parameters:
request - request token containing request identification and requested action name.
Returns:
a complete response token.

createJsonResponseToken

public static org.jwebsocket.token.JSONToken createJsonResponseToken(org.jwebsocket.token.Token request)
Creates a response JSONToken token, copying action name and request identification.

Parameters:
request - request token containing request identification and requested action name.
Returns:
a complete response json token.

createJsonResponseToken

public static org.jwebsocket.token.JSONToken createJsonResponseToken(org.jwebsocket.token.Token request,
                                                                     org.json.JSONObject json)
Creates a response json token with content given in JSONObject parameter, copying action name and request identification.

Parameters:
request - request token containing request identification and requested action name.
json - content of the response token.
Returns:
a complete response token with content given in JSONObject parameter.

createJsonResponseToken

public static org.jwebsocket.token.JSONToken createJsonResponseToken(org.jwebsocket.token.Token request,
                                                                     org.json.JSONArray json,
                                                                     java.lang.String arrayFieldName)
Creates a response json token with content given in JSONArray parameter, copying action name and request identification. Content array is put under name given as last parameter.

Parameters:
request - request token containing request identification and requested action name.
json - content array of the response token.
arrayFieldName - name under which given array is put.
Returns:
a complete response token with content given in JSONArray parameter.

createExceptionToken

public static org.jwebsocket.token.Token createExceptionToken(org.jwebsocket.token.Token request,
                                                              java.lang.String exceptionType)
Creates a response token with filled exception type field, this token will be processed by client's callback onFailure() method. This exception token contains no exception value (only type), but it can be added manually by setting token variable with key EXCEPTION_VALUE_PARAMETER.

Parameters:
request - request token containing request identification and requested action name.
exceptionType - type of exception to thrown.
Returns:
a complete exception response token.

createJsonExceptionToken

public static org.jwebsocket.token.JSONToken createJsonExceptionToken(org.jwebsocket.token.Token request,
                                                                      java.lang.String exceptionType,
                                                                      org.json.JSONObject exceptionValue)
Creates a json exception response token with filled exception type and value field, this token will be processed by client's callback onFailure() method. Exception value parameter is passed in parameter.

Parameters:
request - request token containing request identification and requested action name.
exceptionType - type of exception to thrown.
exceptionValue - value of exception.
Returns:
a complete json exception response token.

createJsonExceptionToken

public static org.jwebsocket.token.JSONToken createJsonExceptionToken(org.jwebsocket.token.Token request,
                                                                      java.lang.String exceptionType)
Creates a json exception response token with filled exception type field, this token will be processed by client's callback onFailure() method. This exception token contains no exception value (only type), but it can be added manually by setting token variable with key EXCEPTION_VALUE_PARAMETER.

Parameters:
request - request token containing request identification and requested action name.
exceptionType - type of exception to thrown.
Returns:
a complete json exception response token.

createValidationExceptionToken

public static org.jwebsocket.token.Token createValidationExceptionToken(org.jwebsocket.token.Token request,
                                                                        BindingResult<?> result)
Creates a json response token with exception type "ValidationException". Value of this exception is set using binding errors. If given binding result wrapper doesn't contain any binding errors, runtime exception is thrown. Exception value has variable named "errors", which contains list of binding errors descriptions. Every error has two variables: "field" (complete path of field) and "type" (type of validation error).

Parameters:
request - request token containing request identification and requested action name.
result - binding operation result wrapper with not empty list of binding errors.
Returns:
a complete json validation exception token, with type "ValidationException".


Copyright © 2011. All Rights Reserved.