org.dellroad.stuff.jibx
Class ParseUtil

java.lang.Object
  extended by org.dellroad.stuff.jibx.ParseUtil

public final class ParseUtil
extends Object

JiBX parsing utility methods. These methods can be used as JiBX value serializer/deserializer methods.


Method Summary
static boolean deserializeBoolean(String string)
          Boolean parser that allows "yes" and "no" as well as the usual "true", "false", "0", "1".
static boolean deserializeBooleanStrictly(String string)
          Deserialize a boolean strictly, only allowing the values true or false.
static byte[] deserializeByteArray(String string)
          Deserialize a byte array using ByteArrayEncoder.
static byte[] deserializeByteArrayWithColons(String string)
          Deserialize a byte array using MAC address notation (colon-separated).
static Date deserializeDate(String date)
          Deserialize a Date in the format supported by DateEncoder.
static Date deserializeDate(String date, String format)
          Deserialize a Date.
static Inet4Address deserializeInet4Address(String string)
          Deserialize an Inet4Address.
static int[] deserializeIntArray(String string)
          Deserialize an array of integers separated by commas and/or whitespace.
static String deserializeMatching(String regex, String string)
          JiBX String deserializer support method that verifies that the input string matches the given regular expression.
static Pattern deserializePattern(String string)
          Deserialize a Pattern.
static
<T> T
deserializeReference(String string, Class<T> type)
          Deserialize an object by reference.
static SimpleDateFormat deserializeSimpleDateFormat(String string)
          Deserialize a SimpleDateFormat.
static String deserializeString(String string)
          Deserialize a String, allowing arbitrary characters via backslash escapes.
static long deserializeTimeInterval(String string)
          Derialize a millisecond-granularity time interval, e.g., "30s", "1d12h", "0.250s", etc.
static TimeZone deserializeTimeZone(String string)
          Deserialize a TimeZone.
static URI deserializeURI(String string)
          Deserialize an URI.
static UUID deserializeUUID(String string)
          Deserialize a UUID.
static Date deserializeXSDDateTime(String date)
          Deserialize a Date in XSD dateTime format.
static String normalize(String string)
          JiBX String deserializer that normalizes a string as is required by the xsd:token XSD type.
static String serializeByteArray(byte[] array)
          Serialize a byte array using ByteArrayEncoder.
static String serializeByteArrayWithColons(byte[] array)
          Serialize a byte array using MAC address notation (colon-separated).
static String serializeDate(Date date)
          Serialize a Date in the format supported by DateEncoder.
static String serializeDate(Date date, String format)
          Serialize a Date.
static String serializeInet4Address(Inet4Address addr)
          Serialize an Inet4Address.
static String serializeIntArray(int[] array)
          Serialize an array of integers.
static String serializePattern(Pattern pattern)
          Deprecated. This method is does the same thing as JiBX's default serialization via Object.toString()
static String serializeReference(Object obj)
          Serialize an object by reference.
static String serializeSimpleDateFormat(SimpleDateFormat simpleDateFormat)
          Serialize a SimpleDateFormat.
static String serializeString(String string)
          Serialize a String.
static String serializeTimeInterval(long value)
          Serialize a millisecond-granularity time interval, e.g., "30s", "1d12h", "0.250s", etc.
static String serializeTimeZone(TimeZone timeZone)
          Serialize a TimeZone.
static String serializeURI(URI uri)
          Deprecated. This method is does the same thing as JiBX's default serialization via Object.toString()
static String serializeXSDDateTime(Date date)
          Serialize a Date to XSD dateTime format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

deserializeString

public static String deserializeString(String string)
                                throws JiBXParseException
Deserialize a String, allowing arbitrary characters via backslash escapes. The string will be decoded by StringEncoder.decode(java.lang.String).

Throws:
JiBXParseException
See Also:
StringEncoder.decode(java.lang.String)

serializeString

public static String serializeString(String string)
Serialize a String. The string will be encoded by StringEncoder.encode(java.lang.String, boolean).

See Also:
StringEncoder.encode(java.lang.String, boolean)

deserializeTimeZone

public static TimeZone deserializeTimeZone(String string)
                                    throws JiBXParseException
Deserialize a TimeZone.

Throws:
JiBXParseException
See Also:
serializeTimeZone(java.util.TimeZone)

serializeTimeZone

public static String serializeTimeZone(TimeZone timeZone)
Serialize a TimeZone.

See Also:
deserializeTimeZone(java.lang.String)

deserializeURI

public static URI deserializeURI(String string)
                          throws JiBXParseException
Deserialize an URI.

Note: there is no need for a custom serializer, as URI.toString() already does the right thing.

Throws:
JiBXParseException

serializeURI

@Deprecated
public static String serializeURI(URI uri)
Deprecated. This method is does the same thing as JiBX's default serialization via Object.toString()

Serialize an URI.


deserializeReference

public static <T> T deserializeReference(String string,
                                         Class<T> type)
                              throws JiBXParseException
Deserialize an object by reference.

Invoke this method from your own custom deserializer to produce an result of the correct type.

The object must have been unmarshalled already and had its ID registered via IdMapper.setId(java.lang.Object, java.lang.String).

Throws:
JiBXParseException
See Also:
serializeReference(java.lang.Object), IdMapper

serializeReference

public static String serializeReference(Object obj)
Serialize an object by reference.

The object must have been marshalled already and had its ID assigned via IdMapper.getId(java.lang.Object).

See Also:
deserializeReference(java.lang.String, java.lang.Class), IdMapper

deserializeUUID

public static UUID deserializeUUID(String string)
                            throws JiBXParseException
Deserialize a UUID.

Note: there is no need for a custom serializer, as UUID.toString() already does the right thing.

Throws:
JiBXParseException

deserializeTimeInterval

public static long deserializeTimeInterval(String string)
                                    throws JiBXParseException
Derialize a millisecond-granularity time interval, e.g., "30s", "1d12h", "0.250s", etc.

Throws:
JiBXParseException
See Also:
serializeTimeInterval(long)

serializeTimeInterval

public static String serializeTimeInterval(long value)
Serialize a millisecond-granularity time interval, e.g., "30s", "1d12h", "0.250s", etc.

See Also:
deserializeTimeInterval(java.lang.String)

deserializeByteArray

public static byte[] deserializeByteArray(String string)
                                   throws JiBXParseException
Deserialize a byte array using ByteArrayEncoder.

Throws:
JiBXParseException
See Also:
ByteArrayEncoder

serializeByteArray

public static String serializeByteArray(byte[] array)
Serialize a byte array using ByteArrayEncoder.

See Also:
ByteArrayEncoder

deserializeByteArrayWithColons

public static byte[] deserializeByteArrayWithColons(String string)
                                             throws JiBXParseException
Deserialize a byte array using MAC address notation (colon-separated). Each byte must have two digits.

Throws:
JiBXParseException
See Also:
serializeByteArrayWithColons(byte[])

serializeByteArrayWithColons

public static String serializeByteArrayWithColons(byte[] array)
Serialize a byte array using MAC address notation (colon-separated). Each byte will have two digits.

See Also:
deserializeByteArrayWithColons(java.lang.String)

deserializeInet4Address

public static Inet4Address deserializeInet4Address(String string)
                                            throws JiBXParseException
Deserialize an Inet4Address. No DNS name resolution of any kind is performed.

Throws:
JiBXParseException
See Also:
serializeInet4Address(java.net.Inet4Address)

serializeInet4Address

public static String serializeInet4Address(Inet4Address addr)
Serialize an Inet4Address.

See Also:
deserializeInet4Address(java.lang.String)

deserializeSimpleDateFormat

public static SimpleDateFormat deserializeSimpleDateFormat(String string)
                                                    throws JiBXParseException
Deserialize a SimpleDateFormat.

Throws:
JiBXParseException
See Also:
serializeSimpleDateFormat(java.text.SimpleDateFormat)

serializeSimpleDateFormat

public static String serializeSimpleDateFormat(SimpleDateFormat simpleDateFormat)
Serialize a SimpleDateFormat.

See Also:
deserializeSimpleDateFormat(java.lang.String)

deserializeDate

public static Date deserializeDate(String date,
                                   String format)
                            throws JiBXParseException
Deserialize a Date. This method can be used as a deserialize support method.

Parameters:
date - date string to parse
format - format for SimpleDateFormat.
Throws:
JiBXParseException
See Also:
serializeDate(java.util.Date, java.lang.String)

serializeDate

public static String serializeDate(Date date,
                                   String format)
                            throws JiBXParseException
Serialize a Date. This method can be used as a serialize support method.

Parameters:
date - date to serialize
format - format for SimpleDateFormat.
Throws:
JiBXParseException
See Also:
deserializeDate(java.lang.String, java.lang.String)

deserializeDate

public static Date deserializeDate(String date)
                            throws JiBXParseException
Deserialize a Date in the format supported by DateEncoder.

Throws:
JiBXParseException
See Also:
DateEncoder

serializeDate

public static String serializeDate(Date date)
                            throws JiBXParseException
Serialize a Date in the format supported by DateEncoder.

Throws:
JiBXParseException
See Also:
DateEncoder

deserializeXSDDateTime

public static Date deserializeXSDDateTime(String date)
                                   throws JiBXParseException
Deserialize a Date in XSD dateTime format.

Throws:
JiBXParseException
See Also:
serializeXSDDateTime(java.util.Date), XSD dateTime datatype

serializeXSDDateTime

public static String serializeXSDDateTime(Date date)
                                   throws JiBXParseException
Serialize a Date to XSD dateTime format.

Throws:
JiBXParseException
See Also:
deserializeXSDDateTime(java.lang.String), XSD dateTime datatype

deserializePattern

public static Pattern deserializePattern(String string)
                                  throws JiBXParseException
Deserialize a Pattern.

Note: there is no need for a custom serializer, as Pattern.toString() already does the right thing.

Throws:
JiBXParseException

serializePattern

@Deprecated
public static String serializePattern(Pattern pattern)
Deprecated. This method is does the same thing as JiBX's default serialization via Object.toString()

Serialize an Pattern.


normalize

public static String normalize(String string)
JiBX String deserializer that normalizes a string as is required by the xsd:token XSD type. This removes leading and trailing whitespace, and collapses all interior whitespace down to a single space character.

Throws:
NullPointerException - if string is null

deserializeMatching

public static String deserializeMatching(String regex,
                                         String string)
                                  throws JiBXParseException
JiBX String deserializer support method that verifies that the input string matches the given regular expression. This method can be invoked by custom deserializers that supply the regular expression to it.

Throws:
NullPointerException - if string of regex is null
JiBXParseException - if string does not match regex
PatternSyntaxException - if regex is not a valid regular expression

deserializeBoolean

public static boolean deserializeBoolean(String string)
                                  throws JiBXParseException
Boolean parser that allows "yes" and "no" as well as the usual "true", "false", "0", "1". Comparisons are case-insensitive.

Throws:
JiBXParseException - if the value is not recognizable as a boolean
See Also:
deserializeBooleanStrictly(java.lang.String)

deserializeBooleanStrictly

public static boolean deserializeBooleanStrictly(String string)
                                          throws JiBXParseException
Deserialize a boolean strictly, only allowing the values true or false.

Throws:
JiBXParseException
See Also:
deserializeBoolean(java.lang.String)

deserializeIntArray

public static int[] deserializeIntArray(String string)
                                 throws JiBXParseException
Deserialize an array of integers separated by commas and/or whitespace.

Throws:
JiBXParseException
See Also:
serializeIntArray(int[])

serializeIntArray

public static String serializeIntArray(int[] array)
                                throws JiBXParseException
Serialize an array of integers. Example: "1, 2, 3".

Throws:
JiBXParseException
See Also:
deserializeIntArray(java.lang.String)