Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ComponentBeanPostProcessor |
|
| 2.0;2 |
1 | /* | |
2 | * Copyright 2007 The Kuali Foundation | |
3 | * | |
4 | * Licensed under the Educational Community License, Version 1.0 (the | |
5 | * "License"); 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/ecl1.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, WITHOUT | |
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |
13 | * License for the specific language governing permissions and limitations under | |
14 | * the License. | |
15 | */ | |
16 | package org.kuali.rice.kns.uif.util; | |
17 | ||
18 | import org.apache.commons.lang.StringUtils; | |
19 | import org.kuali.rice.kns.uif.container.View; | |
20 | import org.kuali.rice.kns.uif.core.Component; | |
21 | import org.springframework.beans.BeansException; | |
22 | import org.springframework.beans.factory.config.BeanPostProcessor; | |
23 | ||
24 | import java.awt.*; | |
25 | ||
26 | /** | |
27 | * Spring <code>BeanPostProcessor</code> that processes configured <code>Component</code> | |
28 | * instances in the dictionary | |
29 | * | |
30 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
31 | */ | |
32 | public class ComponentBeanPostProcessor implements BeanPostProcessor { | |
33 | ||
34 | 0 | public ComponentBeanPostProcessor() { |
35 | 0 | } |
36 | ||
37 | /** | |
38 | * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object, | |
39 | * java.lang.String) | |
40 | */ | |
41 | @Override | |
42 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { | |
43 | 0 | return bean; |
44 | } | |
45 | ||
46 | /** | |
47 | * Sets the unique Id for a <code>Component</code> if not set and adds the definition | |
48 | * to the <code>ComponentFactory</code> | |
49 | * | |
50 | * <p> | |
51 | * Will use the bean name (if not the spring generated) or generate a | |
52 | * numeric identifier | |
53 | * </p> | |
54 | * | |
55 | * @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object, | |
56 | * java.lang.String) | |
57 | */ | |
58 | @Override | |
59 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { | |
60 | 0 | if (bean instanceof Component) { |
61 | 0 | Component component = (Component) bean; |
62 | ||
63 | 0 | if (StringUtils.isBlank(component.getId())) { |
64 | 0 | if (StringUtils.contains(beanName, "#")) { |
65 | 0 | beanName = StringUtils.substringAfterLast(beanName, "#"); |
66 | } | |
67 | ||
68 | 0 | component.setId(beanName); |
69 | } | |
70 | ||
71 | // TODO: removed until ids are fixed to not have underscore | |
72 | // if (StringUtils.contains(component.getId(), "_")) { | |
73 | // throw new RuntimeException(("Component id is not allowed to have an underscore")); | |
74 | // } | |
75 | ||
76 | // hold definition in component factory | |
77 | 0 | ComponentFactory.addComponentDefinition(component.getId(), component); |
78 | } | |
79 | ||
80 | 0 | return bean; |
81 | } | |
82 | } |