KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > type > ListType


1 //$Id: ListType.java,v 1.13 2005/02/20 08:37:56 oneovthafew Exp $
2
package org.hibernate.type;
3
4 import java.io.Serializable JavaDoc;
5 import java.util.ArrayList JavaDoc;
6 import java.util.List JavaDoc;
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 JavaDoc role, String JavaDoc propertyRef, boolean isEmbeddedInXML) {
19         super(role, propertyRef, isEmbeddedInXML);
20     }
21
22     public PersistentCollection instantiate(SessionImplementor session, CollectionPersister persister, Serializable JavaDoc 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 JavaDoc getReturnedClass() {
32         return List JavaDoc.class;
33     }
34
35     public PersistentCollection wrap(SessionImplementor session, Object JavaDoc collection) {
36         if ( session.getEntityMode()==EntityMode.DOM4J ) {
37             return new PersistentListElementHolder( session, (Element) collection );
38         }
39         else {
40             return new PersistentList( session, (List JavaDoc) collection );
41         }
42     }
43
44     public Object JavaDoc instantiate(Object JavaDoc original) {
45         return new ArrayList JavaDoc();
46     }
47     
48     public Object JavaDoc indexOf(Object JavaDoc collection, Object JavaDoc element) {
49         List JavaDoc list = (List JavaDoc) collection;
50         for ( int i=0; i<list.size(); i++ ) {
51             //TODO: proxies!
52
if ( list.get(i)==element ) return new Integer JavaDoc(i);
53         }
54         return null;
55     }
56     
57 }
58
59
60
61
62
63
Popular Tags