001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.core.service.impl;
017:
018: import org.kuali.core.datadictionary.DataDictionary;
019: import org.kuali.core.datadictionary.TransactionalDocumentEntry;
020: import org.kuali.core.document.TransactionalDocument;
021: import org.kuali.core.service.DataDictionaryService;
022: import org.kuali.core.service.TransactionalDocumentDictionaryService;
023:
024: /**
025: * This class is the service implementation for the TransactionalDocumentDictionary structure. Defines the API for the interacting
026: * with Document-related entries in the data dictionary. This is the default implementation that gets delivered with Kuali.
027: */
028: public class TransactionalDocumentDictionaryServiceImpl implements
029: TransactionalDocumentDictionaryService {
030: private DataDictionaryService dataDictionaryService;
031:
032: /**
033: * @see org.kuali.core.service.TransactionalDocumentDictionaryService#getAllowsCopy(org.kuali.bo.TransactionalDocument)
034: */
035: public Boolean getAllowsCopy(TransactionalDocument document) {
036: Boolean allowsCopy = null;
037:
038: TransactionalDocumentEntry entry = getTransactionalDocumentEntry(document);
039: if (entry != null) {
040: allowsCopy = Boolean.valueOf(entry.getAllowsCopy());
041: }
042:
043: return allowsCopy;
044: }
045:
046: /**
047: * @see org.kuali.core.service.TransactionalDocumentDictionaryService#getDocumentClassByName(java.lang.String)
048: */
049: public Class getDocumentClassByName(String documentTypeName) {
050: Class documentClass = null;
051:
052: TransactionalDocumentEntry entry = getTransactionalDocumentEntryBydocumentTypeName(documentTypeName);
053: if (entry != null) {
054: documentClass = entry.getDocumentClass();
055: }
056:
057: return documentClass;
058: }
059:
060: /**
061: * @see org.kuali.core.service.TransactionalDocumentDictionaryService#getAllowsErrorCorrection(org.kuali.bo.TransactionalDocument)
062: */
063: public Boolean getAllowsErrorCorrection(
064: TransactionalDocument document) {
065: Boolean allowsErrorCorrections = null;
066:
067: TransactionalDocumentEntry entry = getTransactionalDocumentEntry(document);
068: if (entry != null) {
069: allowsErrorCorrections = Boolean.valueOf(entry
070: .getAllowsErrorCorrection());
071: }
072:
073: return allowsErrorCorrections;
074: }
075:
076: /**
077: * @see org.kuali.core.service.TransactionalDocumentDictionaryService#getSummary(org.kuali.bo.TransactionalDocument)
078: */
079: public String getSummary(String transactionalDocumentTypeName) {
080: String summary = null;
081:
082: TransactionalDocumentEntry entry = getTransactionalDocumentEntryBydocumentTypeName(transactionalDocumentTypeName);
083: if (entry != null) {
084: summary = String.valueOf(entry.getSummary());
085: }
086:
087: return summary;
088: }
089:
090: /**
091: * @see org.kuali.core.service.TransactionalDocumentDictionaryService#getDescription(org.kuali.bo.TransactionalDocument)
092: */
093: public String getDescription(String transactionalDocumentTypeName) {
094: String description = null;
095:
096: TransactionalDocumentEntry entry = getTransactionalDocumentEntryBydocumentTypeName(transactionalDocumentTypeName);
097: if (entry != null) {
098: description = String.valueOf(entry.getDescription());
099: }
100:
101: return description;
102: }
103:
104: /**
105: * @see org.kuali.core.service.TransactionalDocumentDictionaryService#getDescription(org.kuali.bo.TransactionalDocument)
106: */
107: public String getLabel(String transactionalDocumentTypeName) {
108: String label = null;
109:
110: TransactionalDocumentEntry entry = getTransactionalDocumentEntryBydocumentTypeName(transactionalDocumentTypeName);
111: if (entry != null) {
112: label = String.valueOf(entry.getLabel());
113: }
114:
115: return label;
116: }
117:
118: /**
119: * @see org.kuali.core.service.TransactionalDocumentDictionaryService#getBusinessRulesClass(org.kuali.bo.TransactionalDocument)
120: */
121: public Class getBusinessRulesClass(TransactionalDocument document) {
122: Class businessRulesClass = null;
123:
124: //TransactionalDocumentEntry entry = getTransactionalDocumentEntry(document);
125: String docTypeName = document.getDocumentHeader()
126: .getWorkflowDocument().getDocumentType();
127: TransactionalDocumentEntry entry = getTransactionalDocumentEntryBydocumentTypeName(docTypeName);
128: if (entry != null) {
129: businessRulesClass = entry.getBusinessRulesClass();
130: }
131:
132: return businessRulesClass;
133: }
134:
135: /**
136: * Sets the data dictionary instance.
137: *
138: * @param dataDictionaryService
139: */
140: public void setDataDictionaryService(
141: DataDictionaryService dataDictionaryService) {
142: this .dataDictionaryService = dataDictionaryService;
143: }
144:
145: /**
146: * Retrieves the data dictionary instance.
147: *
148: * @return
149: */
150: public DataDictionary getDataDictionary() {
151: return this .dataDictionaryService.getDataDictionary();
152: }
153:
154: /**
155: * Retrieves the document entry by transactional document class instance.
156: *
157: * @param document
158: * @return TransactionalDocumentEntry
159: */
160: private TransactionalDocumentEntry getTransactionalDocumentEntry(
161: TransactionalDocument document) {
162: if (document == null) {
163: throw new IllegalArgumentException(
164: "invalid (null) document");
165: }
166:
167: TransactionalDocumentEntry entry = (TransactionalDocumentEntry) getDataDictionary()
168: .getDocumentEntry(document.getClass().getName());
169:
170: return entry;
171: }
172:
173: /**
174: * Retrieves the document entry by transactional document type name.
175: *
176: * @param documentTypeName
177: * @return
178: */
179: private TransactionalDocumentEntry getTransactionalDocumentEntryBydocumentTypeName(
180: String documentTypeName) {
181: if (documentTypeName == null) {
182: throw new IllegalArgumentException(
183: "invalid (null) document type name");
184: }
185:
186: TransactionalDocumentEntry entry = (TransactionalDocumentEntry) getDataDictionary()
187: .getDocumentEntry(documentTypeName);
188:
189: return entry;
190: }
191: }
|