1 package org.hibernate.type; 3 4 import java.io.Serializable ; 5 import java.util.ArrayList ; 6 import java.util.List ; 7 8 import org.dom4j.Element; 9 import org.hibernate.EntityMode; 10 import org.hibernate.collection.PersistentCollection; 11 import org.hibernate.collection.PersistentList; 12 import org.hibernate.collection.PersistentListElementHolder; 13 import org.hibernate.engine.SessionImplementor; 14 import org.hibernate.persister.collection.CollectionPersister; 15 16 public class ListType extends CollectionType { 17 18 public ListType(String role, String propertyRef, boolean isEmbeddedInXML) { 19 super(role, propertyRef, isEmbeddedInXML); 20 } 21 22 public PersistentCollection instantiate(SessionImplementor session, CollectionPersister persister, Serializable key) { 23 if ( session.getEntityMode()==EntityMode.DOM4J ) { 24 return new PersistentListElementHolder(session, persister, key); 25 } 26 else { 27 return new PersistentList(session); 28 } 29 } 30 31 public Class getReturnedClass() { 32 return List .class; 33 } 34 35 public PersistentCollection wrap(SessionImplementor session, Object collection) { 36 if ( session.getEntityMode()==EntityMode.DOM4J ) { 37 return new PersistentListElementHolder( session, (Element) collection ); 38 } 39 else { 40 return new PersistentList( session, (List ) collection ); 41 } 42 } 43 44 public Object instantiate(Object original) { 45 return new ArrayList (); 46 } 47 48 public Object indexOf(Object collection, Object element) { 49 List list = (List ) collection; 50 for ( int i=0; i<list.size(); i++ ) { 51 if ( list.get(i)==element ) return new Integer (i); 53 } 54 return null; 55 } 56 57 } 58 59 60 61 62 63 | Popular Tags |