KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: EntityFieldValue.java 5687 2005-09-10 01:10:15Z jonesde $
3  *
4  * Copyright (c) 2002-2004 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.GenericEntity;
32 import org.ofbiz.entity.GenericModelException;
33 import org.ofbiz.entity.config.DatasourceInfo;
34 import org.ofbiz.entity.model.ModelEntity;
35 import org.ofbiz.entity.model.ModelField;
36
37 /**
38  * Encapsulates operations between entities and entity fields. This is a immutable class.
39  *
40  *@author <a HREF='mailto:chris_maurer@altavista.com'>Chris Maurer</a>
41  *@author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
42  *@author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
43  *@since 1.0
44  *@version $Rev: 5687 $
45  */

46 public class EntityFieldValue extends EntityConditionValue {
47
48     protected String JavaDoc fieldName;
49
50     public EntityFieldValue(String JavaDoc fieldName) {
51         this.fieldName = fieldName;
52     }
53
54     public String JavaDoc getFieldName() {
55         return fieldName;
56     }
57
58     public int hashCode() {
59         return fieldName.hashCode();
60     }
61
62     public boolean equals(Object JavaDoc obj) {
63         if (!(obj instanceof EntityFieldValue)) return false;
64         EntityFieldValue otherValue = (EntityFieldValue) obj;
65         return fieldName.equals(otherValue.fieldName);
66     }
67
68     public ModelField getModelField(ModelEntity modelEntity) {
69         return getField(modelEntity, fieldName);
70     }
71
72     public void addSqlValue(StringBuffer JavaDoc sql, Map JavaDoc tableAliases, ModelEntity modelEntity, List JavaDoc entityConditionParams, boolean includeTableNamePrefix, DatasourceInfo datasourceInfo) {
73         sql.append(getColName(tableAliases, modelEntity, fieldName, includeTableNamePrefix, datasourceInfo));
74     }
75
76     public void validateSql(ModelEntity modelEntity) throws GenericModelException {
77         ModelField field = getModelField(modelEntity);
78         if (field == null) {
79             throw new GenericModelException("Field with name " + fieldName + " not found in the " + modelEntity.getEntityName() + " Entity");
80         }
81     }
82
83     public Object JavaDoc getValue(GenericDelegator delegator, Map JavaDoc map) {
84         if (map == null) {
85             return null;
86         }
87         if (map instanceof GenericEntity.NULL) {
88             return null;
89         } else {
90             return map.get(fieldName);
91         }
92     }
93
94     public void visit(EntityConditionVisitor visitor) {
95         visitor.acceptEntityFieldValue(this);
96     }
97
98     public void accept(EntityConditionVisitor visitor) {
99         visitor.acceptEntityFieldValue(this);
100     }
101
102     public EntityConditionValue freeze() {
103         return this;
104     }
105 }
106
Popular Tags