KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: EntityClause.java 5462 2005-08-05 18:35:48Z 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
25 package org.ofbiz.entity.condition;
26
27
28 import org.ofbiz.entity.GenericEntityException;
29 import org.ofbiz.entity.model.ModelEntity;
30 import org.ofbiz.entity.model.ModelReader;
31
32
33 /**
34  * Generic Entity Clause - Used to string together entities to make a find clause
35  *
36  *@author <a HREF='mailto:chris_maurer@altavista.com'>Chris Maurer</a>
37  *@author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
38  *@created Mon Nov 5, 2001
39  *@version 1.0
40  */

41 public class EntityClause {
42
43     private String JavaDoc firstEntity = "";
44     private String JavaDoc secondEntity = "";
45     private String JavaDoc firstField = "";
46     private String JavaDoc secondField = "";
47     private ModelEntity firstModelEntity = null;
48     private ModelEntity secondModelEntity = null;
49     private EntityOperator interFieldOperation = null;
50     private EntityOperator intraFieldOperation = null;
51
52     private Object JavaDoc value = null;
53     public EntityClause() {}
54
55     public EntityClause(String JavaDoc firstEntity, String JavaDoc secondEntity, String JavaDoc firstField, String JavaDoc secondField, EntityOperator interFieldOperation, EntityOperator intraFieldOperation) {
56         this.firstEntity = firstEntity;
57         this.secondEntity = secondEntity;
58         this.firstField = firstField;
59         this.secondField = secondField;
60         this.interFieldOperation = interFieldOperation;
61         this.intraFieldOperation = intraFieldOperation;
62     }
63
64     public EntityClause(String JavaDoc firstEntity, String JavaDoc firstField, Object JavaDoc value, EntityOperator interFieldOperation, EntityOperator intraFieldOperation) {
65         this.firstEntity = firstEntity;
66         this.firstField = firstField;
67         this.value = value;
68         this.interFieldOperation = interFieldOperation;
69         this.intraFieldOperation = intraFieldOperation;
70     }
71
72     public String JavaDoc getFirstEntity() {
73         return firstEntity;
74     }
75
76     public String JavaDoc getSecondEntity() {
77         return secondEntity;
78     }
79
80     public String JavaDoc getFirstField() {
81         return firstField;
82     }
83
84     public String JavaDoc getSecondField() {
85         return secondField;
86     }
87
88     public Object JavaDoc getValue() {
89         if (value == null) value = new Object JavaDoc();
90         return value;
91     }
92
93     public EntityOperator getInterFieldOperation() {
94         return interFieldOperation;
95     }
96
97     public EntityOperator getIntraFieldOperation() {
98         return intraFieldOperation;
99     }
100
101     public void setFirstEntity(String JavaDoc firstEntity) {
102         this.firstEntity = firstEntity;
103     }
104
105     public void setSecondEntity(String JavaDoc secondEntity) {
106         this.secondEntity = secondEntity;
107     }
108
109     public void setFirstField(String JavaDoc firstField) {
110         this.firstField = firstField;
111     }
112
113     public void setSecondField(String JavaDoc secondField) {
114         this.secondField = secondField;
115     }
116
117     public void setInterFieldOperation(EntityOperator interFieldOperation) {
118         this.interFieldOperation = interFieldOperation;
119     }
120
121     public void setIntraFieldOperation(EntityOperator intraFieldOperation) {
122         this.intraFieldOperation = intraFieldOperation;
123     }
124
125     // -- Protected Methods - for internal use only --//
126
protected void setModelEntities(ModelReader modelReader) throws GenericEntityException {
127         firstModelEntity = (ModelEntity) modelReader.getModelEntity(firstEntity);
128         if (secondEntity != null && !secondEntity.equals("")) {
129             secondModelEntity = (ModelEntity) modelReader.getModelEntity(secondEntity);
130         }
131     }
132
133     protected ModelEntity getFirstModelEntity() {
134         return firstModelEntity;
135     }
136
137     protected ModelEntity getSecondModelEntity() {
138         return secondModelEntity;
139     }
140
141     public String JavaDoc toString() {
142         StringBuffer JavaDoc outputBuffer = new StringBuffer JavaDoc();
143
144         outputBuffer.append("[firstEntity," + (firstEntity == null ? "null" : firstEntity) + "]");
145         outputBuffer.append("[secondEntity," + (secondEntity == null ? "null" : secondEntity) + "]");
146         outputBuffer.append("[firstField," + (firstField == null ? "null" : firstField) + "]");
147         outputBuffer.append("[secondField," + (secondField == null ? "null" : secondField) + "]");
148         outputBuffer.append("[firstModelEntity," + (firstModelEntity == null ? "null" : (firstModelEntity.getEntityName() == null ? "null" : firstModelEntity.getEntityName())) + "]");
149         outputBuffer.append("[secondModelEntity," + (secondModelEntity == null ? "null" : (secondModelEntity.getEntityName() == null ? "null" : secondModelEntity.getEntityName())) + "]");
150         outputBuffer.append("[interFieldOperation," + (interFieldOperation == null ? "null" : (interFieldOperation.getCode() == null ? "null" : interFieldOperation.getCode())) + "]");
151         outputBuffer.append("[intraFieldOperation," + (intraFieldOperation == null ? "null" : (intraFieldOperation.getCode() == null ? "null" : intraFieldOperation.getCode())) + "]");
152         outputBuffer.append("[value," + (getValue().toString() == null ? "null" : getValue().toString()) + "]");
153         return outputBuffer.toString();
154     }
155
156 }
157
Popular Tags