001: /*
002: * $Id: EntityConditionFunction.java,v 1.1 2003/11/05 12:08:00 jonesde Exp $
003: *
004: * Copyright (c) 2002 The Open For Business Project - www.ofbiz.org
005: *
006: * 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: * The above copyright notice and this permission notice shall be included
014: * in all copies or substantial portions of the Software.
015: *
016: * 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 java.util.List;
028:
029: import org.ofbiz.entity.GenericEntity;
030: import org.ofbiz.entity.GenericModelException;
031: import org.ofbiz.entity.model.ModelEntity;
032:
033: /**
034: * Encapsulates operations between entities and entity fields. This is a immutable class.
035: *
036: *@author <a href='mailto:chris_maurer@altavista.com'>Chris Maurer</a>
037: *@author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
038: *@author <a href="mailto:jaz@jflow.net">Andy Zeneski</a>
039: *@created Nov 5, 2001
040: *@version 1.0
041: */
042: public abstract class EntityConditionFunction extends EntityCondition {
043:
044: public static final int ID_NOT = 1;
045:
046: public static class NOT extends EntityConditionFunction {
047: public NOT(EntityCondition nested) {
048: super (ID_NOT, "NOT", nested);
049: }
050: };
051:
052: protected int idInt;
053: protected String codeString;
054: protected EntityCondition condition;
055:
056: protected EntityConditionFunction(int id, String code,
057: EntityCondition condition) {
058: idInt = id;
059: codeString = code;
060: this .condition = condition;
061: }
062:
063: public String getCode() {
064: if (codeString == null)
065: return "null";
066: else
067: return codeString;
068: }
069:
070: public int getId() {
071: return idInt;
072: }
073:
074: /*
075: public String toString() {
076: StringBuffer sb = new StringBuffer();
077: sb.append(codeString).append('(');
078: if (nested != null) {
079: sb.append(nested.toString());
080: } else {
081: sb.append(value);
082: }
083: sb.append(')');
084: return sb.toString();
085: }
086: */
087:
088: public boolean equals(Object obj) {
089: EntityConditionFunction otherFunc = (EntityConditionFunction) obj;
090: return this .idInt == otherFunc.idInt
091: && (this .condition != null ? condition
092: .equals(otherFunc.condition)
093: : otherFunc.condition != null);
094: }
095:
096: public String makeWhereString(ModelEntity modelEntity,
097: List entityConditionParams) {
098: StringBuffer sb = new StringBuffer();
099: sb.append(codeString).append('(');
100: sb.append(condition.makeWhereString(modelEntity,
101: entityConditionParams));
102: sb.append(')');
103: return sb.toString();
104: }
105:
106: public void checkCondition(ModelEntity modelEntity)
107: throws GenericModelException {
108: condition.checkCondition(modelEntity);
109: }
110:
111: public boolean entityMatches(GenericEntity entity) {
112: return !condition.entityMatches(entity);
113: }
114: }
|