Coverage Report - org.kuali.rice.krad.datadictionary.exporter.DataDictionaryMap
 
Classes in this File Line Coverage Branch Coverage Complexity
DataDictionaryMap
0%
0/29
0%
0/18
3.25
 
 1  
 /*
 2  
  * Copyright 2007 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.krad.datadictionary.exporter;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.krad.datadictionary.BusinessObjectEntry;
 20  
 import org.kuali.rice.krad.datadictionary.DataDictionaryEntry;
 21  
 import org.kuali.rice.krad.datadictionary.MaintenanceDocumentEntry;
 22  
 import org.kuali.rice.krad.datadictionary.TransactionalDocumentEntry;
 23  
 import org.kuali.rice.krad.service.DataDictionaryService;
 24  
 
 25  
 import java.util.HashMap;
 26  
 import java.util.Map;
 27  
 
 28  
 public class DataDictionaryMap extends DataDictionaryMapBase {
 29  
 
 30  
     private DataDictionaryService dataDictionaryService;
 31  
 
 32  0
     BusinessObjectEntryMapper boMapper = new BusinessObjectEntryMapper();
 33  0
     MaintenanceDocumentEntryMapper maintDocMapper = new MaintenanceDocumentEntryMapper();
 34  0
     TransactionalDocumentEntryMapper transDocMapper = new TransactionalDocumentEntryMapper();
 35  
     
 36  0
     Map<String,Map> ddMap = new HashMap<String,Map>();
 37  
     
 38  
     public DataDictionaryMap(DataDictionaryService dataDictionaryService) {
 39  0
         super();
 40  0
         this.dataDictionaryService = dataDictionaryService;
 41  0
     }
 42  
 
 43  
     public Object get(Object key) {
 44  0
         Map subMap = ddMap.get( key );
 45  0
         if ( subMap == null ) { // need to load from DD
 46  0
             synchronized( this ) { // ensure only one update access happening at a time
 47  0
                 subMap = ddMap.get( key );
 48  0
                 if ( subMap == null ) { // recheck in case it was loaded by another thread while this one was blocked
 49  0
                     DataDictionaryEntry entry = dataDictionaryService.getDataDictionary().getDictionaryObjectEntry( key.toString() );
 50  
                     // if that fails try just using the simple name if a full class name was passed
 51  0
                     if ( entry == null && key.toString().contains(".")) {
 52  0
                             entry = dataDictionaryService.getDataDictionary().getDictionaryObjectEntry( StringUtils.substringAfterLast( key.toString(), "." ) );
 53  
                     }
 54  0
                     if ( entry != null ) {
 55  0
                         if ( entry instanceof BusinessObjectEntry ) {
 56  0
                             subMap = boMapper.mapEntry( (BusinessObjectEntry)entry ).getExportData();                    
 57  0
                         } else if ( entry instanceof MaintenanceDocumentEntry ) {
 58  0
                             subMap = maintDocMapper.mapEntry( (MaintenanceDocumentEntry)entry ).getExportData();                    
 59  0
                         } else if ( entry instanceof TransactionalDocumentEntry ) {
 60  0
                             subMap = transDocMapper.mapEntry( (TransactionalDocumentEntry)entry ).getExportData();                    
 61  
                         }
 62  
                     }
 63  0
                     if ( subMap != null ) {
 64  0
                         ddMap.put( key.toString(), subMap );
 65  
                     }
 66  
                 }
 67  0
             }
 68  
         }
 69  0
         return subMap;
 70  
     }
 71  
 
 72  
     public DataDictionaryService getDataDictionaryService() {
 73  0
         return dataDictionaryService;
 74  
     }
 75  
 
 76  
     public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
 77  0
         this.dataDictionaryService = dataDictionaryService;
 78  0
     }
 79  
 
 80  
 }