com.pkrete.jsip2.parser
Class SIP2ResponseParser

java.lang.Object
  extended by com.pkrete.jsip2.parser.SIP2ResponseParser
Direct Known Subclasses:
SIP2ACSStatusResponseParser, SIP2CheckinResponseParser, SIP2CheckoutResponseParser, SIP2EndSessionResponseParser, SIP2FeePaidResponseParser, SIP2HoldResponseParser, SIP2ItemInformationResponseParser, SIP2ItemStatusUpdateResponseParser, SIP2LoginResponseParser, SIP2PatronEnableResponseParser, SIP2PatronInformationResponseParser, SIP2PatronStatusResponseParser, SIP2RenewAllResponseParser, SIP2RenewResponseParser

public abstract class SIP2ResponseParser
extends Object

This is an abstract base class for all the response message parser classes, which task is to parse the response messages received from the ILS SIP server and create the corresponding objects.

Author:
Petteri Kivimäki

Constructor Summary
SIP2ResponseParser()
           
 
Method Summary
protected  boolean charEmptyToBool(char character)
          Converts the given character to a boolean value.
protected  boolean charToBool(char character)
          Converts the given character to a boolean value.
protected  boolean exists(String variable, String data)
          Returns true if and only if the given variable is present in the given string.
protected  boolean existsAndNotEmpty(String variable, String data)
          Returns true if and only if the given variable and a value are present in the given string.
protected  boolean intToBool(char character)
          Converts the given character to a boolean value.
abstract  SIP2MessageResponse parse(String data)
          Parses a SIP2MessageResponse from the given string.
protected  String parseChecksum(String data)
          Parses the checksum from the given string.
protected  String parseSequence(String data)
          Parses the sequence from the given string.
protected  String parseVariable(String variable, String data)
          Parses the value of the given variable from the given data string.
protected  String parseVariable(String variable, String data, boolean required)
          Parses the value of the given variable from the given data string.
protected  List<String> parseVariableMulti(String variable, String data)
          Parses the value of the given variable from the given data string.
protected  String parseVariableWithoutDelimiter(String variable, String data)
          Parses the value of the given variable from the given data string.
protected  String parseVariableWithoutDelimiter(String variable, String data, boolean required)
          Parses the value of the given variable from the given data string.
protected  int stringToInt(String value)
          Converts the given string to an integer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SIP2ResponseParser

public SIP2ResponseParser()
Method Detail

parse

public abstract SIP2MessageResponse parse(String data)
                                   throws InvalidSIP2ResponseValueException,
                                          InvalidSIP2ResponseException
Parses a SIP2MessageResponse from the given string.

Parameters:
data - message response data
Returns:
SIP2MessageResponse object parsed from the data
Throws:
InvalidSIP2ResponseValueException
InvalidSIP2ResponseException

intToBool

protected boolean intToBool(char character)
                     throws InvalidSIP2ResponseValueException
Converts the given character to a boolean value. Character must be 0 or 1, 0 = false, 1 = true. Otherwise an exception is thrown.

Parameters:
character - char to be converted
Returns:
boolean value
Throws:
InvalidSIP2ResponseValueException

charToBool

protected boolean charToBool(char character)
                      throws InvalidSIP2ResponseValueException
Converts the given character to a boolean value. Character must be Y or N. Otherwise an exception is thrown.

Parameters:
character - char to be converted
Returns:
boolean value
Throws:
InvalidSIP2ResponseValueException

stringToInt

protected int stringToInt(String value)
                   throws InvalidSIP2ResponseValueException
Converts the given string to an integer.

Parameters:
value - string to be converted
Returns:
integer value
Throws:
InvalidSIP2ResponseValueException

charEmptyToBool

protected boolean charEmptyToBool(char character)
                           throws InvalidSIP2ResponseValueException
Converts the given character to a boolean value. Character must be 'Y' or ' '. Otherwise an exception is thrown.

Parameters:
character - char to be converted
Returns:
boolean value
Throws:
InvalidSIP2ResponseValueException

parseVariable

protected String parseVariable(String variable,
                               String data,
                               boolean required)
Parses the value of the given variable from the given data string. A field delimiter must be found before the variable code. Returns an empty string if the variable is required, but it's not present in the data. If the variable is optional and not present in the data, null is returned instead.

Parameters:
variable - code of the variable, 2 characters
data - data string
required - true if the variable is required, false if optional
Returns:
variable value, an empty string or null depending if the variable is found and if it's optional or required

parseVariable

protected String parseVariable(String variable,
                               String data)
Parses the value of the given variable from the given data string. A field delimiter must be found before the variable code. Returns an empty string if the given variable isn't present in the data.

Parameters:
variable - code of the variable, 2 characters
data - data string
Returns:
variable value

parseVariableWithoutDelimiter

protected String parseVariableWithoutDelimiter(String variable,
                                               String data,
                                               boolean required)
Parses the value of the given variable from the given data string. Returns an empty string if the variable is required, but it's not present in the data. If the variable is optional and not present in the data, null is returned instead.

Parameters:
variable - code of the variable, 2 characters
data - data string
required - true if the variable is required, false if optional
Returns:
variable value, an empty string or null depending if the variable is found and if it's optional or required

parseVariableWithoutDelimiter

protected String parseVariableWithoutDelimiter(String variable,
                                               String data)
Parses the value of the given variable from the given data string. Returns an empty string if the given variable isn't present in the data.

Parameters:
variable - code of the variable, 2 characters
data - data string
Returns:
variable value

parseVariableMulti

protected List<String> parseVariableMulti(String variable,
                                          String data)
Parses the value of the given variable from the given data string. The variable can be repeated one or more times, or it may not be used at all. Returns a list containing all the found values, or an empty list if no mathes were found.

Parameters:
variable - code of the variable, 2 characters
data - data string
Returns:
list of found variable values

parseSequence

protected String parseSequence(String data)
Parses the sequence from the given string.

Parameters:
data - data string
Returns:
sequence number or an empty string if the data doesn't contain sequence

parseChecksum

protected String parseChecksum(String data)
Parses the checksum from the given string.

Parameters:
data - data string
Returns:
chekcsum or an empty string if the data doesn't contain checksum

exists

protected boolean exists(String variable,
                         String data)
Returns true if and only if the given variable is present in the given string.

Parameters:
variable - code of the variable, 2 characters
data - data string
Returns:
true if the given field is present in the given string, otherwise false

existsAndNotEmpty

protected boolean existsAndNotEmpty(String variable,
                                    String data)
Returns true if and only if the given variable and a value are present in the given string. If only code is present, false is returned.

Parameters:
variable - code of the variable, 2 characters
data - data string
Returns:
true if the given variable and value are present in the given string, otherwise false


Copyright © 2012-2014. All Rights Reserved.