Dynamic Extensions problems [message #386301] |
Thu, 01 July 2004 11:31  |
Eclipse User |
|
|
|
Hello,
I'm trying to dynamically add a feature to an existing and generated class.
To do so I retrieve the EClass object, I create a dynamic feature, et the
type, name & other properties, and add the feature to the
EStructuralFeatures collection. So far so good ...
Then I try to call object.eGet(eFeature), where of course object is an
instance of my generated class, and eFeature is my dynamic feature.
I run into problems that seemed to be linked to the fact that the method
eDynamicFeatureID(eFeature) returns -1 for my newly added feature. The
code is :
protected int eDynamicFeatureID(EStructuralFeature eStructuralFeature)
{
return
eClass().getEAllStructuralFeatures().indexOf(eStructuralFeat ure) -
eStaticFeatureCount();
}
Which obviously will always return -1 for the latest feature in the list
... or did I miss something ?
After that, the framework believe that my feature is an XSD type dynamic
feature (it looks for the MetaData annotations and don't found it, leading
to NPEs ...)
Is the return value of the eDynamicFeatureID method right or is it a bug ?
Thank you very much ...
Joel.
|
|
|
Re: Dynamic Extensions problems [message #386330 is a reply to message #386301] |
Mon, 05 July 2004 17:28   |
Eclipse User |
|
|
|
Joel,
You can't add dynamic features to a static class. You need to create a
dynamic subclass and add the dynamic feature to it. Then,
eStaticFeatureCount() will be equal to the indexOf of the first dynamic
feature (i.e., eDynamicFeatureID will return 0 instead of -1).
Frank.
Joël Cheuoua wrote:
>Hello,
>
>I'm trying to dynamically add a feature to an existing and generated class.
>To do so I retrieve the EClass object, I create a dynamic feature, et the
>type, name & other properties, and add the feature to the
>EStructuralFeatures collection. So far so good ...
>
>Then I try to call object.eGet(eFeature), where of course object is an
>instance of my generated class, and eFeature is my dynamic feature.
>
>I run into problems that seemed to be linked to the fact that the method
>eDynamicFeatureID(eFeature) returns -1 for my newly added feature. The
>code is :
>
>protected int eDynamicFeatureID(EStructuralFeature eStructuralFeature)
>{
> return
> eClass().getEAllStructuralFeatures().indexOf(eStructuralFeat ure) -
>eStaticFeatureCount();
>}
>
>Which obviously will always return -1 for the latest feature in the list
>.. or did I miss something ?
>
>After that, the framework believe that my feature is an XSD type dynamic
>feature (it looks for the MetaData annotations and don't found it, leading
>to NPEs ...)
>
>Is the return value of the eDynamicFeatureID method right or is it a bug ?
>
>Thank you very much ...
>
>Joel.
>
>
>
>
|
|
|
Re: Dynamic Extensions problems [message #386343 is a reply to message #386330] |
Tue, 06 July 2004 11:37   |
Eclipse User |
|
|
|
Hello Frank,
hmmm ... well I can understand that it is safer not to modify class
attributes to a class that already have some instances, but why is it this
limitation exist if no instance are actually created ?
I want to be able to dynamically enrich a model, but not by using dynamic
subclasses, since instances of this model can and actually will be created
using xxxFactory.eINSTACE.createXXX().
In fact I found this little trick that seem to work : in the Class.javajet
template, I just add the method :
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected int eStaticFeatureCount() {
return
<%=genPackage.getImportedPackageInterfaceName()%>.<%=genClass.getFeatureCountID()% >;
}
This way the eStaticFeatureCount() is exactely the static feature count of
the class.
Do you believe this is a safe strategy ?
Thanks.
Joel.
Frank Budinsky wrote:
> Joel,
> You can't add dynamic features to a static class. You need to create a
> dynamic subclass and add the dynamic feature to it. Then,
> eStaticFeatureCount() will be equal to the indexOf of the first dynamic
> feature (i.e., eDynamicFeatureID will return 0 instead of -1).
> Frank.
> Joël Cheuoua wrote:
> >Hello,
> >
> >I'm trying to dynamically add a feature to an existing and generated class.
> >To do so I retrieve the EClass object, I create a dynamic feature, et the
> >type, name & other properties, and add the feature to the
> >EStructuralFeatures collection. So far so good ...
> >
> >Then I try to call object.eGet(eFeature), where of course object is an
> >instance of my generated class, and eFeature is my dynamic feature.
> >
> >I run into problems that seemed to be linked to the fact that the method
> >eDynamicFeatureID(eFeature) returns -1 for my newly added feature. The
> >code is :
> >
> >protected int eDynamicFeatureID(EStructuralFeature eStructuralFeature)
> >{
> > return
> > eClass().getEAllStructuralFeatures().indexOf(eStructuralFeat ure) -
> >eStaticFeatureCount();
> >}
> >
> >Which obviously will always return -1 for the latest feature in the list
> >.. or did I miss something ?
> >
> >After that, the framework believe that my feature is an XSD type dynamic
> >feature (it looks for the MetaData annotations and don't found it, leading
> >to NPEs ...)
> >
> >Is the return value of the eDynamicFeatureID method right or is it a bug ?
> >
> >Thank you very much ...
> >
> >Joel.
> >
> >
> >
> >
|
|
|
Re: Dynamic Extensions problems [message #386349 is a reply to message #386343] |
Tue, 06 July 2004 16:12  |
Eclipse User |
|
|
|
This is a multi-part message in MIME format.
--------------090707030504000306070707
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8bit
Joel,
Interesting observation. Off hand, it doesn't seem particularly
dangerous as long as you're sure to only add new features to the end.
Removing features or adding anywhere else would surely be a bad thing.
I'll talk to Ed about this when he gets back from vacation.
Frank.
Jo
|
|
|
Powered by
FUDForum. Page generated in 0.03387 seconds