1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.businessobject;
17
18 import java.util.HashMap;
19 import java.util.List;
20 import java.util.Map;
21
22 import org.kuali.ole.sys.context.SpringContext;
23 import org.kuali.rice.kns.service.DataDictionaryService;
24 import org.kuali.rice.krad.bo.BusinessObject;
25 import org.kuali.rice.krad.datadictionary.AttributeDefinition;
26
27
28
29
30 public abstract class BusinessObjectStringParserFieldUtils {
31 protected org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(getClass());
32 private Map<String, Integer> fieldLengthMap;
33 private Map<String, Integer> fieldBeginningPositionMap;
34
35
36
37
38 public Map<String, Integer> getFieldLengthMap() {
39 if (fieldLengthMap == null) {
40 initializeFieldLengthMap();
41 }
42 return fieldLengthMap;
43 }
44
45
46
47
48
49 protected void initializeFieldLengthMap() {
50 fieldLengthMap = new HashMap<String, Integer>();
51 DataDictionaryService dataDictionaryService = SpringContext.getBean(DataDictionaryService.class);
52 List<AttributeDefinition> attributes = dataDictionaryService.getDataDictionary().getBusinessObjectEntry(getBusinessObjectClass().getName()).getAttributes();
53
54 for (AttributeDefinition attributeDefinition : attributes) {
55 Integer fieldLength;
56 fieldLength = dataDictionaryService.getAttributeMaxLength(getBusinessObjectClass(), attributeDefinition.getName());
57 fieldLengthMap.put(attributeDefinition.getName(), fieldLength);
58 }
59 }
60
61
62
63
64 public abstract Class<? extends BusinessObject> getBusinessObjectClass();
65
66
67
68
69 public Map<String, Integer> getFieldBeginningPositionMap() {
70 if (fieldBeginningPositionMap == null) {
71 initializeFieldBeginningPositionMap();
72 }
73 return fieldBeginningPositionMap;
74 }
75
76
77
78
79
80 protected void initializeFieldBeginningPositionMap() {
81 fieldBeginningPositionMap = new HashMap<String, Integer>();
82 Map<String, Integer> lengthMap = getFieldLengthMap();
83
84 int lengthTracker = 0;
85
86 for (String property : getOrderedProperties()) {
87 fieldBeginningPositionMap.put(property, new Integer(lengthTracker));
88 if (LOG.isDebugEnabled()) {
89 LOG.debug("Finding position for property: "+property+"; length = "+lengthMap.get(property));
90 }
91 lengthTracker += lengthMap.get(property).intValue();
92 }
93 }
94
95
96
97
98 public abstract String[] getOrderedProperties();
99 }