KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: EntityConditionFunction.java 5831 2005-09-26 06:52:24Z jonesde $
3  *
4  * Copyright (c) 2002 The Open For Business Project - www.ofbiz.org
5  *
6  * 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  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * 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
25 package org.ofbiz.entity.condition;
26
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.model.ModelEntity;
33
34 /**
35  * Encapsulates operations between entities and entity fields. This is a immutable class.
36  *
37  *@author <a HREF='mailto:chris_maurer@altavista.com'>Chris Maurer</a>
38  *@author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
39  *@author <a HREF="mailto:jaz@jflow.net">Andy Zeneski</a>
40  *@created Nov 5, 2001
41  *@version 1.0
42  */

43 public abstract class EntityConditionFunction extends EntityCondition {
44
45     public static final int ID_NOT = 1;
46
47     public static class NOT extends EntityConditionFunction {
48         public NOT(EntityCondition nested) { super(ID_NOT, "NOT", nested); }
49         public boolean mapMatches(GenericDelegator delegator, Map JavaDoc map) {
50             return !condition.mapMatches(delegator, map);
51         }
52         public EntityCondition freeze() {
53             return new NOT(condition.freeze());
54         }
55         public void encryptConditionFields(ModelEntity modelEntity, GenericDelegator delegator) {
56             // nothing to do here...
57
}
58     };
59
60     protected int idInt;
61     protected String JavaDoc codeString;
62     protected EntityCondition condition;
63
64     protected EntityConditionFunction(int id, String JavaDoc code, EntityCondition condition) {
65         idInt = id;
66         codeString = code;
67         this.condition = condition;
68     }
69
70     public String JavaDoc getCode() {
71         if (codeString == null)
72             return "null";
73         else
74             return codeString;
75     }
76
77     public int getId() {
78         return idInt;
79     }
80
81     public void visit(EntityConditionVisitor visitor) {
82         visitor.acceptEntityConditionFunction(this, condition);
83     }
84
85     public boolean equals(Object JavaDoc obj) {
86         if (!(obj instanceof EntityConditionFunction)) return false;
87         EntityConditionFunction otherFunc = (EntityConditionFunction) obj;
88         return
89             this.idInt == otherFunc.idInt
90             && ( this.condition != null ? condition.equals( otherFunc.condition ) : otherFunc.condition != null );
91     }
92
93     public int hashCode() {
94         return idInt ^ condition.hashCode();
95     }
96
97     public String JavaDoc makeWhereString(ModelEntity modelEntity, List JavaDoc entityConditionParams) {
98         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
99         sb.append(codeString).append('(');
100         sb.append(condition.makeWhereString(modelEntity, entityConditionParams));
101         sb.append(')');
102         return sb.toString();
103     }
104
105     public void checkCondition(ModelEntity modelEntity) throws GenericModelException {
106         condition.checkCondition(modelEntity);
107     }
108 }
109
Popular Tags