KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > test > usercollection > MyListType


1 package org.hibernate.test.usercollection;
2
3 import java.util.Iterator JavaDoc;
4 import java.util.Map JavaDoc;
5
6 import org.hibernate.EntityMode;
7 import org.hibernate.HibernateException;
8 import org.hibernate.collection.PersistentCollection;
9 import org.hibernate.engine.SessionImplementor;
10 import org.hibernate.persister.collection.CollectionPersister;
11 import org.hibernate.usertype.UserCollectionType;
12
13 public class MyListType implements UserCollectionType {
14
15     public PersistentCollection instantiate(SessionImplementor session, CollectionPersister persister) throws HibernateException {
16         return new PersistentMyList(session);
17     }
18
19     public PersistentCollection wrap(SessionImplementor session, Object JavaDoc collection) {
20         if ( session.getEntityMode()==EntityMode.DOM4J ) {
21             throw new IllegalStateException JavaDoc("dom4j not supported");
22         }
23         else {
24             return new PersistentMyList( session, (IMyList) collection );
25         }
26     }
27
28     public Iterator JavaDoc getElementsIterator(Object JavaDoc collection) {
29         return ( (IMyList) collection ).iterator();
30     }
31
32     public boolean contains(Object JavaDoc collection, Object JavaDoc entity) {
33         return ( (IMyList) collection ).contains(entity);
34     }
35
36     public Object JavaDoc indexOf(Object JavaDoc collection, Object JavaDoc entity) {
37         int l = ( (IMyList) collection ).indexOf(entity);
38         if(l<0) {
39             return null;
40         } else {
41             return new Integer JavaDoc(l);
42         }
43     }
44
45     public Object JavaDoc replaceElements(Object JavaDoc original, Object JavaDoc target, CollectionPersister persister, Object JavaDoc owner, Map JavaDoc copyCache, SessionImplementor session) throws HibernateException {
46         
47         IMyList result = (IMyList) target;
48
49         result.clear();
50
51         result.addAll((MyList)original);
52         
53         return result;
54         
55     }
56
57     public Object JavaDoc instantiate() {
58         return new MyList();
59     }
60
61     
62 }
63
Popular Tags