org.jibx.runtime
Class Utility

java.lang.Object
  extended byorg.jibx.runtime.Utility

public abstract class Utility
extends java.lang.Object

Utility class supplying static methods. Date serialization is based on the algorithms published by Peter Baum (http://www.capecod.net/~pbaum). All date handling is done according to the W3C Schema specification, which uses a proleptic Gregorian calendar with no year 0. Note that this differs from the Java date handling, which uses a discontinuous Gregorian calendar.

Version:
1.0
Author:
Dennis M. Sosnoski

Field Summary
private static java.util.Date BEGINNING_OF_TIME
          Date for setting change to Gregorian calendar.
private static long[] BIAS_MONTHMS
          Millisecond count prior to start of month in March 1-biased year.
private static long LMSPERDAY
          Number of milliseconds in a day as a long.
static int MINIMUM_GROWN_ARRAY_SIZE
          Minimum size for array returned by growArray(java.lang.Object).
private static int[] MONTHS_LEAP
          Day number for start of month in non-leap year.
private static int[] MONTHS_NONLEAP
          Day number for start of month in non-leap year.
private static long MSPERAVGYEAR
          Average number of milliseconds in a year within century.
private static long MSPERCENTURY
          Number of milliseconds in a normal century.
private static int MSPERDAY
          Number of milliseconds in a day.
private static int MSPERHOUR
          Number of milliseconds in an hour.
private static int MSPERMINUTE
          Number of milliseconds in a minute.
private static long MSPERYEAR
          Number of milliseconds in a (non-leap) year.
private static char PAD_CHAR
          Pad character for base64 encoding.
private static char[] s_base64Chars
          Characters used in base64 encoding.
private static byte[] s_base64Values
          Values corresponding to characters used in bas64 encoding.
private static long TIME_BASE
          Millisecond value of base time for internal representation.
 
Constructor Summary
Utility()
           
 
Method Summary
static java.util.List arrayListFactory()
          Factory method to create a java.util.ArrayList as the implementation of a java.util.List.
private static int decodeChunk(int base, char[] chrs, int fill, byte[] byts)
          Decode a chunk of data from base64 encoding.
static byte[] deserializeBase64(java.lang.String text)
          Parse base64 data from text.
static char deserializeCharString(java.lang.String text)
          Deserialize char value from text as character value.
static java.util.Date deserializeDate(java.lang.String text)
          Deserialize date from text.
static java.util.Date deserializeDateTime(java.lang.String text)
          Deserialize date from general dateTime text.
static java.util.ArrayList deserializeList(java.lang.String text, IListItemDeserializer ideser)
          Convert whitespace-separated list of values.
static java.sql.Date deserializeSqlDate(java.lang.String text)
          Deserialize SQL date from text.
static java.sql.Time deserializeSqlTime(java.lang.String text)
          Deserialize time from text.
static java.sql.Timestamp deserializeTimestamp(java.lang.String text)
          Deserialize timestamp from general dateTime text.
static java.lang.String[] deserializeTokenList(java.lang.String text)
          Deserialize a list of whitespace-separated tokens into an array of strings.
static void encodeChunk(int base, byte[] byts, java.lang.StringBuffer buff)
          Encode a chunk of data to base64 encoding.
static int enumValue(java.lang.String target, java.lang.String[] enums, int[] vals)
          Find text value in enumeration.
protected static void formatTwoDigits(int value, java.lang.StringBuffer buff)
          Format a positive number as two digits.
protected static void formatYear(long value, java.lang.StringBuffer buff)
          Format time in milliseconds to year number.
protected static long formatYearMonth(long value, java.lang.StringBuffer buff)
          Format time in milliseconds to year number and month number.
protected static int formatYearMonthDay(long value, java.lang.StringBuffer buff)
          Format time in milliseconds to year number, month number, and day number.
protected static void formatYearNumber(long year, java.lang.StringBuffer buff)
          Format year number consistent with W3C XML Schema definitions, using a minimum of four digits padded with zeros if necessary.
static java.lang.Object growArray(java.lang.Object base)
          Grow array of arbitrary type.
static boolean isEqual(java.lang.Object a, java.lang.Object b)
          General object comparison method.
static byte[] parseBase64(java.lang.String text)
          Parse base64 data from text.
static boolean parseBoolean(java.lang.String text)
          Parse boolean value from text.
static byte parseByte(java.lang.String text)
          Parse byte value from text.
static char parseChar(java.lang.String text)
          Parse char value from text as unsigned 16-bit integer.
static char parseCharString(java.lang.String text)
          Parse char value from text as character value.
static long parseDate(java.lang.String text)
          Convert date text to Java date.
static long parseDateTime(java.lang.String text)
          Parse general dateTime value from text.
private static int parseDigits(java.lang.String text, int offset, int length)
          Parse digits in text as integer value.
static double parseDouble(java.lang.String text)
          Parse double value from text.
static float parseFloat(java.lang.String text)
          Parse float value from text.
static int parseInt(java.lang.String text)
          Parse integer value from text.
static long parseLong(java.lang.String text)
          Parse long value from text.
static short parseShort(java.lang.String text)
          Parse short value from text.
static long parseTime(java.lang.String text, int start, int length)
          Parse general time value from text.
static long parseYear(java.lang.String text)
          Convert gYear text to Java date.
static long parseYearMonth(java.lang.String text)
          Convert gYearMonth text to Java date.
static java.lang.Object resizeArray(int size, java.lang.Object base)
          Resize array of arbitrary type.
static java.lang.String serializeBase64(byte[] byts)
          Serialize byte array to base64 text.
static java.lang.String serializeBoolean(boolean value)
          Serialize boolean value to text.
static java.lang.String serializeByte(byte value)
          Serialize byte value to text.
static java.lang.String serializeChar(char value)
          Serialize char value to text as unsigned 16-bit integer.
static java.lang.String serializeCharString(char value)
          Serialize char value to text as string of length one.
static java.lang.String serializeDate(java.util.Date date)
          Serialize date to general date text.
static java.lang.String serializeDate(long time)
          Serialize time to general date text.
static java.lang.String serializeDateTime(java.util.Date date)
          Serialize date to general dateTime text.
static java.lang.String serializeDateTime(long time)
          Serialize time to general dateTime text.
static java.lang.String serializeDateTime(long time, boolean zone)
          Serialize time to general dateTime text.
static java.lang.String serializeDouble(double value)
          Serialize double value to text.
static java.lang.String serializeFloat(float value)
          Serialize float value to text.
static java.lang.String serializeInt(int value)
          Serialize int value to text.
static java.lang.String serializeLong(long value)
          Serialize long value to text.
static java.lang.String serializeShort(short value)
          Serialize short value to text.
static java.lang.String serializeSqlDate(java.sql.Date date)
          Serialize SQL date to general date text.
static java.lang.String serializeSqlTime(java.sql.Time time)
          Serialize time to standard text.
static void serializeTime(int time, java.lang.StringBuffer buff)
          Serialize time to general time text in buffer.
static java.lang.String serializeTimestamp(java.sql.Timestamp stamp)
          Serialize timestamp to general dateTime text.
static java.lang.String serializeTokenList(java.lang.String[] tokens)
          Serialize an array of strings into a whitespace-separated token list.
static java.lang.String serializeYear(java.util.Date date)
          Serialize date to general gYear text.
static java.lang.String serializeYear(long time)
          Serialize time to general gYear text.
static java.lang.String serializeYearMonth(java.util.Date date)
          Serialize date to general gYearMonth text.
static java.lang.String serializeYearMonth(long time)
          Serialize time to general gYearMonth text.
private static int validateDate(java.lang.String text)
          Validate a date text string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MINIMUM_GROWN_ARRAY_SIZE

public static final int MINIMUM_GROWN_ARRAY_SIZE
Minimum size for array returned by growArray(java.lang.Object).

See Also:
Constant Field Values

MSPERMINUTE

private static final int MSPERMINUTE
Number of milliseconds in a minute.

See Also:
Constant Field Values

MSPERHOUR

private static final int MSPERHOUR
Number of milliseconds in an hour.

See Also:
Constant Field Values

MSPERDAY

private static final int MSPERDAY
Number of milliseconds in a day.

See Also:
Constant Field Values

LMSPERDAY

private static final long LMSPERDAY
Number of milliseconds in a day as a long.

See Also:
Constant Field Values

MSPERYEAR

private static final long MSPERYEAR
Number of milliseconds in a (non-leap) year.

See Also:
Constant Field Values

MSPERAVGYEAR

private static final long MSPERAVGYEAR
Average number of milliseconds in a year within century.

See Also:
Constant Field Values

MSPERCENTURY

private static final long MSPERCENTURY
Number of milliseconds in a normal century.

See Also:
Constant Field Values

TIME_BASE

private static final long TIME_BASE
Millisecond value of base time for internal representation. This gives the bias relative to January 1 of the year 1 C.E.

See Also:
Constant Field Values

MONTHS_NONLEAP

private static final int[] MONTHS_NONLEAP
Day number for start of month in non-leap year.


MONTHS_LEAP

private static final int[] MONTHS_LEAP
Day number for start of month in non-leap year.


BIAS_MONTHMS

private static final long[] BIAS_MONTHMS
Millisecond count prior to start of month in March 1-biased year.


BEGINNING_OF_TIME

private static java.util.Date BEGINNING_OF_TIME
Date for setting change to Gregorian calendar.


PAD_CHAR

private static final char PAD_CHAR
Pad character for base64 encoding.

See Also:
Constant Field Values

s_base64Chars

private static final char[] s_base64Chars
Characters used in base64 encoding.


s_base64Values

private static final byte[] s_base64Values
Values corresponding to characters used in bas64 encoding.

Constructor Detail

Utility

public Utility()
Method Detail

parseDigits

private static int parseDigits(java.lang.String text,
                               int offset,
                               int length)
                        throws JiBXException
Parse digits in text as integer value. This internal method is used for number values embedded within lexical structures. Only decimal digits can be included in the text range parsed.

Parameters:
text - text to be parsed
offset - starting offset in text
length - number of digits to be parsed
Returns:
converted positive integer value
Throws:
JiBXException - on parse error

parseInt

public static int parseInt(java.lang.String text)
                    throws JiBXException
Parse integer value from text. Integer values are parsed with optional leading sign flag, followed by any number of digits.

Parameters:
text - text to be parsed
Returns:
converted integer value
Throws:
JiBXException - on parse error

serializeInt

public static java.lang.String serializeInt(int value)
Serialize int value to text.

Parameters:
value - int value to be serialized
Returns:
text representation of value

parseLong

public static long parseLong(java.lang.String text)
                      throws JiBXException
Parse long value from text. Long values are parsed with optional leading sign flag, followed by any number of digits.

Parameters:
text - text to be parsed
Returns:
converted long value
Throws:
JiBXException - on parse error

serializeLong

public static java.lang.String serializeLong(long value)
Serialize long value to text.

Parameters:
value - long value to be serialized
Returns:
text representation of value

parseYear

public static long parseYear(java.lang.String text)
                      throws JiBXException
Convert gYear text to Java date. Date values are expected to be in W3C XML Schema standard format as CCYY, with optional leading sign.

Parameters:
text - text to be parsed
Returns:
start of year date as millisecond value from 1 C.E.
Throws:
JiBXException - on parse error

parseShort

public static short parseShort(java.lang.String text)
                        throws JiBXException
Parse short value from text. Short values are parsed with optional leading sign flag, followed by any number of digits.

Parameters:
text - text to be parsed
Returns:
converted short value
Throws:
JiBXException - on parse error

serializeShort

public static java.lang.String serializeShort(short value)
Serialize short value to text.

Parameters:
value - short value to be serialized
Returns:
text representation of value

parseByte

public static byte parseByte(java.lang.String text)
                      throws JiBXException
Parse byte value from text. Byte values are parsed with optional leading sign flag, followed by any number of digits.

Parameters:
text - text to be parsed
Returns:
converted byte value
Throws:
JiBXException - on parse error

serializeByte

public static java.lang.String serializeByte(byte value)
Serialize byte value to text.

Parameters:
value - byte value to be serialized
Returns:
text representation of value

parseBoolean

public static boolean parseBoolean(java.lang.String text)
                            throws JiBXException
Parse boolean value from text. Boolean values are parsed as either text "true" and "false", or "1" and "0" numeric equivalents.

Parameters:
text - text to be parsed
Returns:
converted boolean value
Throws:
JiBXException - on parse error

serializeBoolean

public static java.lang.String serializeBoolean(boolean value)
Serialize boolean value to text. This serializes the value using the text representation as "true" or "false".

Parameters:
value - boolean value to be serialized
Returns:
text representation of value

parseChar

public static char parseChar(java.lang.String text)
                      throws JiBXException
Parse char value from text as unsigned 16-bit integer. Char values are parsed with optional leading sign flag, followed by any number of digits.

Parameters:
text - text to be parsed
Returns:
converted char value
Throws:
JiBXException - on parse error

serializeChar

public static java.lang.String serializeChar(char value)
Serialize char value to text as unsigned 16-bit integer.

Parameters:
value - char value to be serialized
Returns:
text representation of value

parseCharString

public static char parseCharString(java.lang.String text)
                            throws JiBXException
Parse char value from text as character value. This requires that the string must be of length one.

Parameters:
text - text to be parsed
Returns:
converted char value
Throws:
JiBXException - on parse error

deserializeCharString

public static char deserializeCharString(java.lang.String text)
                                  throws JiBXException
Deserialize char value from text as character value. This requires that the string must be null or of length one.

Parameters:
text - text to be parsed (may be null)
Returns:
converted char value
Throws:
JiBXException - on parse error

serializeCharString

public static java.lang.String serializeCharString(char value)
Serialize char value to text as string of length one.

Parameters:
value - char value to be serialized
Returns:
text representation of value

parseFloat

public static float parseFloat(java.lang.String text)
                        throws JiBXException
Parse float value from text. This uses the W3C XML Schema format for floats, with the exception that it will accept "+NaN" and "-NaN" as valid formats. This is not in strict compliance with the specification, but is included for interoperability with other Java XML processing.

Parameters:
text - text to be parsed
Returns:
converted float value
Throws:
JiBXException - on parse error

serializeFloat

public static java.lang.String serializeFloat(float value)
Serialize float value to text.

Parameters:
value - float value to be serialized
Returns:
text representation of value

parseDouble

public static double parseDouble(java.lang.String text)
                          throws JiBXException
Parse double value from text. This uses the W3C XML Schema format for doubles, with the exception that it will accept "+NaN" and "-NaN" as valid formats. This is not in strict compliance with the specification, but is included for interoperability with other Java XML processing.

Parameters:
text - text to be parsed
Returns:
converted double value
Throws:
JiBXException - on parse error

serializeDouble

public static java.lang.String serializeDouble(double value)
Serialize double value to text.

Parameters:
value - double value to be serialized
Returns:
text representation of value

parseYearMonth

public static long parseYearMonth(java.lang.String text)
                           throws JiBXException
Convert gYearMonth text to Java date. Date values are expected to be in W3C XML Schema standard format as CCYY-MM, with optional leading sign.

Parameters:
text - text to be parsed
Returns:
start of month in year date as millisecond value
Throws:
JiBXException - on parse error

parseDate

public static long parseDate(java.lang.String text)
                      throws JiBXException
Convert date text to Java date. Date values are expected to be in W3C XML Schema standard format as CCYY-MM-DD, with optional leading sign and trailing time zone (though the time zone is ignored in this case).

Parameters:
text - text to be parsed
Returns:
start of day in month and year date as millisecond value
Throws:
JiBXException - on parse error

deserializeDate

public static java.util.Date deserializeDate(java.lang.String text)
                                      throws JiBXException
Deserialize date from text. Date values are expected to match W3C XML Schema standard format as CCYY-MM-DD, with optional leading minus sign if necessary. This method follows standard JiBX deserializer usage requirements by accepting a null input.

Parameters:
text - text to be parsed (may be null)
Returns:
converted date, or null if passed null input
Throws:
JiBXException - on parse error

validateDate

private static int validateDate(java.lang.String text)
                         throws JiBXException
Validate a date text string.

Parameters:
text -
Returns:
offset past end of year in text
Throws:
JiBXException - on validation error

deserializeSqlDate

public static java.sql.Date deserializeSqlDate(java.lang.String text)
                                        throws JiBXException
Deserialize SQL date from text. Date values are expected to match W3C XML Schema standard format as CCYY-MM-DD, with optional leading minus sign if necessary. This method follows standard JiBX deserializer usage requirements by accepting a null input.

Parameters:
text - text to be parsed (may be null)
Returns:
converted date, or null if passed null input
Throws:
JiBXException - on parse error

parseTime

public static long parseTime(java.lang.String text,
                             int start,
                             int length)
                      throws JiBXException
Parse general time value from text. Time values are expected to be in W3C XML Schema standard format as hh:mm:ss.fff, with optional leading sign and trailing time zone.

Parameters:
text - text to be parsed
start - offset of first character of time value
length - number of characters in time value
Returns:
converted time as millisecond value
Throws:
JiBXException - on parse error

parseDateTime

public static long parseDateTime(java.lang.String text)
                          throws JiBXException
Parse general dateTime value from text. Date values are expected to be in W3C XML Schema standard format as CCYY-MM-DDThh:mm:ss.fff, with optional leading sign and trailing time zone.

Parameters:
text - text to be parsed
Returns:
converted date as millisecond value
Throws:
JiBXException - on parse error

deserializeDateTime

public static java.util.Date deserializeDateTime(java.lang.String text)
                                          throws JiBXException
Deserialize date from general dateTime text. Date values are expected to match W3C XML Schema standard format as CCYY-MM-DDThh:mm:ss, with optional leading minus sign and trailing seconds decimal, as necessary. This method follows standard JiBX deserializer usage requirements by accepting a null input.

Parameters:
text - text to be parsed (may be null)
Returns:
converted date, or null if passed null input
Throws:
JiBXException - on parse error

deserializeTimestamp

public static java.sql.Timestamp deserializeTimestamp(java.lang.String text)
                                               throws JiBXException
Deserialize timestamp from general dateTime text. Timestamp values are represented in the same way as regular dates, but allow more precision in the fractional second value (down to nanoseconds). This method follows standard JiBX deserializer usage requirements by accepting a null input.

Parameters:
text - text to be parsed (may be null)
Returns:
converted timestamp, or null if passed null input
Throws:
JiBXException - on parse error

deserializeSqlTime

public static java.sql.Time deserializeSqlTime(java.lang.String text)
                                        throws JiBXException
Deserialize time from text. Time values obey the rules of the time portion of a dataTime value. This method follows standard JiBX deserializer usage requirements by accepting a null input.

Parameters:
text - text to be parsed (may be null)
Returns:
converted time, or null if passed null input
Throws:
JiBXException - on parse error

formatYearNumber

protected static void formatYearNumber(long year,
                                       java.lang.StringBuffer buff)
Format year number consistent with W3C XML Schema definitions, using a minimum of four digits padded with zeros if necessary. A leading minus sign is included for years prior to 1 C.E.

Parameters:
year - number to be formatted
buff - text formatting buffer

formatTwoDigits

protected static void formatTwoDigits(int value,
                                      java.lang.StringBuffer buff)
Format a positive number as two digits. This uses an optional leading zero digit for values less than ten.

Parameters:
value - number to be formatted (0 to 99)
buff - text formatting buffer

formatYear

protected static void formatYear(long value,
                                 java.lang.StringBuffer buff)
Format time in milliseconds to year number. The resulting year number format is consistent with W3C XML Schema definitions, using a minimum of four digits padded with zeros if necessary. A leading minus sign is included for years prior to 1 C.E.

Parameters:
value - time in milliseconds to be converted (from 1 C.E.)
buff - text formatting buffer

formatYearMonth

protected static long formatYearMonth(long value,
                                      java.lang.StringBuffer buff)
Format time in milliseconds to year number and month number. The resulting year number format is consistent with W3C XML Schema definitions, using a minimum of four digits for the year and exactly two digits for the month.

Parameters:
value - time in milliseconds to be converted (from 1 C.E.)
buff - text formatting buffer
Returns:
number of milliseconds into month

formatYearMonthDay

protected static int formatYearMonthDay(long value,
                                        java.lang.StringBuffer buff)
Format time in milliseconds to year number, month number, and day number. The resulting year number format is consistent with W3C XML Schema definitions, using a minimum of four digits for the year and exactly two digits each for the month and day.

Parameters:
value - time in milliseconds to be converted (from 1 C.E.)
buff - text formatting buffer
Returns:
number of milliseconds into day

serializeYear

public static java.lang.String serializeYear(long time)
Serialize time to general gYear text. Date values are formatted in W3C XML Schema standard format as CCYY, with optional leading sign included if necessary.

Parameters:
time - time to be converted, as milliseconds from January 1, 1970
Returns:
converted gYear text

serializeYear

public static java.lang.String serializeYear(java.util.Date date)
Serialize date to general gYear text. Date values are formatted in W3C XML Schema standard format as CCYY, with optional leading sign included if necessary.

Parameters:
date - date to be converted
Returns:
converted gYear text

serializeYearMonth

public static java.lang.String serializeYearMonth(long time)
Serialize time to general gYearMonth text. Date values are formatted in W3C XML Schema standard format as CCYY-MM, with optional leading sign included if necessary.

Parameters:
time - time to be converted, as milliseconds from January 1, 1970
Returns:
converted gYearMonth text

serializeYearMonth

public static java.lang.String serializeYearMonth(java.util.Date date)
Serialize date to general gYearMonth text. Date values are formatted in W3C XML Schema standard format as CCYY-MM, with optional leading sign included if necessary.

Parameters:
date - date to be converted
Returns:
converted gYearMonth text

serializeDate

public static java.lang.String serializeDate(long time)
Serialize time to general date text. Date values are formatted in W3C XML Schema standard format as CCYY-MM-DD, with optional leading sign included if necessary.

Parameters:
time - time to be converted, as milliseconds from January 1, 1970
Returns:
converted date text

serializeDate

public static java.lang.String serializeDate(java.util.Date date)
Serialize date to general date text. Date values are formatted in W3C XML Schema standard format as CCYY-MM-DD, with optional leading sign included if necessary.

Parameters:
date - date to be converted
Returns:
converted date text

serializeSqlDate

public static java.lang.String serializeSqlDate(java.sql.Date date)
Serialize SQL date to general date text. Date values are formatted in W3C XML Schema standard format as CCYY-MM-DD, with optional leading sign included if necessary.

Parameters:
date - date to be converted
Returns:
converted date text

serializeTime

public static void serializeTime(int time,
                                 java.lang.StringBuffer buff)
Serialize time to general time text in buffer. Time values are formatted in W3C XML Schema standard format as hh:mm:ss, with optional trailing seconds decimal, as necessary. This form uses a supplied buffer to support flexible use, including with dateTime combination values.

Parameters:
time - time to be converted, as milliseconds in day
buff - buffer for appending time text

serializeDateTime

public static java.lang.String serializeDateTime(long time,
                                                 boolean zone)
Serialize time to general dateTime text. Date values are formatted in W3C XML Schema standard format as CCYY-MM-DDThh:mm:ss, with optional leading sign and trailing seconds decimal, as necessary.

Parameters:
time - time to be converted, as milliseconds from January 1, 1970
zone - flag for trailing 'Z' to be appended to indicate UTC
Returns:
converted dateTime text

serializeDateTime

public static java.lang.String serializeDateTime(long time)
Serialize time to general dateTime text. This method is provided for backward compatibility. It generates the dateTime text without the trailing 'Z' to indicate UTC.

Parameters:
time - time to be converted, as milliseconds from January 1, 1970
Returns:
converted dateTime text

serializeDateTime

public static java.lang.String serializeDateTime(java.util.Date date)
Serialize date to general dateTime text. Date values are formatted in W3C XML Schema standard format as CCYY-MM-DDThh:mm:ssZ, with optional leading sign and trailing seconds decimal, as necessary.

Parameters:
date - date to be converted
Returns:
converted dateTime text

serializeTimestamp

public static java.lang.String serializeTimestamp(java.sql.Timestamp stamp)
Serialize timestamp to general dateTime text. Timestamp values are represented in the same way as regular dates, but allow more precision in the fractional second value (down to nanoseconds).

Parameters:
stamp - timestamp to be converted
Returns:
converted dateTime text

serializeSqlTime

public static java.lang.String serializeSqlTime(java.sql.Time time)
Serialize time to standard text. Time values are formatted in W3C XML Schema standard format as hh:mm:ss, with optional trailing seconds decimal, as necessary. The standard conversion does not append a time zone indication.

Parameters:
time - time to be converted
Returns:
converted time text

isEqual

public static boolean isEqual(java.lang.Object a,
                              java.lang.Object b)
General object comparison method. Don't know why Sun hasn't seen fit to include this somewhere, but at least it's easy to write (over and over again).

Parameters:
a - first object to be compared
b - second object to be compared
Returns:
true if both objects are null, or if a.equals(b); false otherwise

enumValue

public static int enumValue(java.lang.String target,
                            java.lang.String[] enums,
                            int[] vals)
                     throws JiBXException
Find text value in enumeration. This first does a binary search through an array of allowed text matches. If a separate array of corresponding values is supplied, the value at the matched position is returned; otherwise the match index is returned directly.

Parameters:
target - text to be found in enumeration
enums - ordered array of texts included in enumeration
vals - array of values to be returned for corresponding text match positions (position returned directly if this is null)
Returns:
enumeration value for target text
Throws:
JiBXException - if target text not found in enumeration

decodeChunk

private static int decodeChunk(int base,
                               char[] chrs,
                               int fill,
                               byte[] byts)
Decode a chunk of data from base64 encoding. The length of a chunk is always 4 characters in the base64 representation, but may be 1, 2, or 3 bytes of data, as determined by whether there are any pad characters at the end of the base64 representation

Parameters:
base - starting offset within base64 character array
chrs - character array for base64 text representation
fill - starting offset within byte data array
byts - byte data array
Returns:
number of decoded bytes

parseBase64

public static byte[] parseBase64(java.lang.String text)
                          throws JiBXException
Parse base64 data from text. This converts the base64 data into a byte array of the appopriate length. In keeping with the recommendations,

Parameters:
text - text to be parsed (may include extra characters)
Returns:
byte array of data
Throws:
JiBXException - if invalid character in base64 representation

deserializeBase64

public static byte[] deserializeBase64(java.lang.String text)
                                throws JiBXException
Parse base64 data from text. This converts the base64 data into a byte array of the appopriate length. In keeping with the recommendations,

Parameters:
text - text to be parsed (may be null, or include extra characters)
Returns:
byte array of data
Throws:
JiBXException - if invalid character in base64 representation

encodeChunk

public static void encodeChunk(int base,
                               byte[] byts,
                               java.lang.StringBuffer buff)
Encode a chunk of data to base64 encoding. Converts the next three bytes of data into four characters of text representation, using padding at the end of less than three bytes of data remain.

Parameters:
base - starting offset within byte array
byts - byte data array
buff - buffer for encoded text

serializeBase64

public static java.lang.String serializeBase64(byte[] byts)
Serialize byte array to base64 text. In keeping with the specification, this adds a line break every 76 characters in the encoded representation.

Parameters:
byts - byte data array
Returns:
base64 encoded text

resizeArray

public static java.lang.Object resizeArray(int size,
                                           java.lang.Object base)
Resize array of arbitrary type.

Parameters:
size - new aray size
base - array to be resized
Returns:
resized array, with all data to minimum of the two sizes copied

growArray

public static java.lang.Object growArray(java.lang.Object base)
Grow array of arbitrary type. The returned array is double the size of the original array, providing this is at least the defined minimum size.

Parameters:
base - array to be grown
Returns:
array of twice the size as original array, with all data copied

arrayListFactory

public static java.util.List arrayListFactory()
Factory method to create a java.util.ArrayList as the implementation of a java.util.List.

Returns:
new java.util.ArrayList

deserializeList

public static java.util.ArrayList deserializeList(java.lang.String text,
                                                  IListItemDeserializer ideser)
                                           throws JiBXException
Convert whitespace-separated list of values. This implements the whitespace skipping, calling the supplied item deserializer for handling each individual value.

Parameters:
text - value to be converted
ideser - list item deserializer
Returns:
list of deserialized items (null if input null, or if nonrecoverable error)
Throws:
JiBXException - if error in deserializing text

deserializeTokenList

public static java.lang.String[] deserializeTokenList(java.lang.String text)
                                               throws JiBXException
Deserialize a list of whitespace-separated tokens into an array of strings.

Parameters:
text - value text
Returns:
created class instance
Throws:
JiBXException - on error in marshalling

serializeTokenList

public static java.lang.String serializeTokenList(java.lang.String[] tokens)
Serialize an array of strings into a whitespace-separated token list.

Parameters:
tokens - array of strings to be serialized
Returns:
list text


Project Web Site