| 30 | === The notification mechanism |
| 31 | As mentioned the Model notifies all listeners when something in the model changes. The convention we try to stick to (but can not enforce) is that {{{IllegalStateException}}} is thrown whenever the change in the model can not be accepted. This works as follows |
| 32 | * When setValue (or equivalent functions) receive a value that is unacceptable, eg because it's out of range, an IllegalArgumentException is thrown immediately |
| 33 | * In the case of a compound object, the problem may not arise immediately but only indirectly. For instance suppose that Parsons with a name starting with "A" can not be older than 100 years. This check can not be done on the submodels containing the name or the age, but has to be done on the Person level. The Person model has to listen to changes to name and age, and this listener will throw if there is a conflict. This throw will then end up in the event notifier of the name or age model where the offending change will have to be reverted. Therefore the event notification in general is of the type ThrowingListenable and changes need to be reverted in case of conflicts. The notification mechanism generally will look like this |
| 34 | {{{ |
| 35 | public void setValue(newval) |
| 36 | oldval=this.val1; |
| 37 | this.val1=newval; |
| 38 | try { |
| 39 | check(); |
| 40 | notifyListeners(); |
| 41 | } catch (IllegalStateException e) { |
| 42 | log(e.getMessage()); |
| 43 | this.val1=oldval; |
| 44 | notifyListeners(); |
| 45 | } |
| 46 | } |
| 47 | }}} |
| 48 | |
| 49 | Also note that any issues are pushed into the log system. This allows the GUI implementation to show any logged issues in a proper way to the user. |
| 50 | |