| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| RiceConfigBeanDefinitionVisitor |
|
| 3.5;3.5 |
| 1 | /** | |
| 2 | * Copyright 2010 The Kuali Foundation Licensed under the | |
| 3 | * Educational Community License, Version 2.0 (the "License"); you may | |
| 4 | * not use this file except in compliance with the License. You may | |
| 5 | * obtain a copy of the License at | |
| 6 | * | |
| 7 | * http://www.osedu.org/licenses/ECL-2.0 | |
| 8 | * | |
| 9 | * Unless required by applicable law or agreed to in writing, | |
| 10 | * software distributed under the License is distributed on an "AS IS" | |
| 11 | * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | * or implied. See the License for the specific language governing | |
| 13 | * permissions and limitations under the License. | |
| 14 | */ | |
| 15 | ||
| 16 | package org.kuali.rice.student.core.config.spring; | |
| 17 | ||
| 18 | import org.kuali.rice.student.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 | ||
| 41 | //------------------------------------------------------------------------------------ | |
| 42 | // begin spring 2.0 compatible impl | |
| 43 | //------------------------------------------------------------------------------------ | |
| 44 | // @Override | |
| 45 | // protected String resolveStringValue(String strVal) { | |
| 46 | // return null; | |
| 47 | // } | |
| 48 | // | |
| 49 | // protected Properties resolvePropertiesValue(String strVal) { | |
| 50 | // return null; | |
| 51 | // } | |
| 52 | // | |
| 53 | // @Override | |
| 54 | // protected Object resolveValue(Object value) { | |
| 55 | // value = super.resolveValue(value); | |
| 56 | // String strValue = null; | |
| 57 | // | |
| 58 | // if (value instanceof String) { | |
| 59 | // strValue = (String) value; | |
| 60 | // } else if (value instanceof TypedStringValue) { | |
| 61 | // strValue = ((TypedStringValue) value).getValue(); | |
| 62 | // } | |
| 63 | // | |
| 64 | // if (strValue != null && strValue.startsWith("$[") && strValue.endsWith("]")) { | |
| 65 | // value = resolvePropertiesValue(strValue.substring(2, strValue.length() - 1)); | |
| 66 | // } | |
| 67 | // | |
| 68 | // return value; | |
| 69 | // } | |
| 70 | //------------------------------------------------------------------------------------ | |
| 71 | // end spring 2.0 compatible impl | |
| 72 | //------------------------------------------------------------------------------------ | |
| 73 | ||
| 74 | ||
| 75 | //------------------------------------------------------------------------------------ | |
| 76 | // begin spring 2.5 compatible impl | |
| 77 | //------------------------------------------------------------------------------------ | |
| 78 | ||
| 79 | PlaceholderResolvingStringValueResolver valueResolver; | |
| 80 | ||
| 81 | public RiceConfigBeanDefinitionVisitor(StringValueResolver valueResolver) { | |
| 82 | 0 | super(valueResolver); |
| 83 | 0 | this.valueResolver=(PlaceholderResolvingStringValueResolver) valueResolver; |
| 84 | 0 | } |
| 85 | ||
| 86 | ||
| 87 | @Override | |
| 88 | protected Object resolveValue(Object value) { | |
| 89 | 0 | value = super.resolveValue(value); |
| 90 | 0 | String strValue = null; |
| 91 | ||
| 92 | 0 | if(value instanceof String){ |
| 93 | 0 | strValue=(String)value; |
| 94 | 0 | }else if(value instanceof TypedStringValue){ |
| 95 | 0 | strValue=((TypedStringValue)value).getValue(); |
| 96 | } | |
| 97 | ||
| 98 | 0 | if(strValue!=null&&strValue.startsWith("$[") && strValue.endsWith("]")){ |
| 99 | 0 | value = valueResolver.resolvePropertiesValue(strValue.substring(2, strValue.length()-1)); |
| 100 | } | |
| 101 | ||
| 102 | 0 | return value; |
| 103 | } | |
| 104 | //------------------------------------------------------------------------------------ | |
| 105 | // end spring 2.5 compatible impl | |
| 106 | //------------------------------------------------------------------------------------ | |
| 107 | ||
| 108 | } |