1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.datadictionary;
17
18 import java.util.ArrayList;
19 import java.util.Collections;
20 import java.util.List;
21 import java.util.Map;
22 import java.util.Set;
23
24 import org.apache.commons.lang.StringUtils;
25 import org.apache.log4j.Logger;
26 import org.kuali.rice.kns.service.KNSServiceLocator;
27 import org.kuali.rice.kns.service.ModuleService;
28
29
30
31
32
33
34
35 public class DataDictionaryIndexMapper implements DataDictionaryMapper {
36 private static final Logger LOG = Logger.getLogger(DataDictionaryIndexMapper.class);
37
38
39
40
41 public Set<InactivationBlockingMetadata> getAllInactivationBlockingMetadatas(DataDictionaryIndex index, Class blockedClass) {
42 return index.getInactivationBlockersForClass().get(blockedClass);
43 }
44
45
46
47
48 public List<String> getBusinessObjectClassNames(DataDictionaryIndex index) {
49 List classNames = new ArrayList();
50 classNames.addAll(index.getBusinessObjectEntries().keySet());
51
52 return Collections.unmodifiableList(classNames);
53 }
54
55
56
57
58 public Map<String, BusinessObjectEntry> getBusinessObjectEntries(DataDictionaryIndex index) {
59 return index.getBusinessObjectEntries();
60 }
61
62
63
64
65 public BusinessObjectEntry getBusinessObjectEntryForConcreteClass(DataDictionaryIndex ddIndex, String className) {
66 if (StringUtils.isBlank(className)) {
67 throw new IllegalArgumentException("invalid (blank) className");
68 }
69 if ( LOG.isDebugEnabled() ) {
70 LOG.debug("calling getBusinessObjectEntry '" + className + "'");
71 }
72 int index = className.indexOf("$$");
73 if (index >= 0) {
74 className = className.substring(0, index);
75 }
76 return ddIndex.getBusinessObjectEntries().get(className);
77 }
78
79
80
81
82 public DataDictionaryEntry getDictionaryObjectEntry(DataDictionaryIndex ddIndex, String className) {
83 if (StringUtils.isBlank(className)) {
84 throw new IllegalArgumentException("invalid (blank) className");
85 }
86 if ( LOG.isDebugEnabled() ) {
87 LOG.debug("calling getDictionaryObjectEntry '" + className + "'");
88 }
89 int index = className.indexOf("$$");
90 if (index >= 0) {
91 className = className.substring(0, index);
92 }
93
94
95 DataDictionaryEntry entry = ddIndex.getEntriesByJstlKey().get(className);
96
97 if ( entry == null ) {
98 entry = getBusinessObjectEntry(ddIndex, className);
99 }
100
101 if ( entry == null ) {
102 entry = getDocumentEntry(ddIndex, className);
103 }
104 return entry;
105 }
106
107 public BusinessObjectEntry getBusinessObjectEntry(DataDictionaryIndex index, String className ) {
108 BusinessObjectEntry entry = getBusinessObjectEntryForConcreteClass(index, className);
109 if (entry == null) {
110 Class boClass = null;
111 try{
112 boClass = Class.forName(className);
113 ModuleService responsibleModuleService = KNSServiceLocator.getKualiModuleService().getResponsibleModuleService(boClass);
114 if(responsibleModuleService!=null && responsibleModuleService.isExternalizable(boClass)) {
115 return responsibleModuleService.getExternalizableBusinessObjectDictionaryEntry(boClass);
116 }
117 } catch(ClassNotFoundException cnfex){
118 }
119 return null;
120 }
121 else {
122 return entry;
123 }
124 }
125
126
127
128
129 public Map<String, DocumentEntry> getDocumentEntries(DataDictionaryIndex index) {
130 return Collections.unmodifiableMap(index.getDocumentEntries());
131 }
132
133
134
135
136 public DocumentEntry getDocumentEntry(DataDictionaryIndex index, String documentTypeDDKey) {
137
138 if (StringUtils.isBlank(documentTypeDDKey)) {
139 throw new IllegalArgumentException("invalid (blank) documentTypeName");
140 }
141 if ( LOG.isDebugEnabled() ) {
142 LOG.debug("calling getDocumentEntry by documentTypeName '" + documentTypeDDKey + "'");
143 }
144
145 DocumentEntry de = index.getDocumentEntries().get(documentTypeDDKey);
146
147 if ( de == null ) {
148 try {
149 Class clazz = Class.forName( documentTypeDDKey );
150 de = index.getDocumentEntriesByBusinessObjectClass().get(clazz);
151 if ( de == null ) {
152 de = index.getDocumentEntriesByMaintainableClass().get(clazz);
153 }
154 } catch ( ClassNotFoundException ex ) {
155 LOG.warn( "Unable to find document entry for key: " + documentTypeDDKey );
156 }
157 }
158
159 return de;
160 }
161
162
163
164
165 public String getDocumentTypeName(DataDictionaryIndex index,
166 String documentTypeName) {
167
168 return null;
169 }
170
171
172
173
174 public MaintenanceDocumentEntry getMaintenanceDocumentEntryForBusinessObjectClass(DataDictionaryIndex index, Class businessObjectClass) {
175 if (businessObjectClass == null) {
176 throw new IllegalArgumentException("invalid (null) businessObjectClass");
177 }
178 if ( LOG.isDebugEnabled() ) {
179 LOG.debug("calling getDocumentEntry by businessObjectClass '" + businessObjectClass + "'");
180 }
181
182 return (MaintenanceDocumentEntry) index.getDocumentEntriesByBusinessObjectClass().get(businessObjectClass);
183 }
184 }