KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > ecore > impl > EClassifierImpl


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: EClassifierImpl.java,v 1.10 2005/06/12 13:29:22 emerks Exp $
16  */

17 package org.eclipse.emf.ecore.impl;
18
19
20 import java.util.Collection JavaDoc;
21
22 import org.eclipse.emf.common.notify.Notification;
23 import org.eclipse.emf.common.notify.NotificationChain;
24 import org.eclipse.emf.common.util.WrappedException;
25 import org.eclipse.emf.ecore.EClass;
26 import org.eclipse.emf.ecore.EClassifier;
27 import org.eclipse.emf.ecore.EObject;
28 import org.eclipse.emf.ecore.EPackage;
29 import org.eclipse.emf.ecore.EStructuralFeature;
30 import org.eclipse.emf.ecore.EcorePackage;
31 import org.eclipse.emf.ecore.InternalEObject;
32 import org.eclipse.emf.ecore.util.BasicExtendedMetaData;
33 import org.eclipse.emf.ecore.util.InternalEList;
34
35
36 /**
37  * <!-- begin-user-doc -->
38  * An implementation of the model object '<em><b>EMeta Object</b></em>'.
39  * @extends BasicExtendedMetaData.EClassifierExtendedMetaData.Holder
40  * <!-- end-user-doc -->
41  * <p>
42  * The following features are implemented:
43  * <ul>
44  * <li>{@link org.eclipse.emf.ecore.impl.EClassifierImpl#getInstanceClassName <em>Instance Class Name</em>}</li>
45  * <li>{@link org.eclipse.emf.ecore.impl.EClassifierImpl#getInstanceClass <em>Instance Class</em>}</li>
46  * <li>{@link org.eclipse.emf.ecore.impl.EClassifierImpl#getDefaultValue <em>Default Value</em>}</li>
47  * <li>{@link org.eclipse.emf.ecore.impl.EClassifierImpl#getEPackage <em>EPackage</em>}</li>
48  * </ul>
49  * </p>
50  *
51  * @generated
52  */

53 public abstract class EClassifierImpl extends ENamedElementImpl implements EClassifier, BasicExtendedMetaData.EClassifierExtendedMetaData.Holder
54 {
55   protected int metaObjectID = -1;
56
57   /**
58    * <!-- begin-user-doc -->
59    * <!-- end-user-doc -->
60    * @generated
61    */

62   protected EClassifierImpl()
63   {
64     super();
65   }
66
67   /**
68    * <!-- begin-user-doc -->
69    * <!-- end-user-doc -->
70    * @generated
71    */

72   protected EClass eStaticClass()
73   {
74     return EcorePackage.eINSTANCE.getEClassifier();
75   }
76
77   /**
78    * <!-- begin-user-doc -->
79    * <!-- end-user-doc -->
80    * @modifiable
81    */

82   public int getClassifierID()
83   {
84     return metaObjectID;
85   }
86
87   /**
88    * <!-- begin-user-doc -->
89    * <!-- end-user-doc -->
90    * @generated
91    */

92   public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class JavaDoc baseClass, NotificationChain msgs)
93   {
94     if (featureID >= 0)
95     {
96       switch (eDerivedStructuralFeatureID(featureID, baseClass))
97       {
98         case EcorePackage.ECLASSIFIER__EANNOTATIONS:
99           return ((InternalEList)getEAnnotations()).basicAdd(otherEnd, msgs);
100         case EcorePackage.ECLASSIFIER__EPACKAGE:
101           if (eContainer != null)
102             msgs = eBasicRemoveFromContainer(msgs);
103           return eBasicSetContainer(otherEnd, EcorePackage.ECLASSIFIER__EPACKAGE, msgs);
104         default:
105           return eDynamicInverseAdd(otherEnd, featureID, baseClass, msgs);
106       }
107     }
108     if (eContainer != null)
109       msgs = eBasicRemoveFromContainer(msgs);
110     return eBasicSetContainer(otherEnd, featureID, msgs);
111   }
112
113   /**
114    * <!-- begin-user-doc -->
115    * <!-- end-user-doc -->
116    * @generated
117    */

118   public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class JavaDoc baseClass, NotificationChain msgs)
119   {
120     if (featureID >= 0)
121     {
122       switch (eDerivedStructuralFeatureID(featureID, baseClass))
123       {
124         case EcorePackage.ECLASSIFIER__EANNOTATIONS:
125           return ((InternalEList)getEAnnotations()).basicRemove(otherEnd, msgs);
126         case EcorePackage.ECLASSIFIER__EPACKAGE:
127           return eBasicSetContainer(null, EcorePackage.ECLASSIFIER__EPACKAGE, msgs);
128         default:
129           return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs);
130       }
131     }
132     return eBasicSetContainer(null, featureID, msgs);
133   }
134
135   public void setClassifierID(int id)
136   {
137     metaObjectID = id;
138   }
139
140   /**
141    * Returns whether the object is an instance of this classifier.
142    * @param object the object in question.
143    * @return whether the object is an instance.
144    * @see Class#isInstance
145    */

146   public boolean isInstance(Object JavaDoc object)
147   {
148     if (object != null)
149     {
150       Class JavaDoc instanceClass = getInstanceClass();
151       if (instanceClass != null)
152       {
153         if (instanceClass.isPrimitive())
154         {
155           if (instanceClass == Boolean.TYPE)
156           {
157             return object instanceof Boolean JavaDoc;
158           }
159           else if (instanceClass == Integer.TYPE)
160           {
161             return object instanceof Integer JavaDoc;
162           }
163           else if (instanceClass == Float.TYPE)
164           {
165             return object instanceof Float JavaDoc;
166           }
167           else if (instanceClass == Byte.TYPE)
168           {
169             return object instanceof Byte JavaDoc;
170           }
171           else if (instanceClass == Character.TYPE)
172           {
173             return object instanceof Character JavaDoc;
174           }
175           else if (instanceClass == Double.TYPE)
176           {
177             return object instanceof Double JavaDoc;
178           }
179           else if (instanceClass == Short.TYPE)
180           {
181             return object instanceof Short JavaDoc;
182           }
183           else if (instanceClass == Long.TYPE)
184           {
185             return object instanceof Long JavaDoc;
186           }
187         }
188         else
189         {
190           return instanceClass.isInstance(object);
191         }
192       }
193       else if (object instanceof EObject)
194       {
195         return dynamicIsInstance((EObject)object);
196       }
197     }
198
199     return false;
200   }
201
202   protected boolean dynamicIsInstance(EObject eObject)
203   {
204     return eObject.eClass() == this;
205   }
206
207   /**
208    * <!-- begin-user-doc -->
209    * <!-- end-user-doc -->
210    * @generated
211    */

212   public Object JavaDoc eGet(EStructuralFeature eFeature, boolean resolve)
213   {
214     switch (eDerivedStructuralFeatureID(eFeature))
215     {
216       case EcorePackage.ECLASSIFIER__EANNOTATIONS:
217         return getEAnnotations();
218       case EcorePackage.ECLASSIFIER__NAME:
219         return getName();
220       case EcorePackage.ECLASSIFIER__INSTANCE_CLASS_NAME:
221         return getInstanceClassName();
222       case EcorePackage.ECLASSIFIER__INSTANCE_CLASS:
223         return getInstanceClass();
224       case EcorePackage.ECLASSIFIER__DEFAULT_VALUE:
225         return getDefaultValue();
226       case EcorePackage.ECLASSIFIER__EPACKAGE:
227         return getEPackage();
228     }
229     return eDynamicGet(eFeature, resolve);
230   }
231
232   /**
233    * <!-- begin-user-doc -->
234    * <!-- end-user-doc -->
235    * @generated
236    */

237   public boolean eIsSet(EStructuralFeature eFeature)
238   {
239     switch (eDerivedStructuralFeatureID(eFeature))
240     {
241       case EcorePackage.ECLASSIFIER__EANNOTATIONS:
242         return eAnnotations != null && !eAnnotations.isEmpty();
243       case EcorePackage.ECLASSIFIER__NAME:
244         return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
245       case EcorePackage.ECLASSIFIER__INSTANCE_CLASS_NAME:
246         return INSTANCE_CLASS_NAME_EDEFAULT == null ? instanceClassName != null : !INSTANCE_CLASS_NAME_EDEFAULT.equals(instanceClassName);
247       case EcorePackage.ECLASSIFIER__INSTANCE_CLASS:
248         return INSTANCE_CLASS_EDEFAULT == null ? getInstanceClass() != null : !INSTANCE_CLASS_EDEFAULT.equals(getInstanceClass());
249       case EcorePackage.ECLASSIFIER__DEFAULT_VALUE:
250         return DEFAULT_VALUE_EDEFAULT == null ? getDefaultValue() != null : !DEFAULT_VALUE_EDEFAULT.equals(getDefaultValue());
251       case EcorePackage.ECLASSIFIER__EPACKAGE:
252         return getEPackage() != null;
253     }
254     return eDynamicIsSet(eFeature);
255   }
256
257   /**
258    * <!-- begin-user-doc -->
259    * <!-- end-user-doc -->
260    * @generated
261    */

262   public void eSet(EStructuralFeature eFeature, Object JavaDoc newValue)
263   {
264     switch (eDerivedStructuralFeatureID(eFeature))
265     {
266       case EcorePackage.ECLASSIFIER__EANNOTATIONS:
267         getEAnnotations().clear();
268         getEAnnotations().addAll((Collection JavaDoc)newValue);
269         return;
270       case EcorePackage.ECLASSIFIER__NAME:
271         setName((String JavaDoc)newValue);
272         return;
273       case EcorePackage.ECLASSIFIER__INSTANCE_CLASS_NAME:
274         setInstanceClassName((String JavaDoc)newValue);
275         return;
276     }
277     eDynamicSet(eFeature, newValue);
278   }
279
280   /**
281    * <!-- begin-user-doc -->
282    * <!-- end-user-doc -->
283    * @generated
284    */

285   public void eUnset(EStructuralFeature eFeature)
286   {
287     switch (eDerivedStructuralFeatureID(eFeature))
288     {
289       case EcorePackage.ECLASSIFIER__EANNOTATIONS:
290         getEAnnotations().clear();
291         return;
292       case EcorePackage.ECLASSIFIER__NAME:
293         setName(NAME_EDEFAULT);
294         return;
295       case EcorePackage.ECLASSIFIER__INSTANCE_CLASS_NAME:
296         setInstanceClassName(INSTANCE_CLASS_NAME_EDEFAULT);
297         return;
298     }
299     eDynamicUnset(eFeature);
300   }
301
302   /**
303    * The default value of the '{@link #getInstanceClassName() <em>Instance Class Name</em>}' attribute.
304    * <!-- begin-user-doc -->
305    * <!-- end-user-doc -->
306    * @see #getInstanceClassName()
307    * @generated
308    * @ordered
309    */

310   protected static final String JavaDoc INSTANCE_CLASS_NAME_EDEFAULT = null;
311
312   /**
313    * The cached value of the '{@link #getInstanceClassName() <em>Instance Class Name</em>}' attribute.
314    * <!-- begin-user-doc -->
315    * <!-- end-user-doc -->
316    * @see #getInstanceClassName()
317    * @generated
318    * @ordered
319    */

320   protected String JavaDoc instanceClassName = INSTANCE_CLASS_NAME_EDEFAULT;
321
322   /**
323    * <!-- begin-user-doc -->
324    * <!-- end-user-doc -->
325    * @generated
326    */

327   public String JavaDoc getInstanceClassNameGen()
328   {
329     return instanceClassName;
330   }
331
332   public String JavaDoc getInstanceClassName()
333   {
334     return getInstanceClassNameGen() != null ? getInstanceClassNameGen() : generatedInstanceClassName;
335   }
336
337   protected String JavaDoc generatedInstanceClassName;
338
339   public void setGeneratedInstanceClass(boolean isGenerated)
340   {
341     if (isGenerated)
342     {
343       if (generatedInstanceClassName == null)
344       {
345         generatedInstanceClassName = instanceClassName;
346         instanceClassName = null;
347       }
348     }
349     else if (generatedInstanceClassName != null)
350     {
351       instanceClassName = generatedInstanceClassName;
352       generatedInstanceClassName = null;
353     }
354   }
355
356   public void setInstanceClassName(String JavaDoc value)
357   {
358     if (instanceClassName == null && generatedInstanceClassName != null)
359     {
360       instanceClassName = generatedInstanceClassName;
361       generatedInstanceClassName = null;
362     }
363     setInstanceClassNameGen(value == null ? null : value.intern());
364     if (instanceClass != null)
365     {
366       setInstanceClassGen(null);
367     }
368   }
369
370   /**
371    * <!-- begin-user-doc -->
372    * <!-- end-user-doc -->
373    * @generated
374    */

375   public void setInstanceClassNameGen(String JavaDoc newInstanceClassName)
376   {
377     String JavaDoc oldInstanceClassName = instanceClassName;
378     instanceClassName = newInstanceClassName;
379     if (eNotificationRequired())
380       eNotify(new ENotificationImpl(this, Notification.SET, EcorePackage.ECLASSIFIER__INSTANCE_CLASS_NAME, oldInstanceClassName, instanceClassName));
381   }
382
383   /**
384    * The default value of the '{@link #getInstanceClass() <em>Instance Class</em>}' attribute.
385    * @see #getInstanceClass()
386    */

387   protected static final Class JavaDoc INSTANCE_CLASS_EDEFAULT = null;
388
389   /**
390    * The default value of the '{@link #getDefaultValue() <em>Default Value</em>}' attribute.
391    * <!-- begin-user-doc -->
392    * <!-- end-user-doc -->
393    * @see #getDefaultValue()
394    * @generated
395    * @ordered
396    */

397   protected static final Object JavaDoc DEFAULT_VALUE_EDEFAULT = null;
398
399   /**
400    * The cached value of the '{@link #getInstanceClass() <em>Instance Class</em>}' attribute.
401    * @see #getInstanceClass()
402    */

403   protected Class JavaDoc instanceClass = INSTANCE_CLASS_EDEFAULT;
404
405   public Class JavaDoc getInstanceClass()
406   {
407     if (instanceClass == null && (instanceClassName != null || generatedInstanceClassName != null))
408     {
409       try
410       {
411         setInstanceClassGen(getClassForName(getInstanceClassName()));
412       }
413       catch (ClassNotFoundException JavaDoc e)
414       {
415         Class JavaDoc primitiveClass = getPrimitiveOrArrayClass();
416         if (primitiveClass != null)
417           setInstanceClassGen(primitiveClass);
418         else
419           throw new WrappedException(e);
420       }
421     }
422     return getInstanceClassGen();
423   }
424
425   /**
426    * Returns the <code>Class</code> object associated with the class or interface with the given name, as from a {@link
427    * java.lang.Class#forName(String)} call; however, if this classifier belongs to a package, that package's class loader is
428    * used. Since the package may be model-specific code in another plug-in, its class loader may be able to see classes
429    * that Ecore's can't.
430    */

431   protected Class JavaDoc getClassForName(String JavaDoc name) throws ClassNotFoundException JavaDoc
432   {
433     EPackage p = getEPackage();
434     return p != null ? Class.forName(name, true, p.getClass().getClassLoader()) : Class.forName(name);
435   }
436   
437   protected Class JavaDoc getPrimitiveOrArrayClass()
438   {
439     String JavaDoc className = getInstanceClassName();
440     int arrayIndex = className.indexOf('[');
441     if (arrayIndex != -1)
442     {
443       String JavaDoc componentClassName = className.substring(0, arrayIndex);
444       StringBuffer JavaDoc result = new StringBuffer JavaDoc();
445       do result.append('['); while ((arrayIndex = className.indexOf('[', ++arrayIndex)) != -1);
446       if (componentClassName.equals("boolean"))
447         result.append('Z');
448       else if (componentClassName.equals("byte"))
449         result.append('B');
450       else if (componentClassName.equals("char"))
451         result.append('C');
452       else if (componentClassName.equals("double"))
453         result.append('D');
454       else if (componentClassName.equals("float"))
455         result.append('F');
456       else if (componentClassName.equals("int"))
457         result.append('I');
458       else if (componentClassName.equals("long"))
459         result.append('J');
460       else if (componentClassName.equals("short"))
461         result.append('S');
462       else {
463         result.append('L');
464         result.append(componentClassName);
465         result.append(';');
466       }
467       try
468       {
469         return getClassForName(result.toString());
470       }
471       catch (ClassNotFoundException JavaDoc e) {}
472     }
473     else
474     {
475       if (className.equals("boolean"))
476         return java.lang.Boolean.TYPE;
477       else if (className.equals("byte"))
478         return java.lang.Byte.TYPE;
479       else if (className.equals("char"))
480         return java.lang.Character.TYPE;
481       else if (className.equals("double"))
482         return java.lang.Double.TYPE;
483       else if (className.equals("float"))
484         return java.lang.Float.TYPE;
485       else if (className.equals("int"))
486         return java.lang.Integer.TYPE;
487       else if (className.equals("long"))
488         return java.lang.Long.TYPE;
489       else if (className.equals("short"))
490         return java.lang.Short.TYPE;
491     }
492     return null;
493   }
494
495   /**
496    */

497   public Class JavaDoc getInstanceClassGen()
498   {
499     return instanceClass;
500   }
501
502   public void setInstanceClass(Class JavaDoc value)
503   {
504     if (value == null)
505     {
506       setInstanceClassNameGen(null);
507     }
508     else if (value.isArray())
509     {
510       String JavaDoc indices = "[]";
511       for (Class JavaDoc component = value.getComponentType(); ; component = component.getComponentType())
512       {
513         if (!component.isArray())
514         {
515           setInstanceClassNameGen((component.getName() + indices).intern());
516           break;
517         }
518         indices += "[]";
519       }
520     }
521     else
522     {
523       setInstanceClassNameGen(value.getName().intern());
524     }
525
526     setInstanceClassGen(value);
527   }
528
529   /**
530    */

531   public void setInstanceClassGen(Class JavaDoc newInstanceClass)
532   {
533     instanceClass = newInstanceClass;
534   }
535
536   /**
537    */

538   public Object JavaDoc getDefaultValue()
539   {
540     return null;
541   }
542
543   /**
544    * <!-- begin-user-doc -->
545    * <!-- end-user-doc -->
546    * @generated modifiable
547    */

548   public EPackage getEPackage()
549   {
550     return (eContainerFeatureID == EcorePackage.ECLASSIFIER__EPACKAGE) ? (EPackage)eContainer : null;
551   }
552
553   /**
554    * <!-- begin-user-doc -->
555    * <!-- end-user-doc -->
556    * @generated
557    */

558   public String JavaDoc toString()
559   {
560     if (eIsProxy()) return super.toString();
561
562     StringBuffer JavaDoc result = new StringBuffer JavaDoc(super.toString());
563     result.append(" (instanceClassName: ");
564     result.append(instanceClassName);
565     result.append(')');
566     return result.toString();
567   }
568
569   /**
570    * <!-- begin-user-doc -->
571    * <!-- end-user-doc -->
572    * @generated
573    */

574   public NotificationChain eBasicRemoveFromContainer(NotificationChain msgs)
575   {
576     if (eContainerFeatureID >= 0)
577     {
578       switch (eContainerFeatureID)
579       {
580         case EcorePackage.ECLASSIFIER__EPACKAGE:
581           return eContainer.eInverseRemove(this, EcorePackage.EPACKAGE__ECLASSIFIERS, EPackage.class, msgs);
582         default:
583           return eDynamicBasicRemoveFromContainer(msgs);
584       }
585     }
586     return eContainer.eInverseRemove(this, EOPPOSITE_FEATURE_BASE - eContainerFeatureID, null, msgs);
587   }
588
589   protected BasicExtendedMetaData.EClassifierExtendedMetaData eClassifierExtendedMetaData;
590
591   public BasicExtendedMetaData.EClassifierExtendedMetaData getExtendedMetaData()
592   {
593     return eClassifierExtendedMetaData;
594   }
595
596   public void setExtendedMetaData(BasicExtendedMetaData.EClassifierExtendedMetaData eClassifierExtendedMetaData)
597   {
598     this.eClassifierExtendedMetaData = eClassifierExtendedMetaData;
599   }
600 }
601
Popular Tags