Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
DataContainerPostProcessor |
|
| 1.3333333333333333;1.333 |
1 | package org.jtheque.core.spring.processors; | |
2 | ||
3 | import org.jtheque.core.managers.persistence.able.DataContainer; | |
4 | import org.jtheque.core.managers.persistence.able.DataContainerProvider; | |
5 | import org.jtheque.core.managers.persistence.able.Entity; | |
6 | import org.springframework.beans.factory.config.BeanPostProcessor; | |
7 | ||
8 | /* | |
9 | * This file is part of JTheque. | |
10 | * | |
11 | * JTheque is free software: you can redistribute it and/or modify | |
12 | * it under the terms of the GNU General Public License as published by | |
13 | * the Free Software Foundation, either version 3 of the License. | |
14 | * | |
15 | * JTheque is distributed in the hope that it will be useful, | |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | * GNU General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with JTheque. If not, see <http://www.gnu.org/licenses/>. | |
22 | */ | |
23 | ||
24 | /** | |
25 | * A post processor for the data container. | |
26 | * | |
27 | * @author Baptiste Wicht | |
28 | */ | |
29 | 0 | public final class DataContainerPostProcessor implements BeanPostProcessor { |
30 | @Override | |
31 | public Object postProcessAfterInitialization(Object bean, String beanName) { | |
32 | 0 | return bean; |
33 | } | |
34 | ||
35 | @Override | |
36 | public Object postProcessBeforeInitialization(Object bean, String beanName) { | |
37 | 0 | Class<?> c = bean.getClass(); |
38 | ||
39 | 0 | if (isDataContainer(c)) { |
40 | 0 | DataContainerProvider.getInstance().addContainer((DataContainer<Entity>) bean); |
41 | } | |
42 | ||
43 | 0 | return bean; |
44 | } | |
45 | ||
46 | /** | |
47 | * Test if a class is a data container or not. | |
48 | * | |
49 | * @param c The class to test. | |
50 | * @return true if the class is a data container else false. | |
51 | */ | |
52 | private static boolean isDataContainer(Class<?> c) { | |
53 | 0 | return DataContainer.class.isAssignableFrom(c); |
54 | } | |
55 | } |