KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > entity > condition > EntityCondition


1 /*
2  * $Id: EntityCondition.java 5831 2005-09-26 06:52:24Z jonesde $
3  *
4  * <p>Copyright (c) 2001 The Open For Business Project - www.ofbiz.org
5  *
6  * <p>Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * <p>The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */

24 package org.ofbiz.entity.condition;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.Map JavaDoc;
29
30 import org.ofbiz.entity.GenericDelegator;
31 import org.ofbiz.entity.GenericModelException;
32 import org.ofbiz.entity.GenericEntity;
33 import org.ofbiz.entity.model.ModelEntity;
34
35 /**
36  * Represents the conditions to be used to constrain a query
37  * <br/>An EntityCondition can represent various type of constraints, including:
38  * <ul>
39  * <li>EntityConditionList: a list of EntityConditions, combined with the operator specified
40  * <li>EntityExpr: for simple expressions or expressions that combine EntityConditions
41  * <li>EntityFieldMap: a map of fields where the field (key) equals the value, combined with the operator specified
42  * </ul>
43  * These can be used in various combinations using the EntityConditionList and EntityExpr objects.
44  *
45  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
46  * @version $Rev: 5831 $
47  * @since 2.0
48  */

49 public abstract class EntityCondition extends EntityConditionBase {
50
51     public String JavaDoc toString() {
52         return makeWhereString(null, new ArrayList JavaDoc());
53     }
54
55     public void accept(EntityConditionVisitor visitor) {
56         throw new IllegalArgumentException JavaDoc(getClass().getName() + ".accept not implemented");
57     }
58
59     abstract public String JavaDoc makeWhereString(ModelEntity modelEntity, List JavaDoc entityConditionParams);
60
61     abstract public void checkCondition(ModelEntity modelEntity) throws GenericModelException;
62
63     public boolean entityMatches(GenericEntity entity) {
64         return mapMatches(entity.getDelegator(), entity);
65     }
66
67     public Object JavaDoc eval(GenericEntity entity) {
68         return eval(entity.getDelegator(), entity);
69     }
70
71     public Object JavaDoc eval(GenericDelegator delegator, Map JavaDoc map) {
72         return mapMatches(delegator, map) ? Boolean.TRUE : Boolean.FALSE;
73     }
74
75     abstract public boolean mapMatches(GenericDelegator delegator, Map JavaDoc map);
76
77     abstract public EntityCondition freeze();
78
79     abstract public void encryptConditionFields(ModelEntity modelEntity, GenericDelegator delegator);
80     
81     public void visit(EntityConditionVisitor visitor) {
82         throw new IllegalArgumentException JavaDoc(getClass().getName() + ".visit not implemented");
83     }
84 }
85
Popular Tags