1 package org.hibernate.collection; 3 4 import java.io.Serializable ; 5 import java.util.List ; 6 7 import org.dom4j.Element; 8 import org.hibernate.Hibernate; 9 import org.hibernate.HibernateException; 10 import org.hibernate.engine.SessionImplementor; 11 import org.hibernate.persister.collection.CollectionPersister; 12 import org.hibernate.type.Type; 13 14 17 public class PersistentListElementHolder extends PersistentIndexedElementHolder { 18 19 public PersistentListElementHolder(SessionImplementor session, Element element) { 20 super( session, element ); 21 } 22 23 public PersistentListElementHolder(SessionImplementor session, CollectionPersister persister, 24 Serializable key) throws HibernateException { 25 super( session, persister, key ); 26 } 27 28 public void initializeFromCache(CollectionPersister persister, Serializable disassembled, Object owner) 29 throws HibernateException { 30 31 Type elementType = persister.getElementType(); 32 final String indexNodeName = getIndexAttributeName(persister); 33 Serializable [] cached = (Serializable []) disassembled; 34 for ( int i=0; i<cached.length; i++ ) { 35 Object object = elementType.assemble( cached[i], getSession(), owner ); 36 Element subelement = element.addElement( persister.getElementNodeName() ); 37 elementType.setToXMLNode( subelement, object, persister.getFactory() ); 38 setIndex( subelement, indexNodeName, Integer.toString(i) ); 39 } 40 41 } 42 43 public Serializable disassemble(CollectionPersister persister) throws HibernateException { 44 45 Type elementType = persister.getElementType(); 46 final String indexNodeName = getIndexAttributeName(persister); 47 List elements = element.elements( persister.getElementNodeName() ); 48 int length = elements.size(); 49 Serializable [] result = new Serializable [length]; 50 for ( int i=0; i<length; i++ ) { 51 Element elem = (Element) elements.get(i); 52 Object object = elementType.fromXMLNode( elem, persister.getFactory() ); 53 Integer index = (Integer ) Hibernate.INTEGER.fromStringValue( getIndex(elem, indexNodeName, i) ); 54 result[ index.intValue() ] = elementType.disassemble( object, getSession(), null ); 55 } 56 return result; 57 } 58 59 60 } 61 | Popular Tags |