001/*
002 * Copyright 2002-2012 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.orm.hibernate3;
018
019import java.util.Properties;
020
021import org.springframework.beans.factory.BeanNameAware;
022import org.springframework.beans.factory.InitializingBean;
023
024/**
025 * Bean that encapsulates a Hibernate type definition.
026 *
027 * <p>Typically defined as inner bean within a LocalSessionFactoryBean
028 * definition, as list element for the "typeDefinitions" bean property.
029 * For example:
030 *
031 * <pre class="code">
032 * &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;
033 *   ...
034 *   &lt;property name="typeDefinitions"&gt;
035 *     &lt;list&gt;
036 *       &lt;bean class="org.springframework.orm.hibernate3.TypeDefinitionBean"&gt;
037 *         &lt;property name="typeName" value="myType"/&gt;
038 *         &lt;property name="typeClass" value="mypackage.MyTypeClass"/&gt;
039 *       &lt;/bean&gt;
040 *     &lt;/list&gt;
041 *   &lt;/property&gt;
042 *   ...
043 * &lt;/bean&gt;</pre>
044 *
045 * Alternatively, specify a bean id (or name) attribute for the inner bean,
046 * instead of the "typeName" property.
047 *
048 * @author Juergen Hoeller
049 * @since 1.2
050 * @see LocalSessionFactoryBean#setTypeDefinitions(TypeDefinitionBean[])
051 * @deprecated as of Spring 4.3, in favor of Hibernate 4.x/5.x
052 */
053@Deprecated
054public class TypeDefinitionBean implements BeanNameAware, InitializingBean {
055
056        private String typeName;
057
058        private String typeClass;
059
060        private Properties parameters = new Properties();
061
062
063        /**
064         * Set the name of the type.
065         * @see org.hibernate.cfg.Mappings#addTypeDef(String, String, java.util.Properties)
066         */
067        public void setTypeName(String typeName) {
068                this.typeName = typeName;
069        }
070
071        /**
072         * Return the name of the type.
073         */
074        public String getTypeName() {
075                return typeName;
076        }
077
078        /**
079         * Set the type implementation class.
080         * @see org.hibernate.cfg.Mappings#addTypeDef(String, String, java.util.Properties)
081         */
082        public void setTypeClass(String typeClass) {
083                this.typeClass = typeClass;
084        }
085
086        /**
087         * Return the type implementation class.
088         */
089        public String getTypeClass() {
090                return typeClass;
091        }
092
093        /**
094         * Specify default parameters for the type.
095         * This only applies to parameterized types.
096         * @see org.hibernate.cfg.Mappings#addTypeDef(String, String, java.util.Properties)
097         * @see org.hibernate.usertype.ParameterizedType
098         */
099        public void setParameters(Properties parameters) {
100                this.parameters = parameters;
101        }
102
103        /**
104         * Return the default parameters for the type.
105         */
106        public Properties getParameters() {
107                return parameters;
108        }
109
110
111        /**
112         * If no explicit type name has been specified, the bean name of
113         * the TypeDefinitionBean will be used.
114         * @see #setTypeName
115         */
116        @Override
117        public void setBeanName(String name) {
118                if (this.typeName == null) {
119                        this.typeName = name;
120                }
121        }
122
123        @Override
124        public void afterPropertiesSet() {
125                if (this.typeName == null) {
126                        throw new IllegalArgumentException("typeName is required");
127                }
128                if (this.typeClass == null) {
129                        throw new IllegalArgumentException("typeClass is required");
130                }
131        }
132
133}