1 29 package net.sourceforge.groboutils.pmti.v1.defimpl; 30 31 import net.sourceforge.groboutils.pmti.v1.IEditableAttribute; 32 import net.sourceforge.groboutils.pmti.v1.IAttributeInfo; 33 import net.sourceforge.groboutils.pmti.v1.IAttribute; 34 35 36 44 public abstract class AbstractEditableAttribute implements IEditableAttribute 45 { 46 private Object newvalue; 47 private boolean valueChanged = false; 48 private IAttribute baseAttrib; 49 50 51 public AbstractEditableAttribute( IAttribute base ) 52 { 53 if (base == null) 54 { 55 throw new IllegalArgumentException ("no null arguments"); 56 } 57 this.baseAttrib = base; 58 } 59 60 61 62 65 public Object getValue() 66 { 67 Object ret; 68 if (this.valueChanged) 69 { 70 ret = this.newvalue; 71 } 72 else 73 { 74 ret = this.baseAttrib.getValue(); 75 } 76 return ret; 77 } 78 79 80 83 public IAttributeInfo getInfo() 84 { 85 return this.baseAttrib.getInfo(); 86 } 87 88 89 93 public void setValue( Object value ) 94 { 95 if (!isValidValue( value )) 96 { 97 throw new IllegalArgumentException ( "invalid value "+value ); 98 } 99 Object orig = this.baseAttrib.getValue(); 100 if ( value == orig || ( value != null && value.equals( orig ) ) ) 101 { 102 this.valueChanged = false; 104 } 105 else 106 { 107 this.valueChanged = true; 108 this.newvalue = value; 109 } 110 } 111 112 113 119 public boolean hasValueChanged() 120 { 121 return this.valueChanged; 122 } 123 124 125 128 public abstract boolean isValidValue( Object value ); 129 } 130 131 | Popular Tags |