001: /*
002: * $Id: EntityClause.java,v 1.1 2003/08/17 04:56:25 jonesde Exp $
003: *
004: * <p>Copyright (c) 2001 The Open For Business Project - www.ofbiz.org
005: *
006: * <p>Permission is hereby granted, free of charge, to any person obtaining a
007: * copy of this software and associated documentation files (the "Software"),
008: * to deal in the Software without restriction, including without limitation
009: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
010: * and/or sell copies of the Software, and to permit persons to whom the
011: * Software is furnished to do so, subject to the following conditions:
012: *
013: * <p>The above copyright notice and this permission notice shall be included
014: * in all copies or substantial portions of the Software.
015: *
016: * <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023: */
024:
025: package org.ofbiz.entity.condition;
026:
027: import org.ofbiz.entity.GenericEntityException;
028: import org.ofbiz.entity.model.ModelEntity;
029: import org.ofbiz.entity.model.ModelReader;
030:
031: /**
032: * Generic Entity Clause - Used to string together entities to make a find clause
033: *
034: *@author <a href='mailto:chris_maurer@altavista.com'>Chris Maurer</a>
035: *@author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
036: *@created Mon Nov 5, 2001
037: *@version 1.0
038: */
039: public class EntityClause {
040:
041: private String firstEntity = "";
042: private String secondEntity = "";
043: private String firstField = "";
044: private String secondField = "";
045: private ModelEntity firstModelEntity = null;
046: private ModelEntity secondModelEntity = null;
047: private EntityOperator interFieldOperation = null;
048: private EntityOperator intraFieldOperation = null;
049:
050: private Object value = null;
051:
052: public EntityClause() {
053: }
054:
055: public EntityClause(String firstEntity, String secondEntity,
056: String firstField, String secondField,
057: EntityOperator interFieldOperation,
058: EntityOperator intraFieldOperation) {
059: this .firstEntity = firstEntity;
060: this .secondEntity = secondEntity;
061: this .firstField = firstField;
062: this .secondField = secondField;
063: this .interFieldOperation = interFieldOperation;
064: this .intraFieldOperation = intraFieldOperation;
065: }
066:
067: public EntityClause(String firstEntity, String firstField,
068: Object value, EntityOperator interFieldOperation,
069: EntityOperator intraFieldOperation) {
070: this .firstEntity = firstEntity;
071: this .firstField = firstField;
072: this .value = value;
073: this .interFieldOperation = interFieldOperation;
074: this .intraFieldOperation = intraFieldOperation;
075: }
076:
077: public String getFirstEntity() {
078: return firstEntity;
079: }
080:
081: public String getSecondEntity() {
082: return secondEntity;
083: }
084:
085: public String getFirstField() {
086: return firstField;
087: }
088:
089: public String getSecondField() {
090: return secondField;
091: }
092:
093: public Object getValue() {
094: if (value == null)
095: value = new Object();
096: return value;
097: }
098:
099: public EntityOperator getInterFieldOperation() {
100: return interFieldOperation;
101: }
102:
103: public EntityOperator getIntraFieldOperation() {
104: return intraFieldOperation;
105: }
106:
107: public void setFirstEntity(String firstEntity) {
108: this .firstEntity = firstEntity;
109: }
110:
111: public void setSecondEntity(String secondEntity) {
112: this .secondEntity = secondEntity;
113: }
114:
115: public void setFirstField(String firstField) {
116: this .firstField = firstField;
117: }
118:
119: public void setSecondField(String secondField) {
120: this .secondField = secondField;
121: }
122:
123: public void setInterFieldOperation(
124: EntityOperator interFieldOperation) {
125: this .interFieldOperation = interFieldOperation;
126: }
127:
128: public void setIntraFieldOperation(
129: EntityOperator intraFieldOperation) {
130: this .intraFieldOperation = intraFieldOperation;
131: }
132:
133: // -- Protected Methods - for internal use only --//
134: protected void setModelEntities(ModelReader modelReader)
135: throws GenericEntityException {
136: firstModelEntity = (ModelEntity) modelReader
137: .getModelEntity(firstEntity);
138: if (secondEntity != null && !secondEntity.equals("")) {
139: secondModelEntity = (ModelEntity) modelReader
140: .getModelEntity(secondEntity);
141: }
142: }
143:
144: protected ModelEntity getFirstModelEntity() {
145: return firstModelEntity;
146: }
147:
148: protected ModelEntity getSecondModelEntity() {
149: return secondModelEntity;
150: }
151:
152: public String toString() {
153: StringBuffer outputBuffer = new StringBuffer();
154:
155: outputBuffer.append("[firstEntity,"
156: + (firstEntity == null ? "null" : firstEntity) + "]");
157: outputBuffer.append("[secondEntity,"
158: + (secondEntity == null ? "null" : secondEntity) + "]");
159: outputBuffer.append("[firstField,"
160: + (firstField == null ? "null" : firstField) + "]");
161: outputBuffer.append("[secondField,"
162: + (secondField == null ? "null" : secondField) + "]");
163: outputBuffer
164: .append("[firstModelEntity,"
165: + (firstModelEntity == null ? "null"
166: : (firstModelEntity.getEntityName() == null ? "null"
167: : firstModelEntity
168: .getEntityName()))
169: + "]");
170: outputBuffer
171: .append("[secondModelEntity,"
172: + (secondModelEntity == null ? "null"
173: : (secondModelEntity.getEntityName() == null ? "null"
174: : secondModelEntity
175: .getEntityName()))
176: + "]");
177: outputBuffer
178: .append("[interFieldOperation,"
179: + (interFieldOperation == null ? "null"
180: : (interFieldOperation.getCode() == null ? "null"
181: : interFieldOperation.getCode()))
182: + "]");
183: outputBuffer
184: .append("[intraFieldOperation,"
185: + (intraFieldOperation == null ? "null"
186: : (intraFieldOperation.getCode() == null ? "null"
187: : intraFieldOperation.getCode()))
188: + "]");
189: outputBuffer.append("[value,"
190: + (getValue().toString() == null ? "null" : getValue()
191: .toString()) + "]");
192: return outputBuffer.toString();
193: }
194:
195: }
|