KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > archive > crawler > settings > LegalValueTypeConstraint


1 /*
2  * legalValueListConstraint
3  *
4  * $Id: LegalValueTypeConstraint.java,v 1.4 2005/07/06 19:23:52 stack-sf Exp $
5  *
6  * Created on Mar 30, 2004
7  *
8  * Copyright (C) 2004 Internet Archive.
9  *
10  * This file is part of the Heritrix web crawler (crawler.archive.org).
11  *
12  * Heritrix is free software; you can redistribute it and/or modify it under the
13  * terms of the GNU Lesser Public License as published by the Free Software
14  * Foundation; either version 2.1 of the License, or any later version.
15  *
16  * Heritrix is distributed in the hope that it will be useful, but WITHOUT ANY
17  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18  * A PARTICULAR PURPOSE. See the GNU Lesser Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser Public License along with
21  * Heritrix; if not, write to the Free Software Foundation, Inc., 59 Temple
22  * Place, Suite 330, Boston, MA 02111-1307 USA
23  */

24 package org.archive.crawler.settings;
25
26 import java.io.Serializable JavaDoc;
27 import java.util.logging.Level JavaDoc;
28
29 /**
30  * A constraint that checks that an attribute value is of the right type
31  *
32  * @author John Erik Halse
33  */

34 public class LegalValueTypeConstraint
35 extends Constraint implements Serializable JavaDoc {
36     private static final long serialVersionUID = 6106774072922858976L;
37
38     /**
39      * Constructs a new LegalValueListConstraint.
40      *
41      * @param level the severity level.
42      * @param msg the default error message.
43      */

44     public LegalValueTypeConstraint(Level JavaDoc level, String JavaDoc msg) {
45         super(level, msg);
46     }
47
48     /**
49      * Constructs a new LegalValueListConstraint using default severity level
50      * ({@link Level#WARNING}).
51      *
52      * @param msg the default error message.
53      */

54     public LegalValueTypeConstraint(String JavaDoc msg) {
55         this(Level.SEVERE, msg);
56     }
57
58     /**
59      * Constructs a new LegalValueListConstraint using default error message.
60      *
61      * @param level
62      */

63     public LegalValueTypeConstraint(Level JavaDoc level) {
64         this(level, "Value of illegal type: ''{3}'', ''{4}'' was expected.");
65     }
66
67     /**
68      * Constructs a new LegalValueListConstraint using default severity level
69      * ({@link Level#WARNING}) and default error message.
70      *
71      */

72     public LegalValueTypeConstraint() {
73         this(Level.SEVERE);
74     }
75
76     public FailedCheck innerCheck(CrawlerSettings settings, ComplexType owner,
77             Type definition, Object JavaDoc value) {
78         FailedCheck res = null;
79
80         // Check that the value is of right type
81
if (!definition.getLegalValueType().isInstance(value)) {
82             res = new FailedCheck(settings, owner, definition, value);
83             res.messageArguments.add((value != null)?
84                 value.getClass().getName(): "null");
85             res.messageArguments.add(definition.getLegalValueType().getName());
86         }
87         return res;
88     }
89 }
Popular Tags