001 /*
002 * Copyright 2011 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.kfs.sys.document.validation.impl;
017
018 import org.kuali.kfs.sys.context.SpringContext;
019 import org.kuali.rice.kns.service.DataDictionaryService;
020
021 /**
022 * This class refers to an attribute which has a value and is labeled in the DataDictionary.
023 */
024 public class AttributeReference {
025 private final String propertyName;
026 private final String valueString;
027 private final String label;
028
029 /**
030 * Constructor. It takes the value instead of the BO instance (using PropertyUtils or BeanUtils with the propertyName), in order
031 * to promote the use of the property getter, to help usage searches and automated refactorings.
032 *
033 * @param businessObjectClass a class with a business object entry in the DataDictionary
034 * @param propertyName the name of the attribute in the DD entry and on the form (for the error path)
035 * @param value the value of the property on the form (may be null).
036 */
037 public AttributeReference(Class businessObjectClass, String propertyName, Object value) {
038 this.propertyName = propertyName;
039 this.valueString = value == null ? null : value.toString();
040 this.label = SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(businessObjectClass, propertyName);
041 }
042
043 /**
044 * @return the name of the attribute in the DD entry and on the form (for the error path)
045 */
046 public String getPropertyName() {
047 return propertyName;
048 }
049
050 /**
051 * @return the attribute value as a String
052 */
053 public String getValueString() {
054 return valueString;
055 }
056
057 /**
058 * @return the label of the attribute in the DD
059 */
060 public String getLabel() {
061 return label;
062 }
063 }