01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-util/tool-lib/src/java/org/sakaiproject/metaobj/utils/mvc/impl/beans/AddableSessionFactoryBean.java $
03: * $Id: AddableSessionFactoryBean.java 14230 2006-09-05 18:02:51Z chmaurer@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.metaobj.utils.mvc.impl.beans;
21:
22: import java.io.IOException;
23: import java.util.Collection;
24: import java.util.Iterator;
25: import java.util.Map;
26:
27: import org.apache.commons.logging.Log;
28: import org.apache.commons.logging.LogFactory;
29: import org.hibernate.HibernateException;
30: import org.hibernate.cfg.Configuration;
31: import org.sakaiproject.metaobj.shared.model.OspException;
32: import org.springframework.beans.BeansException;
33: import org.springframework.context.ApplicationContext;
34: import org.springframework.context.ApplicationContextAware;
35: import org.springframework.orm.hibernate3.LocalSessionFactoryBean;
36:
37: public class AddableSessionFactoryBean extends LocalSessionFactoryBean
38: implements ApplicationContextAware {
39: protected final transient Log logger = LogFactory
40: .getLog(getClass());
41:
42: private ApplicationContext applicationContext;
43:
44: /**
45: * To be implemented by subclasses that want to to perform custom
46: * post-processing of the Configuration object after this FactoryBean
47: * performed its default initialization.
48: *
49: * @param config the current Configuration object
50: * @throws org.hibernate.HibernateException
51: * in case of Hibernate initialization errors
52: */
53: protected void postProcessConfiguration(Configuration config)
54: throws HibernateException {
55: super .postProcessConfiguration(config);
56:
57: Map beanMap = applicationContext.getBeansOfType(
58: AdditionalHibernateMappings.class, true, true);
59:
60: if (beanMap == null) {
61: return;
62: }
63:
64: Collection beans = beanMap.values();
65:
66: try {
67: for (Iterator i = beans.iterator(); i.hasNext();) {
68: AdditionalHibernateMappings mappings = (AdditionalHibernateMappings) i
69: .next();
70: mappings.processConfig(config);
71: }
72: } catch (IOException e) {
73: logger.error("", e);
74: throw new OspException(e);
75: }
76: }
77:
78: /**
79: * Set the ApplicationContext that this object runs in.
80: * Normally this call will be used to initialize the object.
81: * <p>Invoked after population of normal bean properties but before an init
82: * callback like InitializingBean's afterPropertiesSet or a custom init-method.
83: * Invoked after ResourceLoaderAware's setResourceLoader.
84: *
85: * @param applicationContext ApplicationContext object to be used by this object
86: * @throws org.springframework.context.ApplicationContextException
87: * in case of applicationContext initialization errors
88: * @throws org.springframework.beans.BeansException
89: * if thrown by application applicationContext methods
90: * @see org.springframework.beans.factory.BeanInitializationException
91: */
92: public void setApplicationContext(
93: ApplicationContext applicationContext)
94: throws BeansException {
95: this.applicationContext = applicationContext;
96: }
97: }
|