Finally unlazy enough to get a good syntax highlighter…
Code: http://alexgorbatchev.com/SyntaxHighlighter/
Instructions: http://www.cyberack.com/2007/07/adding-syntax-highlighter-to-blogger.html
Escape L-trims: http://accessify.com/tools-and-wizards/developer-tools/quick-escape/default.php
<!– oxm integration –>
<bean id=“objectXmlMarshaller” class=“org.springframework.oxm.xstream.XStreamMarshaller”/>
package com.wookets.hibernate;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.HibernateException;
import org.hibernate.usertype.UserType;
import org.springframework.oxm.xstream.XStreamMarshaller;
import org.springframework.util.ObjectUtils;
import com.wookets.spring.ServiceLocator;
public class XmlType implements UserType {
private static final int[] SQL_TYPES = { Types.CLOB };
@Override
public int[] sqlTypes() {
return SQL_TYPES;
}
@Override
public Class returnedClass() {
return Object.class;
}
@Override
public boolean equals(Object x, Object y) throws HibernateException {
return ObjectUtils.nullSafeEquals(x, y);
}
@Override
public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner) throws HibernateException, SQLException {
Object result = null;
String rawxml = resultSet.getString(names[0]);
if(!resultSet.wasNull()) {
result = getObjectXmlMarshaller().getXStream().fromXML(rawxml);
}
return result;
}
@Override
public void nullSafeSet(PreparedStatement statement, Object value, int index) throws HibernateException, SQLException {
statement.setString(index, getObjectXmlMarshaller().getXStream().toXML(value));
}
@Override
public Object deepCopy(Object value) throws HibernateException {
return value;
}
@Override
public boolean isMutable() {
return true;
}
@Override
public Object assemble(Serializable arg0, Object arg1) throws HibernateException {
throw new RuntimeException(“Assemble is not implemented!”);
}
@Override
public Serializable disassemble(Object arg0) throws HibernateException {
throw new RuntimeException(“Disassemble is not implemented!”);
}
@Override
public int hashCode(Object arg0) throws HibernateException {
return super.hashCode();
}
@Override
public Object replace(Object original, Object target, Object owner) throws HibernateException {
return original;
}
private XStreamMarshaller objectXmlMarshaller;
private XStreamMarshaller getObjectXmlMarshaller() {
if(objectXmlMarshaller == null) {
objectXmlMarshaller = ServiceLocator.getBean(XStreamMarshaller.class);
}
return objectXmlMarshaller;
}
}