KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > mapping > Array


1 //$Id: Array.java,v 1.8 2005/02/20 03:34:49 oneovthafew Exp $
2
package org.hibernate.mapping;
3
4 import org.hibernate.MappingException;
5 import org.hibernate.type.CollectionType;
6 import org.hibernate.type.PrimitiveType;
7 import org.hibernate.type.TypeFactory;
8 import org.hibernate.util.ReflectHelper;
9
10 /**
11  * An array mapping has a primary key consisting of
12  * the key columns + index column.
13  * @author Gavin King
14  */

15 public class Array extends List {
16
17     private String JavaDoc elementClassName;
18
19     /**
20      * Constructor for Array.
21      * @param owner
22      */

23     public Array(PersistentClass owner) {
24         super(owner);
25     }
26
27     public Class JavaDoc getElementClass() throws MappingException {
28         if (elementClassName==null) {
29             org.hibernate.type.Type elementType = getElement().getType();
30             return isPrimitiveArray() ?
31                 ( (PrimitiveType) elementType ).getPrimitiveClass() :
32                 elementType.getReturnedClass();
33         }
34         else {
35             try {
36                 return ReflectHelper.classForName(elementClassName);
37             }
38             catch (ClassNotFoundException JavaDoc cnfe) {
39                 throw new MappingException(cnfe);
40             }
41         }
42     }
43
44     public CollectionType getDefaultCollectionType() throws MappingException {
45         return TypeFactory.array( getRole(), getReferencedPropertyName(), isEmbedded(), getElementClass() );
46     }
47
48     public boolean isArray() {
49         return true;
50     }
51
52     /**
53      * @return Returns the elementClassName.
54      */

55     public String JavaDoc getElementClassName() {
56         return elementClassName;
57     }
58     /**
59      * @param elementClassName The elementClassName to set.
60      */

61     public void setElementClassName(String JavaDoc elementClassName) {
62         this.elementClassName = elementClassName;
63     }
64     
65     public Object JavaDoc accept(ValueVisitor visitor) {
66         return visitor.accept(this);
67     }
68 }
69
Popular Tags