1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.bo;
17
18 import java.util.Iterator;
19 import java.util.LinkedHashMap;
20 import java.util.Map;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.kuali.rice.kns.util.TypeUtils;
24
25
26
27
28 public abstract class BusinessObjectBase implements BusinessObject {
29
30
31
32
33
34
35 public BusinessObjectBase() {
36 }
37
38
39
40
41
42 protected String toStringBuilder(LinkedHashMap fieldValues) {
43 String built = null;
44 String className = StringUtils.uncapitalize(StringUtils.substringAfterLast(this.getClass().getName(), "."));
45
46 if ((fieldValues == null) || fieldValues.isEmpty()) {
47 built = super.toString();
48 }
49 else {
50
51 StringBuffer prefix = new StringBuffer(className);
52 StringBuffer suffix = new StringBuffer("=");
53
54 prefix.append("(");
55 suffix.append("(");
56 for (Iterator i = fieldValues.entrySet().iterator(); i.hasNext();) {
57 Map.Entry e = (Map.Entry) i.next();
58
59 String fieldName = e.getKey().toString();
60 Object fieldValue = e.getValue();
61
62 String fieldValueString = String.valueOf(e.getValue());
63
64
65 if ((fieldValue == null) || TypeUtils.isSimpleType(fieldValue.getClass())) {
66 prefix.append(fieldName);
67 suffix.append(fieldValueString);
68 }
69 else {
70 prefix.append("{");
71 prefix.append(fieldName);
72 prefix.append("}");
73
74 suffix.append("{");
75 suffix.append(fieldValueString);
76 suffix.append("}");
77 }
78
79 if (i.hasNext()) {
80 prefix.append(",");
81 suffix.append(",");
82 }
83 }
84 prefix.append(")");
85 suffix.append(")");
86
87 built = prefix.toString() + suffix.toString();
88 }
89
90 return built;
91 }
92
93
94
95
96 abstract protected LinkedHashMap toStringMapper();
97
98
99
100
101
102 public String toString() {
103 if (!StringUtils.contains(this.getClass().getName(), "$$")) {
104 return toStringBuilder(toStringMapper());
105 }
106 else {
107 return "Proxy: " + this.getClass().getName();
108 }
109 }
110
111 public void prepareForWorkflow() {
112
113 }
114 }