KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > storage > search > implementation > BasicLegacyConstraint


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9  */

10 package org.mmbase.storage.search.implementation;
11
12 import org.mmbase.storage.search.*;
13 import org.mmbase.util.logging.*;
14
15 /**
16  * Basic implementation.
17  * <p>
18  * <em>This constraint type is provided for the sole purpose of aligning
19  * existing legacy code with the new search query framework, and will
20  * eventually be phased out.</em>
21  *
22  * @author Rob van Maris
23  * @version $Id: BasicLegacyConstraint.java,v 1.7 2005/05/02 13:03:30 michiel Exp $
24  * @since MMBase-1.7
25  */

26 public class BasicLegacyConstraint extends BasicConstraint
27 implements LegacyConstraint {
28
29     /** Logger instance. */
30     private static final Logger log = Logging.getLoggerInstance(BasicLegacyConstraint.class);
31
32     /** The constraint. */
33     private String JavaDoc constraint = null;
34
35     /**
36      * Constructor.
37      *
38      * @param constraint The non-null constraint as it appears in
39      * the where-clause.
40      * @throws IllegalArgumentException When an invalid argument is supplied.
41      */

42     public BasicLegacyConstraint(String JavaDoc constraint) {
43         setConstraint(constraint);
44     }
45
46     /**
47      * Sets the constraint.
48      *
49      * @param constraint The non-null constraint as it appears in
50      * the where-clause (may also not be empty string)
51      * @return This <code>BasicLegacyConstraint</code> instance.
52      * @throws IllegalArgumentException When an invalid argument is supplied.
53      */

54     public BasicLegacyConstraint setConstraint(String JavaDoc constraint) {
55         if (log.isDebugEnabled()) {
56             log.debug("Legacy constraint: " + constraint);
57         }
58         // Test constraint is not null or empty (empty goes wrong in composite constraints)
59
if (constraint == null || constraint.equals("")) {
60             throw new IllegalArgumentException JavaDoc("Invalid constraint value: " + constraint);
61         }
62
63         this.constraint = constraint;
64         return this;
65     }
66
67     // javadoc is inherited
68
public String JavaDoc getConstraint() {
69         return constraint;
70     }
71
72     // javadoc is inherited
73
public boolean equals(Object JavaDoc obj) {
74         // Must be same class (subclasses should override this)!
75
if (obj != null && obj.getClass() == getClass()) {
76             BasicLegacyConstraint lc = (BasicLegacyConstraint) obj;
77             return isInverse() == lc.isInverse() && constraint.equals(lc.getConstraint());
78         } else {
79             return false;
80         }
81     }
82
83     // javadoc is inherited
84
public int hashCode() {
85         return 31 * (constraint.hashCode() + super.hashCode());
86     }
87
88     // javadoc is inherited
89
public String JavaDoc toString() {
90         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("LegacyConstraint(inverse:").
91         append(isInverse()).
92         append(", constraint:").append(getConstraint()).
93         append(")");
94         return sb.toString();
95     }
96 }
97
Popular Tags