001: /*
002: * $Id: ModelKeyMap.java,v 1.4 2003/10/18 06:24:50 jonesde Exp $
003: *
004: * Copyright (c) 2001, 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: package org.ofbiz.entity.model;
025:
026: import java.util.List;
027: import org.ofbiz.base.util.UtilMisc;
028: import org.ofbiz.base.util.UtilXml;
029: import org.w3c.dom.Element;
030:
031: /**
032: * Generic Entity - KeyMap model class
033: *
034: * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
035: * @version $Revision: 1.4 $
036: * @since 2.0
037: */
038: public class ModelKeyMap {
039:
040: /** name of the field in this entity */
041: protected String fieldName = "";
042:
043: /** name of the field in related entity */
044: protected String relFieldName = "";
045:
046: /** Default Constructor */
047: public ModelKeyMap() {
048: }
049:
050: /** Data Constructor, if relFieldName is null defaults to fieldName */
051: public ModelKeyMap(String fieldName, String relFieldName) {
052: this .fieldName = fieldName;
053: this .relFieldName = UtilXml.checkEmpty(relFieldName,
054: this .fieldName);
055: }
056:
057: /** XML Constructor */
058: public ModelKeyMap(Element keyMapElement) {
059: this .fieldName = UtilXml.checkEmpty(keyMapElement
060: .getAttribute("field-name"));
061: // if no relFieldName is specified, use the fieldName; this is convenient for when they are named the same, which is often the case
062: this .relFieldName = UtilXml.checkEmpty(keyMapElement
063: .getAttribute("rel-field-name"), this .fieldName);
064: }
065:
066: /** name of the field in this entity */
067: public String getFieldName() {
068: return this .fieldName;
069: }
070:
071: public void setFieldName(String fieldName) {
072: this .fieldName = fieldName;
073: }
074:
075: /** name of the field in related entity */
076: public String getRelFieldName() {
077: return this .relFieldName;
078: }
079:
080: public void setRelFieldName(String relFieldName) {
081: this .relFieldName = relFieldName;
082: }
083:
084: // ======= Some Convenience Oriented Factory Methods =======
085: public static List makeKeyMapList(String fieldName1) {
086: return UtilMisc.toList(new ModelKeyMap(fieldName1, null));
087: }
088:
089: public static List makeKeyMapList(String fieldName1,
090: String relFieldName1) {
091: return UtilMisc.toList(new ModelKeyMap(fieldName1,
092: relFieldName1));
093: }
094:
095: public static List makeKeyMapList(String fieldName1,
096: String relFieldName1, String fieldName2,
097: String relFieldName2) {
098: return UtilMisc.toList(new ModelKeyMap(fieldName1,
099: relFieldName1), new ModelKeyMap(fieldName2,
100: relFieldName2));
101: }
102:
103: public static List makeKeyMapList(String fieldName1,
104: String relFieldName1, String fieldName2,
105: String relFieldName2, String fieldName3,
106: String relFieldName3) {
107: return UtilMisc.toList(new ModelKeyMap(fieldName1,
108: relFieldName1), new ModelKeyMap(fieldName2,
109: relFieldName2), new ModelKeyMap(fieldName3,
110: relFieldName3));
111: }
112: }
|