01: /*
02:
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
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.8 2006/10/16 12:56:57 pierre Exp $
24: * @since MMBase-1.7
25: */
26: public class BasicLegacyConstraint extends BasicConstraint implements
27: LegacyConstraint {
28:
29: /** Logger instance. */
30: private static final Logger log = Logging
31: .getLoggerInstance(BasicLegacyConstraint.class);
32:
33: /** The constraint. */
34: private String constraint = null;
35:
36: /**
37: * Constructor.
38: *
39: * @param constraint The non-null constraint as it appears in
40: * the where-clause.
41: * @throws IllegalArgumentException When an invalid argument is supplied.
42: */
43: public BasicLegacyConstraint(String constraint) {
44: setConstraint(constraint);
45: }
46:
47: /**
48: * Sets the constraint.
49: *
50: * @param constraint The non-null constraint as it appears in
51: * the where-clause (may also not be empty string)
52: * @return This <code>BasicLegacyConstraint</code> instance.
53: * @throws IllegalArgumentException When an invalid argument is supplied.
54: */
55: public BasicLegacyConstraint setConstraint(String constraint) {
56: if (log.isDebugEnabled()) {
57: log.debug("Legacy constraint: " + constraint);
58: }
59: // Test constraint is not null or empty (empty goes wrong in composite constraints)
60: if (constraint == null || constraint.equals("")) {
61: throw new IllegalArgumentException(
62: "Invalid constraint value: " + constraint);
63: }
64:
65: this .constraint = constraint;
66: return this ;
67: }
68:
69: // javadoc is inherited
70: public String getConstraint() {
71: return constraint;
72: }
73:
74: // javadoc is inherited
75: public boolean equals(Object obj) {
76: // Must be same class (subclasses should override this)!
77: if (obj != null && obj.getClass() == getClass()) {
78: BasicLegacyConstraint lc = (BasicLegacyConstraint) obj;
79: return isInverse() == lc.isInverse()
80: && constraint.equals(lc.getConstraint());
81: } else {
82: return false;
83: }
84: }
85:
86: // javadoc is inherited
87: public int hashCode() {
88: return 31 * (constraint.hashCode() + super .hashCode());
89: }
90:
91: // javadoc is inherited
92: public String toString() {
93: StringBuilder sb = new StringBuilder(
94: "LegacyConstraint(inverse:").append(isInverse())
95: .append(", constraint:").append(getConstraint())
96: .append(")");
97: return sb.toString();
98: }
99: }
|