Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SupportAttributeDefinition |
|
| 2.0;2 |
1 | /* | |
2 | * Copyright 2007-2008 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.rice.kns.datadictionary; | |
17 | ||
18 | import org.kuali.rice.kns.datadictionary.exception.AttributeValidationException; | |
19 | import org.kuali.rice.kns.util.ExternalizableBusinessObjectUtils; | |
20 | ||
21 | /** | |
22 | Support attributes define additional attributes that can be used to generate | |
23 | lookup field conversions and lookup parameters. | |
24 | ||
25 | Field conversions and lookup parameters are normally generated using foreign key relationships | |
26 | defined within OJB and the DD. Because Person objects are linked in a special way (i.e. they may | |
27 | come from an external data source and not from the DB, such as LDAP), it is often necessary to define | |
28 | extra fields that are related to each other, sort of like a supplemental foreign key. | |
29 | ||
30 | sourceName is the name of the POJO property of the business object | |
31 | targetName is the name of attribute that corresponds to the sourceName in the looked up BO | |
32 | identifier when true, only the field marked as an identifier will be passed in as a lookup parameter | |
33 | at most one supportAttribute for each relationship should be defined as identifier="true" | |
34 | */ | |
35 | public class SupportAttributeDefinition extends PrimitiveAttributeDefinition { | |
36 | private static final long serialVersionUID = -1719022365280776405L; | |
37 | ||
38 | protected boolean identifier; | |
39 | ||
40 | 0 | public SupportAttributeDefinition() {} |
41 | ||
42 | public boolean isIdentifier() { | |
43 | 0 | return identifier; |
44 | } | |
45 | ||
46 | /** | |
47 | * identifier when true, only the field marked as an identifier will be passed in as a lookup parameter | |
48 | at most one supportAttribute for each relationship should be defined as identifier="true" | |
49 | */ | |
50 | public void setIdentifier(boolean identifier) { | |
51 | 0 | this.identifier = identifier; |
52 | 0 | } |
53 | ||
54 | /** | |
55 | * Directly validate simple fields. | |
56 | * | |
57 | * @see org.kuali.rice.kns.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Object) | |
58 | */ | |
59 | public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) { | |
60 | 0 | if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, getSourceName())) { |
61 | 0 | throw new AttributeValidationException("unable to find attribute '" + getSourceName() + "' in relationship class '" + rootBusinessObjectClass + "' (" + "" + ")"); |
62 | } | |
63 | 0 | if (!DataDictionary.isPropertyOf(otherBusinessObjectClass, getTargetName()) |
64 | && !ExternalizableBusinessObjectUtils.isExternalizableBusinessObjectInterface( otherBusinessObjectClass )) { | |
65 | 0 | throw new AttributeValidationException("unable to find attribute '" + getTargetName() + "' in related class '" + otherBusinessObjectClass.getName() + "' (" + "" + ")"); |
66 | } | |
67 | 0 | } |
68 | ||
69 | /** | |
70 | * @see java.lang.Object#toString() | |
71 | */ | |
72 | @Override | |
73 | public String toString() { | |
74 | 0 | return "SupportAttributeDefinition (" + getSourceName()+","+getTargetName()+","+identifier+")"; |
75 | } | |
76 | ||
77 | } | |
78 |