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