Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [emf-dev] Need help - How to get correct value of a feature ? Why container class is Null ?


Kaniska,

Please use the newsgroup not the mailing list for questions like this.   I'll only answer any follow up questions you might have on the newsgroup....

EStructuralFeature.getContainingClass is supposed to return null for a dynamic feature, but it should not cause null pointer exceptions.  E.g., this method in BasicEObjectImpl should properly handle the case that the container class is null:

  public int eDerivedStructuralFeatureID(EStructuralFeature eStructuralFeature)
  {
    Class containerClass = eStructuralFeature.getContainerClass();
    return
      containerClass == null ?
        eClass().getFeatureID(eStructuralFeature) :
        eDerivedStructuralFeatureID(eStructuralFeature.getFeatureID(), containerClass);
  }

The exception you mention should only happen for eObject.eGet(f) only if eObject.eClass().getEAllStructuralFeatures().contains(f) is false.


Ed Merks/Toronto/IBM@IBMCA
mailto: merks@xxxxxxxxxx
905-413-3265  (t/l 969)




"kaniska" <kaniska@xxxxxxxxxxx>
Sent by: emf-dev-bounces@xxxxxxxxxxx

06/28/2006 12:53 AM

Please respond to
Eclipse Modelling Framework <emf-dev@xxxxxxxxxxx>

To
<emf-dev@xxxxxxxxxxx>
cc
Subject
[emf-dev] Need help - How to get correct value of a feature ? Why        container class is Null ?





EMF Gurus,
 
Dynamically, I get hold of an EPackage from the Ecore which is discovered during runtime ...
 
EPackage pkg = .......            
EClass eClass  = getDriverClass(pkg);                                        
feature = eClass.getEStructuralFeature(propertyName);  // returns a correct feature
 
// THE PROBLEM IS container class of feature is null
// SO I get an exception 'Invalid feature xxx ..' when I do someEObject.eGet(feature) to extract the value
 
// NOW IF I STATICALLY TRY TO RETRIEVE THE FEATURE ... its container class is NOT NULL and someEObject.eGet(feature) .. gives me correct value from xmi file.
EStructuralFeature feature = null;
if (driverName.equalsIgnoreCase("jms")){
      feature = JMSDriverPackageImpl.eINSTANCE.getJMSDriver().getEStructuralFeature(propertyName);
}
           
//
private EClass getDriverClass() {
   EClass eClass = null;
   for (Iterator i = pkg.getEClassifiers().iterator(); i.hasNext();) {
            EClassifier eClassifier = (EClassifier) i.next();
            if (eClassifier instanceof EClass) {
                        eClass = (EClass) eClassifier;                                        
                        // Get the eClass whose super type is Driver
                        List eSuperTypes = eClass.getESuperTypes();
                        //
                        for (Iterator iter = eSuperTypes.iterator(); iter.hasNext();) {
                                    EClass eSuperType = (EClass)iter.next();
                                    //
                                    URI eClassURI = EcoreUtil.getURI(eSuperType);
                                    String eClassURIFragment = eClassURI.fragment();
                                    if (eClassURIFragment.contains("Driver")){
                                                return eClass;
                                    }          
                        }
            }                                  
   }
   return eClass ;
}
                                   
What is the solution to this problem ? How do I get hold of the feature correctly ?
 
Rgds,
Kaniska_______________________________________________
emf-dev mailing list
emf-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/emf-dev


Back to the top