SqlTimestampConverter.java :  » Development » jodd » jodd » typeconverter » Java Open Source

Java Open Source » Development » jodd 
jodd » jodd » typeconverter » SqlTimestampConverter.java
// Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.

package jodd.typeconverter;

import java.sql.Timestamp;

/**
 * Converts given object to java.sql.Timestamp.
 */
public class SqlTimestampConverter implements TypeConverter {


  public static Timestamp valueOf(Object value) {
    if (value == null) {
      return null;
    }
    if (value instanceof Timestamp) {
      return (Timestamp) value;
    }
    if (value instanceof Number) {
      return new Timestamp(((Number)value).longValue()); 
    }
    try {
      return (Timestamp.valueOf(value.toString()));
    } catch (IllegalArgumentException iaex) {
      throw new TypeConversionException(iaex);
    }
  }

  public Object convert(Object value) {
    return valueOf(value);
  }
  

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.