KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > common > notify > impl > NotificationImpl


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: NotificationImpl.java,v 1.4 2005/06/08 06:19:08 nickb Exp $
16  */

17 package org.eclipse.emf.common.notify.impl;
18
19
20 import org.eclipse.emf.common.notify.Notification;
21 import org.eclipse.emf.common.notify.NotificationChain;
22 import org.eclipse.emf.common.notify.Notifier;
23
24
25 /**
26  * An extensible notification implementation.
27  */

28 public class NotificationImpl implements Notification, NotificationChain
29 {
30   /**
31    * An {@link #primitiveType indicator} that the feature is not a primitive type.
32    * @see #primitiveType
33    */

34   public static final int PRIMITIVE_TYPE_OBJECT = -1;
35
36   /**
37    * An {@link #primitiveType indicator} that the feature is a <code>boolean</code>.
38    * @see #primitiveType
39    */

40   public static final int PRIMITIVE_TYPE_BOOLEAN = 0;
41
42   /**
43    * An {@link #primitiveType indicator} that the feature is a <code>byte</code>.
44    * @see #primitiveType
45    */

46   public static final int PRIMITIVE_TYPE_BYTE = 1;
47
48   /**
49    * An {@link #primitiveType indicator} that the feature is a <code>char</code>.
50    * @see #primitiveType
51    */

52   public static final int PRIMITIVE_TYPE_CHAR = 2;
53
54   /**
55    * An {@link #primitiveType indicator} that the feature is a <code>double</code>.
56    * @see #primitiveType
57    */

58   public static final int PRIMITIVE_TYPE_DOUBLE = 3;
59
60   /**
61    * An {@link #primitiveType indicator} that the feature is a <code>float</code>.
62    * @see #primitiveType
63    */

64   public static final int PRIMITIVE_TYPE_FLOAT = 4;
65
66   /**
67    * An {@link #primitiveType indicator} that the feature is a <code>int</code>.
68    * @see #primitiveType
69    */

70   public static final int PRIMITIVE_TYPE_INT = 5;
71
72   /**
73    * An {@link #primitiveType indicator} that the feature is a <code>long</code>.
74    * @see #primitiveType
75    */

76   public static final int PRIMITIVE_TYPE_LONG = 6;
77
78   /**
79    * An {@link #primitiveType indicator} that the feature is a <code>short</code>.
80    * @see #primitiveType
81    */

82   public static final int PRIMITIVE_TYPE_SHORT = 7;
83
84   /**
85    * A {@link #position position} value which indicates that {@link #isTouch} should return <code>false</code>.
86    * @see #primitiveType
87    */

88   protected static final int IS_SET_CHANGE_INDEX = NO_INDEX - 1;
89
90   /**
91    * The type of the feature.
92    * @see #PRIMITIVE_TYPE_OBJECT
93    * @see #PRIMITIVE_TYPE_BOOLEAN
94    * @see #PRIMITIVE_TYPE_BYTE
95    * @see #PRIMITIVE_TYPE_CHAR
96    * @see #PRIMITIVE_TYPE_DOUBLE
97    * @see #PRIMITIVE_TYPE_FLOAT
98    * @see #PRIMITIVE_TYPE_INT
99    * @see #PRIMITIVE_TYPE_LONG
100    * @see #PRIMITIVE_TYPE_SHORT
101    */

102   protected int primitiveType;
103
104   /**
105    * The type of the change.
106    * @see #getEventType()
107    */

108   protected int eventType;
109
110   /**
111    * The old value for the case of {@link #PRIMITIVE_TYPE_OBJECT}.
112    * @see #getOldValue()
113    */

114   protected Object JavaDoc oldValue;
115
116   /**
117    * The new value for the case of {@link #PRIMITIVE_TYPE_OBJECT}.
118    * @see #getNewValue()
119    */

120   protected Object JavaDoc newValue;
121
122   /**
123    * The old value for the case of
124    * {@link #PRIMITIVE_TYPE_BOOLEAN},
125    * {@link #PRIMITIVE_TYPE_BYTE},
126    * {@link #PRIMITIVE_TYPE_CHAR},
127    * {@link #PRIMITIVE_TYPE_INT},
128    * {@link #PRIMITIVE_TYPE_LONG},
129    * and {@link #PRIMITIVE_TYPE_SHORT}.
130    * @see #getOldValue()
131    * @see #getOldBooleanValue()
132    * @see #getOldByteValue()
133    * @see #getOldCharValue()
134    * @see #getOldIntValue()
135    * @see #getOldLongValue()
136    * @see #getOldShortValue()
137    */

138   protected long oldSimplePrimitiveValue;
139
140   /**
141    * The new value for the case of
142    * {@link #PRIMITIVE_TYPE_BOOLEAN},
143    * {@link #PRIMITIVE_TYPE_BYTE},
144    * {@link #PRIMITIVE_TYPE_CHAR},
145    * {@link #PRIMITIVE_TYPE_INT},
146    * {@link #PRIMITIVE_TYPE_LONG},
147    * and {@link #PRIMITIVE_TYPE_SHORT}.
148    * @see #getNewValue()
149    * @see #getNewBooleanValue()
150    * @see #getNewByteValue()
151    * @see #getNewCharValue()
152    * @see #getNewIntValue()
153    * @see #getNewLongValue()
154    * @see #getNewShortValue()
155    */

156   protected long newSimplePrimitiveValue;
157
158   /**
159    * The old value for the case of
160    * {@link #PRIMITIVE_TYPE_DOUBLE},
161    * and {@link #PRIMITIVE_TYPE_FLOAT}.
162    * @see #getOldValue()
163    * @see #getOldDoubleValue()
164    * @see #getOldFloatValue()
165    */

166   protected double oldIEEEPrimitiveValue;
167
168   /**
169    * The old value for the case of
170    * {@link #PRIMITIVE_TYPE_DOUBLE},
171    * and {@link #PRIMITIVE_TYPE_FLOAT}.
172    * @see #getOldValue()
173    * @see #getOldDoubleValue()
174    * @see #getOldFloatValue()
175    */

176   protected double newIEEEPrimitiveValue;
177
178   /**
179    * The position.
180    * @see #getPosition()
181    */

182   protected int position;
183
184   /**
185    * The internal chain.
186    */

187   protected NotificationChain next;
188
189   /**
190    * Creates an instance.
191    * @param eventType the type of the change.
192    * @param oldValue the old value before the change.
193    * @param newValue the new value after the change.
194    */

195   public NotificationImpl(int eventType, Object JavaDoc oldValue, Object JavaDoc newValue)
196   {
197     this(eventType, oldValue, newValue, NO_INDEX);
198   }
199
200   /**
201    * Creates an instance.
202    * @param eventType the type of the change.
203    * @param oldValue the old value before the change.
204    * @param newValue the new value after the change.
205    * @param isSetChange the indication of whether the state has changed.
206    */

207   public NotificationImpl(int eventType, Object JavaDoc oldValue, Object JavaDoc newValue, boolean isSetChange)
208   {
209     this(eventType, oldValue, newValue, isSetChange ? IS_SET_CHANGE_INDEX : NO_INDEX);
210   }
211
212   /**
213    * Creates an instance.
214    * @param eventType the type of the change.
215    * @param oldValue the old value before the change.
216    * @param newValue the new value after the change.
217    */

218   public NotificationImpl(int eventType, Object JavaDoc oldValue, Object JavaDoc newValue, int position)
219   {
220     this.eventType = eventType;
221     this.oldValue = oldValue;
222     this.newValue = newValue;
223     this.position = position;
224     this.primitiveType = PRIMITIVE_TYPE_OBJECT;
225   }
226
227   /**
228    * Creates an instance.
229    * @param eventType the type of the change.
230    * @param oldValue the old value before the change.
231    * @param newValue the new value after the change.
232    * @param wasSet whether the feature was set before the change.
233    */

234   public NotificationImpl(int eventType, Object JavaDoc oldValue, Object JavaDoc newValue, int position, boolean wasSet)
235   {
236     this.eventType = eventType;
237     this.oldValue = oldValue;
238     this.newValue = newValue;
239     this.position = position;
240     this.primitiveType = PRIMITIVE_TYPE_OBJECT;
241     if (!wasSet)
242     {
243       this.position = IS_SET_CHANGE_INDEX - position - 1;
244     }
245   }
246
247   /**
248    * Creates an instance.
249    * @param eventType the type of the change.
250    * @param oldBooleanValue the old value before the change.
251    * @param newBooleanValue the new value after the change.
252    * @param isSetChange the indication of whether the state has changed.
253    */

254   public NotificationImpl(int eventType, boolean oldBooleanValue, boolean newBooleanValue, boolean isSetChange)
255   {
256     this(eventType, oldBooleanValue, newBooleanValue);
257     if (isSetChange)
258     {
259       this.position = IS_SET_CHANGE_INDEX;
260     }
261   }
262
263   /**
264    * Creates an instance.
265    * @param eventType the type of the change.
266    * @param oldBooleanValue the old value before the change.
267    * @param newBooleanValue the new value after the change.
268    */

269   public NotificationImpl(int eventType, boolean oldBooleanValue, boolean newBooleanValue)
270   {
271     this.eventType = eventType;
272     this.oldSimplePrimitiveValue = oldBooleanValue ? 1 : 0;
273     this.newSimplePrimitiveValue = newBooleanValue ? 1 : 0;
274     this.position = NO_INDEX;
275     this.primitiveType = PRIMITIVE_TYPE_BOOLEAN;
276   }
277
278   /**
279    * Creates an instance.
280    * @param eventType the type of the change.
281    * @param oldByteValue the old value before the change.
282    * @param newByteValue the new value after the change.
283    * @param isSetChange the indication of whether the state has changed.
284    */

285   public NotificationImpl(int eventType, byte oldByteValue, byte newByteValue, boolean isSetChange)
286   {
287     this(eventType, oldByteValue, newByteValue);
288     if (isSetChange)
289     {
290       this.position = IS_SET_CHANGE_INDEX;
291     }
292   }
293
294   /**
295    * Creates an instance.
296    * @param eventType the type of the change.
297    * @param oldByteValue the old value before the change.
298    * @param newByteValue the new value after the change.
299    */

300   public NotificationImpl(int eventType, byte oldByteValue, byte newByteValue)
301   {
302     this.eventType = eventType;
303     this.oldSimplePrimitiveValue = oldByteValue;
304     this.newSimplePrimitiveValue = newByteValue;
305     this.position = Notification.NO_INDEX;
306     this.primitiveType = PRIMITIVE_TYPE_BYTE;
307   }
308
309   /**
310    * Creates an instance.
311    * @param eventType the type of the change.
312    * @param oldCharValue the old value before the change.
313    * @param newCharValue the new value after the change.
314    * @param isSetChange the indication of whether the state has changed.
315    */

316   public NotificationImpl(int eventType, char oldCharValue, char newCharValue, boolean isSetChange)
317   {
318     this(eventType, oldCharValue, newCharValue);
319     if (isSetChange)
320     {
321       this.position = IS_SET_CHANGE_INDEX;
322     }
323   }
324
325   /**
326    * Creates an instance.
327    * @param eventType the type of the change.
328    * @param oldCharValue the old value before the change.
329    * @param newCharValue the new value after the change.
330    */

331   public NotificationImpl(int eventType, char oldCharValue, char newCharValue)
332   {
333     this.eventType = eventType;
334     this.oldSimplePrimitiveValue = oldCharValue;
335     this.newSimplePrimitiveValue = newCharValue;
336     this.position = Notification.NO_INDEX;
337     this.primitiveType = PRIMITIVE_TYPE_CHAR;
338   }
339
340   /**
341    * Creates an instance.
342    * @param eventType the type of the change.
343    * @param oldDoubleValue the old value before the change.
344    * @param newDoubleValue the new value after the change.
345    * @param isSetChange the indication of whether the state has changed.
346    */

347   public NotificationImpl(int eventType, double oldDoubleValue, double newDoubleValue, boolean isSetChange)
348   {
349     this(eventType, oldDoubleValue, newDoubleValue);
350     if (isSetChange)
351     {
352       this.position = IS_SET_CHANGE_INDEX;
353     }
354   }
355
356   /**
357    * Creates an instance.
358    * @param eventType the type of the change.
359    * @param oldDoubleValue the old value before the change.
360    * @param newDoubleValue the new value after the change.
361    */

362   public NotificationImpl(int eventType, double oldDoubleValue, double newDoubleValue)
363   {
364     this.eventType = eventType;
365     this.oldIEEEPrimitiveValue = oldDoubleValue;
366     this.newIEEEPrimitiveValue = newDoubleValue;
367     this.position = Notification.NO_INDEX;
368     this.primitiveType = PRIMITIVE_TYPE_DOUBLE;
369   }
370
371   /**
372    * Creates an instance.
373    * @param eventType the type of the change.
374    * @param oldFloatValue the old value before the change.
375    * @param newFloatValue the new value after the change.
376    * @param isSetChange the indication of whether the state has changed.
377    */

378   public NotificationImpl(int eventType, float oldFloatValue, float newFloatValue, boolean isSetChange)
379   {
380     this(eventType, oldFloatValue, newFloatValue);
381     if (isSetChange)
382     {
383       this.position = IS_SET_CHANGE_INDEX;
384     }
385   }
386
387   /**
388    * Creates an instance.
389    * @param eventType the type of the change.
390    * @param oldFloatValue the old value before the change.
391    * @param newFloatValue the new value after the change.
392    */

393   public NotificationImpl(int eventType, float oldFloatValue, float newFloatValue)
394   {
395     this.eventType = eventType;
396     this.oldIEEEPrimitiveValue = oldFloatValue;
397     this.newIEEEPrimitiveValue = newFloatValue;
398     this.position = Notification.NO_INDEX;
399     this.primitiveType = PRIMITIVE_TYPE_FLOAT;
400   }
401
402   /**
403    * Creates an instance.
404    * @param eventType the type of the change.
405    * @param oldIntValue the old value before the change.
406    * @param newIntValue the new value after the change.
407    * @param isSetChange the indication of whether the state has changed.
408    */

409   public NotificationImpl(int eventType, int oldIntValue, int newIntValue, boolean isSetChange)
410   {
411     this(eventType, oldIntValue, newIntValue);
412     if (isSetChange)
413     {
414       this.position = IS_SET_CHANGE_INDEX;
415     }
416   }
417
418   /**
419    * Creates an instance.
420    * @param eventType the type of the change.
421    * @param oldIntValue the old value before the change.
422    * @param newIntValue the new value after the change.
423    */

424   public NotificationImpl(int eventType, int oldIntValue, int newIntValue)
425   {
426     this.eventType = eventType;
427     this.oldSimplePrimitiveValue = oldIntValue;
428     this.newSimplePrimitiveValue = newIntValue;
429     this.position = Notification.NO_INDEX;
430     this.primitiveType = PRIMITIVE_TYPE_INT;
431   }
432
433   /**
434    * Creates an instance.
435    * @param eventType the type of the change.
436    * @param oldLongValue the old value before the change.
437    * @param newLongValue the new value after the change.
438    * @param isSetChange the indication of whether the state has changed.
439    */

440   public NotificationImpl(int eventType, long oldLongValue, long newLongValue, boolean isSetChange)
441   {
442     this(eventType, oldLongValue, newLongValue);
443     if (isSetChange)
444     {
445       this.position = IS_SET_CHANGE_INDEX;
446     }
447   }
448
449   /**
450    * Creates an instance.
451    * @param eventType the type of the change.
452    * @param oldLongValue the old value before the change.
453    * @param newLongValue the new value after the change.
454    */

455   public NotificationImpl(int eventType, long oldLongValue, long newLongValue)
456   {
457     this.eventType = eventType;
458     this.oldSimplePrimitiveValue = oldLongValue;
459     this.newSimplePrimitiveValue = newLongValue;
460     this.position = Notification.NO_INDEX;
461     this.primitiveType = PRIMITIVE_TYPE_LONG;
462   }
463
464   /**
465    * Creates an instance.
466    * @param eventType the type of the change.
467    * @param oldShortValue the old value before the change.
468    * @param newShortValue the new value after the change.
469    * @param isSetChange the indication of whether the state has changed.
470    */

471   public NotificationImpl(int eventType, short oldShortValue, short newShortValue, boolean isSetChange)
472   {
473     this(eventType, oldShortValue, newShortValue);
474     if (isSetChange)
475     {
476       this.position = IS_SET_CHANGE_INDEX;
477     }
478   }
479
480   /**
481    * Creates an instance.
482    * @param eventType the type of the change.
483    * @param oldShortValue the old value before the change.
484    * @param newShortValue the new value after the change.
485    */

486   public NotificationImpl(int eventType, short oldShortValue, short newShortValue)
487   {
488     this.eventType = eventType;
489     this.oldSimplePrimitiveValue = oldShortValue;
490     this.newSimplePrimitiveValue = newShortValue;
491     this.position = Notification.NO_INDEX;
492     this.primitiveType = PRIMITIVE_TYPE_SHORT;
493   }
494
495   public Object JavaDoc getNotifier()
496   {
497     return null;
498   }
499
500   public int getEventType()
501   {
502     return eventType;
503   }
504
505   public Object JavaDoc getFeature()
506   {
507     return null;
508   }
509
510   public int getFeatureID(Class JavaDoc expectedClass)
511   {
512     return NO_FEATURE_ID;
513   }
514
515   public Object JavaDoc getOldValue()
516   {
517     if (oldValue == null)
518     {
519       switch (primitiveType)
520       {
521         case PRIMITIVE_TYPE_BOOLEAN:
522           oldValue = getOldBooleanValue() ? Boolean.TRUE : Boolean.FALSE;
523           break;
524         case PRIMITIVE_TYPE_BYTE:
525           oldValue = new Byte JavaDoc(getOldByteValue());
526           break;
527         case PRIMITIVE_TYPE_CHAR:
528           oldValue = new Character JavaDoc(getOldCharValue());
529           break;
530         case PRIMITIVE_TYPE_DOUBLE:
531           oldValue = new Double JavaDoc(getOldDoubleValue());
532           break;
533         case PRIMITIVE_TYPE_FLOAT:
534           oldValue = new Float JavaDoc(getOldFloatValue());
535           break;
536         case PRIMITIVE_TYPE_LONG:
537           oldValue = new Long JavaDoc(getOldLongValue());
538           break;
539         case PRIMITIVE_TYPE_INT:
540           oldValue = new Integer JavaDoc(getOldIntValue());
541           break;
542         case PRIMITIVE_TYPE_SHORT:
543           oldValue = new Short JavaDoc(getOldShortValue());
544           break;
545       }
546     }
547     return oldValue;
548   }
549
550   public Object JavaDoc getNewValue()
551   {
552     if (newValue == null)
553     {
554       switch (primitiveType)
555       {
556         case PRIMITIVE_TYPE_BOOLEAN:
557           newValue = getNewBooleanValue() ? Boolean.TRUE : Boolean.FALSE;
558           break;
559         case PRIMITIVE_TYPE_BYTE:
560           newValue = new Byte JavaDoc(getNewByteValue());
561           break;
562         case PRIMITIVE_TYPE_CHAR:
563           newValue = new Character JavaDoc(getNewCharValue());
564           break;
565         case PRIMITIVE_TYPE_DOUBLE:
566           newValue = new Double JavaDoc(getNewDoubleValue());
567           break;
568         case PRIMITIVE_TYPE_FLOAT:
569           newValue = new Float JavaDoc(getNewFloatValue());
570           break;
571         case PRIMITIVE_TYPE_LONG:
572           newValue = new Long JavaDoc(getNewLongValue());
573           break;
574         case PRIMITIVE_TYPE_INT:
575           newValue = new Integer JavaDoc(getNewIntValue());
576           break;
577         case PRIMITIVE_TYPE_SHORT:
578           newValue = new Short JavaDoc(getNewShortValue());
579           break;
580       }
581     }
582     return newValue;
583   }
584
585   public boolean isTouch()
586   {
587     switch (eventType)
588     {
589       case Notification.RESOLVE:
590       case Notification.REMOVING_ADAPTER:
591       {
592         return true;
593       }
594       case Notification.ADD:
595       case Notification.ADD_MANY:
596       case Notification.REMOVE:
597       case Notification.REMOVE_MANY:
598       case Notification.MOVE:
599       {
600         return false;
601       }
602       case Notification.SET:
603       case Notification.UNSET:
604       {
605         if (position == IS_SET_CHANGE_INDEX)
606         {
607           return false;
608         }
609         else
610         {
611           switch (primitiveType)
612           {
613             case PRIMITIVE_TYPE_BOOLEAN:
614             case PRIMITIVE_TYPE_BYTE:
615             case PRIMITIVE_TYPE_CHAR:
616             case PRIMITIVE_TYPE_LONG:
617             case PRIMITIVE_TYPE_INT:
618             case PRIMITIVE_TYPE_SHORT:
619             {
620               return oldSimplePrimitiveValue == newSimplePrimitiveValue;
621             }
622             case PRIMITIVE_TYPE_DOUBLE:
623             case PRIMITIVE_TYPE_FLOAT:
624             {
625               return oldIEEEPrimitiveValue == newIEEEPrimitiveValue;
626             }
627             default:
628             {
629               return oldValue == null ? newValue == null : oldValue.equals(newValue);
630             }
631           }
632         }
633       }
634       default:
635       {
636         return false;
637       }
638     }
639   }
640
641   public boolean isReset()
642   {
643     switch (eventType)
644     {
645       case Notification.SET:
646         Object JavaDoc defaultValue = getFeatureDefaultValue();
647         switch (primitiveType)
648         {
649           case PRIMITIVE_TYPE_BOOLEAN:
650             return defaultValue != null && ((Boolean JavaDoc)defaultValue).booleanValue() == (newSimplePrimitiveValue != 0);
651           case PRIMITIVE_TYPE_BYTE:
652             return defaultValue != null && ((Byte JavaDoc)defaultValue).byteValue() == (byte)newSimplePrimitiveValue;
653           case PRIMITIVE_TYPE_CHAR:
654             return defaultValue != null && ((Character JavaDoc)defaultValue).charValue() == (char)newSimplePrimitiveValue;
655           case PRIMITIVE_TYPE_LONG:
656             return defaultValue != null && ((Long JavaDoc)defaultValue).longValue() == newSimplePrimitiveValue;
657           case PRIMITIVE_TYPE_INT:
658             return defaultValue != null && ((Integer JavaDoc)defaultValue).intValue() == (int)newSimplePrimitiveValue;
659           case PRIMITIVE_TYPE_SHORT:
660             return defaultValue != null && ((Short JavaDoc)defaultValue).shortValue() == (short)newSimplePrimitiveValue;
661           case PRIMITIVE_TYPE_DOUBLE:
662             return defaultValue != null && ((Double JavaDoc)defaultValue).doubleValue() == newIEEEPrimitiveValue;
663           case PRIMITIVE_TYPE_FLOAT:
664             return defaultValue != null && ((Float JavaDoc)defaultValue).floatValue() == (float)newIEEEPrimitiveValue;
665           default:
666             return defaultValue == null ? newValue == null : defaultValue.equals(newValue);
667         }
668       case Notification.UNSET:
669         return true;
670       default:
671         return false;
672     }
673   }
674
675   public boolean wasSet()
676   {
677     switch (eventType)
678     {
679       case Notification.SET:
680       {
681         if (isFeatureUnsettable())
682         {
683           return position != IS_SET_CHANGE_INDEX;
684         }
685         break;
686       }
687       case Notification.UNSET:
688       {
689         if (isFeatureUnsettable())
690         {
691           return position == IS_SET_CHANGE_INDEX;
692         }
693         break;
694       }
695       case Notification.ADD:
696       case Notification.ADD_MANY:
697       case Notification.REMOVE:
698       case Notification.REMOVE_MANY:
699       case Notification.MOVE:
700       {
701         return position > IS_SET_CHANGE_INDEX;
702       }
703       default:
704       {
705         return false;
706       }
707     }
708
709     Object JavaDoc defaultValue = getFeatureDefaultValue();
710     switch (primitiveType)
711     {
712       case PRIMITIVE_TYPE_BOOLEAN:
713         return defaultValue != null && ((Boolean JavaDoc)defaultValue).booleanValue() != (oldSimplePrimitiveValue != 0);
714       case PRIMITIVE_TYPE_BYTE:
715         return defaultValue != null && ((Byte JavaDoc)defaultValue).byteValue() != (byte)oldSimplePrimitiveValue;
716       case PRIMITIVE_TYPE_CHAR:
717         return defaultValue != null && ((Character JavaDoc)defaultValue).charValue() != (char)oldSimplePrimitiveValue;
718       case PRIMITIVE_TYPE_LONG:
719         return defaultValue != null && ((Long JavaDoc)defaultValue).longValue() != oldSimplePrimitiveValue;
720       case PRIMITIVE_TYPE_INT:
721         return defaultValue != null && ((Integer JavaDoc)defaultValue).intValue() != (int)oldSimplePrimitiveValue;
722       case PRIMITIVE_TYPE_SHORT:
723         return defaultValue != null && ((Short JavaDoc)defaultValue).shortValue() != (short)oldSimplePrimitiveValue;
724       case PRIMITIVE_TYPE_DOUBLE:
725         return defaultValue != null && ((Double JavaDoc)defaultValue).doubleValue() != oldIEEEPrimitiveValue;
726       case PRIMITIVE_TYPE_FLOAT:
727         return defaultValue != null && ((Float JavaDoc)defaultValue).floatValue() != (float)oldIEEEPrimitiveValue;
728       default:
729         return defaultValue == null ? oldValue != null : !defaultValue.equals(oldValue);
730     }
731   }
732
733   protected boolean isFeatureUnsettable()
734   {
735     return false;
736   }
737
738   protected Object JavaDoc getFeatureDefaultValue()
739   {
740     return null;
741   }
742
743   public int getPosition()
744   {
745     return position < 0 ? position < IS_SET_CHANGE_INDEX ? IS_SET_CHANGE_INDEX - position - 1 : NO_INDEX : position;
746   }
747
748   public boolean merge(Notification notification)
749   {
750     switch (eventType)
751     {
752       case Notification.SET:
753       case Notification.UNSET:
754       {
755         int notificationEventType = notification.getEventType();
756         switch (notificationEventType)
757         {
758           case Notification.SET:
759           case Notification.UNSET:
760           {
761             Object JavaDoc notificationNotifier = notification.getNotifier();
762             if (notificationNotifier == getNotifier() && getFeatureID(null) == notification.getFeatureID(null))
763             {
764               newValue = notification.getNewValue();
765               if (notification.getEventType() == Notification.SET)
766               {
767                 eventType = Notification.SET;
768               }
769               return true;
770             }
771           }
772         }
773       }
774     }
775
776     return false;
777   }
778
779   public boolean getOldBooleanValue()
780   {
781     if (primitiveType != PRIMITIVE_TYPE_BOOLEAN) throw new IllegalStateException JavaDoc();
782     return oldSimplePrimitiveValue != 0;
783   }
784
785   public boolean getNewBooleanValue()
786   {
787     if (primitiveType != PRIMITIVE_TYPE_BOOLEAN) throw new IllegalStateException JavaDoc();
788     return newSimplePrimitiveValue != 0;
789   }
790
791   public byte getOldByteValue()
792   {
793     if (primitiveType != PRIMITIVE_TYPE_BYTE) throw new IllegalStateException JavaDoc();
794     return (byte)oldSimplePrimitiveValue;
795   }
796
797   public byte getNewByteValue()
798   {
799     if (primitiveType != PRIMITIVE_TYPE_BYTE) throw new IllegalStateException JavaDoc();
800     return (byte)newSimplePrimitiveValue;
801   }
802
803   public char getOldCharValue()
804   {
805     if (primitiveType != PRIMITIVE_TYPE_CHAR) throw new IllegalStateException JavaDoc();
806     return (char)oldSimplePrimitiveValue;
807   }
808
809   public char getNewCharValue()
810   {
811     if (primitiveType != PRIMITIVE_TYPE_CHAR) throw new IllegalStateException JavaDoc();
812     return (char)newSimplePrimitiveValue;
813   }
814
815   public double getOldDoubleValue()
816   {
817     if (primitiveType != PRIMITIVE_TYPE_DOUBLE) throw new IllegalStateException JavaDoc();
818     return oldIEEEPrimitiveValue;
819   }
820
821   public double getNewDoubleValue()
822   {
823     if (primitiveType != PRIMITIVE_TYPE_DOUBLE) throw new IllegalStateException JavaDoc();
824     return newIEEEPrimitiveValue;
825   }
826
827   public float getOldFloatValue()
828   {
829     if (primitiveType != PRIMITIVE_TYPE_FLOAT) throw new IllegalStateException JavaDoc();
830     return (float)oldIEEEPrimitiveValue;
831   }
832
833   public float getNewFloatValue()
834   {
835     if (primitiveType != PRIMITIVE_TYPE_FLOAT) throw new IllegalStateException JavaDoc();
836     return (float)newIEEEPrimitiveValue;
837   }
838
839   public int getOldIntValue()
840   {
841     if (primitiveType != PRIMITIVE_TYPE_INT) throw new IllegalStateException JavaDoc();
842     return (int)oldSimplePrimitiveValue;
843   }
844
845   public int getNewIntValue()
846   {
847     if (primitiveType != PRIMITIVE_TYPE_INT) throw new IllegalStateException JavaDoc();
848     return (int)newSimplePrimitiveValue;
849   }
850
851   public long getOldLongValue()
852   {
853     if (primitiveType != PRIMITIVE_TYPE_LONG) throw new IllegalStateException JavaDoc();
854     return oldSimplePrimitiveValue;
855   }
856
857   public long getNewLongValue()
858   {
859     if (primitiveType != PRIMITIVE_TYPE_LONG) throw new IllegalStateException JavaDoc();
860     return newSimplePrimitiveValue;
861   }
862
863   public short getOldShortValue()
864   {
865     if (primitiveType != PRIMITIVE_TYPE_SHORT) throw new IllegalStateException JavaDoc();
866     return (short)oldSimplePrimitiveValue;
867   }
868
869   public short getNewShortValue()
870   {
871     if (primitiveType != PRIMITIVE_TYPE_SHORT) throw new IllegalStateException JavaDoc();
872     return (short)newSimplePrimitiveValue;
873   }
874
875   public String JavaDoc getOldStringValue()
876   {
877     return oldValue == null ? null : oldValue.toString();
878   }
879
880   public String JavaDoc getNewStringValue()
881   {
882     return newValue == null ? null : newValue.toString();
883   }
884
885   /**
886    * Adds or merges a new notification.
887    * @param newNotification a notification.
888    * @return <code>true</code> when the notification is added and <code>false</code> when it is merged.
889    */

890   public boolean add(Notification newNotification)
891   {
892     if (newNotification == null)
893     {
894       return false;
895     }
896     else
897     {
898       if (merge(newNotification))
899       {
900         return false;
901       }
902
903       if (next == null)
904       {
905         try
906         {
907           next = (NotificationChain)newNotification;
908           return true;
909         }
910         catch (ClassCastException JavaDoc exception)
911         {
912           next = new NotificationChainImpl();
913           return next.add(newNotification);
914         }
915       }
916       else
917       {
918         return next.add(newNotification);
919       }
920     }
921   }
922
923   /*
924    * Javadoc copied from interface.
925    */

926   public void dispatch()
927   {
928     Object JavaDoc notifier = getNotifier();
929     if (notifier != null && getEventType() != -1)
930     {
931       ((Notifier)notifier).eNotify(this);
932     }
933
934     if (next != null)
935     {
936       next.dispatch();
937     }
938   }
939
940   public String JavaDoc toString()
941   {
942     StringBuffer JavaDoc result = new StringBuffer JavaDoc(super.toString());
943     result.append(" (eventType: ");
944     switch (eventType)
945     {
946       case Notification.SET:
947       {
948         result.append("SET");
949         break;
950       }
951       case Notification.UNSET:
952       {
953         result.append("UNSET");
954         break;
955       }
956       case Notification.ADD:
957       {
958         result.append("ADD");
959         break;
960       }
961       case Notification.ADD_MANY:
962       {
963         result.append("ADD_MANY");
964         break;
965       }
966       case Notification.REMOVE:
967       {
968         result.append("REMOVE");
969         break;
970       }
971       case Notification.REMOVE_MANY:
972       {
973         result.append("REMOVE_MANY");
974         break;
975       }
976       case Notification.MOVE:
977       {
978         result.append("MOVE");
979         break;
980       }
981       case Notification.REMOVING_ADAPTER:
982       {
983         result.append("REMOVING_ADPATER");
984         break;
985       }
986       case Notification.RESOLVE:
987       {
988         result.append("RESOLVE");
989         break;
990       }
991       default:
992       {
993         result.append(eventType);
994         break;
995       }
996     }
997     if (isTouch())
998     {
999       result.append(", touch: true");
1000    }
1001    result.append(", position: ");
1002    result.append(getPosition());
1003    result.append(", notifier: ");
1004    result.append(getNotifier());
1005    result.append(", feature: ");
1006    result.append(getFeature());
1007    result.append(", oldValue: ");
1008    result.append(getOldValue());
1009    result.append(", newValue: ");
1010    if (eventType == Notification.REMOVE_MANY && newValue instanceof int [])
1011    {
1012      int [] positions = (int [])newValue;
1013      result.append("[");
1014      for (int i = 0; i < positions.length; )
1015      {
1016        result.append(positions[i]);
1017        if (++i < positions.length)
1018        {
1019          result.append(", ");
1020        }
1021      }
1022      result.append("]");
1023    }
1024    else
1025    {
1026      result.append(getNewValue());
1027    }
1028
1029    result.append(", isTouch: ");
1030    result.append(isTouch());
1031    result.append(", wasSet: ");
1032    result.append(wasSet());
1033    result.append(")");
1034
1035    return result.toString();
1036  }
1037}
1038
Popular Tags