1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.oness.user.model.spring;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.springframework.beans.BeansException;
22 import org.springframework.beans.factory.config.BeanPostProcessor;
23 import org.springframework.orm.hibernate.LocalSessionFactoryBean;
24
25 /***
26 * Postprocess an Hibernate {@link LocalSessionFactoryBean}to add user mapping
27 * resources.
28 *
29 * @deprecated Use mappingDirectoryLocations in session factory to avoid defining each module mappingResources
30 *
31 * @author Carlos Sanchez
32 * @version $Revision: 1.2 $
33 */
34 public class SessionFactoryPostProcessor implements BeanPostProcessor {
35
36 private List userMappingResources, mappingResources;
37
38 /***
39 * @param mappingResources
40 * The mappingResources to set.
41 */
42 public void setMappingResources(List mappingResources) {
43 this.mappingResources = mappingResources;
44 }
45
46 /***
47 * @return Returns the mappingResources.
48 */
49 public List getMappingResources() {
50 return mappingResources;
51 }
52
53 /***
54 * @param userMappingResources
55 * The userMappingResources to set.
56 */
57 public void setUserMappingResources(List userMappingResources) {
58 this.userMappingResources = userMappingResources;
59 }
60
61 /***
62 * @return Returns the userMappingResources.
63 */
64 public List getUserMappingResources() {
65 return userMappingResources;
66 }
67
68 /***
69 * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object,
70 * java.lang.String)
71 */
72 public Object postProcessBeforeInitialization(Object bean, String name)
73 throws BeansException {
74 if (bean instanceof LocalSessionFactoryBean) {
75 LocalSessionFactoryBean sessionFactoryBean = (LocalSessionFactoryBean) bean;
76 List list = new ArrayList(mappingResources.size()
77 + userMappingResources.size());
78 list.addAll(mappingResources);
79 list.addAll(userMappingResources);
80 sessionFactoryBean.setMappingResources((String[]) list
81 .toArray(new String[0]));
82 }
83 return bean;
84 }
85
86 /***
87 * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object,
88 * java.lang.String)
89 */
90 public Object postProcessAfterInitialization(Object bean, String name)
91 throws BeansException {
92 return bean;
93 }
94
95 }