KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > ecore > util > EcoreEMap


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: EcoreEMap.java,v 1.3 2005/06/08 06:20:10 nickb Exp $
16  */

17 package org.eclipse.emf.ecore.util;
18
19
20 import java.lang.reflect.Array JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.ListIterator JavaDoc;
24
25 import org.eclipse.emf.common.notify.NotificationChain;
26 import org.eclipse.emf.common.util.BasicEList;
27 import org.eclipse.emf.common.util.BasicEMap;
28 import org.eclipse.emf.ecore.EClass;
29 import org.eclipse.emf.ecore.EObject;
30 import org.eclipse.emf.ecore.EStructuralFeature;
31 import org.eclipse.emf.ecore.InternalEObject;
32
33
34 public class EcoreEMap extends BasicEMap implements InternalEList, EStructuralFeature.Setting
35 {
36   protected EClass entryEClass;
37   protected Class JavaDoc entryClass;
38
39   public EcoreEMap(EClass entryEClass, Class JavaDoc entryClass, InternalEObject owner, int featureID)
40   {
41     this.entryClass = entryClass;
42     this.entryEClass = entryEClass;
43     delegateEList = new DelegateEObjectContainmentEList(entryClass, owner, featureID);
44   }
45
46   protected void initializeDelegateEList()
47   {
48   }
49
50   protected class DelegateEObjectContainmentEList extends EObjectContainmentEList
51   {
52     public DelegateEObjectContainmentEList(Class JavaDoc entryClass, InternalEObject owner, int featureID)
53     {
54       super(entryClass, owner, featureID);
55     }
56
57     protected void didAdd(int index, Object JavaDoc newObject)
58     {
59       doPut((Entry)newObject);
60     }
61
62     protected void didSet(int index, Object JavaDoc newObject, Object JavaDoc oldObject)
63     {
64       didRemove(index, oldObject);
65       didAdd(index, newObject);
66     }
67
68     protected void didRemove(int index, Object JavaDoc oldObject)
69     {
70       doRemove((Entry)oldObject);
71     }
72
73     protected void didClear(int size, Object JavaDoc [] oldObjects)
74     {
75       doClear();
76     }
77
78     protected void didMove(int index, Object JavaDoc movedObject, int oldIndex)
79     {
80       doMove((Entry)movedObject);
81     }
82   }
83
84   protected BasicEList newList()
85   {
86     return
87       new BasicEList()
88       {
89         public Object JavaDoc [] newData(int listCapacity)
90         {
91           return (Object JavaDoc [])Array.newInstance(entryClass, listCapacity);
92         }
93       };
94   }
95
96   protected Entry newEntry(int hash, Object JavaDoc key, Object JavaDoc value)
97   {
98     Entry entry = (Entry)entryEClass.getEPackage().getEFactoryInstance().create(entryEClass);
99     entry.setHash(hash);
100     entry.setKey(key);
101     entry.setValue(value);
102     return entry;
103   }
104
105   public Object JavaDoc basicGet(int index)
106   {
107     return ((InternalEList)delegateEList).basicGet(index);
108   }
109
110   public List JavaDoc basicList()
111   {
112     return ((InternalEList)delegateEList).basicList();
113   }
114
115   /**
116    * Returns an iterator that yields unresolved values.
117    */

118   public Iterator JavaDoc basicIterator()
119   {
120     return ((InternalEList)delegateEList).basicIterator();
121   }
122
123   /**
124    * Returns a list iterator that yields unresolved values.
125    */

126   public ListIterator JavaDoc basicListIterator()
127   {
128     return ((InternalEList)delegateEList).basicListIterator();
129   }
130
131   /**
132    * Returns a list iterator that yields unresolved values.
133    */

134   public ListIterator JavaDoc basicListIterator(int index)
135   {
136     return ((InternalEList)delegateEList).basicListIterator(index);
137   }
138
139   /**
140    * Remove the object with without updating the inverse.
141    */

142   public NotificationChain basicRemove(Object JavaDoc object, NotificationChain notifications)
143   {
144     return ((InternalEList)delegateEList).basicRemove(object, notifications);
145   }
146
147   /**
148    * Add the object without updating the inverse.
149    */

150   public NotificationChain basicAdd(Object JavaDoc object, NotificationChain notifications)
151   {
152     return ((InternalEList)delegateEList).basicAdd(object, notifications);
153   }
154
155   /**
156    * Add the object without verifying uniqueness.
157    */

158   public void addUnique(Object JavaDoc object)
159   {
160     ((InternalEList)delegateEList).addUnique(object);
161   }
162
163   /**
164    * Add the object without verifying uniqueness.
165    */

166   public void addUnique(int index, Object JavaDoc object)
167   {
168     ((InternalEList)delegateEList).addUnique(index, object);
169   }
170
171   /**
172    * Set the object without verifying uniqueness.
173    */

174   public Object JavaDoc setUnique(int index, Object JavaDoc object)
175   {
176     return ((InternalEList)delegateEList).setUnique(index, object);
177   }
178
179   public EObject getEObject()
180   {
181     return ((EStructuralFeature.Setting)delegateEList).getEObject();
182   }
183
184   public EStructuralFeature getEStructuralFeature()
185   {
186     return ((EStructuralFeature.Setting)delegateEList).getEStructuralFeature();
187   }
188
189   public Object JavaDoc get(boolean resolve)
190   {
191     return ((EStructuralFeature.Setting)delegateEList).get(resolve);
192   }
193
194   public void set(Object JavaDoc value)
195   {
196     ((EStructuralFeature.Setting)delegateEList).set(value);
197   }
198
199   public boolean isSet()
200   {
201     return ((EStructuralFeature.Setting)delegateEList).isSet();
202   }
203
204   public void unset()
205   {
206     ((EStructuralFeature.Setting)delegateEList).unset();
207   }
208 }
209
Popular Tags