Convertor

public final class Convertor

A Convertor is mainly responsible for data format conversion.

Author:Hugo Y. K. Lam

Methods

convertObject

public static Object convertObject(Object source, Class target)

Converts the given source Object to an instance of the specified target class. The constructor of the target class which has an argument of the source object type will be looked up first. It it succeeds, the source Object will be passed in as the argument. Otherwise, the constructor which has a String argument will be looked up and the source object will be passed in as a String by calling its toString method. Null will be returned if the conversion cannot be performed.

Parameters:
  • source – the source Object.
  • target – the target class.
Returns:

an instance of the target class representing the given source Object.

deepCopy

public static Object deepCopy(Serializable obj)

Performs a deep copy of the given serializable Object.

Parameters:
  • obj – the serializable Object to be copied.
Returns:

a copy of the given Object.

toFile

public static File toFile(URL url)

Converts a java.net.URL into a java.io.File.

Parameters:
  • url – the java.net.URL to be converted.
Returns:

a java.io.File representing the given URL.

toSQLDate

public static java.sql.Date toSQLDate(java.util.Date date)

Converts a java.util.Date to a java.sql.Date.

Parameters:
  • date – The java.util.Date to be converted.
Returns:

a java.sql.Date representing the given date.

toTimestamp

public static java.sql.Timestamp toTimestamp(java.util.Date date)

Converts a java.util.Date to a java.sql.Timestamp.

Parameters:
  • date – The java.util.Date to be converted.
Returns:

a java.sql.Timestamp representing the given date.

toVector

public static Vector toVector(Object obj)

Converts the given Object to a Vector. If the given Object is already a Vector, the Object will be directly returned. Otherwise, the Oobject will be added to a new Vector and the Vector will be returned.

Parameters:
  • obj – The Object to be converted.
Returns:

The Vector converted by the given Object.

translateProperties

public static void translateProperties(javax.servlet.http.HttpServletRequest request, Object bean)

Translates the request parameters in the given HttpServletRequest to the properties in the given bean Object.

Parameters:
  • request – the HttpServletRequest which contains the request parameters to be translated.
  • bean – the bean Object into which the request parameters to be translated.