1 64 package com.jcorporate.expresso.core.dataobjects; 65 66 import com.jcorporate.expresso.core.db.DBException; 67 import org.apache.oro.text.regex.Pattern; 68 69 import java.util.Iterator ; 70 71 72 77 78 abstract public class BaseDataObject implements DataObject 79 , java.io.Serializable { 80 81 82 85 protected String currentStatus = BaseDataObject.STATUS_NEW; 86 87 protected Pattern globalMask = null; 88 89 public BaseDataObject() { 90 } 91 92 93 102 public void setStatus(String newStatus) { 103 if (newStatus.equalsIgnoreCase(DataObject.STATUS_NEW) || 104 newStatus.equalsIgnoreCase(DataObject.STATUS_CURRENT) || 105 newStatus.equalsIgnoreCase(DataObject.STATUS_UPDATED) || 106 newStatus.equalsIgnoreCase(DataObject.STATUS_DELETED)) { 107 currentStatus = newStatus; 108 } else { 109 throw new IllegalArgumentException ("Unknown status '" + newStatus + 110 "'"); 111 } 112 } 113 114 115 116 121 public String getStatus() { 122 return currentStatus; 123 } 124 125 126 136 public void setGlobalMask(Pattern newMask) { 137 globalMask = newMask; 138 } 139 140 147 public Pattern getGlobalMask() { 148 return globalMask; 149 } 150 151 152 159 public boolean isGlobalMasked() { 160 return globalMask != null; 161 } 162 163 164 169 public void setFieldsWithDefaults() throws DataException { 170 171 DataObjectMetaData metadata = this.getMetaData(); 172 for (Iterator it = metadata.getFieldListArray() 173 .iterator(); it.hasNext();) { 174 String fieldname = (String ) it.next(); 175 String fieldValue = null; 176 try { 177 fieldValue = this.getField(fieldname); 178 } catch (DBException ex) { 179 throw new DataException("Error getting field current value.", ex); 180 } 181 182 if ((fieldValue == null) || (fieldValue.length() == 0)) { 183 fieldValue = metadata.getDefaultValue(fieldname); 184 if (fieldValue != null) { 185 this.set(fieldname, fieldValue); 186 } 187 } 188 189 } 190 } 191 192 } 193 | Popular Tags |