Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ComponentBeanPostProcessor |
|
| 2.3333333333333335;2.333 |
1 | /** | |
2 | * Copyright 2005-2011 The Kuali Foundation | |
3 | * | |
4 | * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php | |
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 | package org.kuali.rice.krad.uif.util; | |
17 | ||
18 | import org.apache.commons.lang.StringUtils; | |
19 | import org.kuali.rice.krad.uif.component.Component; | |
20 | import org.springframework.beans.BeansException; | |
21 | import org.springframework.beans.factory.config.BeanPostProcessor; | |
22 | ||
23 | /** | |
24 | * Spring <code>BeanPostProcessor</code> that processes configured <code>Component</code> | |
25 | * instances in the dictionary | |
26 | * | |
27 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
28 | */ | |
29 | public class ComponentBeanPostProcessor implements BeanPostProcessor { | |
30 | ||
31 | 0 | public ComponentBeanPostProcessor() { |
32 | 0 | } |
33 | ||
34 | /** | |
35 | * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object, | |
36 | * java.lang.String) | |
37 | */ | |
38 | @Override | |
39 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { | |
40 | 0 | return bean; |
41 | } | |
42 | ||
43 | /** | |
44 | * Sets the unique Id for a <code>Component</code> if bean name given (not generated) and the id property was | |
45 | * not set for the view | |
46 | * | |
47 | * <p> | |
48 | * The ID will only be set here if an id is given for the Spring bean. For inner beans, the ID will be generated | |
49 | * during the view lifecycle | |
50 | * </p> | |
51 | * | |
52 | * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object, | |
53 | * java.lang.String) | |
54 | */ | |
55 | @Override | |
56 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { | |
57 | 0 | if (bean instanceof Component) { |
58 | 0 | Component component = (Component) bean; |
59 | ||
60 | 0 | if (StringUtils.isBlank(component.getId())) { |
61 | 0 | if (!StringUtils.contains(beanName, "$") && !StringUtils.contains(beanName, "#")) { |
62 | 0 | component.setId(beanName); |
63 | 0 | component.setFactoryId(beanName); |
64 | } | |
65 | } else { | |
66 | 0 | component.setFactoryId(component.getId()); |
67 | } | |
68 | } | |
69 | ||
70 | 0 | return bean; |
71 | } | |
72 | } |