001 /**
002 * Copyright 2010 The Kuali Foundation Licensed under the
003 * Educational Community License, Version 2.0 (the "License"); you may
004 * not use this file except in compliance with the License. You may
005 * obtain a copy of the License at
006 *
007 * http://www.osedu.org/licenses/ECL-2.0
008 *
009 * Unless required by applicable law or agreed to in writing,
010 * software distributed under the License is distributed on an "AS IS"
011 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
012 * or implied. See the License for the specific language governing
013 * permissions and limitations under the License.
014 */
015
016 package org.kuali.student.common.util;
017
018 import org.kuali.student.common.util.ModPropertyPlaceholderConfigurer.PlaceholderResolvingStringValueResolver;
019 import org.springframework.beans.factory.config.BeanDefinitionVisitor;
020 import org.springframework.beans.factory.config.TypedStringValue;
021 import org.springframework.util.StringValueResolver;
022
023 public class ModBeanDefinitionVisitor extends BeanDefinitionVisitor {
024
025 PlaceholderResolvingStringValueResolver valueResolver;
026
027 public ModBeanDefinitionVisitor(StringValueResolver valueResolver) {
028 super(valueResolver);
029 this.valueResolver=(PlaceholderResolvingStringValueResolver) valueResolver;
030 }
031
032
033 @Override
034 protected Object resolveValue(Object value) {
035 value = super.resolveValue(value);
036 String strValue = null;
037
038 if(value instanceof String){
039 strValue=(String)value;
040 }else if(value instanceof TypedStringValue){
041 strValue=((TypedStringValue)value).getValue();
042 }
043
044 if(strValue!=null&&strValue.startsWith("$[") && strValue.endsWith("]")){
045 value = valueResolver.resolvePropertyValue(strValue.substring(2, strValue.length()-1));
046 }
047
048 return value;
049 }
050
051 }