001 /**
002 * Copyright 2005-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.krad.datadictionary.parse;
017
018 import org.kuali.rice.krad.util.KRADUtils;
019 import org.springframework.core.convert.TypeDescriptor;
020 import org.springframework.core.convert.converter.GenericConverter;
021
022 import java.util.HashSet;
023 import java.util.List;
024 import java.util.Set;
025
026 /**
027 * Converts a string configured in the dictionary for a list property type to a List
028 * object using the convention of commas to separate list entries
029 *
030 * @author Kuali Rice Team (rice.collab@kuali.org)
031 */
032 public class StringListConverter implements GenericConverter {
033
034 @Override
035 public Set<ConvertiblePair> getConvertibleTypes() {
036 Set<ConvertiblePair> pairs = new HashSet<ConvertiblePair>();
037
038 ConvertiblePair stringListPair = new ConvertiblePair(String.class, List.class);
039 pairs.add(stringListPair);
040
041 return pairs;
042 }
043
044 @Override
045 public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
046 return KRADUtils.convertStringParameterToList((String) source);
047 }
048 }