KickJava   Java API By Example, From Geeks To Geeks.

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


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

17 package org.eclipse.emf.ecore.impl;
18
19
20 import java.math.BigDecimal JavaDoc;
21 import java.math.BigInteger JavaDoc;
22 import java.text.ParseException JavaDoc;
23 import java.util.Date JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import org.eclipse.emf.common.util.WrappedException;
27 import org.eclipse.emf.ecore.*;
28 import org.eclipse.emf.ecore.EClass;
29 import org.eclipse.emf.ecore.EObject;
30 import org.eclipse.emf.ecore.util.FeatureMap;
31
32 /**
33  * <!-- begin-user-doc -->
34  * An implementation of the model <b>Factory</b>.
35  * <!-- end-user-doc -->
36  * @generated
37  */

38 public class EcoreFactoryImpl extends EFactoryImpl implements EcoreFactory
39 {
40   /**
41    * Creates an instance of the factory.
42    * <!-- begin-user-doc -->
43    * <!-- end-user-doc -->
44    * @generated
45    */

46   public EcoreFactoryImpl()
47   {
48     super();
49   }
50
51   /**
52    * <!-- begin-user-doc -->
53    * <!-- end-user-doc -->
54    * @generated
55    */

56   public EObject create(EClass eClass)
57   {
58     switch (eClass.getClassifierID())
59     {
60       case EcorePackage.EATTRIBUTE: return createEAttribute();
61       case EcorePackage.EANNOTATION: return createEAnnotation();
62       case EcorePackage.ECLASS: return createEClass();
63       case EcorePackage.EDATA_TYPE: return createEDataType();
64       case EcorePackage.EENUM: return createEEnum();
65       case EcorePackage.EENUM_LITERAL: return createEEnumLiteral();
66       case EcorePackage.EFACTORY: return createEFactory();
67       case EcorePackage.EOBJECT: return createEObject();
68       case EcorePackage.EOPERATION: return createEOperation();
69       case EcorePackage.EPACKAGE: return createEPackage();
70       case EcorePackage.EPARAMETER: return createEParameter();
71       case EcorePackage.EREFERENCE: return createEReference();
72       case EcorePackage.ESTRING_TO_STRING_MAP_ENTRY: return (EObject)createEStringToStringMapEntry();
73       default:
74         throw new IllegalArgumentException JavaDoc("The class '" + eClass.getName() + "' is not a valid classifier");
75     }
76   }
77
78   /**
79    * <!-- begin-user-doc -->
80    * <!-- end-user-doc -->
81    * @generated
82    */

83   public Object JavaDoc createFromString(EDataType eDataType, String JavaDoc initialValue)
84   {
85     switch (eDataType.getClassifierID())
86     {
87       case EcorePackage.EBIG_DECIMAL:
88         return createEBigDecimalFromString(eDataType, initialValue);
89       case EcorePackage.EBIG_INTEGER:
90         return createEBigIntegerFromString(eDataType, initialValue);
91       case EcorePackage.EBOOLEAN:
92         return createEBooleanFromString(eDataType, initialValue);
93       case EcorePackage.EBOOLEAN_OBJECT:
94         return createEBooleanObjectFromString(eDataType, initialValue);
95       case EcorePackage.EBYTE:
96         return createEByteFromString(eDataType, initialValue);
97       case EcorePackage.EBYTE_ARRAY:
98         return createEByteArrayFromString(eDataType, initialValue);
99       case EcorePackage.EBYTE_OBJECT:
100         return createEByteObjectFromString(eDataType, initialValue);
101       case EcorePackage.ECHAR:
102         return createECharFromString(eDataType, initialValue);
103       case EcorePackage.ECHARACTER_OBJECT:
104         return createECharacterObjectFromString(eDataType, initialValue);
105       case EcorePackage.EDATE:
106         return createEDateFromString(eDataType, initialValue);
107       case EcorePackage.EDOUBLE:
108         return createEDoubleFromString(eDataType, initialValue);
109       case EcorePackage.EDOUBLE_OBJECT:
110         return createEDoubleObjectFromString(eDataType, initialValue);
111       case EcorePackage.EFEATURE_MAP_ENTRY:
112         return createEFeatureMapEntryFromString(eDataType, initialValue);
113       case EcorePackage.EFLOAT:
114         return createEFloatFromString(eDataType, initialValue);
115       case EcorePackage.EFLOAT_OBJECT:
116         return createEFloatObjectFromString(eDataType, initialValue);
117       case EcorePackage.EINT:
118         return createEIntFromString(eDataType, initialValue);
119       case EcorePackage.EINTEGER_OBJECT:
120         return createEIntegerObjectFromString(eDataType, initialValue);
121       case EcorePackage.EJAVA_CLASS:
122         return createEJavaClassFromString(eDataType, initialValue);
123       case EcorePackage.ELONG:
124         return createELongFromString(eDataType, initialValue);
125       case EcorePackage.ELONG_OBJECT:
126         return createELongObjectFromString(eDataType, initialValue);
127       case EcorePackage.ESHORT:
128         return createEShortFromString(eDataType, initialValue);
129       case EcorePackage.ESHORT_OBJECT:
130         return createEShortObjectFromString(eDataType, initialValue);
131       case EcorePackage.ESTRING:
132         return createEStringFromString(eDataType, initialValue);
133       default:
134         throw new IllegalArgumentException JavaDoc("The datatype '" + eDataType.getName() + "' is not a valid classifier");
135     }
136   }
137
138   /**
139    * <!-- begin-user-doc -->
140    * <!-- end-user-doc -->
141    * @generated
142    */

143   public String JavaDoc convertToString(EDataType eDataType, Object JavaDoc instanceValue)
144   {
145     switch (eDataType.getClassifierID())
146     {
147       case EcorePackage.EBIG_DECIMAL:
148         return convertEBigDecimalToString(eDataType, instanceValue);
149       case EcorePackage.EBIG_INTEGER:
150         return convertEBigIntegerToString(eDataType, instanceValue);
151       case EcorePackage.EBOOLEAN:
152         return convertEBooleanToString(eDataType, instanceValue);
153       case EcorePackage.EBOOLEAN_OBJECT:
154         return convertEBooleanObjectToString(eDataType, instanceValue);
155       case EcorePackage.EBYTE:
156         return convertEByteToString(eDataType, instanceValue);
157       case EcorePackage.EBYTE_ARRAY:
158         return convertEByteArrayToString(eDataType, instanceValue);
159       case EcorePackage.EBYTE_OBJECT:
160         return convertEByteObjectToString(eDataType, instanceValue);
161       case EcorePackage.ECHAR:
162         return convertECharToString(eDataType, instanceValue);
163       case EcorePackage.ECHARACTER_OBJECT:
164         return convertECharacterObjectToString(eDataType, instanceValue);
165       case EcorePackage.EDATE:
166         return convertEDateToString(eDataType, instanceValue);
167       case EcorePackage.EDOUBLE:
168         return convertEDoubleToString(eDataType, instanceValue);
169       case EcorePackage.EDOUBLE_OBJECT:
170         return convertEDoubleObjectToString(eDataType, instanceValue);
171       case EcorePackage.EFEATURE_MAP_ENTRY:
172         return convertEFeatureMapEntryToString(eDataType, instanceValue);
173       case EcorePackage.EFLOAT:
174         return convertEFloatToString(eDataType, instanceValue);
175       case EcorePackage.EFLOAT_OBJECT:
176         return convertEFloatObjectToString(eDataType, instanceValue);
177       case EcorePackage.EINT:
178         return convertEIntToString(eDataType, instanceValue);
179       case EcorePackage.EINTEGER_OBJECT:
180         return convertEIntegerObjectToString(eDataType, instanceValue);
181       case EcorePackage.EJAVA_CLASS:
182         return convertEJavaClassToString(eDataType, instanceValue);
183       case EcorePackage.ELONG:
184         return convertELongToString(eDataType, instanceValue);
185       case EcorePackage.ELONG_OBJECT:
186         return convertELongObjectToString(eDataType, instanceValue);
187       case EcorePackage.ESHORT:
188         return convertEShortToString(eDataType, instanceValue);
189       case EcorePackage.ESHORT_OBJECT:
190         return convertEShortObjectToString(eDataType, instanceValue);
191       case EcorePackage.ESTRING:
192         return convertEStringToString(eDataType, instanceValue);
193       default:
194         throw new IllegalArgumentException JavaDoc("The datatype '" + eDataType.getName() + "' is not a valid classifier");
195     }
196   }
197
198   /**
199    * <!-- begin-user-doc -->
200    * <!-- end-user-doc -->
201    * @generated
202    */

203   public EObject createEObject()
204   {
205     EObjectImpl eObject = new EObjectImpl();
206     return eObject;
207   }
208
209   /**
210    * <!-- begin-user-doc -->
211    * <!-- end-user-doc -->
212    * @generated
213    */

214   public EAttribute createEAttribute()
215   {
216     EAttributeImpl eAttribute = new EAttributeImpl();
217     return eAttribute;
218   }
219
220   /**
221    * <!-- begin-user-doc -->
222    * <!-- end-user-doc -->
223    * @generated
224    */

225   public EAnnotation createEAnnotation()
226   {
227     EAnnotationImpl eAnnotation = new EAnnotationImpl();
228     return eAnnotation;
229   }
230
231   /**
232    * <!-- begin-user-doc -->
233    * <!-- end-user-doc -->
234    * @generated
235    */

236   public EClass createEClass()
237   {
238     EClassImpl eClass = new EClassImpl();
239     return eClass;
240   }
241
242   /**
243    * <!-- begin-user-doc -->
244    * <!-- end-user-doc -->
245    * @generated
246    */

247   public EDataType createEDataType()
248   {
249     EDataTypeImpl eDataType = new EDataTypeImpl();
250     return eDataType;
251   }
252
253   /**
254    * <!-- begin-user-doc -->
255    * <!-- end-user-doc -->
256    * @generated
257    */

258   public EParameter createEParameter()
259   {
260     EParameterImpl eParameter = new EParameterImpl();
261     return eParameter;
262   }
263
264   /**
265    * <!-- begin-user-doc -->
266    * <!-- end-user-doc -->
267    * @generated
268    */

269   public EOperation createEOperation()
270   {
271     EOperationImpl eOperation = new EOperationImpl();
272     return eOperation;
273   }
274
275   /**
276    * <!-- begin-user-doc -->
277    * <!-- end-user-doc -->
278    * @generated
279    */

280   public EPackage createEPackage()
281   {
282     EPackageImpl ePackage = new EPackageImpl();
283     return ePackage;
284   }
285
286   /**
287    * <!-- begin-user-doc -->
288    * <!-- end-user-doc -->
289    * @generated
290    */

291   public EFactory createEFactory()
292   {
293     EFactoryImpl eFactory = new EFactoryImpl();
294     return eFactory;
295   }
296
297   /**
298    * <!-- begin-user-doc -->
299    * <!-- end-user-doc -->
300    * @generated
301    */

302   public EEnumLiteral createEEnumLiteral()
303   {
304     EEnumLiteralImpl eEnumLiteral = new EEnumLiteralImpl();
305     return eEnumLiteral;
306   }
307
308   /**
309    * <!-- begin-user-doc -->
310    * <!-- end-user-doc -->
311    * @generated
312    */

313   public EEnum createEEnum()
314   {
315     EEnumImpl eEnum = new EEnumImpl();
316     return eEnum;
317   }
318
319   protected Boolean JavaDoc booleanValueOf(String JavaDoc initialValue)
320   {
321     if ("true".equalsIgnoreCase(initialValue))
322     {
323       return Boolean.TRUE;
324     }
325     else if ("false".equalsIgnoreCase(initialValue))
326     {
327       return Boolean.FALSE;
328     }
329     else
330     {
331       throw new IllegalArgumentException JavaDoc("Expecting true or false");
332     }
333   }
334
335   /**
336    * <!-- begin-user-doc -->
337    * <!-- end-user-doc -->
338    * @generated NOT
339    */

340   public Boolean JavaDoc createEBooleanObjectFromString(EDataType metaObject, String JavaDoc initialValue)
341   {
342     return initialValue == null ? null : booleanValueOf(initialValue);
343   }
344
345   /**
346    * <!-- begin-user-doc -->
347    * <!-- end-user-doc -->
348    * @generated NOT
349    */

350   public String JavaDoc convertEBooleanObjectToString(EDataType metaObject, Object JavaDoc instanceValue)
351   {
352     return instanceValue == null ? null : instanceValue.toString();
353   }
354
355   /**
356    * <!-- begin-user-doc -->
357    * <!-- end-user-doc -->
358    * @generated NOT
359    */

360   public Character JavaDoc createECharacterObjectFromString(EDataType metaObject, String JavaDoc initialValue)
361   {
362     if (initialValue == null)
363     {
364       return null;
365     }
366
367     char charValue = 0;
368     try
369     {
370       Integer JavaDoc value = new Integer JavaDoc(initialValue);
371       charValue = (char) value.intValue();
372     }
373     catch (NumberFormatException JavaDoc e)
374     {
375       char[] carray = initialValue.toCharArray();
376       charValue = carray[0];
377     }
378     return new Character JavaDoc(charValue);
379   }
380
381   /**
382    * <!-- begin-user-doc -->
383    * <!-- end-user-doc -->
384    * @generated NOT
385    */

386   public String JavaDoc convertECharacterObjectToString(EDataType metaObject, Object JavaDoc instanceValue)
387   {
388     if (instanceValue instanceof Character JavaDoc)
389     {
390       int charInt = ((Character JavaDoc) instanceValue).charValue();
391       Integer JavaDoc value = new Integer JavaDoc(charInt);
392       return value.toString();
393     }
394
395     return instanceValue == null ? null : instanceValue.toString();
396   }
397
398   /**
399    * <!-- begin-user-doc -->
400    * <!-- end-user-doc -->
401    * @generated NOT
402    */

403   public Date JavaDoc createEDateFromString(EDataType eDataType, String JavaDoc initialValue)
404   {
405     if (initialValue == null)
406     {
407       return null;
408     }
409
410     Exception JavaDoc exception = null;
411     for (int i = 0; i < EDATE_FORMATS.length; ++i)
412     {
413       try
414       {
415         return EDATE_FORMATS[i].parse(initialValue);
416       }
417       catch (ParseException JavaDoc parseException)
418       {
419         exception = parseException;
420       }
421     }
422     throw new WrappedException(exception);
423   }
424
425   /**
426    * <!-- begin-user-doc -->
427    * <!-- end-user-doc -->
428    * @generated NOT
429    */

430   public String JavaDoc convertEDateToString(EDataType eDataType, Object JavaDoc instanceValue)
431   {
432     if (instanceValue == null)
433     {
434       return null;
435     }
436     else
437     {
438       return EDATE_FORMATS[0].format((Date JavaDoc)instanceValue);
439     }
440   }
441
442   /**
443    * <!-- begin-user-doc -->
444    * <!-- end-user-doc -->
445    * @generated NOT
446    */

447   public Double JavaDoc createEDoubleObjectFromString(EDataType metaObject, String JavaDoc initialValue)
448   {
449     return initialValue == null ? null : Double.valueOf(initialValue);
450   }
451
452   /**
453    * <!-- begin-user-doc -->
454    * <!-- end-user-doc -->
455    * @generated NOT
456    */

457   public String JavaDoc convertEDoubleObjectToString(EDataType metaObject, Object JavaDoc instanceValue)
458   {
459     return instanceValue == null ? null : instanceValue.toString();
460   }
461
462   /**
463    * <!-- begin-user-doc -->
464    * <!-- end-user-doc -->
465    * @generated NOT
466    */

467   public Float JavaDoc createEFloatObjectFromString(EDataType metaObject, String JavaDoc initialValue)
468   {
469     return initialValue == null ? null : Float.valueOf(initialValue);
470   }
471
472   /**
473    * <!-- begin-user-doc -->
474    * <!-- end-user-doc -->
475    * @generated NOT
476    */

477   public String JavaDoc convertEFloatObjectToString(EDataType metaObject, Object JavaDoc instanceValue)
478   {
479     return instanceValue == null ? null : instanceValue.toString();
480   }
481
482   /**
483    * <!-- begin-user-doc -->
484    * <!-- end-user-doc -->
485    * @generated NOT
486    */

487   public Integer JavaDoc createEIntegerObjectFromString(EDataType metaObject, String JavaDoc initialValue)
488   {
489     return initialValue == null ? null : Integer.valueOf(initialValue);
490   }
491
492   /**
493    * <!-- begin-user-doc -->
494    * <!-- end-user-doc -->
495    * @generated NOT
496    */

497   public String JavaDoc convertEIntegerObjectToString(EDataType metaObject, Object JavaDoc instanceValue)
498   {
499     return instanceValue == null ? null : instanceValue.toString();
500   }
501
502   /**
503    * <!-- begin-user-doc -->
504    * <!-- end-user-doc -->
505    * @generated
506    */

507   public EReference createEReference()
508   {
509     EReferenceImpl eReference = new EReferenceImpl();
510     return eReference;
511   }
512
513   /**
514    * <!-- begin-user-doc -->
515    * <!-- end-user-doc -->
516    * @generated
517    */

518   public Map.Entry JavaDoc createEStringToStringMapEntry()
519   {
520     EStringToStringMapEntryImpl eStringToStringMapEntry = new EStringToStringMapEntryImpl();
521     return eStringToStringMapEntry;
522   }
523
524   /**
525    * <!-- begin-user-doc -->
526    * <!-- end-user-doc -->
527    * @generated NOT
528    */

529   public BigDecimal JavaDoc createEBigDecimalFromString(EDataType eDataType, String JavaDoc initialValue)
530   {
531     return initialValue == null ? null : new BigDecimal JavaDoc(initialValue);
532   }
533
534   /**
535    * <!-- begin-user-doc -->
536    * <!-- end-user-doc -->
537    * @generated NOT
538    */

539   public String JavaDoc convertEBigDecimalToString(EDataType eDataType, Object JavaDoc instanceValue)
540   {
541     return instanceValue == null ? null : instanceValue.toString();
542   }
543
544   /**
545    * <!-- begin-user-doc -->
546    * <!-- end-user-doc -->
547    * @generated NOT
548    */

549   public BigInteger JavaDoc createEBigIntegerFromString(EDataType eDataType, String JavaDoc initialValue)
550   {
551     return initialValue == null ? null : new BigInteger JavaDoc(initialValue);
552   }
553
554   /**
555    * <!-- begin-user-doc -->
556    * <!-- end-user-doc -->
557    * @generated NOT
558    */

559   public String JavaDoc convertEBigIntegerToString(EDataType eDataType, Object JavaDoc instanceValue)
560   {
561     return instanceValue == null ? null : instanceValue.toString();
562   }
563
564   /**
565    * <!-- begin-user-doc -->
566    * <!-- end-user-doc -->
567    * @generated
568    */

569   public EcorePackage getEcorePackage()
570   {
571     return (EcorePackage)getEPackage();
572   }
573
574   /**
575    * @deprecated
576    */

577   public static EcorePackage getPackage()
578   {
579     return EcorePackage.eINSTANCE;
580   }
581
582   /**
583    * <!-- begin-user-doc -->
584    * <!-- end-user-doc -->
585    * @generated NOT
586    */

587   public String JavaDoc createEStringFromString(EDataType metaObject, String JavaDoc initialValue)
588   {
589     return initialValue;
590   }
591
592   /**
593    * <!-- begin-user-doc -->
594    * <!-- end-user-doc -->
595    * @generated NOT
596    */

597   public String JavaDoc convertEStringToString(EDataType metaObject, Object JavaDoc instanceValue)
598   {
599     return (String JavaDoc)instanceValue;
600   }
601
602   /**
603    * <!-- begin-user-doc -->
604    * <!-- end-user-doc -->
605    * @generated
606    */

607   public FeatureMap.Entry createEFeatureMapEntryFromString(EDataType eDataType, String JavaDoc initialValue)
608   {
609     return (FeatureMap.Entry)super.createFromString(eDataType, initialValue);
610   }
611
612   /**
613    * <!-- begin-user-doc -->
614    * <!-- end-user-doc -->
615    * @generated
616    */

617   public String JavaDoc convertEFeatureMapEntryToString(EDataType eDataType, Object JavaDoc instanceValue)
618   {
619     return super.convertToString(eDataType, instanceValue);
620   }
621
622   /**
623    * <!-- begin-user-doc -->
624    * <!-- end-user-doc -->
625    * @generated NOT
626    */

627   public Integer JavaDoc createEIntFromString(EDataType metaObject, String JavaDoc initialValue)
628   {
629     return initialValue == null ? null : Integer.valueOf(initialValue);
630   }
631
632   /**
633    * <!-- begin-user-doc -->
634    * <!-- end-user-doc -->
635    * @generated NOT
636    */

637   public String JavaDoc convertEIntToString(EDataType metaObject, Object JavaDoc instanceValue)
638   {
639     return instanceValue == null ? null : instanceValue.toString();
640   }
641
642   /**
643    * <!-- begin-user-doc -->
644    * <!-- end-user-doc -->
645    * @generated NOT
646    */

647   public Boolean JavaDoc createEBooleanFromString(EDataType metaObject, String JavaDoc initialValue)
648   {
649     return initialValue == null ? null : booleanValueOf(initialValue);
650   }
651
652   /**
653    * <!-- begin-user-doc -->
654    * <!-- end-user-doc -->
655    * @generated NOT
656    */

657   public String JavaDoc convertEBooleanToString(EDataType metaObject, Object JavaDoc instanceValue)
658   {
659     return instanceValue == null ? null : instanceValue.toString();
660   }
661
662   /**
663    * <!-- begin-user-doc -->
664    * <!-- end-user-doc -->
665    * @generated NOT
666    */

667   public Byte JavaDoc createEByteObjectFromString(EDataType metaObject, String JavaDoc initialValue)
668   {
669     return initialValue == null ? null : Byte.valueOf(initialValue);
670   }
671
672   /**
673    * <!-- begin-user-doc -->
674    * <!-- end-user-doc -->
675    * @generated NOT
676    */

677   public String JavaDoc convertEByteObjectToString(EDataType metaObject, Object JavaDoc instanceValue)
678   {
679     return instanceValue == null ? null : instanceValue.toString();
680   }
681
682   /**
683    * <!-- begin-user-doc -->
684    * <!-- end-user-doc -->
685    * @generated NOT
686    */

687   public Float JavaDoc createEFloatFromString(EDataType metaObject, String JavaDoc initialValue)
688   {
689     return initialValue == null ? null : Float.valueOf(initialValue);
690   }
691
692   /**
693    * <!-- begin-user-doc -->
694    * <!-- end-user-doc -->
695    * @generated NOT
696    */

697   public String JavaDoc convertEFloatToString(EDataType metaObject, Object JavaDoc instanceValue)
698   {
699     return instanceValue == null ? null : instanceValue.toString();
700   }
701
702   /**
703    * <!-- begin-user-doc -->
704    * <!-- end-user-doc -->
705    * @generated NOT
706    */

707   public Character JavaDoc createECharFromString(EDataType metaObject, String JavaDoc initialValue)
708   {
709     if (initialValue == null)
710     {
711       return null;
712     }
713     char charValue = 0;
714     try
715     {
716       Integer JavaDoc value = new Integer JavaDoc(initialValue);
717       charValue = (char) value.intValue();
718     }
719     catch (NumberFormatException JavaDoc e)
720     {
721       char[] carray = initialValue.toCharArray();
722       charValue = carray[0];
723     }
724     return new Character JavaDoc(charValue);
725   }
726
727   /**
728    * <!-- begin-user-doc -->
729    * <!-- end-user-doc -->
730    * @generated NOT
731    */

732   public String JavaDoc convertECharToString(EDataType metaObject, Object JavaDoc instanceValue)
733   {
734     if (instanceValue instanceof Character JavaDoc)
735     {
736       int charInt = ((Character JavaDoc) instanceValue).charValue();
737       Integer JavaDoc value = new Integer JavaDoc(charInt);
738       return value.toString();
739     }
740
741     return instanceValue == null ? null : instanceValue.toString();
742   }
743
744   /**
745    * <!-- begin-user-doc -->
746    * <!-- end-user-doc -->
747    * @generated NOT
748    */

749   public Long JavaDoc createELongFromString(EDataType metaObject, String JavaDoc initialValue)
750   {
751     return initialValue == null ? null : Long.valueOf(initialValue);
752   }
753
754   /**
755    * <!-- begin-user-doc -->
756    * <!-- end-user-doc -->
757    * @generated NOT
758    */

759   public String JavaDoc convertELongToString(EDataType metaObject, Object JavaDoc instanceValue)
760   {
761     return instanceValue == null ? null : instanceValue.toString();
762   }
763
764   /**
765    * <!-- begin-user-doc -->
766    * <!-- end-user-doc -->
767    * @generated NOT
768    */

769   public Double JavaDoc createEDoubleFromString(EDataType metaObject, String JavaDoc initialValue)
770   {
771     return initialValue == null ? null : Double.valueOf(initialValue);
772   }
773
774   /**
775    * <!-- begin-user-doc -->
776    * <!-- end-user-doc -->
777    * @generated NOT
778    */

779   public String JavaDoc convertEDoubleToString(EDataType metaObject, Object JavaDoc instanceValue)
780   {
781     return instanceValue == null ? null : instanceValue.toString();
782   }
783
784   /**
785    * <!-- begin-user-doc -->
786    * <!-- end-user-doc -->
787    * @generated NOT
788    */

789   public Byte JavaDoc createEByteFromString(EDataType metaObject, String JavaDoc initialValue)
790   {
791     return initialValue == null ? null : Byte.valueOf(initialValue);
792   }
793
794   /**
795    * <!-- begin-user-doc -->
796    * <!-- end-user-doc -->
797    * @generated NOT
798    */

799   public String JavaDoc convertEByteToString(EDataType metaObject, Object JavaDoc instanceValue)
800   {
801     return instanceValue == null ? null : instanceValue.toString();
802   }
803
804
805   /**
806    * <!-- begin-user-doc -->
807    * <!-- end-user-doc -->
808    * @generated NOT
809    */

810   public byte[] createEByteArrayFromString(EDataType eDataType, String JavaDoc initialValue)
811   {
812     if (initialValue == null)
813     {
814       return null;
815     }
816
817     int size = initialValue.length();
818     int limit = (size + 1) / 2;
819     byte [] result = new byte[limit];
820     if (size % 2 != 0)
821     {
822       result[--limit] = hexCharToByte(initialValue.charAt(size - 1));
823     }
824     
825     for (int i = 0, j = 0; i < limit; ++i)
826     {
827       byte high = hexCharToByte(initialValue.charAt(j++));
828       byte low = hexCharToByte(initialValue.charAt(j++));
829       result[i] = (byte)(high << 4 | low);
830     }
831     return result;
832   }
833
834   protected static byte hexCharToByte(char character)
835   {
836     switch (character)
837     {
838       case '0':
839       case '1':
840       case '2':
841       case '3':
842       case '4':
843       case '5':
844       case '6':
845       case '7':
846       case '8':
847       case '9':
848       {
849         return (byte)(character - '0');
850       }
851       case 'a':
852       case 'b':
853       case 'c':
854       case 'd':
855       case 'e':
856       case 'f':
857       {
858         return (byte)(character - 'a' + 10);
859       }
860       case 'A':
861       case 'B':
862       case 'C':
863       case 'D':
864       case 'E':
865       case 'F':
866       {
867         return (byte)(character - 'A' + 10);
868       }
869       default:
870       {
871         throw new NumberFormatException JavaDoc("Invalid hexadecimal");
872       }
873     }
874   }
875
876   protected static final char [] HEX_DIGITS =
877     { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
878
879   /**
880    * <!-- begin-user-doc -->
881    * <!-- end-user-doc -->
882    * @generated NOT
883    */

884   public String JavaDoc convertEByteArrayToString(EDataType eDataType, Object JavaDoc instanceValue)
885   {
886     if (instanceValue == null)
887     {
888       return null;
889     }
890     else
891     {
892       byte [] bytes = (byte[])instanceValue;
893       char [] result = new char[2 * bytes.length];
894       for (int i = 0, j = 0; i < bytes.length; ++i)
895       {
896         int high = (bytes[i] >> 4) & 0xF;
897         int low = bytes[i] & 0xF;
898         result[j++] = HEX_DIGITS[high];
899         result[j++] = HEX_DIGITS[low];
900       }
901       return new String JavaDoc(result);
902     }
903   }
904
905   /**
906    * <!-- begin-user-doc -->
907    * <!-- end-user-doc -->
908    * @generated NOT
909    */

910   public Short JavaDoc createEShortFromString(EDataType metaObject, String JavaDoc initialValue)
911   {
912     return initialValue == null ? null : Short.valueOf(initialValue);
913   }
914
915   /**
916    * <!-- begin-user-doc -->
917    * <!-- end-user-doc -->
918    * @generated NOT
919    */

920   public String JavaDoc convertEShortToString(EDataType metaObject, Object JavaDoc instanceValue)
921   {
922     return instanceValue == null ? null : instanceValue.toString();
923   }
924
925   /**
926    * <!-- begin-user-doc -->
927    * <!-- end-user-doc -->
928    * @generated NOT
929    */

930   public Class JavaDoc createEJavaClassFromString(EDataType metaObject, String JavaDoc initialValue)
931   {
932     try
933     {
934       if (initialValue == null) return null;
935       else if ("boolean".equals(initialValue)) return boolean.class;
936       else if ("byte".equals(initialValue)) return byte.class;
937       else if ("char".equals(initialValue)) return char.class;
938       else if ("double".equals(initialValue)) return double.class;
939       else if ("float".equals(initialValue)) return float.class;
940       else if ("int".equals(initialValue)) return int.class;
941       else if ("long".equals(initialValue)) return long.class;
942       else if ("short".equals(initialValue)) return short.class;
943       else return Class.forName(initialValue);
944     }
945     catch (ClassNotFoundException JavaDoc e)
946     {
947       throw new WrappedException(e);
948     }
949   }
950
951   /**
952    * <!-- begin-user-doc -->
953    * <!-- end-user-doc -->
954    * @generated NOT
955    */

956   public String JavaDoc convertEJavaClassToString(EDataType metaObject, Object JavaDoc instanceValue)
957   {
958     return instanceValue == null ? "" : ((Class JavaDoc)instanceValue).getName();
959   }
960
961   /**
962    * <!-- begin-user-doc -->
963    * <!-- end-user-doc -->
964    * @generated NOT
965    */

966   public Long JavaDoc createELongObjectFromString(EDataType metaObject, String JavaDoc initialValue)
967   {
968     return initialValue == null ? null : Long.valueOf(initialValue);
969   }
970
971   /**
972    * <!-- begin-user-doc -->
973    * <!-- end-user-doc -->
974    * @generated NOT
975    */

976   public String JavaDoc convertELongObjectToString(EDataType metaObject, Object JavaDoc instanceValue)
977   {
978     return instanceValue == null ? null : instanceValue.toString();
979   }
980
981   /**
982    * <!-- begin-user-doc -->
983    * <!-- end-user-doc -->
984    * @generated NOT
985    */

986   public Short JavaDoc createEShortObjectFromString(EDataType metaObject, String JavaDoc initialValue)
987   {
988     return initialValue == null ? null : Short.valueOf(initialValue);
989   }
990
991   /**
992    * <!-- begin-user-doc -->
993    * <!-- end-user-doc -->
994    * @generated NOT
995    */

996   public String JavaDoc convertEShortObjectToString(EDataType metaObject, Object JavaDoc instanceValue)
997   {
998     return instanceValue == null ? null : instanceValue.toString();
999   }
1000} //EcoreFactoryImpl
1001
Popular Tags