1 24 package org.ofbiz.entity.model; 25 26 import java.util.List ; 27 28 import org.w3c.dom.Document ; 29 import org.w3c.dom.Element ; 30 31 import org.ofbiz.base.util.UtilMisc; 32 import org.ofbiz.base.util.UtilXml; 33 34 35 42 public class ModelKeyMap implements java.io.Serializable { 43 44 45 protected String fieldName = ""; 46 47 48 protected String relFieldName = ""; 49 50 51 public ModelKeyMap() {} 52 53 54 public ModelKeyMap(String fieldName, String relFieldName) { 55 this.fieldName = fieldName; 56 this.relFieldName = UtilXml.checkEmpty(relFieldName, this.fieldName); 57 } 58 59 60 public ModelKeyMap(Element keyMapElement) { 61 this.fieldName = UtilXml.checkEmpty(keyMapElement.getAttribute("field-name")); 62 this.relFieldName = UtilXml.checkEmpty(keyMapElement.getAttribute("rel-field-name"), this.fieldName); 64 } 65 66 67 public String getFieldName() { 68 return this.fieldName; 69 } 70 71 public void setFieldName(String fieldName) { 72 this.fieldName = fieldName; 73 } 74 75 76 public String getRelFieldName() { 77 return this.relFieldName; 78 } 79 80 public void setRelFieldName(String relFieldName) { 81 this.relFieldName = relFieldName; 82 } 83 84 public static List makeKeyMapList(String fieldName1) { 86 return UtilMisc.toList(new ModelKeyMap(fieldName1, null)); 87 } 88 public static List makeKeyMapList(String fieldName1, String relFieldName1) { 89 return UtilMisc.toList(new ModelKeyMap(fieldName1, relFieldName1)); 90 } 91 public static List makeKeyMapList(String fieldName1, String relFieldName1, String fieldName2, String relFieldName2) { 92 return UtilMisc.toList(new ModelKeyMap(fieldName1, relFieldName1), new ModelKeyMap(fieldName2, relFieldName2)); 93 } 94 public static List makeKeyMapList(String fieldName1, String relFieldName1, String fieldName2, String relFieldName2, String fieldName3, String relFieldName3) { 95 return UtilMisc.toList(new ModelKeyMap(fieldName1, relFieldName1), new ModelKeyMap(fieldName2, relFieldName2), new ModelKeyMap(fieldName3, relFieldName3)); 96 } 97 98 public int hashCode() { 99 return this.fieldName.hashCode() + this.relFieldName.hashCode(); 100 } 101 102 public boolean equals(Object other) { 103 ModelKeyMap otherKeyMap = (ModelKeyMap) other; 104 105 if (!otherKeyMap.fieldName.equals(this.fieldName)) return false; 106 if (!otherKeyMap.relFieldName.equals(this.relFieldName)) return false; 107 108 return true; 109 } 110 111 public Element toXmlElement(Document document) { 112 Element root = document.createElement("key-map"); 113 root.setAttribute("field-name", this.getFieldName()); 114 if (!this.getFieldName().equals(this.getRelFieldName())) { 115 root.setAttribute("rel-field-name", this.getRelFieldName()); 116 } 117 118 return root; 119 } 120 } 121 | Popular Tags |