KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > orm > hibernate3 > TypeDefinitionBean


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.orm.hibernate3;
18
19 import java.util.Properties JavaDoc;
20
21 import org.springframework.beans.factory.BeanNameAware;
22 import org.springframework.beans.factory.InitializingBean;
23
24 /**
25  * Bean that encapsulates a Hibernate type definition.
26  *
27  * <p>Typically defined as inner bean within a LocalSessionFactoryBean
28  * definition, as list element for the "typeDefinitions" bean property.
29  * For example:
30  *
31  * <pre>
32  * &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;
33  * ...
34  * &lt;property name="typeDefinitions"&gt;
35  * &lt;list&gt;
36  * &lt;bean class="org.springframework.orm.hibernate3.TypeDefinitionBean"&gt;
37  * &lt;property name="typeName" value="myType"/&gt;
38  * &lt;property name="typeClass" value="mypackage.MyTypeClass"/&gt;
39  * &lt;/bean&gt;
40  * &lt;/list&gt;
41  * &lt;/property&gt;
42  * ...
43  * &lt;/bean&gt;</pre>
44  *
45  * Alternatively, specify a bean id (or name) attribute for the inner bean,
46  * instead of the "typeName" property.
47  *
48  * @author Juergen Hoeller
49  * @since 1.2
50  * @see LocalSessionFactoryBean#setTypeDefinitions(TypeDefinitionBean[])
51  */

52 public class TypeDefinitionBean implements BeanNameAware, InitializingBean {
53
54     private String JavaDoc typeName;
55
56     private String JavaDoc typeClass;
57
58     private Properties JavaDoc parameters = new Properties JavaDoc();
59
60
61     /**
62      * Set the name of the type.
63      * @see org.hibernate.cfg.Mappings#addTypeDef(String, String, java.util.Properties)
64      */

65     public void setTypeName(String JavaDoc typeName) {
66         this.typeName = typeName;
67     }
68
69     /**
70      * Return the name of the type.
71      */

72     public String JavaDoc getTypeName() {
73         return typeName;
74     }
75
76     /**
77      * Set the type implementation class.
78      * @see org.hibernate.cfg.Mappings#addTypeDef(String, String, java.util.Properties)
79      */

80     public void setTypeClass(String JavaDoc typeClass) {
81         this.typeClass = typeClass;
82     }
83
84     /**
85      * Return the type implementation class.
86      */

87     public String JavaDoc getTypeClass() {
88         return typeClass;
89     }
90
91     /**
92      * Specify default parameters for the type.
93      * This only applies to parameterized types.
94      * @see org.hibernate.cfg.Mappings#addTypeDef(String, String, java.util.Properties)
95      * @see org.hibernate.usertype.ParameterizedType
96      */

97     public void setParameters(Properties JavaDoc parameters) {
98         this.parameters = parameters;
99     }
100
101     /**
102      * Return the default parameters for the type.
103      */

104     public Properties JavaDoc getParameters() {
105         return parameters;
106     }
107
108
109     /**
110      * If no explicit type name has been specified, the bean name of
111      * the TypeDefinitionBean will be used.
112      * @see #setTypeName
113      */

114     public void setBeanName(String JavaDoc name) {
115         if (this.typeName == null) {
116             this.typeName = name;
117         }
118     }
119
120     public void afterPropertiesSet() {
121         if (this.typeName == null) {
122             throw new IllegalArgumentException JavaDoc("typeName is required");
123         }
124         if (this.typeClass == null) {
125             throw new IllegalArgumentException JavaDoc("typeClass is required");
126         }
127     }
128
129 }
130
Popular Tags