Coverage Report - org.kuali.rice.kns.datadictionary.DataDictionaryIndexMapper
 
Classes in this File Line Coverage Branch Coverage Complexity
DataDictionaryIndexMapper
0%
0/60
0%
0/34
3.5
 
 1  
 /*
 2  
  * Copyright 2007-2010 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.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  
  * A DataDictionaryMapper that simply consults the statically initialized
 31  
  * DataDictionaryIndex mappings
 32  
  * 
 33  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 34  
  */
 35  0
 public class DataDictionaryIndexMapper implements DataDictionaryMapper {
 36  0
         private static final Logger LOG = Logger.getLogger(DataDictionaryIndexMapper.class);
 37  
 
 38  
         /**
 39  
          * @see org.kuali.rice.kns.datadictionary.DataDictionaryMapper#getAllInactivationBlockingMetadatas(org.kuali.rice.kns.datadictionary.DataDictionaryIndex, java.lang.Class)
 40  
          */
 41  
         public Set<InactivationBlockingMetadata> getAllInactivationBlockingMetadatas(DataDictionaryIndex index, Class blockedClass) {
 42  0
         return index.getInactivationBlockersForClass().get(blockedClass);
 43  
         }
 44  
 
 45  
         /**
 46  
          * @see org.kuali.rice.kns.datadictionary.DataDictionaryMapper#getBusinessObjectClassNames(org.kuali.rice.kns.datadictionary.DataDictionaryIndex)
 47  
          */
 48  
         public List<String> getBusinessObjectClassNames(DataDictionaryIndex index) {
 49  0
                 List classNames = new ArrayList();
 50  0
                 classNames.addAll(index.getBusinessObjectEntries().keySet());
 51  
 
 52  0
                 return Collections.unmodifiableList(classNames);
 53  
         }
 54  
 
 55  
         /**
 56  
          * @see org.kuali.rice.kns.datadictionary.DataDictionaryMapper#getBusinessObjectEntries(org.kuali.rice.kns.datadictionary.DataDictionaryIndex)
 57  
          */
 58  
         public Map<String, BusinessObjectEntry> getBusinessObjectEntries(DataDictionaryIndex index) {
 59  0
                 return index.getBusinessObjectEntries();
 60  
         }
 61  
 
 62  
         /**
 63  
          * @see org.kuali.rice.kns.datadictionary.DataDictionaryMapper#getBusinessObjectEntryForConcreteClass(java.lang.String)
 64  
          */
 65  
         public BusinessObjectEntry getBusinessObjectEntryForConcreteClass(DataDictionaryIndex ddIndex, String className) {
 66  0
                 if (StringUtils.isBlank(className)) {
 67  0
                         throw new IllegalArgumentException("invalid (blank) className");
 68  
                 }
 69  0
                 if ( LOG.isDebugEnabled() ) {
 70  0
                     LOG.debug("calling getBusinessObjectEntry '" + className + "'");
 71  
                 }
 72  0
                 int index = className.indexOf("$$");
 73  0
                 if (index >= 0) {
 74  0
                         className = className.substring(0, index);
 75  
                 }
 76  0
                 return ddIndex.getBusinessObjectEntries().get(className);
 77  
         }
 78  
 
 79  
         /**
 80  
          * @see org.kuali.rice.kns.datadictionary.DataDictionaryMapper#getDictionaryObjectEntry(org.kuali.rice.kns.datadictionary.DataDictionaryIndex, java.lang.String)
 81  
          */
 82  
         public DataDictionaryEntry getDictionaryObjectEntry(DataDictionaryIndex ddIndex, String className) {
 83  0
                 if (StringUtils.isBlank(className)) {
 84  0
                         throw new IllegalArgumentException("invalid (blank) className");
 85  
                 }
 86  0
                 if ( LOG.isDebugEnabled() ) {
 87  0
                     LOG.debug("calling getDictionaryObjectEntry '" + className + "'");
 88  
                 }
 89  0
                 int index = className.indexOf("$$");
 90  0
                 if (index >= 0) {
 91  0
                         className = className.substring(0, index);
 92  
                 }
 93  
 
 94  
                 // look in the JSTL key cache
 95  0
                 DataDictionaryEntry entry = ddIndex.getEntriesByJstlKey().get(className);
 96  
                 // check the BO list
 97  0
                 if ( entry == null ) {
 98  0
                     entry = getBusinessObjectEntry(ddIndex, className);
 99  
                 }
 100  
                 // check the document list
 101  0
                 if ( entry == null ) {
 102  0
                     entry = getDocumentEntry(ddIndex, className);
 103  
                 }
 104  0
                 return entry;
 105  
         }
 106  
 
 107  
         public BusinessObjectEntry getBusinessObjectEntry(DataDictionaryIndex index, String className ) {
 108  0
                 BusinessObjectEntry entry = getBusinessObjectEntryForConcreteClass(index, className);
 109  0
                 if (entry == null) {
 110  0
                         Class boClass = null;
 111  
                         try{
 112  0
                                 boClass = Class.forName(className);
 113  0
                                 ModuleService responsibleModuleService = KNSServiceLocator.getKualiModuleService().getResponsibleModuleService(boClass);
 114  0
                                 if(responsibleModuleService!=null && responsibleModuleService.isExternalizable(boClass)) {
 115  0
                                         return responsibleModuleService.getExternalizableBusinessObjectDictionaryEntry(boClass);
 116  
                                 }
 117  0
                         } catch(ClassNotFoundException cnfex){
 118  0
                         }
 119  0
                         return null;
 120  
                 }
 121  
                 else {
 122  0
                         return entry;
 123  
                 }
 124  
         }
 125  
         
 126  
         /**
 127  
          * @see org.kuali.rice.kns.datadictionary.DataDictionaryMapper#getDocumentEntries(org.kuali.rice.kns.datadictionary.DataDictionaryIndex)
 128  
          */
 129  
         public Map<String, DocumentEntry> getDocumentEntries(DataDictionaryIndex index) {
 130  0
                 return Collections.unmodifiableMap(index.getDocumentEntries());
 131  
         }
 132  
 
 133  
         /**
 134  
          * @see org.kuali.rice.kns.datadictionary.DataDictionaryMapper#getDocumentEntry(org.kuali.rice.kns.datadictionary.DataDictionaryIndex, java.lang.String)
 135  
          */
 136  
         public DocumentEntry getDocumentEntry(DataDictionaryIndex index, String documentTypeDDKey) {
 137  
 
 138  0
                 if (StringUtils.isBlank(documentTypeDDKey)) {
 139  0
                         throw new IllegalArgumentException("invalid (blank) documentTypeName");
 140  
                 }
 141  0
                 if ( LOG.isDebugEnabled() ) {
 142  0
                     LOG.debug("calling getDocumentEntry by documentTypeName '" + documentTypeDDKey + "'");
 143  
                 }
 144  
 
 145  0
                 DocumentEntry de = index.getDocumentEntries().get(documentTypeDDKey);        
 146  
                 
 147  0
                 if ( de == null ) {
 148  
                     try {
 149  0
                         Class clazz = Class.forName( documentTypeDDKey );
 150  0
                         de = index.getDocumentEntriesByBusinessObjectClass().get(clazz);
 151  0
                         if ( de == null ) {
 152  0
                             de = index.getDocumentEntriesByMaintainableClass().get(clazz);
 153  
                         }
 154  0
                     } catch ( ClassNotFoundException ex ) {
 155  0
                         LOG.warn( "Unable to find document entry for key: " + documentTypeDDKey );
 156  0
                     }
 157  
                 }
 158  
                 
 159  0
         return de;
 160  
         }
 161  
 
 162  
         /**
 163  
          * @see org.kuali.rice.kns.datadictionary.DataDictionaryMapper#getDocumentTypeName(org.kuali.rice.kns.datadictionary.DataDictionaryIndex, java.lang.String)
 164  
          */
 165  
         public String getDocumentTypeName(DataDictionaryIndex index,
 166  
                         String documentTypeName) {
 167  
                 // TODO arh14 - THIS METHOD NEEDS JAVADOCS
 168  0
                 return null;
 169  
         }
 170  
 
 171  
         /**
 172  
          * @see org.kuali.rice.kns.datadictionary.DataDictionaryMapper#getMaintenanceDocumentEntryForBusinessObjectClass(org.kuali.rice.kns.datadictionary.DataDictionaryIndex, java.lang.Class)
 173  
          */
 174  
         public MaintenanceDocumentEntry getMaintenanceDocumentEntryForBusinessObjectClass(DataDictionaryIndex index, Class businessObjectClass) {
 175  0
                 if (businessObjectClass == null) {
 176  0
                         throw new IllegalArgumentException("invalid (null) businessObjectClass");
 177  
                 }
 178  0
                 if ( LOG.isDebugEnabled() ) {
 179  0
                     LOG.debug("calling getDocumentEntry by businessObjectClass '" + businessObjectClass + "'");
 180  
                 }
 181  
 
 182  0
                 return (MaintenanceDocumentEntry) index.getDocumentEntriesByBusinessObjectClass().get(businessObjectClass);
 183  
         }
 184  
 }