View Javadoc

1   /*
2    * Copyright 2006-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 org.kuali.rice.kns.datadictionary.DataDictionaryEntryBase;
19  import org.kuali.rice.kns.datadictionary.PrimitiveAttributeDefinition;
20  import org.kuali.rice.kns.datadictionary.RelationshipDefinition;
21  
22  /**
23   * RelationshipsMapBuilder
24   * 
25   * 
26   */
27  public class RelationshipsMapBuilder {
28  
29      /**
30       * Default constructor
31       */
32      public RelationshipsMapBuilder() {
33      }
34  
35  
36      /**
37       * @param entry
38       * @return ExportMap containing the standard entries for the entry's RelationshipDefinitions
39       */
40      public ExportMap buildRelationshipsMap(DataDictionaryEntryBase entry) {
41          ExportMap relationshipsMap = new ExportMap("relationships");
42  
43          for ( RelationshipDefinition relationship : entry.getRelationships() ) {
44              relationshipsMap.set(buildRelationshipMap(relationship));
45          }
46  
47          return relationshipsMap;
48      }
49  
50      private ExportMap buildRelationshipMap(RelationshipDefinition relationship) {
51          ExportMap relationshipMap = new ExportMap(relationship.getObjectAttributeName());
52  
53          ExportMap attributesMap = new ExportMap("primitiveAttributes");
54  
55          int count = 0;
56          for (PrimitiveAttributeDefinition primitiveAttributeDefinition : relationship.getPrimitiveAttributes()) {
57              ExportMap attributeMap = new ExportMap(Integer.toString(count++));
58              attributeMap.set("sourceName", primitiveAttributeDefinition.getSourceName());
59              attributeMap.set("targetName", primitiveAttributeDefinition.getTargetName());
60  
61              attributesMap.set(attributeMap);
62          }
63  
64          relationshipMap.set(attributesMap);
65  
66          return relationshipMap;
67      }
68  
69  }