-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFillInspectionsModel.java
More file actions
176 lines (139 loc) · 6.52 KB
/
Copy pathFillInspectionsModel.java
File metadata and controls
176 lines (139 loc) · 6.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package com.ndepend.inspections;
import java.util.ArrayList;
public class FillInspectionsModel {
public static InspectionsExport Go(XmlElement xmlElement) throws ModelException {
InspectionsExport inspectionsExport = GetInspectionsExport(xmlElement);
if(inspectionsExport == null) {
throw new ModelException(xmlElement, new String[] { TAG_InspectionsExport});
}
return inspectionsExport;
}
final static String TAG_InspectionsExport = "InspectionsExport";
private static InspectionsExport GetInspectionsExport(XmlElement xmlElement) throws ModelException {
if (!xmlElement.Name.equals(TAG_InspectionsExport)) {
return null;
}
InspectionsExport inspectionsExport = new InspectionsExport();
for (XmlElement child : xmlElement.Elements) {
ArrayList<InspectionTypeInfo> inspectionTypeInfos = GetInspectionTypes(child);
if(inspectionTypeInfos != null) {
inspectionsExport.inspectionTypes.addAll(inspectionTypeInfos);
continue;
}
ArrayList<InspectionInstance> inspectionInstances = GetInspections(child);
if(inspectionInstances != null){
inspectionsExport.inspections.addAll(inspectionInstances);
continue;
}
throw new ModelException(child, new String[] { TAG_InspectionTypes, TAG_Inspections });
}
return inspectionsExport;
}
final static String TAG_InspectionTypes = "InspectionTypes";
private static ArrayList<InspectionTypeInfo> GetInspectionTypes(XmlElement xmlElement) throws ModelException {
if (!xmlElement.Name.equals(TAG_InspectionTypes)) {
return null;
}
ArrayList<InspectionTypeInfo> inspectionTypeInfos = new ArrayList<>();
for (XmlElement child : xmlElement.Elements) {
InspectionTypeInfo inspectionTypeInfo = GetInspectionTypeInfo(child);
if(inspectionTypeInfo != null) {
inspectionTypeInfos.add(inspectionTypeInfo);
} else {
throw new ModelException(child, new String[] {TAG_InspectionTypeInfo});
}
}
return inspectionTypeInfos;
}
final static String TAG_InspectionTypeInfo = "InspectionTypeInfo";
final static String TAG_Description = "Description";
final static String TAG_Id = "Id";
final static String TAG_Name = "Name";
final static String TAG_Category = "Category";
private static InspectionTypeInfo GetInspectionTypeInfo(XmlElement xmlElement) throws ModelException {
if (!xmlElement.Name.equals(TAG_InspectionTypeInfo)) {
return null;
}
InspectionTypeInfo inspectionTypeInfo = new InspectionTypeInfo();
if (xmlElement.Elements.size() > 0) {
XmlElement child = xmlElement.Elements.get(0);
if (!child.Name.equals(TAG_Description)) {
throw new ModelException(child, new String[] {TAG_Description});
}
inspectionTypeInfo.description = child.Content;
}
for (XmlAttribute attr : xmlElement.Attributes) {
String val = attr.Value;
switch (attr.Name) {
case TAG_Id: inspectionTypeInfo.id = val; break;
case TAG_Name: inspectionTypeInfo.name = val; break;
case TAG_Category: inspectionTypeInfo.category = val; break;
default: throw new ModelException(attr, new String[] {TAG_Id, TAG_Name, TAG_Category});
}
}
return inspectionTypeInfo;
}
final static String TAG_Inspections = "Inspections";
private static ArrayList<InspectionInstance> GetInspections(XmlElement xmlElement) throws ModelException {
if (!xmlElement.Name.equals(TAG_Inspections)) {
return null;
}
ArrayList<InspectionInstance> inspectionInstances = new ArrayList<>();
for (XmlElement child : xmlElement.Elements) {
InspectionInstance inspectionInstance = GetInspectionInstance(child);
if(inspectionInstance != null) {
inspectionInstances.add(inspectionInstance);
} else {
throw new ModelException(child, new String[] {TAG_InspectionInstance});
}
}
return inspectionInstances;
}
final static String TAG_InspectionInstance = "InspectionInstance";
final static String TAG_Message = "Message";
final static String TAG_FilePath = "FilePath";
final static String TAG_Line = "Line";
final static String TAG_Severity = "Severity";
private static InspectionInstance GetInspectionInstance(XmlElement xmlElement) throws ModelException {
if (!xmlElement.Name.equals(TAG_InspectionInstance)) {
return null;
}
InspectionInstance inspectionInstance = new InspectionInstance();
// Read child elem Message FilePath
for (XmlElement child : xmlElement.Elements) {
if (child.Name.equals(TAG_Message)) {
inspectionInstance.message = child.Content;
continue;
}
if (child.Name.equals(TAG_FilePath)) {
inspectionInstance.filePath = child.Content;
continue;
}
throw new ModelException(child, new String[] {TAG_Message, TAG_FilePath});
}
// Read attributes
for (XmlAttribute attr : xmlElement.Attributes) {
String val = attr.Value;
switch (attr.Name) {
case TAG_Id: inspectionInstance.id = val; break;
case TAG_Line:
int iVal = tryParseInt(val);
if (iVal == Integer.MIN_VALUE) {
throw new ModelException("Expected an integer value for attribute "+attr.Name+", got instead "+val);
}
inspectionInstance.line = iVal;
break;
case TAG_Severity: inspectionInstance.severity = val; break;
default: throw new ModelException(attr, new String[] {TAG_Id, TAG_Line, TAG_Severity});
}
}
return inspectionInstance;
}
static int tryParseInt(String value) {
try {
return Integer.parseInt(value);
} catch (NumberFormatException e) {
return Integer.MIN_VALUE;
}
}
}