001/**
002 * Copyright 2005-2015 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 */
016package org.kuali.rice.krad.datadictionary.validation;
017
018import org.kuali.rice.core.framework.persistence.jdbc.sql.SQLUtils;
019import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
020import org.kuali.rice.krad.util.DataTypeUtil;
021
022import java.util.List;
023
024/**
025 * A class that implements the required accessors and legacy processing for an attribute value reader. This provides a convenient base class
026 * from which other attribute value readers can be derived. 
027 * 
028 * @author Kuali Rice Team (rice.collab@kuali.org) 
029 */
030public abstract class BaseAttributeValueReader implements AttributeValueReader {
031
032        protected String entryName;
033        protected String attributeName;
034        
035        @Override
036        public List<String> getCleanSearchableValues(String attributeKey) throws AttributeValidationException {
037                Class<?> attributeType = getType(attributeKey);           
038                Object rawValue = getValue(attributeKey);
039                
040                String attributeInValue = rawValue != null ? rawValue.toString() : "";
041                String attributeDataType = DataTypeUtil.determineDataType(attributeType);
042                return SQLUtils.getCleanedSearchableValues(attributeInValue, attributeDataType);
043        }
044
045        /**
046         * @return the currentName
047         */
048        @Override
049        public String getAttributeName() {
050                return this.attributeName;
051        }
052
053        /**
054         * @param currentName the currentName to set
055         */
056        @Override
057        public void setAttributeName(String currentName) {
058                this.attributeName = currentName;
059        }
060
061        /**
062         * @return the entryName
063         */
064        @Override
065        public String getEntryName() {
066                return this.entryName;
067        }
068
069    @Override
070    public abstract AttributeValueReader clone();
071
072}