01: /*
02: * Copyright 2002-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.dao.support;
18:
19: import org.apache.commons.logging.Log;
20: import org.apache.commons.logging.LogFactory;
21:
22: import org.springframework.beans.factory.BeanInitializationException;
23: import org.springframework.beans.factory.InitializingBean;
24:
25: /**
26: * Generic base class for DAOs, defining template methods for DAO initialization.
27: *
28: * <p>Extended by Spring's specific DAO support classes, such as:
29: * JdbcDaoSupport, JdoDaoSupport, etc.
30: *
31: * @author Juergen Hoeller
32: * @since 1.2.2
33: * @see org.springframework.jdbc.core.support.JdbcDaoSupport
34: * @see org.springframework.orm.jdo.support.JdoDaoSupport
35: */
36: public abstract class DaoSupport implements InitializingBean {
37:
38: /** Logger available to subclasses */
39: protected final Log logger = LogFactory.getLog(getClass());
40:
41: public final void afterPropertiesSet()
42: throws IllegalArgumentException,
43: BeanInitializationException {
44: // Let abstract subclasses check their configuration.
45: checkDaoConfig();
46:
47: // Let concrete implementations initialize themselves.
48: try {
49: initDao();
50: } catch (Exception ex) {
51: throw new BeanInitializationException(
52: "Initialization of DAO failed", ex);
53: }
54: }
55:
56: /**
57: * Abstract subclasses must override this to check their configuration.
58: * <p>Implementors should be marked as <code>final</code if concrete subclasses
59: * are not supposed to override this template method themselves.
60: * @throws IllegalArgumentException in case of illegal configuration
61: */
62: protected abstract void checkDaoConfig()
63: throws IllegalArgumentException;
64:
65: /**
66: * Concrete subclasses can override this for custom initialization behavior.
67: * Gets called after population of this instance's bean properties.
68: * @throws Exception if DAO initialization fails
69: * (will be rethrown as a BeanInitializationException)
70: * @see org.springframework.beans.factory.BeanInitializationException
71: */
72: protected void initDao() throws Exception {
73: }
74:
75: }
|