01: /*
02: * Copyright 2006-2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.core.datadictionary.exporter;
17:
18: import java.util.Iterator;
19: import java.util.Map;
20:
21: import org.kuali.core.datadictionary.DataDictionaryEntryBase;
22: import org.kuali.core.datadictionary.PrimitiveAttributeDefinition;
23: import org.kuali.core.datadictionary.RelationshipDefinition;
24:
25: /**
26: * RelationshipsMapBuilder
27: *
28: *
29: */
30: public class RelationshipsMapBuilder {
31:
32: /**
33: * Default constructor
34: */
35: public RelationshipsMapBuilder() {
36: }
37:
38: /**
39: * @param entry
40: * @return ExportMap containing the standard entries for the entry's RelationshipDefinitions
41: */
42: public ExportMap buildRelationshipsMap(DataDictionaryEntryBase entry) {
43: ExportMap relationshipsMap = new ExportMap("relationships");
44:
45: for (Iterator i = entry.getRelationships().entrySet()
46: .iterator(); i.hasNext();) {
47: Map.Entry e = (Map.Entry) i.next();
48:
49: RelationshipDefinition relationship = (RelationshipDefinition) e
50: .getValue();
51: relationshipsMap.set(buildRelationshipMap(relationship));
52: }
53:
54: return relationshipsMap;
55: }
56:
57: private ExportMap buildRelationshipMap(
58: RelationshipDefinition relationship) {
59: ExportMap relationshipMap = new ExportMap(relationship
60: .getObjectAttributeName());
61:
62: ExportMap attributesMap = new ExportMap("primitiveAttributes");
63:
64: int count = 0;
65: for (PrimitiveAttributeDefinition primitiveAttributeDefinition : relationship
66: .getPrimitiveAttributes()) {
67: ExportMap attributeMap = new ExportMap(Integer
68: .toString(count++));
69: attributeMap.set("sourceName", primitiveAttributeDefinition
70: .getSourceName());
71: attributeMap.set("targetName", primitiveAttributeDefinition
72: .getTargetName());
73:
74: attributesMap.set(attributeMap);
75: }
76:
77: relationshipMap.set(attributesMap);
78:
79: return relationshipMap;
80: }
81:
82: }
|