1 package org.hibernate.tuple; 3 4 import java.io.Serializable ; 5 import java.util.HashSet ; 6 import java.util.Iterator ; 7 8 import org.dom4j.Element; 9 import org.hibernate.util.XMLHelper; 10 import org.hibernate.mapping.PersistentClass; 11 import org.hibernate.mapping.Component; 12 13 16 public class Dom4jInstantiator implements Instantiator { 17 private final String nodeName; 18 private final HashSet isInstanceNodeNames = new HashSet (); 19 20 public Dom4jInstantiator(Component component) { 21 this.nodeName = component.getNodeName(); 22 isInstanceNodeNames.add( nodeName ); 23 } 24 25 public Dom4jInstantiator(PersistentClass mappingInfo) { 26 this.nodeName = mappingInfo.getNodeName(); 27 isInstanceNodeNames.add( nodeName ); 28 29 if ( mappingInfo.hasSubclasses() ) { 30 Iterator itr = mappingInfo.getSubclassClosureIterator(); 31 while ( itr.hasNext() ) { 32 final PersistentClass subclassInfo = ( PersistentClass ) itr.next(); 33 isInstanceNodeNames.add( subclassInfo.getNodeName() ); 34 } 35 } 36 } 37 38 public Object instantiate(Serializable id) { 39 return instantiate(); 40 } 41 42 public Object instantiate() { 43 return XMLHelper.generateDom4jElement( nodeName ); 44 } 45 46 public boolean isInstance(Object object) { 47 if ( object instanceof Element ) { 48 return isInstanceNodeNames.contains( ( ( Element ) object ).getName() ); 49 } 50 else { 51 return false; 52 } 53 } 54 } | Popular Tags |