3
* $Date: 2007-01-04 18:46:10 +0100 (Thu, 04 Jan 2007) $
6
* Copyright (C) 2003-2007 The Chemistry Development Kit (CDK) project
8
* Contact: cdk-devel@lists.sourceforge.net
10
* This program is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU Lesser General Public License
12
* as published by the Free Software Foundation; either version 2.1
13
* of the License, or (at your option) any later version.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU Lesser General Public License for more details.
20
* You should have received a copy of the GNU Lesser General Public License
21
* along with this program; if not, write to the Free Software
22
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25
package org.openscience.cdk.validate;
27
import java.util.Iterator;
30
import org.openscience.cdk.interfaces.IChemObject;
31
import org.openscience.cdk.dict.DictionaryDatabase;
32
import org.openscience.cdk.tools.LoggingTool;
35
* Validates the existence of references to dictionaries.
37
* @author Egon Willighagen
38
* @cdk.created 2003-03-28
40
public class DictionaryValidator extends AbstractValidator {
42
private static LoggingTool logger;
45
logger = new LoggingTool(DictionaryValidator.class);
48
private DictionaryDatabase db;
50
public DictionaryValidator(DictionaryDatabase db) {
54
public ValidationReport validateChemObject(IChemObject subject) {
55
ValidationReport report = new ValidationReport();
56
Map properties = subject.getProperties();
57
Iterator iter = properties.keySet().iterator();
58
ValidationTest noNamespace = new ValidationTest(subject,
59
"Dictionary Reference lacks a namespace indicating the dictionary."
61
ValidationTest noDict = new ValidationTest(subject,
62
"The referenced dictionary does not exist."
64
ValidationTest noEntry = new ValidationTest(subject,
65
"The referenced entry does not exist in the dictionary."
67
while (iter.hasNext()) {
68
Object key = iter.next();
69
if (key instanceof String) {
70
String keyName = (String)key;
71
if (keyName.startsWith(DictionaryDatabase.DICTREFPROPERTYNAME)) {
72
String dictRef = (String)properties.get(keyName);
73
String details = "Dictref being anaylyzed: " + dictRef + ". ";
74
noNamespace.setDetails(details);
75
noDict.setDetails(details);
76
noEntry.setDetails(details);
77
int index = dictRef.indexOf(':');
79
report.addOK(noNamespace);
80
String dict = dictRef.substring(0,index);
81
logger.debug("Looking for dictionary:" + dict);
82
if (db.hasDictionary(dict)) {
84
if (dictRef.length() > index+1) {
85
String entry = dictRef.substring(index+1);
86
logger.debug("Looking for entry:" + entry);
87
if (db.hasEntry(dict, entry)) {
88
report.addOK(noEntry);
90
report.addError(noEntry);
93
report.addError(noEntry);
96
details += "The dictionary searched: " + dict + ".";
97
noDict.setDetails(details);
98
report.addError(noDict);
99
report.addError(noEntry);
102
// The dictRef has no namespace
103
details += "There is not a namespace given.";
104
noNamespace.setDetails(details);
105
report.addError(noNamespace);
106
report.addError(noDict);
107
report.addError(noEntry);