KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > se > query > constraint > ConstraintImpl


1 /*
2  * Jalisto - JAva LIght STOrage
3  * Copyright (C) 2000-2005 Xcalia http://www.xcalia.com
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Xcalia
20  * 71, rue Desnouettes
21  * 75014 Paris - France
22  * http://www.xcalia.com
23  */

24 package org.objectweb.jalisto.se.query.constraint;
25
26 import org.objectweb.jalisto.se.api.Session;
27 import org.objectweb.jalisto.se.api.query.FielComparator;
28 import org.objectweb.jalisto.se.api.query.Constraint;
29 import org.objectweb.jalisto.se.query.exception.QueryEngineException;
30
31 import java.util.HashSet JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import java.util.Set JavaDoc;
34
35 public class ConstraintImpl implements Constraint {
36     public ConstraintImpl() {
37         this.fathers = new HashSet JavaDoc();
38     }
39
40     public Constraint and(Constraint with) {
41         BinaryBooleanOperatorConstraint binaryConstraint =
42                 new BinaryBooleanOperatorConstraint(this, with, BinaryBooleanOperatorConstraint.AND_OP);
43         fathers.add(binaryConstraint);
44         ((ConstraintImpl) with).addBinaryConstraint(binaryConstraint);
45         return binaryConstraint;
46     }
47
48     public Constraint or(Constraint with) {
49         BinaryBooleanOperatorConstraint binaryConstraint =
50                 new BinaryBooleanOperatorConstraint(this, with, BinaryBooleanOperatorConstraint.OR_OP);
51         fathers.add(binaryConstraint);
52         ((ConstraintImpl) with).addBinaryConstraint(binaryConstraint);
53         return binaryConstraint;
54     }
55
56     public Constraint equal() {
57         throw new QueryEngineException();
58     }
59
60     public Constraint greater() {
61         throw new QueryEngineException();
62     }
63
64     public Constraint smaller() {
65         throw new QueryEngineException();
66     }
67
68     public Constraint identity() {
69         throw new QueryEngineException();
70     }
71
72     public Constraint like() {
73         throw new QueryEngineException();
74     }
75
76     public Constraint contains() {
77         throw new QueryEngineException();
78     }
79
80     public Constraint not() {
81         throw new QueryEngineException();
82     }
83
84     public Object JavaDoc getObject() {
85         throw new QueryEngineException();
86     }
87
88     public boolean execute(Session session, FielComparator comparator, Object JavaDoc candidate) {
89         return false;
90     }
91
92     protected void addBinaryConstraint(BinaryBooleanOperatorConstraint binaryConstraint) {
93         if (!fathers.contains(binaryConstraint)) {
94             fathers.add(binaryConstraint);
95         }
96     }
97
98     public Set JavaDoc getRootFathers() {
99         HashSet JavaDoc result = new HashSet JavaDoc();
100         if (!fathers.isEmpty()) {
101             Iterator JavaDoc bcIt = fathers.iterator();
102             while (bcIt.hasNext()) {
103                 BinaryBooleanOperatorConstraint bc = (BinaryBooleanOperatorConstraint) bcIt.next();
104                 result.addAll(bc.getRootFathers());
105             }
106         } else {
107             result.add(this);
108         }
109         return result;
110     }
111
112
113     protected Set JavaDoc fathers;
114 }
115
Popular Tags