KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > ecore > sdo > util > SDOUtil


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2003-2005 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: SDOUtil.java,v 1.22 2005/06/14 16:41:09 emerks Exp $
16  */

17 package org.eclipse.emf.ecore.sdo.util;
18
19
20 import java.io.IOException JavaDoc;
21 import java.io.InputStream JavaDoc;
22 import java.io.InvalidObjectException JavaDoc;
23 import java.io.ObjectStreamException JavaDoc;
24 import java.math.BigDecimal JavaDoc;
25 import java.math.BigInteger JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Date JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.Map JavaDoc;
31
32 import org.eclipse.emf.common.util.BasicEList;
33 import org.eclipse.emf.common.util.URI;
34 import org.eclipse.emf.common.util.UniqueEList;
35 import org.eclipse.emf.ecore.EClass;
36 import org.eclipse.emf.ecore.EClassifier;
37 import org.eclipse.emf.ecore.EDataType;
38 import org.eclipse.emf.ecore.EObject;
39 import org.eclipse.emf.ecore.EReference;
40 import org.eclipse.emf.ecore.EStructuralFeature;
41 import org.eclipse.emf.ecore.resource.Resource;
42 import org.eclipse.emf.ecore.resource.ResourceSet;
43 import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
44 import org.eclipse.emf.ecore.sdo.EDataGraph;
45 import org.eclipse.emf.ecore.sdo.EDataObject;
46 import org.eclipse.emf.ecore.sdo.EProperty;
47 import org.eclipse.emf.ecore.sdo.EType;
48 import org.eclipse.emf.ecore.sdo.SDOFactory;
49 import org.eclipse.emf.ecore.sdo.impl.EPropertyImpl;
50 import org.eclipse.emf.ecore.util.EcoreUtil;
51 import org.eclipse.emf.ecore.util.ExtendedMetaData;
52 import org.eclipse.emf.ecore.util.FeatureMap;
53 import org.eclipse.emf.ecore.util.FeatureMapUtil;
54 import org.eclipse.emf.ecore.xmi.impl.EMOFResourceFactoryImpl;
55 import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
56 import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
57 import org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl;
58 import org.eclipse.emf.ecore.xml.type.internal.XMLCalendar;
59
60 import commonj.sdo.DataGraph;
61 import commonj.sdo.DataObject;
62 import commonj.sdo.Property;
63 import commonj.sdo.Sequence;
64 import commonj.sdo.Type;
65
66
67 public final class SDOUtil
68 {
69   public static List JavaDoc getInstanceProperties(EObject eObject)
70   {
71     List JavaDoc result = new UniqueEList();
72     EClass eClass = eObject.eClass();
73     for (int i = 0, count = eClass.getFeatureCount(); i < count; ++i)
74     {
75       EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature(i);
76       if (FeatureMapUtil.isFeatureMap(eStructuralFeature))
77       {
78         List JavaDoc features = (List JavaDoc)eObject.eGet(eStructuralFeature);
79         for (int j = 0, size = features.size(); j < size; ++j)
80         {
81           FeatureMap.Entry entry = (FeatureMap.Entry)features.get(j);
82           EStructuralFeature entryFeature = entry.getEStructuralFeature();
83           result.add(entryFeature);
84         }
85       }
86       else
87       {
88         result.add(eStructuralFeature);
89       }
90     }
91     return result;
92   }
93
94   protected static EStructuralFeature getEStructuralFeature(EObject eObject, String JavaDoc propertyName)
95   {
96     EProperty property = getType(eObject).getEProperty(propertyName);
97     if (property == null)
98     {
99       List JavaDoc instanceProperties = getInstanceProperties(eObject);
100       for (int i = 0, size = instanceProperties.size(); i < size; ++i)
101       {
102         EStructuralFeature eStructuralFeature = (EStructuralFeature)instanceProperties.get(i);
103         if (eStructuralFeature.getName().equals(propertyName))
104         {
105           return eStructuralFeature;
106         }
107       }
108
109       for (int i = 0, size = instanceProperties.size(); i < size; ++i)
110       {
111         EStructuralFeature eStructuralFeature = (EStructuralFeature)instanceProperties.get(i);
112         if (ExtendedMetaData.INSTANCE.getName(eStructuralFeature).equals(propertyName))
113         {
114           return eStructuralFeature;
115         }
116       }
117
118       throw new IllegalArgumentException JavaDoc("Class '" + eObject.eClass().getName() + "' does not have a feature named '" + propertyName + "'");
119     }
120     return property.getEStructuralFeature();
121   }
122
123   protected static EReference getContainmentEReference(EObject eObject, String JavaDoc propertyName)
124   {
125     EProperty property = getType(eObject).getEProperty(propertyName);
126     if (property == null)
127     {
128       throw new IllegalArgumentException JavaDoc("Class '" + eObject.eClass().getName() + "' does not have a feature named '" + propertyName + "'");
129     }
130
131     return getContainmentEReference(property);
132   }
133
134   protected static EReference getContainmentEReference(EProperty property)
135   {
136     EStructuralFeature feature = property.getEStructuralFeature();
137     if (feature instanceof EReference)
138     {
139       EReference reference = (EReference)feature;
140       if (reference.isContainment())
141       {
142         return reference;
143       }
144     }
145     throw new IllegalArgumentException JavaDoc("The feature '" + property.getName() + "' of '" + property.getContainingType().getName()
146       + "' isn't a containment");
147   }
148
149   public static Object JavaDoc get(EObject eObject, String JavaDoc path)
150   {
151     EStructuralFeature eStructuralFeature = eObject.eClass().getEStructuralFeature(path);
152     if (eStructuralFeature != null)
153     {
154       return get(eObject, eStructuralFeature);
155     }
156     else
157     {
158       EProperty property = getType(eObject).getEProperty(path);
159       if (property != null)
160       {
161         return get(eObject, property.getEStructuralFeature());
162       }
163       else
164       {
165         return Accessor.create(eObject, path).getAndRecyle();
166       }
167     }
168   }
169
170   public static void set(EObject eObject, String JavaDoc path, Object JavaDoc value)
171   {
172     EStructuralFeature eStructuralFeature = eObject.eClass().getEStructuralFeature(path);
173     if (eStructuralFeature != null)
174     {
175       set(eObject, eStructuralFeature, value);
176     }
177     else
178     {
179       EProperty property = getType(eObject).getEProperty(path);
180       if (property != null)
181       {
182         set(eObject, property.getEStructuralFeature(), value);
183       }
184       else
185       {
186         Accessor.create(eObject, path).setAndRecyle(value);
187       }
188     }
189   }
190
191   public static boolean isSet(EObject eObject, String JavaDoc path)
192   {
193     EStructuralFeature eStructuralFeature = eObject.eClass().getEStructuralFeature(path);
194     if (eStructuralFeature != null)
195     {
196       return isSet(eObject, eStructuralFeature);
197     }
198     else
199     {
200       EProperty property = getType(eObject).getEProperty(path);
201       if (property != null)
202       {
203         return isSet(eObject, property.getEStructuralFeature());
204       }
205       else
206       {
207         return Accessor.create(eObject, path).isSetAndRecyle();
208       }
209     }
210   }
211
212   public static void unset(EObject eObject, String JavaDoc path)
213   {
214     EStructuralFeature eStructuralFeature = eObject.eClass().getEStructuralFeature(path);
215     if (eStructuralFeature != null)
216     {
217       unset(eObject, eStructuralFeature);
218     }
219     else
220     {
221       EProperty property = getType(eObject).getEProperty(path);
222       if (property != null)
223       {
224         unset(eObject, property.getEStructuralFeature());
225       }
226       else
227       {
228         Accessor.create(eObject, path).unsetAndRecyle();
229       }
230     }
231   }
232
233   public static DataObject getDataObject(EObject eObject, String JavaDoc path)
234   {
235     return (DataObject)get(eObject, path);
236   }
237
238   public static List JavaDoc getList(EObject eObject, String JavaDoc path)
239   {
240     return (List JavaDoc)get(eObject, path);
241   }
242
243   public static Sequence getSequence(EObject eObject, String JavaDoc path)
244   {
245     return (Sequence)get(eObject, path);
246   }
247
248   public static void setDataObject(EObject eObject, String JavaDoc path, DataObject value)
249   {
250     set(eObject, path, value);
251   }
252
253   public static void setList(EObject eObject, String JavaDoc path, List JavaDoc value)
254   {
255     set(eObject, path, value);
256   }
257
258   protected static EStructuralFeature getFeature(EObject eObject, int propertyIndex)
259   {
260     return eObject.eClass().getEStructuralFeature(propertyIndex);
261   }
262
263   public static Object JavaDoc get(EObject eObject, int propertyIndex)
264   {
265     return get(eObject, getFeature(eObject, propertyIndex));
266   }
267
268   public static void set(EObject eObject, int propertyIndex, Object JavaDoc value)
269   {
270     set(eObject, getFeature(eObject, propertyIndex), value);
271   }
272
273   public static boolean isSet(EObject eObject, int propertyIndex)
274   {
275     return isSet(eObject, getFeature(eObject, propertyIndex));
276   }
277
278   public static void unset(EObject eObject, int propertyIndex)
279   {
280     unset(eObject, getFeature(eObject, propertyIndex));
281   }
282
283   public static DataObject getDataObject(EObject eObject, int propertyIndex)
284   {
285     return (DataObject)get(eObject, getFeature(eObject, propertyIndex));
286   }
287
288   public static List JavaDoc getList(EObject eObject, int propertyIndex)
289   {
290     return (List JavaDoc)get(eObject, getFeature(eObject, propertyIndex));
291   }
292
293   public static Sequence getSequence(EObject eObject, int propertyIndex)
294   {
295     return (Sequence)get(eObject, getFeature(eObject, propertyIndex));
296   }
297
298   public static void setDataObject(EObject eObject, int propertyIndex, DataObject value)
299   {
300     set(eObject, getFeature(eObject, propertyIndex), value);
301   }
302
303   public static void setList(EObject eObject, int propertyIndex, List JavaDoc value)
304   {
305     set(eObject, getFeature(eObject, propertyIndex), value);
306   }
307
308   public static Object JavaDoc get(EObject eObject, Property property)
309   {
310     return get(eObject, ((EProperty)property).getEStructuralFeature());
311   }
312
313   public static void set(EObject eObject, Property property, Object JavaDoc value)
314   {
315     set(eObject, ((EProperty)property).getEStructuralFeature(), value);
316   }
317
318   public static boolean isSet(EObject eObject, Property property)
319   {
320     return isSet(eObject, ((EProperty)property).getEStructuralFeature());
321   }
322
323   public static void unset(EObject eObject, Property property)
324   {
325     unset(eObject, ((EProperty)property).getEStructuralFeature());
326   }
327
328   public static DataObject getDataObject(EObject eObject, Property property)
329   {
330     return (DataObject)get(eObject, ((EPropertyImpl)property).getEStructuralFeature());
331   }
332
333   public static List JavaDoc getList(EObject eObject, Property property)
334   {
335     return (List JavaDoc)get(eObject, ((EProperty)property).getEStructuralFeature());
336   }
337
338   public static Sequence getSequence(EObject eObject, Property property)
339   {
340     return (Sequence)get(eObject, ((EProperty)property).getEStructuralFeature());
341   }
342
343   public static void setDataObject(EObject eObject, Property property, DataObject value)
344   {
345     set(eObject, ((EPropertyImpl)property).getEStructuralFeature(), value);
346   }
347
348   public static void setList(EObject eObject, Property property, List JavaDoc value)
349   {
350     set(eObject, ((EProperty)property).getEStructuralFeature(), value);
351   }
352
353   public static DataObject createDataObject(EObject eObject, String JavaDoc propertyName)
354   {
355     EReference eReference = getContainmentEReference(eObject, propertyName);
356     EDataObject result = create(eReference.getEReferenceType());
357     if (FeatureMapUtil.isMany(eObject, eReference))
358     {
359       ((List JavaDoc)eObject.eGet(eReference)).add(result);
360     }
361     else
362     {
363       eObject.eSet(eReference, result);
364     }
365     return result;
366   }
367
368   public static DataObject createDataObject(EObject eObject, int propertyIndex)
369   {
370     EReference eReference = getContainmentEReference((EProperty)getType(eObject).getProperties().get(propertyIndex));
371     EDataObject result = create(eReference.getEReferenceType());
372     if (FeatureMapUtil.isMany(eObject, eReference))
373     {
374       ((List JavaDoc)eObject.eGet(eReference)).add(result);
375     }
376     else
377     {
378       eObject.eSet(eReference, result);
379     }
380     return result;
381   }
382
383   public static DataObject createDataObject(EObject eObject, Property property)
384   {
385     EReference eReference = getContainmentEReference((EProperty)property);
386     EDataObject result = create(eReference.getEReferenceType());
387     if (FeatureMapUtil.isMany(eObject, eReference))
388     {
389       ((List JavaDoc)eObject.eGet(eReference)).add(result);
390     }
391     else
392     {
393       eObject.eSet(eReference, result);
394     }
395     return result;
396   }
397
398   public static DataObject createDataObject(EObject eObject, String JavaDoc propertyName, String JavaDoc namespaceURI, String JavaDoc typeName)
399   {
400     return createDataObject(eObject, propertyName, getDataGraph(eObject).getType(namespaceURI, typeName));
401   }
402
403   public static DataObject createDataObject(EObject eObject, String JavaDoc propertyName, Type type)
404   {
405     EReference eReference = getContainmentEReference(eObject, propertyName);
406     EDataObject result = create(type);
407     if (FeatureMapUtil.isMany(eObject, eReference))
408     {
409       ((List JavaDoc)eObject.eGet(eReference)).add(result);
410     }
411     else
412     {
413       eObject.eSet(eReference, result);
414     }
415     return result;
416   }
417
418   public static DataObject createDataObject(EObject eObject, int propertyIndex, String JavaDoc namespaceURI, String JavaDoc typeName)
419   {
420     return createDataObject(eObject, propertyIndex, getDataGraph(eObject).getType(namespaceURI, typeName));
421   }
422
423   public static DataObject createDataObject(EObject eObject, int propertyIndex, Type type)
424   {
425     EReference eReference = getContainmentEReference((EProperty)getType(eObject).getProperties().get(propertyIndex));
426     EDataObject result = create(type);
427     if (FeatureMapUtil.isMany(eObject, eReference))
428     {
429       ((List JavaDoc)eObject.eGet(eReference)).add(result);
430     }
431     else
432     {
433       eObject.eSet(eReference, result);
434     }
435     return result;
436   }
437
438   public static DataObject createDataObject(EObject eObject, Property property, Type type)
439   {
440     EReference eReference = getContainmentEReference((EProperty)property);
441     EDataObject result = create(type);
442     if (FeatureMapUtil.isMany(eObject, eReference))
443     {
444       ((List JavaDoc)eObject.eGet(eReference)).add(result);
445     }
446     else
447     {
448       eObject.eSet(eReference, result);
449     }
450     return result;
451   }
452
453   public static void delete(EObject eObject)
454   {
455     EcoreUtil.remove(eObject);
456     List JavaDoc contents = new ArrayList JavaDoc(eObject.eContents());
457     for (int i = 0, size = contents.size(); i < size; ++i)
458     {
459       delete((EObject)contents.get(i));
460     }
461     EClass eClass = eObject.eClass();
462     for (int i = 0, size = eClass.getFeatureCount(); i < size; ++i)
463     {
464       EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature(i);
465       if (eStructuralFeature.isChangeable() && !eStructuralFeature.isDerived() && !adaptProperty(eStructuralFeature).isReadOnly())
466       {
467         eObject.eUnset(eStructuralFeature);
468       }
469     }
470   }
471
472   public static DataObject getContainer(EObject eObject)
473   {
474     return (DataObject)eObject.eContainer();
475   }
476
477   public static EProperty getContainmentProperty(EObject eObject)
478   {
479     EReference eContainmentFeature = eObject.eContainmentFeature();
480     return eContainmentFeature == null ? null : adaptProperty(eContainmentFeature);
481   }
482
483   public static EDataGraph getEDataGraph(EObject eObject)
484   {
485     Resource resource = eObject.eResource();
486     if (resource != null)
487     {
488       ResourceSet resourceSet = resource.getResourceSet();
489       if (resourceSet != null)
490       {
491         return (EDataGraph)EcoreUtil.getAdapter(resourceSet.eAdapters(), EDataGraph.class);
492       }
493     }
494
495     return null;
496   }
497
498   public static DataGraph getDataGraph(EObject eObject)
499   {
500     return getEDataGraph(eObject);
501   }
502
503   public static EType getType(EObject eObject)
504   {
505     return adaptType(eObject.eClass());
506   }
507
508   public static EType adaptType(EClassifier eClassifier)
509   {
510     List JavaDoc adapters = eClassifier.eAdapters();
511     Object JavaDoc result = EcoreUtil.getAdapter(adapters, EType.class);
512     if (result != null)
513     {
514       return (EType)result;
515     }
516     else
517     {
518       EType eType = SDOFactory.eINSTANCE.createEType();
519       adapters.add(0, eType);
520       return eType;
521     }
522   }
523
524   public static EProperty adaptProperty(EStructuralFeature eStructuralFeature)
525   {
526     List JavaDoc adapters = eStructuralFeature.eAdapters();
527     Object JavaDoc result = EcoreUtil.getAdapter(adapters, EProperty.class);
528     if (result != null)
529     {
530       return (EProperty)result;
531     }
532     else
533     {
534       EProperty eProperty = SDOFactory.eINSTANCE.createEProperty();
535       adapters.add(eProperty);
536       return eProperty;
537     }
538   }
539
540   public static EDataObject create(Type type)
541   {
542     return create((EType)type);
543   }
544
545   public static EDataObject create(EType eType)
546   {
547     return create((EClass)eType.getEClassifier());
548   }
549
550   public static EDataObject create(EClass eClass)
551   {
552     return (EDataObject)EcoreUtil.create(eClass);
553   }
554
555   public static Object JavaDoc writeReplace(EObject eObject) throws ObjectStreamException JavaDoc
556   {
557     EDataGraph eDataGraph = getEDataGraph(eObject);
558     if (eDataGraph != null)
559     {
560       return ((EDataGraph.Internal)eDataGraph).getWriteReplacement(eObject);
561     }
562     else
563     {
564       throw new InvalidObjectException JavaDoc("The object must be in a datagraph to be serialized " + eObject);
565     }
566   }
567
568   public static Object JavaDoc get(EObject eObject, EProperty property)
569   {
570     return get(eObject, property.getEStructuralFeature());
571   }
572
573   public static void set(EObject eObject, EProperty property, Object JavaDoc value)
574   {
575     set(eObject, property.getEStructuralFeature(), value);
576   }
577
578   public static boolean isSet(EObject eObject, EProperty property)
579   {
580     return isSet(eObject, property.getEStructuralFeature());
581   }
582
583   public static void unset(EObject eObject, EProperty property)
584   {
585     unset(eObject, property.getEStructuralFeature());
586   }
587
588   protected static Object JavaDoc get(EObject eObject, EStructuralFeature feature)
589   {
590     Object JavaDoc result = eObject.eGet(feature);
591     if (FeatureMapUtil.isFeatureMap(feature))
592     {
593       result = new BasicESequence((FeatureMap.Internal)result);
594     }
595     return result;
596   }
597
598   protected static void set(EObject eObject, EStructuralFeature feature, Object JavaDoc value)
599   {
600     eObject.eSet(feature, value);
601   }
602
603   protected static boolean isSet(EObject eObject, EStructuralFeature feature)
604   {
605     return eObject.eIsSet(feature);
606   }
607
608   protected static void unset(EObject eObject, EStructuralFeature feature)
609   {
610     eObject.eUnset(feature);
611   }
612
613   /**
614    * Process the default EMF path and minimal XPath syntax.
615    * This design is still under review and construction.
616    *
617    * Syntax:
618    *
619    *<pre>
620    * path = /? (step '/')* step
621    * step = feature
622    * | feature '.' index_from_0
623    * | feature '[' index_from_1 ']'
624    * | reference '[' attribute '=' value ']'
625    * | ..
626    * | '@' step
627    *</pre>
628    *
629    * feature = the name of an attribute or reference
630    * attribute = the name of an attribute
631    * reference = the name of a reference
632    * index = positive integer
633    * value = the string value of an attribute
634    * leading / begins at the root
635    * .. is containing object
636    *
637    * features must be multi-valued to use '.' and '[' operations.
638    * Only the last step may have an attribute as the feature.
639    */

640   protected static final class Accessor
641   {
642     /**
643      * Creates an accessor for the path of the object.
644      */

645     public static Accessor create(EObject eObject, String JavaDoc path)
646     {
647       Accessor result = pool.get();
648       result.init(eObject, path);
649       return result;
650     }
651
652     /**
653      * Only the get and recycle methods should be call; they are the only synchronized methods.
654      */

655     protected static class Pool extends BasicEList
656     {
657       protected Accessor[] accessors;
658
659       public Pool()
660       {
661         super(10);
662       }
663
664       protected Object JavaDoc[] newData(int capacity)
665       {
666         return accessors = new Accessor [capacity];
667       }
668
669       /**
670        * Returns a recyled instance or a new instance.
671        */

672       public synchronized Accessor get()
673       {
674         if (size > 0)
675         {
676           return accessors[--size];
677         }
678         else
679         {
680           return new Accessor();
681         }
682       }
683
684       /** Safely gives the accessor back for recycled use.
685        */

686       public synchronized void recycle(Accessor accessor)
687       {
688         int minimumCapacity = size + 1;
689         if (minimumCapacity > data.length)
690         {
691           grow(minimumCapacity);
692         }
693         accessors[size++] = accessor;
694       }
695     }
696
697     /**
698      * A static thread safe pool of Accessors.
699      */

700     static final Pool pool = new Pool();
701
702     protected static final int NO_INDEX = -1;
703
704     protected EObject eObject;
705
706     protected EStructuralFeature feature;
707
708     protected int index;
709
710     protected Accessor()
711     {
712     }
713
714     protected Accessor(EObject eObject, String JavaDoc path)
715     {
716       init(eObject, path);
717     }
718
719     protected void init(EObject eObject, String JavaDoc path)
720     {
721       this.eObject = eObject;
722
723       // This should only be called with a path right now.
724
//
725
//feature = getType(eObject).getEProperty(path).getEStructuralFeature();
726
//if (feature == null)
727
{
728         process(path);
729       }
730       //else
731
{
732         //index = NO_INDEX;
733
}
734     }
735
736     public Object JavaDoc get()
737     {
738       if (feature == null)
739       {
740         return eObject;
741       }
742       else
743       {
744         Object JavaDoc value = eObject.eGet(feature, true);
745         if (index >= 0)
746         {
747           value = ((List JavaDoc)value).get(index);
748           if (value instanceof FeatureMap.Entry)
749           {
750             value = ((FeatureMap.Entry)value).getValue();
751           }
752         }
753         else if (FeatureMapUtil.isFeatureMap(feature))
754         {
755           value = new BasicESequence((FeatureMap.Internal)value);
756         }
757         return value;
758       }
759     }
760
761     public Object JavaDoc getAndRecyle()
762     {
763       Object JavaDoc result = get();
764       pool.recycle(this);
765       return result;
766     }
767
768     public void set(Object JavaDoc newValue)
769     {
770       if (index >= 0)
771       {
772         List JavaDoc list = (List JavaDoc)eObject.eGet(feature, true);
773         list.set(index, newValue);
774       }
775       else
776       {
777         // EATM newValue = string2Enum(feature, newValue);
778
eObject.eSet(feature, newValue);
779       }
780     }
781
782     public void setAndRecyle(Object JavaDoc newValue)
783     {
784       set(newValue);
785       pool.recycle(this);
786     }
787
788     public boolean isSet()
789     {
790       return eObject.eIsSet(feature);
791     }
792
793     public boolean isSetAndRecyle()
794     {
795       boolean result = isSet();
796       pool.recycle(this);
797       return result;
798     }
799
800     public void unset()
801     {
802       eObject.eUnset(feature);
803     }
804
805     public void unsetAndRecyle()
806     {
807       unset();
808       pool.recycle(this);
809     }
810
811     public void recycle()
812     {
813       pool.recycle(this);
814     }
815
816     public EObject getEObject()
817     {
818       return eObject;
819     }
820
821     protected void setEObject(EObject eObject)
822     {
823       this.eObject = eObject;
824       feature = null;
825       index = NO_INDEX;
826     }
827
828     public EStructuralFeature getEStructuralFeature()
829     {
830       return feature;
831     }
832
833     protected void setFeatureName(String JavaDoc name)
834     {
835       if (name != null)
836       {
837         feature = SDOUtil.getEStructuralFeature(eObject, name);
838       }
839       else
840       {
841         feature = null;
842       }
843       index = NO_INDEX;
844     }
845
846     protected int getIndex()
847     {
848       return index;
849     }
850
851     protected void setIndex(int index)
852     {
853       this.index = index;
854       if (!FeatureMapUtil.isMany(eObject, feature))
855       {
856         throw new IndexOutOfBoundsException JavaDoc("Index applies only to multi-valued features.");
857       }
858     }
859
860     protected void process(String JavaDoc pathString)
861     {
862       TokenList tokens = new TokenList(pathString.toCharArray());
863       String JavaDoc token;
864       int size = tokens.size();
865       int x = 0;
866
867       if ("/".equals(tokens.peek(0)))
868       {
869         setEObject(EcoreUtil.getRootContainer(eObject));
870         x++;
871       }
872
873       for (; x < size; x++)
874       {
875         token = tokens.peek(x);
876         char c = token.charAt(0);
877         if ('/' == c)
878         {
879           setEObject((EObject)get());
880         }
881         else if ("..".equals(token))
882         {
883           EObject container = eObject.eContainer();
884           if (container == null)
885           {
886             throw new IllegalArgumentException JavaDoc("No containing object for " + eObject);
887           }
888           setEObject(container);
889         }
890         else if ('.' == c)
891         {
892           x++; // skip .
893
token = tokens.peek(x);
894           int index = Integer.parseInt(token);
895           setIndex(index);
896         }
897         else if ('[' == c)
898         {
899           x++; // skip [
900
token = tokens.peek(x); // name or index
901
char following = tokens.peek(x + 1).charAt(0);
902           if ('=' != following)
903           {
904             int index = Integer.parseInt(token) - 1;
905             setIndex(index);
906             x++; // skip ]
907
}
908           else
909           {
910             x++; // done name
911
x++; // skip =
912
String JavaDoc attributeValue = tokens.peek(x); // value
913
if ("\"".equals(attributeValue))
914             {
915               x++; // skip "
916
attributeValue = tokens.peek(++x);
917             }
918             x++; // skip ]
919
int index = matchingIndex((List JavaDoc)get(), token, attributeValue);
920             if (index < 0)
921             {
922               setEObject(null);
923             }
924             else
925             {
926               setIndex(index);
927             }
928           }
929         }
930         else if ('@' == c)
931         {
932           x++; // skip @
933
}
934         else
935         {
936           setFeatureName(token);
937         }
938       }
939     }
940
941     protected static int matchingIndex(List JavaDoc eObjects, String JavaDoc attributeName, String JavaDoc attributeValue)
942     {
943       for (int i = 0, size = eObjects.size(); i < size; i++)
944       {
945         EObject eObject = (EObject)eObjects.get(i);
946         EStructuralFeature feature = getType(eObject).getEProperty(attributeName).getEStructuralFeature();
947         if (feature != null)
948         {
949           Object JavaDoc test = eObject.eGet(feature, true);
950           if (test != null)
951           {
952             String JavaDoc testString = EcoreUtil.convertToString((EDataType)feature.getEType(), test);
953             if (attributeValue.equals(testString))
954             {
955               return i;
956             }
957           }
958         }
959       }
960       return -1;
961     }
962
963     protected static class TokenList extends BasicEList
964     {
965       public TokenList(char[] path)
966       {
967         super(4);
968
969         int pathLength = path.length;
970         StringBuffer JavaDoc token = new StringBuffer JavaDoc();
971         char cPrev;
972         char c = 0;
973         char cNext;
974         char stringConstant = 0;
975         for (int pos = 0; pos < pathLength; pos++)
976         {
977           cPrev = c;
978           c = path[pos];
979           cNext = pos < pathLength - 1 ? path[pos + 1] : 0;
980
981           if (stringConstant != 0)
982           {
983             if (c == stringConstant)
984             {
985               endToken(token, true);
986               stringConstant = 0;
987             }
988             else
989             {
990               token.append(c);
991             }
992           }
993           else
994           {
995             switch (c)
996             {
997               case ' ':
998               case 0xA:
999               case 0xD:
1000              case 0x9:
1001                if (cPrev != ' ')
1002                {
1003                  endToken(token, false);
1004                }
1005                c = ' ';
1006                break;
1007
1008              case '"':
1009              case '\'':
1010                endToken(token, false);
1011                stringConstant = c;
1012                break;
1013
1014              // double or single tokens
1015
case '/':
1016              case ':':
1017              case '.':
1018                if (cPrev != c)
1019                {
1020                  endToken(token, false);
1021                }
1022                token.append(c);
1023                if (cNext != c)
1024                {
1025                  endToken(token, false);
1026                }
1027                break;
1028
1029              // single tokens
1030
case '*':
1031              case '@':
1032              case '[':
1033              case ']':
1034              case '(':
1035              case ')':
1036              case '|':
1037                endToken(token, false);
1038                add(String.valueOf(c));
1039                break;
1040
1041              // TODO: < > <= >= + - !=
1042
case '!':
1043                endToken(token, false);
1044                token.append(c);
1045                break;
1046
1047              case '=':
1048                endToken(token, false);
1049                add(String.valueOf(c));
1050                break;
1051
1052              default:
1053                token.append(c);
1054            }
1055          }
1056        }
1057        endToken(token, false);
1058      }
1059
1060      public String JavaDoc peek()
1061      {
1062        return size > 0 ? (String JavaDoc)data[0] : " ";
1063      }
1064
1065      public String JavaDoc peek(int index)
1066      {
1067        return index < size ? (String JavaDoc)data[index] : " ";
1068      }
1069
1070      public TokenList pop()
1071      {
1072        remove(0);
1073        return this;
1074      }
1075
1076      public TokenList pop(int count)
1077      {
1078        while (count-- > 0)
1079        {
1080          remove(count);
1081        }
1082        return this;
1083      }
1084
1085      protected void endToken(StringBuffer JavaDoc token, boolean includeEmpty)
1086      {
1087        if (includeEmpty || token.length() > 0)
1088        {
1089          add(token.toString());
1090        }
1091        token.setLength(0);
1092      }
1093
1094      protected boolean canContainNull()
1095      {
1096        return false;
1097      }
1098
1099      protected Object JavaDoc[] newData(int capacity)
1100      {
1101        return new String JavaDoc [capacity];
1102      }
1103    }
1104
1105    public String JavaDoc toString()
1106    {
1107      StringBuffer JavaDoc result = new StringBuffer JavaDoc("Accessor (object:");
1108      result.append(eObject == null ? "null" : eObject.toString());
1109      result.append(", feature:");
1110      result.append(feature == null ? "null" : feature.getName());
1111      result.append(", index:");
1112      result.append(index);
1113      result.append(")");
1114      return result.toString();
1115    }
1116  }
1117
1118  public static ResourceSet createResourceSet()
1119  {
1120    ResourceSet result = new ResourceSetImpl();
1121    configureResourceSet(result);
1122    return result;
1123  }
1124
1125  protected static Map JavaDoc registrations;
1126
1127  protected static Map JavaDoc getRegistrations()
1128  {
1129    if (registrations == null)
1130    {
1131      Map JavaDoc result = new HashMap JavaDoc();
1132      ResourceSet resourceSet = new ResourceSetImpl();
1133
1134      if (!(resourceSet.getResourceFactoryRegistry().getFactory(URI.createURI("*.datagraph")) instanceof DataGraphResourceFactoryImpl))
1135      {
1136        result.put("datagraph", new DataGraphResourceFactoryImpl());
1137      }
1138      if (!(resourceSet.getResourceFactoryRegistry().getFactory(URI.createURI("*.ecore")) instanceof EcoreResourceFactoryImpl))
1139      {
1140        result.put("ecore", new EcoreResourceFactoryImpl());
1141      }
1142
1143      if (!(resourceSet.getResourceFactoryRegistry().getFactory(URI.createURI("*.emof")) instanceof EMOFResourceFactoryImpl))
1144      {
1145        result.put("emof", new EMOFResourceFactoryImpl());
1146      }
1147
1148      if (resourceSet.getResourceFactoryRegistry().getFactory(URI.createURI("*.xmi")) == null)
1149      {
1150        result.put("xmi", new XMIResourceFactoryImpl());
1151      }
1152
1153      if (resourceSet.getResourceFactoryRegistry().getFactory(URI.createURI("*.*")) == null)
1154      {
1155        result.put("*", new XMLResourceFactoryImpl());
1156      }
1157
1158      registrations = result;
1159    }
1160
1161    return registrations;
1162  }
1163
1164  public static void configureResourceSet(ResourceSet resourceSet)
1165  {
1166    resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().putAll(getRegistrations());
1167  }
1168
1169  public static EDataGraph loadDataGraph(InputStream JavaDoc inputStream, Map JavaDoc options) throws IOException JavaDoc
1170  {
1171    ResourceSet resourceSet = createResourceSet();
1172    Resource resource = resourceSet.createResource(URI.createURI("all.datagraph"));
1173    resource.load(inputStream, options);
1174    return (EDataGraph)resource.getContents().get(0);
1175  }
1176
1177  public static BigDecimal JavaDoc getBigDecimal(EObject eObject, int propertyIndex)
1178  {
1179    return getBigDecimal(get(eObject, getFeature(eObject, propertyIndex)));
1180  }
1181
1182  public static BigDecimal JavaDoc getBigDecimal(EObject eObject, Property property)
1183  {
1184    return getBigDecimal(get(eObject, ((EPropertyImpl)property).getEStructuralFeature()));
1185  }
1186
1187  public static BigDecimal JavaDoc getBigDecimal(EObject eObject, String JavaDoc path)
1188  {
1189    return getBigDecimal(get(eObject, path));
1190  }
1191
1192  protected static BigDecimal JavaDoc getBigDecimal(Object JavaDoc value)
1193  {
1194    if (value instanceof BigDecimal JavaDoc)
1195    {
1196      return (BigDecimal JavaDoc)value;
1197    }
1198
1199    if (value instanceof BigInteger JavaDoc)
1200    {
1201      return new BigDecimal JavaDoc((BigInteger JavaDoc)value);
1202    }
1203
1204    if (value instanceof Number JavaDoc)
1205    {
1206      return new BigDecimal JavaDoc(((Number JavaDoc)value).doubleValue());
1207    }
1208
1209    if (value instanceof String JavaDoc)
1210    {
1211      return new BigDecimal JavaDoc((String JavaDoc)value);
1212    }
1213
1214    if (value == null)
1215    {
1216      return null;
1217    }
1218
1219    throw new IllegalArgumentException JavaDoc("The value of type '" + value.getClass().getName() + "' cannot be converted to BigDecimal");
1220  }
1221
1222  public static void setBigDecimal(EObject eObject, int propertyIndex, BigDecimal JavaDoc value)
1223  {
1224    EStructuralFeature eStructuralFeature = getFeature(eObject, propertyIndex);
1225    set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1226  }
1227
1228  public static void setBigDecimal(EObject eObject, Property property, BigDecimal JavaDoc value)
1229  {
1230    EStructuralFeature eStructuralFeature = ((EProperty)property).getEStructuralFeature();
1231    set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1232  }
1233
1234  public static void setBigDecimal(EObject eObject, String JavaDoc path, BigDecimal JavaDoc value)
1235  {
1236    EStructuralFeature eStructuralFeature = eObject.eClass().getEStructuralFeature(path);
1237    if (eStructuralFeature != null)
1238    {
1239      set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1240    }
1241    else
1242    {
1243      EProperty property = getType(eObject).getEProperty(path);
1244      if (property != null)
1245      {
1246        eStructuralFeature = property.getEStructuralFeature();
1247        set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1248      }
1249      else
1250      {
1251        Accessor accessor = Accessor.create(eObject, path);
1252        accessor.setAndRecyle(getSetValue(accessor.getEStructuralFeature(), value));
1253      }
1254    }
1255  }
1256
1257  protected static Object JavaDoc getSetValue(EStructuralFeature eStructuralFeature, BigDecimal JavaDoc value)
1258  {
1259    EClassifier eType = eStructuralFeature.getEType();
1260    if (value == null)
1261    {
1262      return eType.getDefaultValue();
1263    }
1264
1265    String JavaDoc name = eType.getInstanceClassName();
1266    if (name == "java.math.BigDecimal")
1267    {
1268      return value;
1269    }
1270
1271    if (name == "java.math.BigInteger")
1272    {
1273      return value.toBigInteger();
1274    }
1275
1276    if (name == "java.lang.Byte" || name == "byte")
1277    {
1278      return new Byte JavaDoc(value.byteValue());
1279    }
1280
1281    if (name == "java.lang.Double" || name == "double")
1282    {
1283      return new Double JavaDoc(value.doubleValue());
1284    }
1285
1286    if (name == "java.lang.Float" || name == "float")
1287    {
1288      return new Float JavaDoc(value.floatValue());
1289    }
1290
1291    if (name == "java.lang.Integer" || name == "int")
1292    {
1293      return new Integer JavaDoc(value.intValue());
1294    }
1295
1296    if (name == "java.lang.Long" || name == "long")
1297    {
1298      return new Long JavaDoc(value.longValue());
1299    }
1300
1301    if (name == "java.lang.Short" || name == "short")
1302    {
1303      return new Short JavaDoc(value.shortValue());
1304    }
1305
1306    if (name == "java.lang.String")
1307    {
1308      return String.valueOf(value);
1309    }
1310
1311    //Instead of throwing an IllegalArgumentException we are passing the value to the feature
1312
return value;
1313  }
1314
1315  public static BigInteger JavaDoc getBigInteger(EObject eObject, int propertyIndex)
1316  {
1317    return getBigInteger(get(eObject, getFeature(eObject, propertyIndex)));
1318  }
1319
1320  public static BigInteger JavaDoc getBigInteger(EObject eObject, Property property)
1321  {
1322    return getBigInteger(get(eObject, ((EProperty)property).getEStructuralFeature()));
1323  }
1324
1325  public static BigInteger JavaDoc getBigInteger(EObject eObject, String JavaDoc path)
1326  {
1327    return getBigInteger(get(eObject, path));
1328  }
1329
1330  protected static BigInteger JavaDoc getBigInteger(Object JavaDoc value)
1331  {
1332    if (value instanceof BigInteger JavaDoc)
1333    {
1334      return (BigInteger JavaDoc)value;
1335    }
1336
1337    if (value instanceof BigDecimal JavaDoc)
1338    {
1339      return ((BigDecimal JavaDoc)value).toBigInteger();
1340    }
1341
1342    if (value instanceof Number JavaDoc)
1343    {
1344      return BigInteger.valueOf(((Number JavaDoc)value).longValue());
1345    }
1346
1347    if (value instanceof String JavaDoc)
1348    {
1349      return new BigInteger JavaDoc((String JavaDoc)value);
1350    }
1351
1352    if (value instanceof byte[])
1353    {
1354      return new BigInteger JavaDoc((byte[])value);
1355    }
1356
1357    if (value == null)
1358    {
1359      return null;
1360    }
1361
1362    throw new IllegalArgumentException JavaDoc("The value of type '" + value.getClass().getName() + "' cannot be converted to BigInteger");
1363  }
1364
1365  public static void setBigInteger(EObject eObject, int propertyIndex, BigInteger JavaDoc value)
1366  {
1367    EStructuralFeature eStructuralFeature = getFeature(eObject, propertyIndex);
1368    set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1369  }
1370
1371  public static void setBigInteger(EObject eObject, Property property, BigInteger JavaDoc value)
1372  {
1373    EStructuralFeature eStructuralFeature = ((EProperty)property).getEStructuralFeature();
1374    set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1375  }
1376
1377  public static void setBigInteger(EObject eObject, String JavaDoc path, BigInteger JavaDoc value)
1378  {
1379    EStructuralFeature eStructuralFeature = eObject.eClass().getEStructuralFeature(path);
1380    if (eStructuralFeature != null)
1381    {
1382      set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1383    }
1384    else
1385    {
1386      EProperty property = getType(eObject).getEProperty(path);
1387      if (property != null)
1388      {
1389        eStructuralFeature = property.getEStructuralFeature();
1390        set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1391      }
1392      else
1393      {
1394        Accessor accessor = Accessor.create(eObject, path);
1395        accessor.setAndRecyle(getSetValue(accessor.getEStructuralFeature(), value));
1396      }
1397    }
1398  }
1399
1400  protected static Object JavaDoc getSetValue(EStructuralFeature eStructuralFeature, BigInteger JavaDoc value)
1401  {
1402    EClassifier eType = eStructuralFeature.getEType();
1403    if (value == null)
1404    {
1405      return eType.getDefaultValue();
1406    }
1407
1408    String JavaDoc name = eType.getInstanceClassName();
1409    if (name == "java.math.BigInteger")
1410    {
1411      return value;
1412    }
1413
1414    if (name == "java.math.BigDecimal")
1415    {
1416      return new BigDecimal JavaDoc(value);
1417    }
1418
1419    if (name == "java.lang.Byte" || name == "byte")
1420    {
1421      return new Byte JavaDoc(value.byteValue());
1422    }
1423
1424    if (name == "java.lang.Double" || name == "double")
1425    {
1426      return new Double JavaDoc(value.doubleValue());
1427    }
1428
1429    if (name == "java.lang.Float" || name == "float")
1430    {
1431      return new Float JavaDoc(value.floatValue());
1432    }
1433
1434    if (name == "java.lang.Integer" || name == "int")
1435    {
1436      return new Integer JavaDoc(value.intValue());
1437    }
1438
1439    if (name == "java.lang.Long" || name == "long")
1440    {
1441      return new Long JavaDoc(value.longValue());
1442    }
1443
1444    if (name == "java.lang.Short" || name == "short")
1445    {
1446      return new Short JavaDoc(value.shortValue());
1447    }
1448
1449    if (name == "java.lang.String")
1450    {
1451      return String.valueOf(value);
1452    }
1453
1454    if (name == "byte[]")
1455    {
1456      return value.toByteArray();
1457    }
1458
1459    //Instead of throwing an IllegalArgumentException we are passing the value to the feature
1460
return value;
1461  }
1462
1463  public static boolean getBoolean(EObject eObject, int propertyIndex)
1464  {
1465    return getBoolean(get(eObject, getFeature(eObject, propertyIndex)));
1466  }
1467
1468  public static boolean getBoolean(EObject eObject, Property property)
1469  {
1470    return getBoolean(get(eObject, ((EProperty)property).getEStructuralFeature()));
1471  }
1472
1473  public static boolean getBoolean(EObject eObject, String JavaDoc path)
1474  {
1475    return getBoolean(get(eObject, path));
1476  }
1477
1478  protected static boolean getBoolean(Object JavaDoc value)
1479  {
1480    if (value instanceof Boolean JavaDoc)
1481    {
1482      return ((Boolean JavaDoc)value).booleanValue();
1483    }
1484
1485    if (value instanceof String JavaDoc)
1486    {
1487      return Boolean.valueOf((String JavaDoc)value).booleanValue();
1488    }
1489
1490    if (value == null)
1491    {
1492      return false;
1493    }
1494
1495    throw new IllegalArgumentException JavaDoc("The value of type '" + value.getClass().getName() + "' cannot be converted to boolean");
1496  }
1497
1498  public static void setBoolean(EObject eObject, int propertyIndex, boolean value)
1499  {
1500    EStructuralFeature eStructuralFeature = getFeature(eObject, propertyIndex);
1501    set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1502  }
1503
1504  public static void setBoolean(EObject eObject, Property property, boolean value)
1505  {
1506    EStructuralFeature eStructuralFeature = ((EProperty)property).getEStructuralFeature();
1507    set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1508  }
1509
1510  public static void setBoolean(EObject eObject, String JavaDoc path, boolean value)
1511  {
1512    EStructuralFeature eStructuralFeature = eObject.eClass().getEStructuralFeature(path);
1513    if (eStructuralFeature != null)
1514    {
1515      set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1516    }
1517    else
1518    {
1519      EProperty property = getType(eObject).getEProperty(path);
1520      if (property != null)
1521      {
1522        eStructuralFeature = property.getEStructuralFeature();
1523        set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1524      }
1525      else
1526      {
1527        Accessor accessor = Accessor.create(eObject, path);
1528        accessor.setAndRecyle(getSetValue(accessor.getEStructuralFeature(), value));
1529      }
1530    }
1531  }
1532
1533  protected static Object JavaDoc getSetValue(EStructuralFeature eStructuralFeature, boolean value)
1534  {
1535    String JavaDoc name = eStructuralFeature.getEType().getInstanceClassName();
1536    if (name == "java.lang.Boolean" || name == "boolean")
1537    {
1538      return value ? Boolean.TRUE : Boolean.FALSE;
1539    }
1540
1541    if (name == "java.lang.String")
1542    {
1543      return String.valueOf(value);
1544    }
1545
1546    //Instead of throwing an IllegalArgumentException we are passing the value to the feature
1547
return value ? Boolean.TRUE : Boolean.FALSE;
1548  }
1549
1550  public static byte getByte(EObject eObject, int propertyIndex)
1551  {
1552    return getByte(get(eObject, getFeature(eObject, propertyIndex)));
1553  }
1554
1555  public static byte getByte(EObject eObject, Property property)
1556  {
1557    return getByte(get(eObject, ((EProperty)property).getEStructuralFeature()));
1558  }
1559
1560  public static byte getByte(EObject eObject, String JavaDoc path)
1561  {
1562    return getByte(get(eObject, path));
1563  }
1564
1565  protected static byte getByte(Object JavaDoc value)
1566  {
1567    if (value instanceof Number JavaDoc)
1568    {
1569      return ((Number JavaDoc)value).byteValue();
1570    }
1571
1572    if (value instanceof String JavaDoc)
1573    {
1574      return Byte.parseByte((String JavaDoc)value);
1575    }
1576
1577    if (value == null)
1578    {
1579      return 0;
1580    }
1581
1582    throw new IllegalArgumentException JavaDoc("The value of type '" + value.getClass().getName() + "' cannot be converted to byte");
1583  }
1584
1585  public static void setByte(EObject eObject, int propertyIndex, byte value)
1586  {
1587    EStructuralFeature eStructuralFeature = getFeature(eObject, propertyIndex);
1588    set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1589  }
1590
1591  public static void setByte(EObject eObject, Property property, byte value)
1592  {
1593    EStructuralFeature eStructuralFeature = ((EProperty)property).getEStructuralFeature();
1594    set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1595  }
1596
1597  public static void setByte(EObject eObject, String JavaDoc path, byte value)
1598  {
1599    EStructuralFeature eStructuralFeature = eObject.eClass().getEStructuralFeature(path);
1600    if (eStructuralFeature != null)
1601    {
1602      set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1603    }
1604    else
1605    {
1606      EProperty property = getType(eObject).getEProperty(path);
1607      if (property != null)
1608      {
1609        eStructuralFeature = property.getEStructuralFeature();
1610        set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1611      }
1612      else
1613      {
1614        Accessor accessor = Accessor.create(eObject, path);
1615        accessor.setAndRecyle(getSetValue(accessor.getEStructuralFeature(), value));
1616      }
1617    }
1618  }
1619
1620  protected static Object JavaDoc getSetValue(EStructuralFeature eStructuralFeature, byte value)
1621  {
1622    String JavaDoc name = eStructuralFeature.getEType().getInstanceClassName();
1623    if (name == "java.lang.Byte" || name == "byte")
1624    {
1625      return new Byte JavaDoc(value);
1626    }
1627
1628    if (name == "java.lang.Double" || name == "double")
1629    {
1630      return new Double JavaDoc(value);
1631    }
1632
1633    if (name == "java.lang.Float" || name == "float")
1634    {
1635      return new Float JavaDoc(value);
1636    }
1637
1638    if (name == "java.lang.Integer" || name == "int")
1639    {
1640      return new Integer JavaDoc(value);
1641    }
1642
1643    if (name == "java.lang.Long" || name == "long")
1644    {
1645      return new Long JavaDoc(value);
1646    }
1647
1648    if (name == "java.lang.Short" || name == "short")
1649    {
1650      return new Short JavaDoc(value);
1651    }
1652
1653    if (name == "java.math.BigDecimal")
1654    {
1655      return getBigDecimal(new Byte JavaDoc(value));
1656    }
1657
1658    if (name == "java.math.BigInteger")
1659    {
1660      return getBigInteger(new Byte JavaDoc(value));
1661    }
1662
1663    if (name == "java.lang.String")
1664    {
1665      return String.valueOf(value);
1666    }
1667
1668    //Instead of throwing an IllegalArgumentException we are passing the value to the feature
1669
return new Byte JavaDoc(value);
1670  }
1671
1672  public static byte[] getBytes(EObject eObject, int propertyIndex)
1673  {
1674    return getBytes(get(eObject, getFeature(eObject, propertyIndex)));
1675  }
1676
1677  public static byte[] getBytes(EObject eObject, Property property)
1678  {
1679    return getBytes(get(eObject, ((EProperty)property).getEStructuralFeature()));
1680  }
1681
1682  public static byte[] getBytes(EObject eObject, String JavaDoc path)
1683  {
1684    return getBytes(get(eObject, path));
1685  }
1686
1687  protected static byte[] getBytes(Object JavaDoc value)
1688  {
1689    if (value instanceof byte[])
1690    {
1691      return (byte[])value;
1692    }
1693
1694    if (value instanceof BigInteger JavaDoc)
1695    {
1696      return ((BigInteger JavaDoc)value).toByteArray();
1697    }
1698
1699    if (value == null)
1700    {
1701      return null;
1702    }
1703
1704    throw new IllegalArgumentException JavaDoc("The value of type '" + value.getClass().getName() + "' cannot be converted to byte array");
1705  }
1706
1707  public static void setBytes(EObject eObject, int propertyIndex, byte[] value)
1708  {
1709    EStructuralFeature eStructuralFeature = getFeature(eObject, propertyIndex);
1710    set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1711  }
1712
1713  public static void setBytes(EObject eObject, Property property, byte[] value)
1714  {
1715    EStructuralFeature eStructuralFeature = ((EProperty)property).getEStructuralFeature();
1716    set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1717  }
1718
1719  public static void setBytes(EObject eObject, String JavaDoc path, byte[] value)
1720  {
1721    EStructuralFeature eStructuralFeature = eObject.eClass().getEStructuralFeature(path);
1722    if (eStructuralFeature != null)
1723    {
1724      set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1725    }
1726    else
1727    {
1728      EProperty property = getType(eObject).getEProperty(path);
1729      if (property != null)
1730      {
1731        eStructuralFeature = property.getEStructuralFeature();
1732        set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1733      }
1734      else
1735      {
1736        Accessor accessor = Accessor.create(eObject, path);
1737        accessor.setAndRecyle(getSetValue(accessor.getEStructuralFeature(), value));
1738      }
1739    }
1740  }
1741
1742  protected static Object JavaDoc getSetValue(EStructuralFeature eStructuralFeature, byte[] value)
1743  {
1744    EClassifier eType = eStructuralFeature.getEType();
1745    if (value == null)
1746    {
1747      return eType.getDefaultValue();
1748    }
1749
1750    String JavaDoc name = eType.getInstanceClassName();
1751    if (name == "byte[]")
1752    {
1753      return value;
1754    }
1755
1756    if (name == "java.math.BigInteger")
1757    {
1758      return new BigInteger JavaDoc(value);
1759    }
1760
1761    //Instead of throwing an IllegalArgumentException we are passing the value to the feature
1762
return value;
1763  }
1764
1765  public static char getChar(EObject eObject, int propertyIndex)
1766  {
1767    return getChar(get(eObject, getFeature(eObject, propertyIndex)));
1768  }
1769
1770  public static char getChar(EObject eObject, Property property)
1771  {
1772    return getChar(get(eObject, ((EProperty)property).getEStructuralFeature()));
1773  }
1774
1775  public static char getChar(EObject eObject, String JavaDoc path)
1776  {
1777    return getChar(get(eObject, path));
1778  }
1779
1780  protected static char getChar(Object JavaDoc value)
1781  {
1782    if (value instanceof Character JavaDoc)
1783    {
1784      return ((Character JavaDoc)value).charValue();
1785    }
1786
1787    if (value instanceof String JavaDoc)
1788    {
1789      return ((String JavaDoc)value).charAt(0);
1790    }
1791
1792    if (value == null)
1793    {
1794      return 0;
1795    }
1796
1797    throw new IllegalArgumentException JavaDoc("The value of type '" + value.getClass().getName() + "' cannot be converted to char");
1798  }
1799
1800  public static void setChar(EObject eObject, int propertyIndex, char value)
1801  {
1802    EStructuralFeature eStructuralFeature = getFeature(eObject, propertyIndex);
1803    set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1804  }
1805
1806  public static void setChar(EObject eObject, Property property, char value)
1807  {
1808    EStructuralFeature eStructuralFeature = ((EProperty)property).getEStructuralFeature();
1809    set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1810  }
1811
1812  public static void setChar(EObject eObject, String JavaDoc path, char value)
1813  {
1814    EStructuralFeature eStructuralFeature = eObject.eClass().getEStructuralFeature(path);
1815    if (eStructuralFeature != null)
1816    {
1817      set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1818    }
1819    else
1820    {
1821      EProperty property = getType(eObject).getEProperty(path);
1822      if (property != null)
1823      {
1824        eStructuralFeature = property.getEStructuralFeature();
1825        set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1826      }
1827      else
1828      {
1829        Accessor accessor = Accessor.create(eObject, path);
1830        accessor.setAndRecyle(getSetValue(accessor.getEStructuralFeature(), value));
1831      }
1832    }
1833  }
1834
1835  protected static Object JavaDoc getSetValue(EStructuralFeature eStructuralFeature, char value)
1836  {
1837    String JavaDoc name = eStructuralFeature.getEType().getInstanceClassName();
1838    if (name == "java.lang.Character" || name == "char")
1839    {
1840      return new Character JavaDoc(value);
1841    }
1842
1843    if (name == "java.lang.String")
1844    {
1845      return String.valueOf(value);
1846    }
1847
1848    //Instead of throwing an IllegalArgumentException we are passing the value to the feature
1849
return new Character JavaDoc(value);
1850  }
1851
1852  public static Date JavaDoc getDate(EObject eObject, int propertyIndex)
1853  {
1854    return getDate(get(eObject, getFeature(eObject, propertyIndex)));
1855  }
1856
1857  public static Date JavaDoc getDate(EObject eObject, Property property)
1858  {
1859    return getDate(get(eObject, ((EProperty)property).getEStructuralFeature()));
1860  }
1861
1862  public static Date JavaDoc getDate(EObject eObject, String JavaDoc path)
1863  {
1864    return getDate(get(eObject, path));
1865  }
1866
1867  protected static Date JavaDoc getDate(Object JavaDoc value)
1868  {
1869    if (value instanceof XMLCalendar)
1870    {
1871      return ((XMLCalendar)value).getDate();
1872    }
1873
1874    if (value instanceof Date JavaDoc)
1875    {
1876      return (Date JavaDoc)value;
1877    }
1878
1879    if (value instanceof Long JavaDoc)
1880    {
1881      return new Date JavaDoc(((Long JavaDoc)value).longValue());
1882    }
1883
1884    if (value == null)
1885    {
1886      return null;
1887    }
1888
1889    throw new IllegalArgumentException JavaDoc("The value of type '" + value.getClass().getName() + "' cannot be converted to Date");
1890  }
1891
1892  public static void setDate(EObject eObject, int propertyIndex, Date JavaDoc value)
1893  {
1894    EStructuralFeature eStructuralFeature = getFeature(eObject, propertyIndex);
1895    set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1896  }
1897
1898  public static void setDate(EObject eObject, Property property, Date JavaDoc value)
1899  {
1900    EStructuralFeature eStructuralFeature = ((EProperty)property).getEStructuralFeature();
1901    set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1902  }
1903
1904  public static void setDate(EObject eObject, String JavaDoc path, Date JavaDoc value)
1905  {
1906    EStructuralFeature eStructuralFeature = eObject.eClass().getEStructuralFeature(path);
1907    if (eStructuralFeature != null)
1908    {
1909      set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1910    }
1911    else
1912    {
1913      EProperty property = getType(eObject).getEProperty(path);
1914      if (property != null)
1915      {
1916        eStructuralFeature = property.getEStructuralFeature();
1917        set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
1918      }
1919      else
1920      {
1921        Accessor accessor = Accessor.create(eObject, path);
1922        accessor.setAndRecyle(getSetValue(accessor.getEStructuralFeature(), value));
1923      }
1924    }
1925  }
1926
1927  protected static Object JavaDoc getSetValue(EStructuralFeature eStructuralFeature, Date JavaDoc value)
1928  {
1929    EClassifier eType = eStructuralFeature.getEType();
1930    if (value == null)
1931    {
1932      return eType.getDefaultValue();
1933    }
1934
1935    String JavaDoc name = eType.getInstanceClassName();
1936    if (name == "java.lang.Object")
1937    {
1938      String JavaDoc typeName = getDateTypeName((EDataType)eType);
1939      if ("Date".equals(typeName))
1940      {
1941        return new XMLCalendar(value, XMLCalendar.DATE);
1942      }
1943      if ("DateTime".equals(typeName))
1944      {
1945        return new XMLCalendar(value, XMLCalendar.DATETIME);
1946      }
1947      // Instead of throwing an IllegalArgumentException we are passing the value to the feature
1948
return value;
1949    }
1950
1951    if (name == "java.lang.Long" || name == "long")
1952    {
1953      return new Long JavaDoc(value.getTime());
1954    }
1955    if (name == "java.lang.String")
1956    {
1957      return value.toString();
1958    }
1959
1960    // Instead of throwing an IllegalArgumentException we are passing the value to the feature
1961
return value;
1962  }
1963
1964  protected static String JavaDoc getDateTypeName(EDataType eDataType)
1965  {
1966    String JavaDoc name = eDataType.getName();
1967    if (("DateTime".equals(name)) || ("Date".equals(name)))
1968    {
1969      return name;
1970    }
1971
1972    EDataType baseType = ExtendedMetaData.INSTANCE.getBaseType(eDataType);
1973    if (baseType != null)
1974    {
1975      return getDateTypeName(baseType);
1976    }
1977
1978    List JavaDoc memberTypes = ExtendedMetaData.INSTANCE.getMemberTypes(eDataType);
1979    if (!memberTypes.isEmpty())
1980    {
1981      for (int i = 0, size = memberTypes.size(); i < size; ++i)
1982      {
1983        EDataType memberType = (EDataType)memberTypes.get(i);
1984        String JavaDoc memberTypeName = getDateTypeName(memberType);
1985        if (("DateTime".equals(memberTypeName)) || ("Date".equals(memberTypeName)))
1986        {
1987          return memberTypeName;
1988        }
1989      }
1990    }
1991
1992    return "";
1993  }
1994
1995  public static double getDouble(EObject eObject, int propertyIndex)
1996  {
1997    return getDouble(get(eObject, getFeature(eObject, propertyIndex)));
1998  }
1999
2000  public static double getDouble(EObject eObject, Property property)
2001  {
2002    return getDouble(get(eObject, ((EProperty)property).getEStructuralFeature()));
2003  }
2004
2005  public static double getDouble(EObject eObject, String JavaDoc path)
2006  {
2007    return getDouble(get(eObject, path));
2008  }
2009
2010  protected static double getDouble(Object JavaDoc value)
2011  {
2012    if (value instanceof Number JavaDoc)
2013    {
2014      return ((Number JavaDoc)value).doubleValue();
2015    }
2016
2017    if (value instanceof String JavaDoc)
2018    {
2019      return Double.parseDouble((String JavaDoc)value);
2020    }
2021
2022    if (value == null)
2023    {
2024      return 0;
2025    }
2026
2027    throw new IllegalArgumentException JavaDoc("The value of type '" + value.getClass().getName() + "' cannot be converted to double");
2028  }
2029
2030  public static void setDouble(EObject eObject, int propertyIndex, double value)
2031  {
2032    EStructuralFeature eStructuralFeature = getFeature(eObject, propertyIndex);
2033    set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
2034  }
2035
2036  public static void setDouble(EObject eObject, Property property, double value)
2037  {
2038    EStructuralFeature eStructuralFeature = ((EProperty)property).getEStructuralFeature();
2039    set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
2040  }
2041
2042  public static void setDouble(EObject eObject, String JavaDoc path, double value)
2043  {
2044    EStructuralFeature eStructuralFeature = eObject.eClass().getEStructuralFeature(path);
2045    if (eStructuralFeature != null)
2046    {
2047      set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
2048    }
2049    else
2050    {
2051      EProperty property = getType(eObject).getEProperty(path);
2052      if (property != null)
2053      {
2054        eStructuralFeature = property.getEStructuralFeature();
2055        set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
2056      }
2057      else
2058      {
2059        Accessor accessor = Accessor.create(eObject, path);
2060        accessor.setAndRecyle(getSetValue(accessor.getEStructuralFeature(), value));
2061      }
2062    }
2063  }
2064
2065  protected static Object JavaDoc getSetValue(EStructuralFeature eStructuralFeature, double value)
2066  {
2067    String JavaDoc name = eStructuralFeature.getEType().getInstanceClassName();
2068    if (name == "java.lang.Byte" || name == "byte")
2069    {
2070      return new Byte JavaDoc((byte)value);
2071    }
2072
2073    if (name == "java.lang.Double" || name == "double")
2074    {
2075      return new Double JavaDoc(value);
2076    }
2077
2078    if (name == "java.lang.Float" || name == "float")
2079    {
2080      return new Float JavaDoc(value);
2081    }
2082
2083    if (name == "java.lang.Integer" || name == "int")
2084    {
2085      return new Integer JavaDoc((int)value);
2086    }
2087
2088    if (name == "java.lang.Long" || name == "long")
2089    {
2090      return new Long JavaDoc((long)value);
2091    }
2092
2093    if (name == "java.lang.Short" || name == "short")
2094    {
2095      return new Short JavaDoc((short)value);
2096    }
2097
2098    if (name == "java.math.BigDecimal")
2099    {
2100      return getBigDecimal(new Double JavaDoc(value));
2101    }
2102
2103    if (name == "java.math.BigInteger")
2104    {
2105      return getBigInteger(new Double JavaDoc(value));
2106    }
2107
2108    if (name == "java.lang.String")
2109    {
2110      return String.valueOf(value);
2111    }
2112
2113    //Instead of throwing an IllegalArgumentException we are passing the value to the feature
2114
return new Double JavaDoc(value);
2115  }
2116
2117  public static float getFloat(EObject eObject, int propertyIndex)
2118  {
2119    return getFloat(get(eObject, getFeature(eObject, propertyIndex)));
2120  }
2121
2122  public static float getFloat(EObject eObject, Property property)
2123  {
2124    return getFloat(get(eObject, ((EProperty)property).getEStructuralFeature()));
2125  }
2126
2127  public static float getFloat(EObject eObject, String JavaDoc path)
2128  {
2129    return getFloat(get(eObject, path));
2130  }
2131
2132  protected static float getFloat(Object JavaDoc value)
2133  {
2134    if (value instanceof Number JavaDoc)
2135    {
2136      return ((Number JavaDoc)value).floatValue();
2137    }
2138
2139    if (value instanceof String JavaDoc)
2140    {
2141      return Float.parseFloat((String JavaDoc)value);
2142    }
2143
2144    if (value == null)
2145    {
2146      return 0;
2147    }
2148
2149    throw new IllegalArgumentException JavaDoc("The value of type '" + value.getClass().getName() + "' cannot be converted to float");
2150  }
2151
2152  public static void setFloat(EObject eObject, int propertyIndex, float value)
2153  {
2154    EStructuralFeature eStructuralFeature = getFeature(eObject, propertyIndex);
2155    set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
2156  }
2157
2158  public static void setFloat(EObject eObject, Property property, float value)
2159  {
2160    EStructuralFeature eStructuralFeature = ((EProperty)property).getEStructuralFeature();
2161    set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
2162  }
2163
2164  public static void setFloat(EObject eObject, String JavaDoc path, float value)
2165  {
2166    EStructuralFeature eStructuralFeature = eObject.eClass().getEStructuralFeature(path);
2167    if (eStructuralFeature != null)
2168    {
2169      set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
2170    }
2171    else
2172    {
2173      EProperty property = getType(eObject).getEProperty(path);
2174      if (property != null)
2175      {
2176        eStructuralFeature = property.getEStructuralFeature();
2177        set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
2178      }
2179      else
2180      {
2181        Accessor accessor = Accessor.create(eObject, path);
2182        accessor.setAndRecyle(getSetValue(accessor.getEStructuralFeature(), value));
2183      }
2184    }
2185  }
2186
2187  protected static Object JavaDoc getSetValue(EStructuralFeature eStructuralFeature, float value)
2188  {
2189    String JavaDoc name = eStructuralFeature.getEType().getInstanceClassName();
2190    if (name == "java.lang.Byte" || name == "byte")
2191    {
2192      return new Byte JavaDoc((byte)value);
2193    }
2194
2195    if (name == "java.lang.Double" || name == "double")
2196    {
2197      return new Double JavaDoc(value);
2198    }
2199
2200    if (name == "java.lang.Float" || name == "float")
2201    {
2202      return new Float JavaDoc(value);
2203    }
2204
2205    if (name == "java.lang.Integer" || name == "int")
2206    {
2207      return new Integer JavaDoc((int)value);
2208    }
2209
2210    if (name == "java.lang.Long" || name == "long")
2211    {
2212      return new Long JavaDoc((long)value);
2213    }
2214
2215    if (name == "java.lang.Short" || name == "short")
2216    {
2217      return new Short JavaDoc((short)value);
2218    }
2219
2220    if (name == "java.math.BigDecimal")
2221    {
2222      return getBigDecimal(new Float JavaDoc(value));
2223    }
2224
2225    if (name == "java.math.BigInteger")
2226    {
2227      return getBigInteger(new Float JavaDoc(value));
2228    }
2229
2230    if (name == "java.lang.String")
2231    {
2232      return String.valueOf(value);
2233    }
2234
2235    // Instead of throwing an IllegalArgumentException we are passing the value to the feature
2236
return new Float JavaDoc(value);
2237  }
2238
2239  public static int getInt(EObject eObject, int propertyIndex)
2240  {
2241    return getInt(get(eObject, getFeature(eObject, propertyIndex)));
2242  }
2243
2244  public static int getInt(EObject eObject, Property property)
2245  {
2246    return getInt(get(eObject, ((EProperty)property).getEStructuralFeature()));
2247  }
2248
2249  public static int getInt(EObject eObject, String JavaDoc path)
2250  {
2251    return getInt(get(eObject, path));
2252  }
2253
2254  protected static int getInt(Object JavaDoc value)
2255  {
2256    if (value instanceof Number JavaDoc)
2257    {
2258      return ((Number JavaDoc)value).intValue();
2259    }
2260
2261    if (value instanceof String JavaDoc)
2262    {
2263      return Integer.parseInt((String JavaDoc)value);
2264    }
2265
2266    if (value == null)
2267    {
2268      return 0;
2269    }
2270
2271    throw new IllegalArgumentException JavaDoc("The value of type '" + value.getClass().getName() + "' cannot be converted to int");
2272  }
2273
2274  public static void setInt(EObject eObject, int propertyIndex, int value)
2275  {
2276    EStructuralFeature eStructuralFeature = getFeature(eObject, propertyIndex);
2277    set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
2278  }
2279
2280  public static void setInt(EObject eObject, Property property, int value)
2281  {
2282    EStructuralFeature eStructuralFeature = ((EProperty)property).getEStructuralFeature();
2283    set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
2284  }
2285
2286  public static void setInt(EObject eObject, String JavaDoc path, int value)
2287  {
2288    EStructuralFeature eStructuralFeature = eObject.eClass().getEStructuralFeature(path);
2289    if (eStructuralFeature != null)
2290    {
2291      set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
2292    }
2293    else
2294    {
2295      EProperty property = getType(eObject).getEProperty(path);
2296      if (property != null)
2297      {
2298        eStructuralFeature = property.getEStructuralFeature();
2299        set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
2300      }
2301      else
2302      {
2303        Accessor accessor = Accessor.create(eObject, path);
2304        accessor.setAndRecyle(getSetValue(accessor.getEStructuralFeature(), value));
2305      }
2306    }
2307  }
2308
2309  protected static Object JavaDoc getSetValue(EStructuralFeature eStructuralFeature, int value)
2310  {
2311    String JavaDoc name = eStructuralFeature.getEType().getInstanceClassName();
2312    if (name == "java.lang.Byte" || name == "byte")
2313    {
2314      return new Byte JavaDoc((byte)value);
2315    }
2316
2317    if (name == "java.lang.Double" || name == "double")
2318    {
2319      return new Double JavaDoc(value);
2320    }
2321
2322    if (name == "java.lang.Float" || name == "float")
2323    {
2324      return new Float JavaDoc(value);
2325    }
2326
2327    if (name == "java.lang.Integer" || name == "int")
2328    {
2329      return new Integer JavaDoc(value);
2330    }
2331
2332    if (name == "java.lang.Long" || name == "long")
2333    {
2334      return new Long JavaDoc(value);
2335    }
2336
2337    if (name == "java.lang.Short" || name == "short")
2338    {
2339      return new Short JavaDoc((short)value);
2340    }
2341
2342    if (name == "java.math.BigDecimal")
2343    {
2344      return getBigDecimal(new Integer JavaDoc(value));
2345    }
2346
2347    if (name == "java.math.BigInteger")
2348    {
2349      return getBigInteger(new Integer JavaDoc(value));
2350    }
2351
2352    if (name == "java.lang.String")
2353    {
2354      return String.valueOf(value);
2355    }
2356
2357    // Instead of throwing an IllegalArgumentException we are passing the value to the feature
2358
return new Integer JavaDoc(value);
2359  }
2360
2361  public static long getLong(EObject eObject, int propertyIndex)
2362  {
2363    return getLong(get(eObject, getFeature(eObject, propertyIndex)));
2364  }
2365
2366  public static long getLong(EObject eObject, Property property)
2367  {
2368    return getLong(get(eObject, ((EProperty)property).getEStructuralFeature()));
2369  }
2370
2371  public static long getLong(EObject eObject, String JavaDoc path)
2372  {
2373    return getLong(get(eObject, path));
2374  }
2375
2376  protected static long getLong(Object JavaDoc value)
2377  {
2378    if (value instanceof Number JavaDoc)
2379    {
2380      return ((Number JavaDoc)value).longValue();
2381    }
2382
2383    if (value instanceof String JavaDoc)
2384    {
2385      return Long.parseLong((String JavaDoc)value);
2386    }
2387
2388    if (value instanceof Date JavaDoc)
2389    {
2390      return ((Date JavaDoc)value).getTime();
2391    }
2392
2393    if (value == null)
2394    {
2395      return 0;
2396    }
2397
2398    throw new IllegalArgumentException JavaDoc("The value of type '" + value.getClass().getName() + "' cannot be converted to long");
2399  }
2400
2401  public static void setLong(EObject eObject, int propertyIndex, long value)
2402  {
2403    EStructuralFeature eStructuralFeature = getFeature(eObject, propertyIndex);
2404    set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
2405  }
2406
2407  public static void setLong(EObject eObject, Property property, long value)
2408  {
2409    EStructuralFeature eStructuralFeature = ((EProperty)property).getEStructuralFeature();
2410    set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
2411  }
2412
2413  public static void setLong(EObject eObject, String JavaDoc path, long value)
2414  {
2415    EStructuralFeature eStructuralFeature = eObject.eClass().getEStructuralFeature(path);
2416    if (eStructuralFeature != null)
2417    {
2418      set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
2419    }
2420    else
2421    {
2422      EProperty property = getType(eObject).getEProperty(path);
2423      if (property != null)
2424      {
2425        eStructuralFeature = property.getEStructuralFeature();
2426        set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
2427      }
2428      else
2429      {
2430        Accessor accessor = Accessor.create(eObject, path);
2431        accessor.setAndRecyle(getSetValue(accessor.getEStructuralFeature(), value));
2432      }
2433    }
2434  }
2435
2436  protected static Object JavaDoc getSetValue(EStructuralFeature eStructuralFeature, long value)
2437  {
2438    String JavaDoc name = eStructuralFeature.getEType().getInstanceClassName();
2439    if (name == "java.lang.Byte" || name == "byte")
2440    {
2441      return new Byte JavaDoc((byte)value);
2442    }
2443
2444    if (name == "java.lang.Double" || name == "double")
2445    {
2446      return new Double JavaDoc(value);
2447    }
2448
2449    if (name == "java.lang.Float" || name == "float")
2450    {
2451      return new Float JavaDoc(value);
2452    }
2453
2454    if (name == "java.lang.Integer" || name == "int")
2455    {
2456      return new Integer JavaDoc((int)value);
2457    }
2458
2459    if (name == "java.lang.Long" || name == "long")
2460    {
2461      return new Long JavaDoc(value);
2462    }
2463
2464    if (name == "java.lang.Short" || name == "short")
2465    {
2466      return new Short JavaDoc((short)value);
2467    }
2468
2469    if (name == "java.math.BigDecimal")
2470    {
2471      return getBigDecimal(new Long JavaDoc(value));
2472    }
2473
2474    if (name == "java.math.BigInteger")
2475    {
2476      return getBigInteger(new Long JavaDoc(value));
2477    }
2478
2479    if (name == "java.lang.String")
2480    {
2481      return String.valueOf(value);
2482    }
2483
2484    if (name == "java.util.Date")
2485    {
2486      return new Date JavaDoc(value);
2487    }
2488
2489    // Instead of throwing an IllegalArgumentException we are passing the value to the feature
2490
return new Long JavaDoc(value);
2491  }
2492
2493  public static short getShort(EObject eObject, int propertyIndex)
2494  {
2495    return getShort(get(eObject, getFeature(eObject, propertyIndex)));
2496  }
2497
2498  public static short getShort(EObject eObject, Property property)
2499  {
2500    return getShort(get(eObject, ((EProperty)property).getEStructuralFeature()));
2501  }
2502
2503  public static short getShort(EObject eObject, String JavaDoc path)
2504  {
2505    return getShort(get(eObject, path));
2506  }
2507
2508  protected static short getShort(Object JavaDoc value)
2509  {
2510    if (value instanceof Number JavaDoc)
2511    {
2512      return ((Number JavaDoc)value).shortValue();
2513    }
2514
2515    if (value instanceof String JavaDoc)
2516    {
2517      return Short.parseShort((String JavaDoc)value);
2518    }
2519
2520    if (value == null)
2521    {
2522      return 0;
2523    }
2524
2525    throw new IllegalArgumentException JavaDoc("The value of type '" + value.getClass().getName() + "' cannot be converted to short");
2526  }
2527
2528  public static void setShort(EObject eObject, int propertyIndex, short value)
2529  {
2530    EStructuralFeature eStructuralFeature = getFeature(eObject, propertyIndex);
2531    set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
2532  }
2533
2534  public static void setShort(EObject eObject, Property property, short value)
2535  {
2536    EStructuralFeature eStructuralFeature = ((EProperty)property).getEStructuralFeature();
2537    set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
2538  }
2539
2540  public static void setShort(EObject eObject, String JavaDoc path, short value)
2541  {
2542    EStructuralFeature eStructuralFeature = eObject.eClass().getEStructuralFeature(path);
2543    if (eStructuralFeature != null)
2544    {
2545      set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
2546    }
2547    else
2548    {
2549      EProperty property = getType(eObject).getEProperty(path);
2550      if (property != null)
2551      {
2552        eStructuralFeature = property.getEStructuralFeature();
2553        set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
2554      }
2555      else
2556      {
2557        Accessor accessor = Accessor.create(eObject, path);
2558        accessor.setAndRecyle(getSetValue(accessor.getEStructuralFeature(), value));
2559      }
2560    }
2561  }
2562
2563  protected static Object JavaDoc getSetValue(EStructuralFeature eStructuralFeature, short value)
2564  {
2565    String JavaDoc name = eStructuralFeature.getEType().getInstanceClassName();
2566    if (name == "java.lang.Byte" || name == "byte")
2567    {
2568      return new Byte JavaDoc((byte)value);
2569    }
2570
2571    if (name == "java.lang.Double" || name == "double")
2572    {
2573      return new Double JavaDoc(value);
2574    }
2575
2576    if (name == "java.lang.Float" || name == "float")
2577    {
2578      return new Float JavaDoc(value);
2579    }
2580
2581    if (name == "java.lang.Integer" || name == "int")
2582    {
2583      return new Integer JavaDoc(value);
2584    }
2585
2586    if (name == "java.lang.Long" || name == "long")
2587    {
2588      return new Long JavaDoc(value);
2589    }
2590
2591    if (name == "java.lang.Short" || name == "short")
2592    {
2593      return new Short JavaDoc(value);
2594    }
2595
2596    if (name == "java.math.BigDecimal")
2597    {
2598      return getBigDecimal(new Short JavaDoc(value));
2599    }
2600
2601    if (name == "java.math.BigInteger")
2602    {
2603      return getBigInteger(new Short JavaDoc(value));
2604    }
2605
2606    if (name == "java.lang.String")
2607    {
2608      return String.valueOf(value);
2609    }
2610
2611    // Instead of throwing an IllegalArgumentException we are passing the value to the feature
2612
return new Short JavaDoc(value);
2613  }
2614
2615  public static String JavaDoc getString(EObject eObject, int propertyIndex)
2616  {
2617    return getString(get(eObject, getFeature(eObject, propertyIndex)));
2618  }
2619
2620  public static String JavaDoc getString(EObject eObject, Property property)
2621  {
2622    return getString(get(eObject, ((EProperty)property).getEStructuralFeature()));
2623  }
2624
2625  public static String JavaDoc getString(EObject eObject, String JavaDoc path)
2626  {
2627    return getString(get(eObject, path));
2628  }
2629
2630  protected static String JavaDoc getString(Object JavaDoc value)
2631  {
2632    if (value instanceof String JavaDoc)
2633    {
2634      return (String JavaDoc)value;
2635    }
2636
2637    if (value instanceof Number JavaDoc || value instanceof Boolean JavaDoc || value instanceof Character JavaDoc)
2638    {
2639      return String.valueOf(value);
2640    }
2641
2642    if (value == null)
2643    {
2644      return null;
2645    }
2646
2647    throw new IllegalArgumentException JavaDoc("The value of type '" + value.getClass().getName() + "' cannot be converted to String");
2648  }
2649
2650  public static void setString(EObject eObject, int propertyIndex, String JavaDoc value)
2651  {
2652    EStructuralFeature eStructuralFeature = getFeature(eObject, propertyIndex);
2653    set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
2654  }
2655
2656  public static void setString(EObject eObject, Property property, String JavaDoc value)
2657  {
2658    EStructuralFeature eStructuralFeature = ((EProperty)property).getEStructuralFeature();
2659    set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
2660  }
2661
2662  public static void setString(EObject eObject, String JavaDoc path, String JavaDoc value)
2663  {
2664    EStructuralFeature eStructuralFeature = eObject.eClass().getEStructuralFeature(path);
2665    if (eStructuralFeature != null)
2666    {
2667      set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
2668    }
2669    else
2670    {
2671      EProperty property = getType(eObject).getEProperty(path);
2672      if (property != null)
2673      {
2674        eStructuralFeature = property.getEStructuralFeature();
2675        set(eObject, eStructuralFeature, getSetValue(eStructuralFeature, value));
2676      }
2677      else
2678      {
2679        Accessor accessor = Accessor.create(eObject, path);
2680        accessor.setAndRecyle(getSetValue(accessor.getEStructuralFeature(), value));
2681      }
2682    }
2683  }
2684
2685  protected static Object JavaDoc getSetValue(EStructuralFeature eStructuralFeature, String JavaDoc value)
2686  {
2687    EClassifier eType = eStructuralFeature.getEType();
2688    if (value == null)
2689    {
2690      return eType.getDefaultValue();
2691    }
2692
2693    String JavaDoc name = eType.getInstanceClassName();
2694    if (name == "java.lang.String")
2695    {
2696      return value;
2697    }
2698
2699    if (name == "java.lang.Byte" || name == "byte")
2700    {
2701      return Byte.valueOf(value);
2702    }
2703
2704    if (name == "java.lang.Double" || name == "double" || name == "java.lang.Number")
2705    {
2706      return Double.valueOf(value);
2707    }
2708
2709    if (name == "java.lang.Float" || name == "float")
2710    {
2711      return new Float JavaDoc(value);
2712    }
2713
2714    if (name == "java.lang.Integer" || name == "int")
2715    {
2716      return Integer.valueOf(value);
2717    }
2718
2719    if (name == "java.lang.Long" || name == "long")
2720    {
2721      return Long.valueOf(value);
2722    }
2723
2724    if (name == "java.lang.Short" || name == "short")
2725    {
2726      return Short.valueOf(value);
2727    }
2728
2729    if (name == "java.lang.Character" || name == "char")
2730    {
2731      return new Character JavaDoc(value.charAt(0));
2732    }
2733
2734    if (name == "java.math.BigDecimal")
2735    {
2736      return getBigDecimal(value);
2737    }
2738
2739    if (name == "java.math.BigInteger")
2740    {
2741      return getBigInteger(value);
2742    }
2743
2744    if (name == "java.lang.Boolean" || name == "boolean")
2745    {
2746      return Boolean.valueOf(value);
2747    }
2748
2749    // Instead of throwing an IllegalArgumentException we are passing the value to the feature
2750
return value;
2751  }
2752}
2753
Popular Tags