Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
RiceConfigBeanDefinitionVisitor |
|
| 3.5;3.5 |
1 | /* | |
2 | * Copyright 2007-2010 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.core.config.spring; | |
17 | ||
18 | import org.kuali.rice.core.config.spring.RiceConfigPropertyPlaceholderConfigurer.PlaceholderResolvingStringValueResolver; | |
19 | import org.springframework.beans.factory.config.BeanDefinitionVisitor; | |
20 | import org.springframework.beans.factory.config.TypedStringValue; | |
21 | import org.springframework.util.StringValueResolver; | |
22 | ||
23 | /** | |
24 | * This BeanDefinitionVisitor that will allow for injection of Properties objects created | |
25 | * from properties of a like prefix identified by a value of $[my.prefix]. | |
26 | * | |
27 | * example: | |
28 | * foo.prop1=bar | |
29 | * foo.prop2=foo | |
30 | * fooPropertyObject=$[foo.] | |
31 | * | |
32 | * results in | |
33 | * fooPropertyObject={prop1=bar; prop2=foo} | |
34 | * | |
35 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
36 | * | |
37 | */ | |
38 | public class RiceConfigBeanDefinitionVisitor extends BeanDefinitionVisitor { | |
39 | ||
40 | PlaceholderResolvingStringValueResolver valueResolver; | |
41 | ||
42 | public RiceConfigBeanDefinitionVisitor(StringValueResolver valueResolver) { | |
43 | 0 | super(valueResolver); |
44 | 0 | this.valueResolver=(PlaceholderResolvingStringValueResolver) valueResolver; |
45 | 0 | } |
46 | ||
47 | ||
48 | @Override | |
49 | protected Object resolveValue(Object value) { | |
50 | 0 | value = super.resolveValue(value); |
51 | 0 | String strValue = null; |
52 | ||
53 | 0 | if(value instanceof String){ |
54 | 0 | strValue=(String)value; |
55 | 0 | }else if(value instanceof TypedStringValue){ |
56 | 0 | strValue=((TypedStringValue)value).getValue(); |
57 | } | |
58 | ||
59 | 0 | if(strValue!=null&&strValue.startsWith("$[") && strValue.endsWith("]")){ |
60 | 0 | value = valueResolver.resolvePropertiesValue(strValue.substring(2, strValue.length()-1)); |
61 | } | |
62 | ||
63 | 0 | return value; |
64 | } | |
65 | ||
66 | } |