HHH-6716 envers should set the TCCL to the envers classloader before constructing a dom4j instance. This will allow applications to use their own version of dom4j

This commit is contained in:
Strong Liu 2011-10-08 15:03:14 +08:00
parent b307a801a7
commit 7b1c172b84
2 changed files with 18 additions and 3 deletions

View File

@ -100,9 +100,23 @@ public final class XMLHelper {
} }
public static Element generateDom4jElement(String elementName) { public static Element generateDom4jElement(String elementName) {
return DocumentFactory.getInstance().createElement( elementName ); return getDocumentFactory().createElement( elementName );
} }
public static DocumentFactory getDocumentFactory() {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
DocumentFactory factory;
try {
Thread.currentThread().setContextClassLoader( XMLHelper.class.getClassLoader() );
factory = DocumentFactory.getInstance();
}
finally {
Thread.currentThread().setContextClassLoader( cl );
}
return factory;
}
public static void dump(Element element) { public static void dump(Element element) {
try { try {
// try to "pretty print" it // try to "pretty print" it

View File

@ -52,6 +52,7 @@ import org.hibernate.envers.revisioninfo.RevisionInfoGenerator;
import org.hibernate.envers.revisioninfo.RevisionInfoNumberReader; import org.hibernate.envers.revisioninfo.RevisionInfoNumberReader;
import org.hibernate.envers.revisioninfo.RevisionInfoQueryCreator; import org.hibernate.envers.revisioninfo.RevisionInfoQueryCreator;
import org.hibernate.envers.tools.MutableBoolean; import org.hibernate.envers.tools.MutableBoolean;
import org.hibernate.internal.util.xml.XMLHelper;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.type.LongType; import org.hibernate.type.LongType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
@ -83,7 +84,7 @@ public class RevisionInfoConfiguration {
} }
private Document generateDefaultRevisionInfoXmlMapping() { private Document generateDefaultRevisionInfoXmlMapping() {
Document document = DocumentHelper.createDocument(); Document document = XMLHelper.getDocumentFactory().createDocument();
Element class_mapping = MetadataTools.createEntity(document, new AuditTableData(null, null, globalCfg.getDefaultSchemaName(), globalCfg.getDefaultCatalogName()), null); Element class_mapping = MetadataTools.createEntity(document, new AuditTableData(null, null, globalCfg.getDefaultSchemaName(), globalCfg.getDefaultCatalogName()), null);
@ -140,7 +141,7 @@ public class RevisionInfoConfiguration {
} }
private Element generateRevisionInfoRelationMapping() { private Element generateRevisionInfoRelationMapping() {
Document document = DocumentHelper.createDocument(); Document document = XMLHelper.getDocumentFactory().createDocument();
Element rev_rel_mapping = document.addElement("key-many-to-one"); Element rev_rel_mapping = document.addElement("key-many-to-one");
rev_rel_mapping.addAttribute("type", revisionPropType); rev_rel_mapping.addAttribute("type", revisionPropType);
rev_rel_mapping.addAttribute("class", revisionInfoEntityName); rev_rel_mapping.addAttribute("class", revisionInfoEntityName);