1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.kuali.student.contract.model.util;
21
22 import java.io.PrintStream;
23 import java.util.Stack;
24
25 import org.kuali.student.contract.model.MessageStructure;
26 import org.kuali.student.contract.model.ServiceContractModel;
27 import org.kuali.student.contract.model.XmlType;
28
29
30
31
32
33 public class MessageStructureHierarchyDumper {
34
35 private ServiceContractModel model;
36 private ModelFinder finder;
37 private PrintStream out;
38
39 public MessageStructureHierarchyDumper(PrintStream out,
40 ServiceContractModel model) {
41 this.out = out;
42 this.model = model;
43 this.finder = new ModelFinder(model);
44 }
45
46 public void writeTabbedHeader() {
47 out.print("id");
48 out.print("\t");
49 out.print("Action");
50 out.print("\t");
51 out.print("xmlObject");
52 out.print("\t");
53 out.print("ShortName");
54 out.print("\t");
55 out.print("Name");
56 out.print("\t");
57 out.print("Type");
58 out.print("\t");
59 out.print("Description");
60 out.print("\t");
61 out.print("Required");
62 out.print("\t");
63 out.print("Cardinality");
64 out.print("\t");
65 out.print("XMLAttribute");
66 out.print("\t");
67 out.print("Status");
68 out.print("\t");
69 out.print("Feedback");
70 out.println("");
71 }
72
73 private String clean(String str) {
74 int len = str.length();
75 StringBuffer buffer = new StringBuffer(len);
76 for (int i = 0; i < len; i++) {
77 char c = str.charAt(i);
78
79 switch (c) {
80 case '\n':
81 case '\r':
82 if (i + 1 < len && str.charAt(i + 1) == '\n') {
83 i++;
84 }
85
86 buffer.append(" ");
87 break;
88 default:
89 buffer.append(c);
90 }
91 }
92 return buffer.toString();
93 }
94
95 public String calcId(MessageStructure ms, Stack<String> parents) {
96 StringBuilder bldr = new StringBuilder();
97 {
98 for (String parent : parents) {
99 bldr.append(parent);
100 bldr.append(".");
101 }
102 }
103 bldr.append(ms.getShortName());
104 return bldr.toString();
105 }
106
107 public void writeTabbedData(MessageStructure ms, Stack<String> parents) {
108 out.print(calcId(ms, parents));
109 out.print("\t");
110 out.print("");
111 out.print("\t");
112 out.print(ms.getXmlObject());
113 out.print("\t");
114 out.print(ms.getShortName());
115 out.print("\t");
116 out.print(ms.getName());
117 out.print("\t");
118 out.print(ms.getType());
119 out.print("\t");
120 out.print(clean(ms.getDescription()));
121 out.print("\t");
122 out.print(ms.getRequired());
123 out.print("\t");
124 out.print(ms.getCardinality());
125 out.print("\t");
126 out.print(ms.getXmlAttribute());
127 out.print("\t");
128 out.print(ms.getStatus());
129 out.print("\t");
130 out.print(ms.getImplNotes());
131 out.println("");
132 XmlType st = finder.findXmlType(stripList(ms.getType()));
133 if (st.getPrimitive().equalsIgnoreCase(XmlType.COMPLEX)) {
134 if (!parents.contains(st.getName())) {
135 parents.push(st.getName());
136 for (MessageStructure childMs : finder.findMessageStructures(st.getName())) {
137 this.writeTabbedData(childMs, parents);
138 }
139 parents.pop();
140 }
141 }
142 }
143
144 private String stripList(String type) {
145 if (type.endsWith("List")) {
146 return type.substring(0, type.length() - "List".length());
147 }
148 return type;
149 }
150 }