KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > dao > support > DaoSupport


1 /*
2  * Copyright 2002-2006 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.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
42     public final void afterPropertiesSet() throws IllegalArgumentException JavaDoc, BeanInitializationException {
43         // Let abstract subclasses check their configuration.
44
checkDaoConfig();
45
46         // Let concrete implementations initialize themselves.
47
try {
48             initDao();
49         }
50         catch (Exception JavaDoc ex) {
51             throw new BeanInitializationException("Initialization of DAO failed", ex);
52         }
53     }
54
55     /**
56      * Abstract subclasses must override this to check their configuration.
57      * <p>Implementors should be marked as <code>final</code if concrete subclasses
58      * are not supposed to override this template method themselves.
59      * @throws IllegalArgumentException in case of illegal configuration
60      */

61     protected abstract void checkDaoConfig() throws IllegalArgumentException JavaDoc;
62
63     /**
64      * Concrete subclasses can override this for custom initialization behavior.
65      * Gets called after population of this instance's bean properties.
66      * @throws Exception if DAO initialization fails
67      * (will be rethrown as a BeanInitializationException)
68      * @see org.springframework.beans.factory.BeanInitializationException
69      */

70     protected void initDao() throws Exception JavaDoc {
71     }
72
73 }
74
Popular Tags