View Javadoc

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  public class DataDictionaryIndexMapper implements DataDictionaryMapper {
36  	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          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  		List classNames = new ArrayList();
50  		classNames.addAll(index.getBusinessObjectEntries().keySet());
51  
52  		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  		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  		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  	 * @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  		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  		// look in the JSTL key cache
95  		DataDictionaryEntry entry = ddIndex.getEntriesByJstlKey().get(className);
96  		// check the BO list
97  		if ( entry == null ) {
98  		    entry = getBusinessObjectEntry(ddIndex, className);
99  		}
100 		// check the document list
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 	 * @see org.kuali.rice.kns.datadictionary.DataDictionaryMapper#getDocumentEntries(org.kuali.rice.kns.datadictionary.DataDictionaryIndex)
128 	 */
129 	public Map<String, DocumentEntry> getDocumentEntries(DataDictionaryIndex index) {
130 		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 		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 	 * @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 		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 		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 }