View Javadoc

1   /*
2    * Copyright 2005-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.kns.datadictionary.exporter;
17  
18  import java.util.Iterator;
19  
20  import org.kuali.rice.kns.datadictionary.BusinessObjectEntry;
21  import org.kuali.rice.kns.datadictionary.FieldDefinition;
22  import org.kuali.rice.kns.datadictionary.InquiryDefinition;
23  import org.kuali.rice.kns.datadictionary.InquirySectionDefinition;
24  
25  /**
26   * InquiryMapBuilder
27   * 
28   * 
29   */
30  public class InquiryMapBuilder {
31  
32      /**
33       * Default constructor
34       */
35      public InquiryMapBuilder() {
36      }
37  
38  
39      /**
40       * @param inquiry
41       * @return ExportMap containing the standard entries for the entry's InquiryDefinition, or null if the given entry has no
42       *         inquiryDefinition
43       */
44      public ExportMap buildInquiryMap(BusinessObjectEntry entry) {
45      	try {
46  	        ExportMap inquiryMap = null;
47  	
48  	        if (entry.hasInquiryDefinition()) {
49  	            InquiryDefinition inquiryDefinition = entry.getInquiryDefinition();
50  	            inquiryMap = new ExportMap("inquiry");
51  	
52  	            inquiryMap.set("title", inquiryDefinition.getTitle());
53  	
54  	            inquiryMap.set(buildInquiryFieldsMap(inquiryDefinition));
55  	        }
56  	
57  	        return inquiryMap;
58      	} catch ( Exception ex ) {
59      		throw new RuntimeException( "Unable to build inquiry Map for " + entry, ex );
60      	}
61      }
62  
63      private ExportMap buildInquiryFieldsMap(InquiryDefinition inquiryDefinition) {
64          ExportMap inquiryFieldsMap = new ExportMap("inquiryFields");
65  
66          for (Iterator i = inquiryDefinition.getInquirySections().iterator(); i.hasNext();) {
67              InquirySectionDefinition inquirySection = (InquirySectionDefinition) i.next();
68              for (Iterator iter = inquirySection.getInquiryFields().iterator(); iter.hasNext();) {
69                  FieldDefinition FieldDefinition = (FieldDefinition) iter.next();
70                  inquiryFieldsMap.set(MapperUtils.buildFieldMap(FieldDefinition));
71              }
72          }
73  
74          return inquiryFieldsMap;
75      }
76  }