1 /*
2 * Copyright 2007 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.kuali.ole.sys.document.validation.impl;
17
18 import org.kuali.ole.sys.context.SpringContext;
19 import org.kuali.rice.kns.service.DataDictionaryService;
20
21 /**
22 * This class refers to an attribute which has a value and is labeled in the DataDictionary.
23 */
24 public class AttributeReference {
25 private final String propertyName;
26 private final String valueString;
27 private final String label;
28
29 /**
30 * Constructor. It takes the value instead of the BO instance (using PropertyUtils or BeanUtils with the propertyName), in order
31 * to promote the use of the property getter, to help usage searches and automated refactorings.
32 *
33 * @param businessObjectClass a class with a business object entry in the DataDictionary
34 * @param propertyName the name of the attribute in the DD entry and on the form (for the error path)
35 * @param value the value of the property on the form (may be null).
36 */
37 public AttributeReference(Class businessObjectClass, String propertyName, Object value) {
38 this.propertyName = propertyName;
39 this.valueString = value == null ? null : value.toString();
40 this.label = SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(businessObjectClass, propertyName);
41 }
42
43 /**
44 * @return the name of the attribute in the DD entry and on the form (for the error path)
45 */
46 public String getPropertyName() {
47 return propertyName;
48 }
49
50 /**
51 * @return the attribute value as a String
52 */
53 public String getValueString() {
54 return valueString;
55 }
56
57 /**
58 * @return the label of the attribute in the DD
59 */
60 public String getLabel() {
61 return label;
62 }
63 }