KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: Any.java,v 1.4 2004/12/07 09:59:47 maxcsaucdk Exp $
2
package org.hibernate.mapping;
3
4 import java.util.Map JavaDoc;
5
6 import org.hibernate.MappingException;
7 import org.hibernate.type.MetaType;
8 import org.hibernate.type.AnyType;
9 import org.hibernate.type.Type;
10 import org.hibernate.type.TypeFactory;
11
12 /**
13  * A Hibernate "any" type (ie. polymorphic association to
14  * one-of-several tables).
15  * @author Gavin King
16  */

17 public class Any extends SimpleValue {
18
19     private String JavaDoc identifierTypeName;
20     private String JavaDoc metaTypeName = "string";
21     private Map metaValues;
22
23     public Any(Table table) {
24         super(table);
25     }
26
27     public String JavaDoc getIdentifierType() {
28         return identifierTypeName;
29     }
30
31     public void setIdentifierType(String JavaDoc identifierType) {
32         this.identifierTypeName = identifierType;
33     }
34
35     public Type getType() throws MappingException {
36         return new AnyType(
37             metaValues==null ?
38                 TypeFactory.heuristicType(metaTypeName) :
39                 new MetaType( metaValues, TypeFactory.heuristicType(metaTypeName) ),
40                 TypeFactory.heuristicType(identifierTypeName)
41         );
42     }
43
44     public void setTypeByReflection(String JavaDoc propertyClass, String JavaDoc propertyName) {}
45
46     public String JavaDoc getMetaType() {
47         return metaTypeName;
48     }
49
50     public void setMetaType(String JavaDoc type) {
51         metaTypeName = type;
52     }
53
54     public Map getMetaValues() {
55         return metaValues;
56     }
57
58     public void setMetaValues(Map metaValues) {
59         this.metaValues = metaValues;
60     }
61
62     public void setTypeUsingReflection(String JavaDoc className, String JavaDoc propertyName)
63         throws MappingException {
64     }
65
66     public Object JavaDoc accept(ValueVisitor visitor) {
67         return visitor.accept(this);
68     }
69 }
70
Popular Tags