01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.core.datadictionary.exporter;
17:
18: import java.util.HashMap;
19: import java.util.Map;
20:
21: import org.apache.commons.lang.StringUtils;
22: import org.kuali.core.datadictionary.BusinessObjectEntry;
23: import org.kuali.core.datadictionary.DataDictionaryEntry;
24: import org.kuali.core.datadictionary.MaintenanceDocumentEntry;
25: import org.kuali.core.datadictionary.TransactionalDocumentEntry;
26: import org.kuali.core.service.DataDictionaryService;
27:
28: public class DataDictionaryMap extends DataDictionaryMapBase {
29:
30: private DataDictionaryService dataDictionaryService;
31:
32: BusinessObjectEntryMapper boMapper = new BusinessObjectEntryMapper();
33: MaintenanceDocumentEntryMapper maintDocMapper = new MaintenanceDocumentEntryMapper();
34: TransactionalDocumentEntryMapper transDocMapper = new TransactionalDocumentEntryMapper();
35:
36: Map<String, Map> ddMap = new HashMap<String, Map>();
37:
38: public DataDictionaryMap(DataDictionaryService dataDictionaryService) {
39: super ();
40: this .dataDictionaryService = dataDictionaryService;
41: }
42:
43: public Object get(Object key) {
44: Map subMap = ddMap.get(key);
45: if (subMap == null) { // need to load from DD
46: synchronized (this ) { // ensure only one update access happening at a time
47: subMap = ddMap.get(key);
48: if (subMap == null) { // recheck in case it was loaded by another thread while this one was blocked
49: DataDictionaryEntry entry = dataDictionaryService
50: .getDataDictionary()
51: .getDictionaryObjectEntry(key.toString());
52: // if that fails try just using the simple name if a full class name was passed
53: if (entry == null
54: && key.toString().indexOf(".") != -1) {
55: entry = dataDictionaryService
56: .getDataDictionary()
57: .getDictionaryObjectEntry(
58: StringUtils.substringAfterLast(
59: key.toString(), "."));
60: }
61: if (entry != null) {
62: if (entry instanceof BusinessObjectEntry) {
63: subMap = boMapper.mapEntry(
64: (BusinessObjectEntry) entry)
65: .getExportData();
66: } else if (entry instanceof MaintenanceDocumentEntry) {
67: subMap = maintDocMapper.mapEntry(
68: (MaintenanceDocumentEntry) entry)
69: .getExportData();
70: } else if (entry instanceof TransactionalDocumentEntry) {
71: subMap = transDocMapper.mapEntry(
72: (TransactionalDocumentEntry) entry)
73: .getExportData();
74: }
75: }
76: if (subMap != null) {
77: ddMap.put(key.toString(), subMap);
78: }
79: }
80: }
81: }
82: return subMap;
83: }
84:
85: public DataDictionaryService getDataDictionaryService() {
86: return dataDictionaryService;
87: }
88:
89: public void setDataDictionaryService(
90: DataDictionaryService dataDictionaryService) {
91: this.dataDictionaryService = dataDictionaryService;
92: }
93:
94: }
|