KickJava   Java API By Example, From Geeks To Geeks.

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


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: NotificationChainImpl.java,v 1.2 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 import org.eclipse.emf.common.util.BasicEList;
24
25
26 /**
27  * A list that acts as a notification chain.
28  */

29 public class NotificationChainImpl extends BasicEList implements NotificationChain
30 {
31   /**
32    * Creates an empty instance.
33    */

34   public NotificationChainImpl()
35   {
36     super();
37   }
38
39   /**
40    * Creates an empty instance with a given capacity.
41    * param initialCapacity the initial capacity of the list before it must grow.
42    */

43   public NotificationChainImpl(int initialCapacity)
44   {
45     super(initialCapacity);
46   }
47
48   /**
49    * Returns new data storage of type {@link Notification}[].
50    * @return new data storage.
51    */

52   protected Object JavaDoc [] newData(int capacity)
53   {
54     return new Notification [capacity];
55   }
56
57   /**
58    * Adds or merges a new notification.
59    * @param newNotification a notification.
60    * @return <code>true</code> when the notification is added and <code>false</code> when it is merged.
61    */

62   public boolean add(Notification newNotification)
63   {
64     if (newNotification == null)
65     {
66       return false;
67     }
68     else
69     {
70       for (int i = 0; i < size; ++i)
71       {
72         Notification notification = (Notification)data[i];
73         if (notification.merge(newNotification))
74         {
75           return false;
76         }
77       }
78
79       return super.add(newNotification);
80     }
81   }
82
83   /**
84    * Returns the result of calling {@link #add(Notification)}.
85    * @param object the notification to add.
86    * @return the result of calling <code>add(Notification)</code>.
87    */

88   public boolean add(Object JavaDoc object)
89   {
90     return add((Notification)object);
91   }
92
93   /*
94    * Javadoc copied from interface.
95    */

96   public void dispatch()
97   {
98     for (int i = 0; i < size; ++i)
99     {
100       Notification notification = (Notification)data[i];
101       dispatch(notification);
102     }
103   }
104
105   /**
106    * Dispatches the notification to it's notifier.
107    */

108   protected void dispatch(Notification notification)
109   {
110     Object JavaDoc notifier = notification.getNotifier();
111     if (notifier != null && notification.getEventType() != -1)
112     {
113       ((Notifier)notifier).eNotify(notification);
114     }
115   }
116 }
117
Popular Tags