KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > cfg > annotations > PropertyBinder


1 //$Id: PropertyBinder.java,v 1.3 2005/06/21 12:54:16 epbernard Exp $
2
package org.hibernate.cfg.annotations;
3
4 import java.util.Properties JavaDoc;
5
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8 import org.hibernate.annotations.Type;
9 import org.hibernate.cfg.Ejb3Column;
10 import org.hibernate.cfg.Mappings;
11 import org.hibernate.cfg.PropertyHolder;
12 import org.hibernate.mapping.Property;
13 import org.hibernate.mapping.SimpleValue;
14 import org.hibernate.mapping.Value;
15
16 /**
17  * @author Emmanuel Bernard
18  */

19 public class PropertyBinder {
20     private static Log log = LogFactory.getLog(PropertyBinder.class);
21     private String JavaDoc name;
22     private String JavaDoc returnedClassName;
23     private boolean lazy;
24     private String JavaDoc propertyAccessorName;
25     private Ejb3Column[] columns;
26     private PropertyHolder holder;
27     private String JavaDoc explicitType = "";
28     private Properties JavaDoc typeParameters;
29     private Mappings mappings;
30     private Value value;
31     private boolean insertable = true;
32     private boolean updatable = true;
33     private String JavaDoc cascade;
34     private Type typeAnn;
35
36     public void setInsertable(boolean insertable) {
37         this.insertable = insertable;
38     }
39
40     public void setUpdatable(boolean updatable) {
41         this.updatable = updatable;
42     }
43
44
45     public void setName(String JavaDoc name) {
46         this.name = name;
47     }
48
49     public void setReturnedClassName(String JavaDoc returnedClassName) {
50         this.returnedClassName = returnedClassName;
51     }
52
53     public void setLazy(boolean lazy) {
54         this.lazy = lazy;
55     }
56
57     public void setPropertyAccessorName(String JavaDoc propertyAccessorName) {
58         this.propertyAccessorName = propertyAccessorName;
59     }
60
61     public void setColumns(Ejb3Column[] columns) {
62         insertable = columns[0].isInsertable();
63         updatable = columns[0].isUpdatable();
64         //concsistency is checked later when we know the proeprty name
65
this.columns = columns;
66     }
67
68     public void setHolder(PropertyHolder holder) {
69         this.holder = holder;
70     }
71
72     public void setExplicitType(String JavaDoc explicitType) {
73         this.explicitType = explicitType;
74     }
75
76     public void setExplicitType(Type typeAnn) {
77         this.typeAnn = typeAnn;
78     }
79
80
81     public void setTypeParameters(Properties JavaDoc typeParameters) {
82         this.typeParameters = typeParameters;
83     }
84
85     public void setValue(Value value) {
86         this.value = value;
87     }
88
89     public void setCascade(String JavaDoc cascadeStrategy) {
90         this.cascade = cascadeStrategy;
91     }
92
93     public void setMappings(Mappings mappings) {
94         this.mappings = mappings;
95     }
96
97     private void validateBind() {
98         //TODO check necessary params for a bind
99
}
100
101     private void validateMake() {
102         //TODO check necessary params for a make
103
}
104
105     public Property bind() {
106         validateBind();
107         if (log.isDebugEnabled()) {
108             log.debug("binding property " + name + " with lazy=" + lazy);
109         }
110         String JavaDoc containerClassName = holder == null ? null : holder.getClassName();
111         SimpleValueBinder value = new SimpleValueBinder();
112         value.setPropertyName(name);
113         value.setReturnedClassName(returnedClassName);
114         value.setColumns(columns);
115         value.setPersistentClassName(containerClassName);
116         if (typeAnn != null) {
117             value.setExplicitType(typeAnn);
118         }
119         else {
120             value.setExplicitType(explicitType);
121             value.setTypeParameters(typeParameters);
122         }
123         value.setMappings(mappings);
124         SimpleValue propertyValue = value.make();
125         setValue(propertyValue);
126         Property prop = make();
127         columns[0].addPropertyToMappingContainer(prop);
128         return prop;
129     }
130
131     public Property make() {
132         validateMake();
133         log.debug("Building property " + name);
134         Property prop = new Property();
135         prop.setName(name);
136         prop.setValue(value);
137         prop.setInsertable(insertable);
138         prop.setUpdateable(updatable);
139         prop.setLazy(lazy);
140         prop.setCascade(cascade);
141         prop.setPropertyAccessorName(propertyAccessorName);
142         log.debug("Cascading " + name + " with " + cascade);
143         return prop;
144     }
145 }
146
Popular Tags