1 56 package org.objectstyle.cayenne.modeler.util; 57 58 import java.util.Map ; 59 60 import org.objectstyle.cayenne.util.Util; 61 import org.scopemvc.core.Selector; 62 import org.scopemvc.model.basic.BasicModel; 63 64 70 public abstract class MapModel extends BasicModel { 71 72 protected Map map; 73 74 public MapModel() { 75 super(); 76 } 77 78 public abstract Selector selectorForKey(String key); 79 80 public abstract String defaultForKey(String key); 81 82 public abstract String [] supportedProperties(); 83 84 87 public void storeProperties(Map map) { 88 String [] properties = supportedProperties(); 89 for (int i = 0; i < properties.length; i++) { 90 map.put(properties[i], this.map.get(properties[i])); 91 } 92 } 93 94 public void setMap(Map map) { 95 this.map = map; 96 } 97 98 public void setProperty(String key, String value) { 99 if (map != null) { 100 101 if (Util.nullSafeEquals(defaultForKey(key), value)) { 102 value = null; 103 } 104 105 Object oldValue = map.put(key, value); 106 if (!Util.nullSafeEquals(oldValue, value)) { 107 fireModelChange(VALUE_CHANGED, selectorForKey(key)); 108 } 109 } 110 } 111 112 public String getProperty(String key) { 113 String value = (map != null) ? (String ) map.get(key) : null; 114 return (value != null) ? value : defaultForKey(key); 115 } 116 117 } 118 | Popular Tags |