3
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
2
|
17 |
|
|
18 |
package com.nokia.carbide.cpp.internal.codescanner.kb;
|
|
19 |
|
|
20 |
import java.net.URL;
|
|
21 |
import java.text.MessageFormat;
|
|
22 |
import java.util.ArrayList;
|
|
23 |
import java.util.Dictionary;
|
|
24 |
import java.util.Enumeration;
|
|
25 |
import java.util.Iterator;
|
|
26 |
import java.util.List;
|
|
27 |
|
|
28 |
import org.eclipse.core.resources.IProject;
|
|
29 |
import org.eclipse.core.runtime.IConfigurationElement;
|
|
30 |
import org.eclipse.core.runtime.IExtension;
|
|
31 |
import org.eclipse.core.runtime.IExtensionPoint;
|
|
32 |
import org.eclipse.core.runtime.IExtensionRegistry;
|
|
33 |
import org.eclipse.core.runtime.IStatus;
|
|
34 |
import org.eclipse.core.runtime.Platform;
|
|
35 |
import org.eclipse.core.runtime.Status;
|
|
36 |
import org.eclipse.emf.common.util.EList;
|
|
37 |
import org.osgi.framework.Bundle;
|
|
38 |
import org.osgi.framework.Version;
|
|
39 |
|
|
40 |
import com.nokia.carbide.cdt.builder.CarbideBuilderPlugin;
|
|
41 |
import com.nokia.carbide.cdt.builder.project.ICarbideBuildConfiguration;
|
|
42 |
import com.nokia.carbide.cdt.builder.project.ICarbideProjectInfo;
|
1434
|
43 |
import com.nokia.carbide.cpp.internal.api.sdk.ISBSv1BuildInfo;
|
2
|
44 |
import com.nokia.carbide.cpp.internal.codescanner.CSPlugin;
|
|
45 |
import com.nokia.carbide.cpp.internal.codescanner.Messages;
|
|
46 |
import com.nokia.carbide.cpp.internal.codescanner.config.CSConfigSettings;
|
|
47 |
import com.nokia.carbide.cpp.internal.codescanner.gen.CSConfig.CSConfigFactory;
|
|
48 |
import com.nokia.carbide.cpp.internal.codescanner.gen.CSConfig.CustomruleType;
|
|
49 |
import com.nokia.carbide.cpp.internal.codescanner.gen.CSConfig.KeywordType;
|
|
50 |
import com.nokia.carbide.cpp.internal.codescanner.gen.Kbdata.CallType;
|
|
51 |
import com.nokia.carbide.cpp.internal.codescanner.gen.Kbdata.ClassType;
|
|
52 |
import com.nokia.carbide.cpp.internal.codescanner.gen.Kbdata.CommentType;
|
|
53 |
import com.nokia.carbide.cpp.internal.codescanner.gen.Kbdata.FiletypeType;
|
|
54 |
import com.nokia.carbide.cpp.internal.codescanner.gen.Kbdata.InheritanceType;
|
|
55 |
import com.nokia.carbide.cpp.internal.codescanner.gen.Kbdata.KbdataBodyType;
|
|
56 |
import com.nokia.carbide.cpp.internal.codescanner.gen.Kbdata.KbdataCategoryType;
|
|
57 |
import com.nokia.carbide.cpp.internal.codescanner.gen.Kbdata.KbdataKeywordType;
|
|
58 |
import com.nokia.carbide.cpp.internal.codescanner.gen.Kbdata.KbdataKeywordsType;
|
|
59 |
import com.nokia.carbide.cpp.internal.codescanner.gen.Kbdata.KbdataMetadataType;
|
|
60 |
import com.nokia.carbide.cpp.internal.codescanner.gen.Kbdata.KbdataPlatformType;
|
|
61 |
import com.nokia.carbide.cpp.internal.codescanner.gen.Kbdata.KbdataRefType;
|
|
62 |
import com.nokia.carbide.cpp.internal.codescanner.gen.Kbdata.KbdataType;
|
|
63 |
import com.nokia.carbide.cpp.internal.codescanner.gen.Kbdata.LocalType;
|
|
64 |
import com.nokia.carbide.cpp.internal.codescanner.gen.Kbdata.MacroType;
|
|
65 |
import com.nokia.carbide.cpp.internal.codescanner.gen.Kbdata.MemberType;
|
|
66 |
import com.nokia.carbide.cpp.internal.codescanner.gen.Kbdata.MessagesType;
|
|
67 |
import com.nokia.carbide.cpp.internal.codescanner.gen.Kbdata.MethodType;
|
|
68 |
import com.nokia.carbide.cpp.internal.codescanner.gen.Kbdata.ParameterType;
|
|
69 |
import com.nokia.carbide.cpp.internal.codescanner.gen.Kbdata.SolutionType;
|
|
70 |
import com.nokia.carbide.cpp.internal.codescanner.gen.Kbdata.SymptomType;
|
|
71 |
import com.nokia.carbide.cpp.internal.codescanner.xml.CSKbdataXMLLoader;
|
1434
|
72 |
import com.nokia.carbide.cpp.sdk.core.ISymbianBuilderID;
|
2
|
73 |
import com.nokia.carbide.cpp.sdk.core.ISymbianSDK;
|
|
74 |
|
|
75 |
/**
|
|
76 |
* A class for handling CodeScanner knowledge base rules.
|
|
77 |
*
|
|
78 |
*/
|
|
79 |
public class CSKbManager {
|
|
80 |
|
|
81 |
public static final String KBASE_EXTENSION_ID = CSPlugin.PLUGIN_ID + ".rules"; //$NON-NLS-1$
|
|
82 |
public static final String LOCATION = "location"; //$NON-NLS-1$
|
|
83 |
public static final String KEYWORDTYPE_BASECLASS = "baseclass"; //$NON-NLS-1$
|
|
84 |
public static final String KEYWORDTYPE_CALL = "call"; //$NON-NLS-1$
|
|
85 |
public static final String KEYWORDTYPE_CLASS = "class"; //$NON-NLS-1$
|
|
86 |
public static final String KEYWORDTYPE_COMMENT = "comment"; //$NON-NLS-1$
|
|
87 |
public static final String KEYWORDTYPE_GENERIC = "generic"; //$NON-NLS-1$
|
|
88 |
public static final String KEYWORDTYPE_LOCAL = "local"; //$NON-NLS-1$
|
|
89 |
public static final String KEYWORDTYPE_MACRO = "macro"; //$NON-NLS-1$
|
|
90 |
public static final String KEYWORDTYPE_MEMBER = "member"; //$NON-NLS-1$
|
|
91 |
public static final String KEYWORDTYPE_METHOD = "method"; //$NON-NLS-1$
|
|
92 |
public static final String KEYWORDTYPE_PARAMETER = "parameter"; //$NON-NLS-1$
|
|
93 |
|
|
94 |
// private members
|
|
95 |
private static final String CATEGORY_ERROR = "error"; //$NON-NLS-1$
|
|
96 |
private static final String CATEGORY_WARNING = "warning"; //$NON-NLS-1$
|
|
97 |
private static final String CATEGORY_INFORMATION = "information"; //$NON-NLS-1$
|
|
98 |
private static final String SEVERITY_HIGH = "high"; //$NON-NLS-1$
|
|
99 |
private static final String SEVERITY_MEDIUM = "medium"; //$NON-NLS-1$
|
|
100 |
private static final String SEVERITY_LOW = "low"; //$NON-NLS-1$
|
|
101 |
private static final String KBDATA_FILE_FILTER = "*.xml"; //$NON-NLS-1$
|
|
102 |
|
|
103 |
private ArrayList<CSKbRule> rules;
|
|
104 |
private ArrayList<CSKbPluginInfo> pluginInfoList;
|
|
105 |
|
|
106 |
/**
|
|
107 |
* Constructor.
|
|
108 |
*/
|
|
109 |
public CSKbManager() {
|
|
110 |
rules = new ArrayList<CSKbRule>();
|
|
111 |
pluginInfoList = new ArrayList<CSKbPluginInfo>();
|
|
112 |
}
|
|
113 |
|
|
114 |
/**
|
|
115 |
* Add a knowledge base rule.
|
|
116 |
* @param rule - knowledge base rule to be added.
|
|
117 |
*/
|
|
118 |
public void addRule(CSKbRule rule) {
|
|
119 |
rules.add(rule);
|
|
120 |
}
|
|
121 |
|
|
122 |
/**
|
|
123 |
* Add a collection of knowledge base rules.
|
|
124 |
* @param rules - knowledge base rules to be added.
|
|
125 |
*/
|
|
126 |
public void addRules(ArrayList<CSKbRule> rules) {
|
|
127 |
this.rules.addAll(rules);
|
|
128 |
}
|
|
129 |
|
|
130 |
/**
|
|
131 |
* Clear all knowledge base rules.
|
|
132 |
*/
|
|
133 |
public void clearRules() {
|
|
134 |
rules.clear();
|
|
135 |
}
|
|
136 |
|
|
137 |
/**
|
|
138 |
* Retrieve all knowledge base rules contributed by a plugin.
|
|
139 |
* @param pluginID - ID of contributing plugin
|
|
140 |
* @return all knowledge base rules contributed by a plugin
|
|
141 |
*/
|
|
142 |
public ArrayList<CSKbRule> getPluginRules(String pluginID) {
|
|
143 |
if (rules.isEmpty()) {
|
|
144 |
return null;
|
|
145 |
}
|
|
146 |
|
|
147 |
ArrayList<CSKbRule> pluginRules = new ArrayList<CSKbRule>();
|
|
148 |
Iterator<CSKbRule> iterator = rules.iterator();
|
|
149 |
while (iterator.hasNext()) {
|
|
150 |
CSKbRule rule = iterator.next();
|
|
151 |
if (rule.getPluginId().equals(pluginID)) {
|
|
152 |
pluginRules.add(rule);
|
|
153 |
}
|
|
154 |
}
|
|
155 |
return pluginRules;
|
|
156 |
}
|
|
157 |
|
|
158 |
/**
|
|
159 |
* Find a knowledge base rule by its name.
|
|
160 |
* @param name - name of rule
|
|
161 |
* @return knowledge base rule with matching name
|
|
162 |
*/
|
|
163 |
public CSKbRule getRule(String name) {
|
|
164 |
Iterator<CSKbRule> iterator = rules.iterator();
|
|
165 |
while (iterator.hasNext()) {
|
|
166 |
CSKbRule rule = iterator.next();
|
|
167 |
if (rule.getName().equals(name)) {
|
|
168 |
return rule;
|
|
169 |
}
|
|
170 |
}
|
|
171 |
return null;
|
|
172 |
}
|
|
173 |
|
|
174 |
/**
|
|
175 |
* Retrieve all knowledge base rules.
|
|
176 |
* @return all knowledge base rules
|
|
177 |
*/
|
|
178 |
public ArrayList<CSKbRule> getRules() {
|
|
179 |
if (rules.isEmpty()) {
|
|
180 |
return null;
|
|
181 |
}
|
|
182 |
else {
|
|
183 |
return rules;
|
|
184 |
}
|
|
185 |
}
|
|
186 |
|
|
187 |
/**
|
|
188 |
* Remove a knowledge base rule.
|
|
189 |
* @param name - name of the rule to be removed.
|
|
190 |
*/
|
|
191 |
public void removeRule(String name) {
|
|
192 |
CSKbRule found = null;
|
|
193 |
Iterator<CSKbRule> iterator = rules.iterator();
|
|
194 |
while (iterator.hasNext()) {
|
|
195 |
CSKbRule current = iterator.next();
|
|
196 |
if (current.getName().equals(name)) {
|
|
197 |
found = current;
|
|
198 |
}
|
|
199 |
}
|
|
200 |
|
|
201 |
if (found != null) {
|
|
202 |
rules.remove(found);
|
|
203 |
}
|
|
204 |
}
|
|
205 |
|
|
206 |
/**
|
|
207 |
* Remove a collection of knowledge base rules.
|
|
208 |
* @param rules - knowledge base rules to be removed.
|
|
209 |
*/
|
|
210 |
public void removeRules(ArrayList<CSKbRule> rules) {
|
|
211 |
this.rules.removeAll(rules);
|
|
212 |
}
|
|
213 |
|
|
214 |
/**
|
|
215 |
* Remove all knowledge base rules contributed by a plugin.
|
|
216 |
* @param pluginID - ID of contributing plugin
|
|
217 |
*/
|
|
218 |
public void removeAllPluginRules(String pluginID) {
|
|
219 |
ArrayList<CSKbRule> pluginRules = getPluginRules(pluginID);
|
|
220 |
rules.removeAll(pluginRules);
|
|
221 |
}
|
|
222 |
|
|
223 |
/**
|
|
224 |
* Copy a collection of knowledge base rules.
|
|
225 |
* @param rules - knowledge base rules to be copied.
|
|
226 |
*/
|
|
227 |
@SuppressWarnings("unchecked")
|
|
228 |
public void setRules(ArrayList<CSKbRule> rules) {
|
|
229 |
Object object = rules.clone();
|
|
230 |
if (object instanceof ArrayList) {
|
|
231 |
this.rules = (ArrayList<CSKbRule>)object;
|
|
232 |
}
|
|
233 |
}
|
|
234 |
|
|
235 |
/**
|
|
236 |
* Add knowledge base rules to CodeScanner configuration settings.
|
|
237 |
* @param configSettings - configuration settings to be updated.
|
|
238 |
*/
|
|
239 |
public void addKBaseRulesToConfigSettings(IProject project, CSConfigSettings configSettings) {
|
|
240 |
readRulesFromPlugins();
|
|
241 |
filterRulesforSDKs(getSDKVersions(project));
|
|
242 |
|
|
243 |
if (rules.size() > 0) {
|
|
244 |
EList<CustomruleType> customRuleList = configSettings.getCustomRules().getCustomrule();
|
|
245 |
customRuleList.clear();
|
|
246 |
for (Iterator<CSKbRule> ruleIterator = rules.iterator(); ruleIterator.hasNext();) {
|
|
247 |
CSKbRule kbRule = ruleIterator.next();
|
|
248 |
CustomruleType customRule = CSConfigFactory.eINSTANCE.createCustomruleType();
|
|
249 |
customRule.setDescription(kbRule.getDescription());
|
|
250 |
customRule.setLink(kbRule.getLink());
|
|
251 |
customRule.setName(kbRule.getName());
|
|
252 |
customRule.setSeverity(kbRule.getSeverity());
|
|
253 |
customRule.setTitle(kbRule.getTitle());
|
|
254 |
|
|
255 |
EList<KeywordType> keywordList = customRule.getKeyword();
|
|
256 |
keywordList.clear();
|
|
257 |
ArrayList<CSKbRuleKeyword> keywords = kbRule.getKeywords();
|
|
258 |
for (Iterator<CSKbRuleKeyword> keywordIterator = keywords.iterator(); keywordIterator.hasNext();) {
|
|
259 |
CSKbRuleKeyword kbaseKeyword = keywordIterator.next();
|
|
260 |
KeywordType customKeyword = CSConfigFactory.eINSTANCE.createKeywordType();
|
|
261 |
customKeyword.setType(kbaseKeyword.getType());
|
|
262 |
customKeyword.setValue(kbaseKeyword.getContent());
|
|
263 |
keywordList.add(customKeyword);
|
|
264 |
}
|
|
265 |
|
|
266 |
EList<String> filetypeList = customRule.getFiletype();
|
|
267 |
filetypeList.clear();
|
|
268 |
filetypeList.addAll(kbRule.getFileTypes());
|
|
269 |
|
|
270 |
customRuleList.add(customRule);
|
|
271 |
}
|
|
272 |
}
|
|
273 |
}
|
|
274 |
|
|
275 |
/**
|
|
276 |
* Retrieve knowledge base rules from contributing plugins using the knowledge base extension.
|
|
277 |
*/
|
|
278 |
@SuppressWarnings("unchecked")
|
|
279 |
public void readRulesFromPlugins() {
|
|
280 |
IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();
|
|
281 |
IExtensionPoint extensionPoint = extensionRegistry.getExtensionPoint(KBASE_EXTENSION_ID);
|
|
282 |
IExtension[] extensions = extensionPoint.getExtensions();
|
|
283 |
|
|
284 |
for (int i = 0; i < extensions.length; i++) {
|
|
285 |
IExtension extension = extensions[i];
|
|
286 |
String pluginID = extension.getNamespaceIdentifier();
|
|
287 |
Bundle bundle = Platform.getBundle(pluginID);
|
|
288 |
CSKbPluginInfo kbPluginInfo = new CSKbPluginInfo(pluginID, getBundleVersion(bundle));
|
|
289 |
pluginInfoList.add(kbPluginInfo);
|
|
290 |
|
|
291 |
IConfigurationElement[] elements = extension.getConfigurationElements();
|
|
292 |
for (int j = 0; j < elements.length; j++) {
|
|
293 |
String location = elements[j].getAttribute(LOCATION);
|
|
294 |
Enumeration e = bundle.findEntries(location, KBDATA_FILE_FILTER, false);
|
|
295 |
while (e!= null && e.hasMoreElements()) {
|
|
296 |
URL url = (URL)e.nextElement();
|
|
297 |
if (url != null) {
|
|
298 |
KbdataType kbdata = loadKbdata(url, pluginID);
|
|
299 |
if (kbdata != null) {
|
|
300 |
CSKbRule rule = createKbRule(kbdata);
|
|
301 |
rule.setPluginId(pluginID);
|
|
302 |
addRule(rule);
|
|
303 |
}
|
|
304 |
}
|
|
305 |
}
|
|
306 |
}
|
|
307 |
}
|
|
308 |
}
|
|
309 |
|
|
310 |
/**
|
|
311 |
* Filter knowledge base rules for a list of SDK versions.
|
|
312 |
* @param sdkVersions - list of SDK versions.
|
|
313 |
*/
|
|
314 |
private void filterRulesforSDKs(ArrayList<Version> sdkVersions) {
|
|
315 |
ArrayList<CSKbRule> filteredRules = new ArrayList<CSKbRule>();
|
|
316 |
for (Iterator<CSKbRule> ruleIterator = rules.iterator(); ruleIterator.hasNext();) {
|
|
317 |
CSKbRule kbRule = ruleIterator.next();
|
|
318 |
ArrayList<Version> platforms = kbRule.getPlatforms();
|
|
319 |
boolean remove = true;
|
|
320 |
for (Iterator<Version> pfIterator = platforms.iterator(); pfIterator.hasNext();) {
|
|
321 |
Version platform = pfIterator.next();
|
|
322 |
if (sdkVersions.contains(platform)) {
|
|
323 |
remove = false;
|
|
324 |
}
|
|
325 |
}
|
|
326 |
if (remove) {
|
|
327 |
filteredRules.add(kbRule);
|
|
328 |
}
|
|
329 |
}
|
|
330 |
removeRules(filteredRules);
|
|
331 |
}
|
|
332 |
|
|
333 |
/**
|
|
334 |
* Create a knowledge base rule using knowledge base data.
|
|
335 |
* @param kbdata - knowledge base data
|
|
336 |
* @return a knowledge base rule
|
|
337 |
*/
|
|
338 |
private CSKbRule createKbRule(KbdataType kbdata) {
|
|
339 |
CSKbRule rule = new CSKbRule();
|
|
340 |
rule.setName(kbdata.getId());
|
|
341 |
KbdataBodyType kbdataBody = kbdata.getKbdataBody();
|
|
342 |
EList<KbdataMetadataType> metaDataList = kbdataBody.getKbdataMetadata();
|
|
343 |
for (Iterator<KbdataMetadataType> iterator1 = metaDataList.iterator(); iterator1.hasNext();) {
|
|
344 |
KbdataMetadataType metaData = iterator1.next();
|
|
345 |
KbdataKeywordsType keywordObject = metaData.getKbdataKeywords();
|
|
346 |
ArrayList<CSKbRuleKeyword> keywords = readKbRuleKeywords(keywordObject);
|
|
347 |
ArrayList<String> filetypes = readFileTypes(keywordObject);
|
|
348 |
ArrayList<Version> platforms = readKbdataPlatforms(keywordObject);
|
|
349 |
rule.setFileTypes(filetypes);
|
|
350 |
rule.setKeywords(keywords);
|
|
351 |
rule.setPlatforms(platforms);
|
|
352 |
}
|
|
353 |
EList<MessagesType> messageList = kbdataBody.getMessages();
|
|
354 |
for (Iterator<MessagesType> iterator2 = messageList.iterator(); iterator2.hasNext();) {
|
|
355 |
MessagesType message = iterator2.next();
|
|
356 |
String severity = readSeverity(message);
|
|
357 |
String title = readTitle(message);
|
|
358 |
String description = readDescription(message);
|
|
359 |
String link = readLink(message);
|
|
360 |
rule.setSeverity(severity);
|
|
361 |
rule.setTitle(title);
|
|
362 |
rule.setDescription(description);
|
|
363 |
rule.setLink(link);
|
|
364 |
}
|
|
365 |
return rule;
|
|
366 |
}
|
|
367 |
|
|
368 |
|
|
369 |
|
|
370 |
/**
|
|
371 |
* Retrieve bundle version from a given bundle.
|
|
372 |
* @param bundle - target bundle
|
|
373 |
* @return bundle version
|
|
374 |
*/
|
|
375 |
@SuppressWarnings("unchecked")
|
|
376 |
private String getBundleVersion(Bundle bundle) {
|
|
377 |
String version = "0.0"; //$NON-NLS-1$
|
|
378 |
Dictionary bundleHeaders = bundle.getHeaders();
|
|
379 |
if (bundleHeaders != null) {
|
|
380 |
version = (String) bundleHeaders.get("Bundle-Version");
|
|
381 |
}
|
|
382 |
return version;
|
|
383 |
}
|
|
384 |
|
|
385 |
/**
|
|
386 |
* Retrieve SDK versions from the build configurations of a project.
|
|
387 |
* @param project - project in question
|
|
388 |
* @return list of SDK versions
|
|
389 |
*/
|
|
390 |
private ArrayList<Version> getSDKVersions(IProject project) {
|
|
391 |
ArrayList<Version> sdkVersions = new ArrayList<Version>();
|
|
392 |
ICarbideProjectInfo projectInfo = CarbideBuilderPlugin.getBuildManager().getProjectInfo(project);
|
|
393 |
if (projectInfo != null) {
|
|
394 |
List<ICarbideBuildConfiguration> buildConfigList = projectInfo.getBuildConfigurations();
|
|
395 |
for (Iterator<ICarbideBuildConfiguration> iterator = buildConfigList.iterator(); iterator.hasNext();) {
|
|
396 |
ICarbideBuildConfiguration buildConfig = iterator.next();
|
1462
|
397 |
Version version = buildConfig.getSDK().getSDKVersion();
|
|
398 |
sdkVersions.add(version);
|
2
|
399 |
}
|
|
400 |
}
|
|
401 |
|
|
402 |
return sdkVersions;
|
|
403 |
}
|
|
404 |
|
|
405 |
/**
|
|
406 |
* Load data from a knowledge base data file.
|
|
407 |
* @param url - url of knowledge base data file
|
|
408 |
* @param pluginID - unique ID of the plugin containing the knowledge base data file
|
|
409 |
* @return knowledge base data
|
|
410 |
*/
|
|
411 |
@SuppressWarnings("static-access")
|
|
412 |
private KbdataType loadKbdata(URL url, String pluginID) {
|
|
413 |
KbdataType kbdata = null;
|
|
414 |
try {
|
|
415 |
kbdata = CSKbdataXMLLoader.loadKbdata(url);
|
|
416 |
}
|
|
417 |
catch (Exception e) {
|
|
418 |
String format = Messages.getString("KbManager.LoadFailMessage");
|
|
419 |
String message = MessageFormat.format(format, url.getFile(), pluginID);
|
|
420 |
IStatus status = new Status(Status.ERROR, CSPlugin.getDefault().PLUGIN_ID, message, e);
|
|
421 |
CSPlugin.getDefault().getLog().log(status);
|
|
422 |
}
|
|
423 |
return kbdata;
|
|
424 |
}
|
|
425 |
|
|
426 |
/**
|
|
427 |
* Read the knowledge base keywords.
|
|
428 |
* @param keywordObject - knowledge base keyword object
|
|
429 |
* @return a list of knowledge base keywords
|
|
430 |
*/
|
|
431 |
private ArrayList<CSKbRuleKeyword> readKbRuleKeywords(KbdataKeywordsType keywordObject) {
|
|
432 |
ArrayList<CSKbRuleKeyword> keywordList = new ArrayList<CSKbRuleKeyword>();
|
|
433 |
CallType call = keywordObject.getCall();
|
|
434 |
if (call != null) {
|
|
435 |
Object object = call.getMixed().getValue(0);
|
|
436 |
if (object != null && object instanceof String) {
|
|
437 |
keywordList.add(new CSKbRuleKeyword((String)object, KEYWORDTYPE_CALL));
|
|
438 |
}
|
|
439 |
}
|
|
440 |
ClassType class_ = keywordObject.getClass_();
|
|
441 |
if (class_ != null) {
|
|
442 |
Object object = class_.getMixed().getValue(0);
|
|
443 |
if (object != null && object instanceof String) {
|
|
444 |
keywordList.add(new CSKbRuleKeyword((String)object, KEYWORDTYPE_CLASS));
|
|
445 |
}
|
|
446 |
}
|
|
447 |
CommentType comment = keywordObject.getComment();
|
|
448 |
if (comment != null) {
|
|
449 |
Object object = comment.getMixed().getValue(0);
|
|
450 |
if (object != null && object instanceof String) {
|
|
451 |
keywordList.add(new CSKbRuleKeyword((String)object, KEYWORDTYPE_COMMENT));
|
|
452 |
}
|
|
453 |
}
|
|
454 |
InheritanceType inheritance = keywordObject.getInheritance();
|
|
455 |
if (inheritance != null) {
|
|
456 |
Object object = inheritance.getMixed().getValue(0);
|
|
457 |
if (object != null && object instanceof String) {
|
|
458 |
keywordList.add(new CSKbRuleKeyword((String)object, KEYWORDTYPE_BASECLASS));
|
|
459 |
}
|
|
460 |
}
|
|
461 |
KbdataKeywordType kbdataKeyword = keywordObject.getKbdataKeyword();
|
|
462 |
if (kbdataKeyword != null) {
|
|
463 |
Object object = kbdataKeyword.getMixed().getValue(0);
|
|
464 |
if (object != null && object instanceof String) {
|
|
465 |
keywordList.add(new CSKbRuleKeyword((String)object, KEYWORDTYPE_GENERIC));
|
|
466 |
}
|
|
467 |
}
|
|
468 |
LocalType local = keywordObject.getLocal();
|
|
469 |
if (local != null) {
|
|
470 |
Object object = local.getMixed().getValue(0);
|
|
471 |
if (object != null && object instanceof String) {
|
|
472 |
keywordList.add(new CSKbRuleKeyword((String)object, KEYWORDTYPE_LOCAL));
|
|
473 |
}
|
|
474 |
}
|
|
475 |
MacroType macro = keywordObject.getMacro();
|
|
476 |
if (macro != null) {
|
|
477 |
Object object = macro.getMixed().getValue(0);
|
|
478 |
if (object != null && object instanceof String) {
|
|
479 |
keywordList.add(new CSKbRuleKeyword((String)object, KEYWORDTYPE_MACRO));
|
|
480 |
}
|
|
481 |
}
|
|
482 |
MemberType member = keywordObject.getMember();
|
|
483 |
if (member != null) {
|
|
484 |
Object object = member.getMixed().getValue(0);
|
|
485 |
if (object != null && object instanceof String) {
|
|
486 |
keywordList.add(new CSKbRuleKeyword((String)object, KEYWORDTYPE_MEMBER));
|
|
487 |
}
|
|
488 |
}
|
|
489 |
MethodType method = keywordObject.getMethod();
|
|
490 |
if (method != null) {
|
|
491 |
Object object = method.getMixed().getValue(0);
|
|
492 |
if (object != null && object instanceof String) {
|
|
493 |
keywordList.add(new CSKbRuleKeyword((String)object, KEYWORDTYPE_METHOD));
|
|
494 |
}
|
|
495 |
}
|
|
496 |
ParameterType parameter = keywordObject.getParameter();
|
|
497 |
if (parameter != null) {
|
|
498 |
Object object = parameter.getMixed().getValue(0);
|
|
499 |
if (object != null && object instanceof String) {
|
|
500 |
keywordList.add(new CSKbRuleKeyword((String)object, KEYWORDTYPE_PARAMETER));
|
|
501 |
}
|
|
502 |
}
|
|
503 |
return keywordList;
|
|
504 |
}
|
|
505 |
|
|
506 |
/**
|
|
507 |
* Read the platforms associated with a knowledge base rule.
|
|
508 |
* @param keywordObject - knowledge base keyword object
|
|
509 |
* @return a list of platforms
|
|
510 |
*/
|
|
511 |
private ArrayList<Version> readKbdataPlatforms(KbdataKeywordsType keywordObject) {
|
|
512 |
EList<KbdataPlatformType> platforms = keywordObject.getKbdataPlatform();
|
|
513 |
ArrayList<Version> platformList = null;
|
|
514 |
if (platforms != null) {
|
|
515 |
platformList = new ArrayList<Version>();
|
|
516 |
for (Iterator<KbdataPlatformType> iterator = platforms.iterator(); iterator.hasNext();) {
|
|
517 |
KbdataPlatformType platform = iterator.next();
|
|
518 |
Object object = platform.getMixed().getValue(0);
|
|
519 |
if (object != null && object instanceof String) {
|
|
520 |
try {
|
|
521 |
Version version = new Version((String)object);
|
|
522 |
platformList.add(version);
|
|
523 |
}
|
|
524 |
catch (IllegalArgumentException e) {
|
|
525 |
platformList.add(new Version("0.0.0"));
|
|
526 |
}
|
|
527 |
}
|
|
528 |
}
|
|
529 |
|
|
530 |
}
|
|
531 |
return platformList;
|
|
532 |
}
|
|
533 |
|
|
534 |
/**
|
|
535 |
* Read the file types associated with a knowledge base.
|
|
536 |
* @param keywordObject - knowledge base keyword object
|
|
537 |
* @return a list of file types, or <code>null</code> if none
|
|
538 |
*/
|
|
539 |
private ArrayList<String> readFileTypes(KbdataKeywordsType keywordObject) {
|
|
540 |
EList<FiletypeType> fileTypes = keywordObject.getFiletype();
|
|
541 |
ArrayList<String> fileTypeList = null;
|
|
542 |
if (fileTypes != null) {
|
|
543 |
fileTypeList = new ArrayList<String>();
|
|
544 |
for (Iterator<FiletypeType> iterator = fileTypes.iterator(); iterator.hasNext();) {
|
|
545 |
FiletypeType fileType = iterator.next();
|
|
546 |
Object object = fileType.getMixed().getValue(0);
|
|
547 |
if (object != null && object instanceof String) {
|
|
548 |
fileTypeList.add((String)object);
|
|
549 |
}
|
|
550 |
}
|
|
551 |
}
|
|
552 |
return fileTypeList;
|
|
553 |
}
|
|
554 |
|
|
555 |
/**
|
|
556 |
* Read the severity level of a knowledge base rule.
|
|
557 |
* @param message - knowledge base message object
|
|
558 |
* @return severity level
|
|
559 |
*/
|
|
560 |
private String readSeverity(MessagesType message) {
|
|
561 |
String severity = SEVERITY_LOW;
|
|
562 |
KbdataCategoryType category = message.getKbdataCategory();
|
|
563 |
if (category != null) {
|
|
564 |
Object object = category.getMixed().getValue(0);
|
|
565 |
if (object != null && object instanceof String) {
|
|
566 |
String categoryString = (String)object;
|
|
567 |
if (categoryString.toLowerCase().equals(CATEGORY_ERROR)) {
|
|
568 |
severity = SEVERITY_HIGH;
|
|
569 |
}
|
|
570 |
else if (categoryString.toLowerCase().equals(CATEGORY_WARNING)) {
|
|
571 |
severity = SEVERITY_MEDIUM;
|
|
572 |
}
|
|
573 |
else if (categoryString.toLowerCase().equals(CATEGORY_INFORMATION)) {
|
|
574 |
severity = SEVERITY_LOW;
|
|
575 |
}
|
|
576 |
}
|
|
577 |
}
|
|
578 |
return severity;
|
|
579 |
}
|
|
580 |
|
|
581 |
/**
|
|
582 |
* Read the message title of a knowledge base rule.
|
|
583 |
* @param message - knowledge base message object
|
|
584 |
* @return message title
|
|
585 |
*/
|
|
586 |
private String readTitle(MessagesType message) {
|
|
587 |
String title = " ";
|
|
588 |
SymptomType symptom = message.getSymptom();
|
|
589 |
if (symptom != null) {
|
|
590 |
Object object = symptom.getMixed().getValue(0);
|
|
591 |
if (object != null && object instanceof String) {
|
|
592 |
title = (String)object;
|
|
593 |
}
|
|
594 |
}
|
|
595 |
return title;
|
|
596 |
}
|
|
597 |
|
|
598 |
/**
|
|
599 |
* Read the description of a knowledge base rule.
|
|
600 |
* @param message - knowledge base message object
|
|
601 |
* @return description
|
|
602 |
*/
|
|
603 |
private String readDescription(MessagesType message) {
|
|
604 |
String description = " ";
|
|
605 |
SolutionType solution = message.getSolution();
|
|
606 |
if (solution != null) {
|
|
607 |
Object object = solution.getMixed().getValue(0);
|
|
608 |
if (object != null && object instanceof String) {
|
|
609 |
description = (String)object;
|
|
610 |
}
|
|
611 |
}
|
|
612 |
return description;
|
|
613 |
}
|
|
614 |
|
|
615 |
/**
|
|
616 |
* Read the external link of a knowledge base rule.
|
|
617 |
* @param message - knowledge base message object
|
|
618 |
* @return external link, or <code>null</code> if none
|
|
619 |
*/
|
|
620 |
private String readLink(MessagesType message) {
|
|
621 |
String link = null;
|
|
622 |
KbdataRefType reference = message.getKbdataRef();
|
|
623 |
if (reference != null) {
|
|
624 |
Object object = reference.getHref();
|
|
625 |
if (object != null && object instanceof String) {
|
|
626 |
link = (String)object;
|
|
627 |
}
|
|
628 |
}
|
|
629 |
return link;
|
|
630 |
}
|
|
631 |
}
|