1 /**
2 * Copyright 2010 The Kuali Foundation Licensed under the
3 * Educational Community License, Version 2.0 (the "License"); you may
4 * not use this file except in compliance with the License. You may
5 * obtain a copy of the License at
6 *
7 * http://www.osedu.org/licenses/ECL-2.0
8 *
9 * Unless required by applicable law or agreed to in writing,
10 * software distributed under the License is distributed on an "AS IS"
11 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12 * or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15
16 package org.kuali.rice.krad.datadictionary.validation;
17
18 import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
19 import org.kuali.rice.krad.datadictionary.validation.capability.Constrainable;
20
21 import java.util.List;
22
23 /**
24 * An interface to define classes that encapsulate access to both dictionary metadata and object field values, for example, by reflection
25 * and introspection, for the purpose of performing validation against constraints defined in the DictionaryValidationService implementation.
26 *
27 * Practically speaking, this interface should only need to be implemented by a small number of classes. The two major use cases are for
28 * (1) a dictionary object with members
29 * (2) a specific member of a dictionary object
30 *
31 * In the first case, implementing classes should provide access to all underlying members of the object via reflection or some other mechanism.
32 * In the second case, implementing classes only need to provide access to the value associated with that specific member, and constraints
33 * requiring access to additional members will be skipped.
34 *
35 * @author Kuali Rice Team (rice.collab@kuali.org)
36 * @since 1.1
37 */
38 public interface AttributeValueReader {
39
40 /**
41 * This method is an accessor for the attribute name that is currently being processed by the DictionaryValidationService implementation.
42 *
43 * @return the current attribute name being processed
44 */
45 public String getAttributeName();
46
47 /**
48 * This method provides access to the constrainable attribute definition of a specific attribute name. If the value of the metadata
49 * associated with the object field does not implement constrainable, or if no metadata is associated with this object field,
50 * then null should be returned.
51 *
52 * @param attributeName - the name of the attribute/field whose metadata is being requested
53 * @return dictionary metadata object implementing some constrainable capability
54 */
55 public Constrainable getDefinition(String attributeName);
56
57 /**
58 * This method returns a list of all constrainable dictionary metadata definitions for attributes or fields encapsulated by this object.
59 *
60 * @return a list of constrainable definitions
61 */
62 public List<Constrainable> getDefinitions();
63
64 /**
65 * The dictionary metadata associated with an object (its "entry" in the dictionary) can also be constrainable, in which case the object
66 * value itself can be validated against one or more constraints. If the specific entry for the dictionary object encapsulated by this
67 * reader is not constrainable, or if no entry exists for this dictionary object, or no dictionary object is being encapsulted, then
68 * null should be returned.
69 *
70 * @return the constrainable dictionary entry metadata for this object, or null
71 */
72 public Constrainable getEntry();
73
74 /**
75 * An entry name should be returned for the purposes of correcting looking up errors, which are generally found by entry name +
76 * attribute name + error key.
77 *
78 * @return the name that the data dictionary uses to store metadata about this object (not its attributes)
79 */
80 public String getEntryName();
81
82 /**
83 * This method looks up a label for a specific attribute name.
84 *
85 * @param attributeName
86 * @return some descriptive label that can be exposed to the end user for error messages
87 */
88 public String getLabel(String attributeName);
89
90 /**
91 * The underlying object itself (not the field/attribute value, but the object).
92 *
93 * @return the object that is being encapsulated by this reader, or null if no object is being encapsulated.
94 */
95 public Object getObject();
96
97 /**
98 * The path is a string representation of specifically which attribute (at some depth) is being accessed, for example, on a
99 * person object there might be the following field path:
100 *
101 * joe.home.mailingAddress.state
102 *
103 * @return the string representation of the attribute identifier currently being processed
104 */
105 public String getPath();
106
107 /**
108 * The type of the attribute specified. A Java class.
109 *
110 * @param attributeName
111 * @return the type of the attribute referenced by the passed name, or null if no attribute exists of that name
112 */
113 public Class<?> getType(String attributeName);
114
115 /**
116 * A convenience method for looking up the attribute value that is currently being processed.
117 *
118 * @param <X>
119 * @return
120 * @throws AttributeValidationException
121 */
122 public <X> X getValue() throws AttributeValidationException;
123
124 /**
125 * A method for looking up any attribute value by name for the object being processed.
126 *
127 * @param <X>
128 * @param attributeName
129 * @return
130 * @throws AttributeValidationException
131 */
132 public <X> X getValue(String attributeName) throws AttributeValidationException;
133
134 /**
135 * A method to enable legacy processing of string representations of attribute values like a date range in the format
136 * 12/03/2001..1/29/2009
137 *
138 * @param attributeName
139 * @return the list of token strings for the attribute value of the named attribute
140 * @throws AttributeValidationException
141 */
142 public List<String> getCleanSearchableValues(String attributeName) throws AttributeValidationException;
143
144 /**
145 * Setter for the current attribute that is being processed.
146 *
147 * @param attributeName
148 */
149 public void setAttributeName(String attributeName);
150
151 }
152