KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > ecore > sdo > impl > ETypeImpl


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2003-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: ETypeImpl.java,v 1.6 2005/06/08 06:24:25 nickb Exp $
16  */

17 package org.eclipse.emf.ecore.sdo.impl;
18
19
20 import java.util.HashMap JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import org.eclipse.emf.common.notify.Adapter;
26 import org.eclipse.emf.common.notify.Notification;
27 import org.eclipse.emf.common.notify.NotificationChain;
28 import org.eclipse.emf.common.notify.Notifier;
29 import org.eclipse.emf.common.util.EList;
30 import org.eclipse.emf.ecore.EClass;
31 import org.eclipse.emf.ecore.EClassifier;
32 import org.eclipse.emf.ecore.EStructuralFeature;
33 import org.eclipse.emf.ecore.InternalEObject;
34 import org.eclipse.emf.ecore.impl.ENotificationImpl;
35 import org.eclipse.emf.ecore.impl.EObjectImpl;
36 import org.eclipse.emf.ecore.sdo.EProperty;
37 import org.eclipse.emf.ecore.sdo.EType;
38 import org.eclipse.emf.ecore.sdo.SDOPackage;
39 import org.eclipse.emf.ecore.sdo.util.SDOUtil;
40 import org.eclipse.emf.ecore.util.EcoreEList;
41 import org.eclipse.emf.ecore.util.ExtendedMetaData;
42 import org.eclipse.emf.ecore.util.InternalEList;
43
44 import commonj.sdo.Property;
45
46
47 /**
48  * <!-- begin-user-doc -->
49  * An implementation of the model object '<em><b>EType</b></em>'.
50  * @extends Adapter
51  * <!-- end-user-doc -->
52  * <p>
53  * The following features are implemented:
54  * <ul>
55  * <li>{@link org.eclipse.emf.ecore.sdo.impl.ETypeImpl#getName <em>Name</em>}</li>
56  * <li>{@link org.eclipse.emf.ecore.sdo.impl.ETypeImpl#getURI <em>URI</em>}</li>
57  * <li>{@link org.eclipse.emf.ecore.sdo.impl.ETypeImpl#getInstanceClass <em>Instance Class</em>}</li>
58  * <li>{@link org.eclipse.emf.ecore.sdo.impl.ETypeImpl#getProperties <em>Properties</em>}</li>
59  * <li>{@link org.eclipse.emf.ecore.sdo.impl.ETypeImpl#getEClassifier <em>EClassifier</em>}</li>
60  * </ul>
61  * </p>
62  *
63  * @generated
64  */

65 public class ETypeImpl extends EObjectImpl implements EType, Adapter
66 {
67   /**
68    * The default value of the '{@link #getName() <em>Name</em>}' attribute.
69    * <!-- begin-user-doc -->
70    * <!-- end-user-doc -->
71    * @see #getName()
72    * @generated
73    * @ordered
74    */

75   protected static final String JavaDoc NAME_EDEFAULT = null;
76
77   /**
78    * The default value of the '{@link #getURI() <em>URI</em>}' attribute.
79    * <!-- begin-user-doc -->
80    * <!-- end-user-doc -->
81    * @see #getURI()
82    * @generated
83    * @ordered
84    */

85   protected static final String JavaDoc URI_EDEFAULT = null;
86
87   /**
88    * The default value of the '{@link #getInstanceClass() <em>Instance Class</em>}' attribute.
89    * <!-- begin-user-doc -->
90    * <!-- end-user-doc -->
91    * @see #getInstanceClass()
92    * @generated
93    * @ordered
94    */

95   protected static final Class JavaDoc INSTANCE_CLASS_EDEFAULT = null;
96
97   /**
98    * The cached value of the '{@link #getEClassifier() <em>EClassifier</em>}' reference.
99    * <!-- begin-user-doc -->
100    * <!-- end-user-doc -->
101    * @see #getEClassifier()
102    * @generated
103    * @ordered
104    */

105   protected EClassifier eClassifier = null;
106
107   /**
108    * <!-- begin-user-doc -->
109    * <!-- end-user-doc -->
110    * @generated
111    */

112   protected ETypeImpl()
113   {
114     super();
115   }
116
117   /**
118    * <!-- begin-user-doc -->
119    * <!-- end-user-doc -->
120    * @generated
121    */

122   protected EClass eStaticClass()
123   {
124     return SDOPackage.eINSTANCE.getEType();
125   }
126
127   /**
128    * <!-- begin-user-doc -->
129    * <!-- end-user-doc -->
130    * @generated NOT
131    */

132   public String JavaDoc getName()
133   {
134     return eClassifier.getName();
135   }
136
137   /**
138    * <!-- begin-user-doc -->
139    * <!-- end-user-doc -->
140    * @generated NOT
141    */

142   public String JavaDoc getURI()
143   {
144     return eClassifier.getEPackage().getNsURI();
145   }
146
147   /**
148    * <!-- begin-user-doc -->
149    * <!-- end-user-doc -->
150    * @generated NOT
151    */

152   public Class JavaDoc getInstanceClass()
153   {
154     return eClassifier.getInstanceClass();
155   }
156
157   protected EList properties;
158   protected EList eAllStructuralFeatures;
159
160   /**
161    * <!-- begin-user-doc -->
162    * <!-- end-user-doc -->
163    * @generated NOT
164    */

165   public EList getPropertiesGen()
166   {
167     if (eAllStructuralFeatures == null)
168     {
169       if (eClassifier instanceof EClass)
170       {
171         EList eAllStructuralFeatures = ((EClass)eClassifier).getEAllStructuralFeatures();
172         properties = adaptProperties(eAllStructuralFeatures);
173         this.eAllStructuralFeatures = eAllStructuralFeatures;
174       }
175       else
176       {
177         properties = new EcoreEList.UnmodifiableEList.FastCompare(this, SDOPackage.eINSTANCE.getType_Properties(), 0, null);
178       }
179     }
180     else
181     {
182       EList eAllStructuralFeatures = ((EClass)eClassifier).getEAllStructuralFeatures();
183       if (this.eAllStructuralFeatures != eAllStructuralFeatures)
184       {
185         properties = adaptProperties(eAllStructuralFeatures);
186         this.eAllStructuralFeatures = eAllStructuralFeatures;
187       }
188     }
189     return properties;
190   }
191
192   protected EList adaptProperties(List JavaDoc eStructuralFeatures)
193   {
194     EProperty [] properties = new EProperty [eStructuralFeatures.size()];
195     for (int i = 0; i < properties.length; ++i)
196     {
197       properties[i] = SDOUtil.adaptProperty((EStructuralFeature)eStructuralFeatures.get(i));
198     }
199
200     return
201       new EcoreEList.UnmodifiableEList.FastCompare
202         (this, SDOPackage.eINSTANCE.getType_Properties(), properties.length, properties);
203   }
204
205   public List JavaDoc getProperties()
206   {
207     return getPropertiesGen();
208   }
209
210   /**
211    * <!-- begin-user-doc -->
212    * <!-- end-user-doc -->
213    * @generated
214    */

215   public EClassifier getEClassifier()
216   {
217     return eClassifier;
218   }
219
220   /**
221    * <!-- begin-user-doc -->
222    * <!-- end-user-doc -->
223    * @generated
224    */

225   public void setEClassifier(EClassifier newEClassifier)
226   {
227     EClassifier oldEClassifier = eClassifier;
228     eClassifier = newEClassifier;
229     if (eNotificationRequired())
230       eNotify(new ENotificationImpl(this, Notification.SET, SDOPackage.ETYPE__ECLASSIFIER, oldEClassifier, eClassifier));
231   }
232
233   /**
234    * <!-- begin-user-doc -->
235    * <!-- end-user-doc -->
236    * @generated NOT
237    */

238   public boolean isInstance(Object JavaDoc object)
239   {
240     return eClassifier.isInstance(object);
241   }
242
243   /**
244    * <!-- begin-user-doc -->
245    * <!-- end-user-doc -->
246    * @generated NOT
247    */

248   public Property getProperty(String JavaDoc propertyName)
249   {
250     return getEProperty(propertyName);
251   }
252
253   protected Map JavaDoc propertyNameToPropertyMap;
254
255   /**
256    * <!-- begin-user-doc -->
257    * <!-- end-user-doc -->
258    * @generated NOT
259    */

260   public EProperty getEProperty(String JavaDoc propertyName)
261   {
262     if (propertyNameToPropertyMap == null)
263     {
264       Map JavaDoc result = new HashMap JavaDoc();
265       for (Iterator JavaDoc i = getProperties().iterator(); i.hasNext(); )
266       {
267         EProperty eProperty = (EProperty)i.next();
268         result.put(eProperty.getName(), eProperty);
269         String JavaDoc xmlName = ExtendedMetaData.INSTANCE.getName(eProperty.getEStructuralFeature());
270         if (!result.containsKey(xmlName))
271         {
272           result.put(xmlName, eProperty);
273         }
274       }
275       propertyNameToPropertyMap = result;
276     }
277
278     return (EProperty)propertyNameToPropertyMap.get(propertyName);
279   }
280
281   public boolean isAdapterForType(Object JavaDoc type)
282   {
283     return type == EType.class;
284   }
285
286   public void notifyChanged(Notification msg)
287   {
288   }
289
290   public Notifier getTarget()
291   {
292     return getEClassifier();
293   }
294
295   public void setTarget(Notifier newTarget)
296   {
297     setEClassifier((EClassifier)newTarget);
298   }
299
300   /**
301    * <!-- begin-user-doc -->
302    * <!-- end-user-doc -->
303    * @generated
304    */

305   public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class JavaDoc baseClass, NotificationChain msgs)
306   {
307     if (featureID >= 0)
308     {
309       switch (eDerivedStructuralFeatureID(featureID, baseClass))
310       {
311         case SDOPackage.ETYPE__PROPERTIES:
312           return ((InternalEList)getProperties()).basicRemove(otherEnd, msgs);
313         default:
314           return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs);
315       }
316     }
317     return eBasicSetContainer(null, featureID, msgs);
318   }
319
320   /**
321    * <!-- begin-user-doc -->
322    * <!-- end-user-doc -->
323    * @generated
324    */

325   public Object JavaDoc eGet(EStructuralFeature eFeature, boolean resolve)
326   {
327     switch (eDerivedStructuralFeatureID(eFeature))
328     {
329       case SDOPackage.ETYPE__NAME:
330         return getName();
331       case SDOPackage.ETYPE__URI:
332         return getURI();
333       case SDOPackage.ETYPE__INSTANCE_CLASS:
334         return getInstanceClass();
335       case SDOPackage.ETYPE__PROPERTIES:
336         return getProperties();
337       case SDOPackage.ETYPE__ECLASSIFIER:
338         return getEClassifier();
339     }
340     return eDynamicGet(eFeature, resolve);
341   }
342
343   /**
344    * <!-- begin-user-doc -->
345    * <!-- end-user-doc -->
346    * @generated
347    */

348   public void eSet(EStructuralFeature eFeature, Object JavaDoc newValue)
349   {
350     switch (eDerivedStructuralFeatureID(eFeature))
351     {
352       case SDOPackage.ETYPE__ECLASSIFIER:
353         setEClassifier((EClassifier)newValue);
354         return;
355     }
356     eDynamicSet(eFeature, newValue);
357   }
358
359   /**
360    * <!-- begin-user-doc -->
361    * <!-- end-user-doc -->
362    * @generated
363    */

364   public void eUnset(EStructuralFeature eFeature)
365   {
366     switch (eDerivedStructuralFeatureID(eFeature))
367     {
368       case SDOPackage.ETYPE__ECLASSIFIER:
369         setEClassifier((EClassifier)null);
370         return;
371     }
372     eDynamicUnset(eFeature);
373   }
374
375   /**
376    * <!-- begin-user-doc -->
377    * <!-- end-user-doc -->
378    * @generated
379    */

380   public boolean eIsSet(EStructuralFeature eFeature)
381   {
382     switch (eDerivedStructuralFeatureID(eFeature))
383     {
384       case SDOPackage.ETYPE__NAME:
385         return NAME_EDEFAULT == null ? getName() != null : !NAME_EDEFAULT.equals(getName());
386       case SDOPackage.ETYPE__URI:
387         return URI_EDEFAULT == null ? getURI() != null : !URI_EDEFAULT.equals(getURI());
388       case SDOPackage.ETYPE__INSTANCE_CLASS:
389         return INSTANCE_CLASS_EDEFAULT == null ? getInstanceClass() != null : !INSTANCE_CLASS_EDEFAULT.equals(getInstanceClass());
390       case SDOPackage.ETYPE__PROPERTIES:
391         return !getProperties().isEmpty();
392       case SDOPackage.ETYPE__ECLASSIFIER:
393         return eClassifier != null;
394     }
395     return eDynamicIsSet(eFeature);
396   }
397
398 } //ETypeImpl
399
Popular Tags