1 package org.hibernate.type; 3 4 import java.sql.PreparedStatement ; 5 import java.sql.ResultSet ; 6 import java.sql.SQLException ; 7 8 import org.hibernate.Hibernate; 9 import org.hibernate.HibernateException; 10 import org.hibernate.util.ReflectHelper; 11 12 16 public class ClassType extends ImmutableType { 17 18 public Object get(ResultSet rs, String name) throws HibernateException, SQLException { 19 String str = (String ) Hibernate.STRING.get(rs, name); 20 if (str == null) { 21 return null; 22 } 23 else { 24 try { 25 return ReflectHelper.classForName(str); 26 } 27 catch (ClassNotFoundException cnfe) { 28 throw new HibernateException("Class not found: " + str); 29 } 30 } 31 } 32 33 public void set(PreparedStatement st, Object value, int index) throws HibernateException, SQLException { 34 Hibernate.STRING.set(st, ( (Class ) value ).getName(), index); 36 } 37 38 public int sqlType() { 39 return Hibernate.STRING.sqlType(); 40 } 41 42 public String toString(Object value) throws HibernateException { 43 return ( (Class ) value ).getName(); 44 } 45 46 public Class getReturnedClass() { 47 return Class .class; 48 } 49 50 public String getName() { 51 return "class"; 52 } 53 54 public Object fromStringValue(String xml) throws HibernateException { 55 try { 56 return ReflectHelper.classForName(xml); 57 } 58 catch (ClassNotFoundException cnfe) { 59 throw new HibernateException("could not parse xml", cnfe); 60 } 61 } 62 63 } 64 65 66 67 68 69 70 | Popular Tags |