Skip to main content



      Home
Home » Modeling » EMF » Serialize An Elist(BasicEList cannot be cast to InternalEList)
icon8.gif  Serialize An Elist [message #495639] Thu, 05 November 2009 10:09 Go to next message
Eclipse UserFriend
Hi Everyone,
New to EMF so please bare with me.

I have a class called Shop and a shop has many items. The shop class has a method which adds a new item to the BasicEList of items.

Adding the new items works fine, however when I try to make a dump to an XMI file I get this error.

Quote:

org.eclipse.emf.common.util.BasicEList cannot be cast to org.eclipse.emf.ecore.util.InternalEList



Does anyone have any code examples that achieve something similar to this? I have Googled the error but don't get anything relevant. When I Google Elist I'm not finding anything with serializaton in it.

Thank you,
Keith
Re: Serialize An Elist [message #495706 is a reply to message #495639] Thu, 05 November 2009 14:40 Go to previous messageGo to next message
Eclipse UserFriend
Keith,

Comments below

Keith wrote:
> Hi Everyone,
> New to EMF so please bare with me.
>
> I have a class called Shop and a shop has many items. The shop class
> has a method which adds a new item to the BasicEList of items.
>
> Adding the new items works fine, however when I try to make a dump to
> an XMI file I get this error.
>
> Quote:
>> org.eclipse.emf.common.util.BasicEList cannot be cast to
>> org.eclipse.emf.ecore.util.InternalEList
A multi-valued feature's list is is expected to implement InternalEList,
so it seems clear you've hand written/modified the getItems method of
ShopImpl. Why?
>
>
> Does anyone have any code examples that achieve something similar to
> this? I have Googled the error but don't get anything relevant. When I
> Google Elist I'm not finding anything with serializaton in it.
>
> Thank you,
> Keith
Re: Serialize An Elist [message #495721 is a reply to message #495706] Thu, 05 November 2009 15:16 Go to previous messageGo to next message
Eclipse UserFriend
Thanks Ed for your reply.

I didn't edit the get method but I did edit the set method. I edited it because after model generation it was just set to "throw new UnsupportedOperationException()". I also had to edit the field variable so that it wasn't being left un-initialized...

I think that the changes that I made were correct because I wrote some test code to check the get method and it returned an EList...I then checked that element 0 was set to an object and it was (the test code added an item). But then again I'm a "noob" so I'm probably after doing something wrong or haven't done something which I should have...
Re: Serialize An Elist [message #495743 is a reply to message #495721] Thu, 05 November 2009 16:19 Go to previous messageGo to next message
Eclipse UserFriend
Keith,

Comments below.

Keith wrote:
> Thanks Ed for your reply.
>
> I didn't edit the get method but I did edit the set method. I edited
> it because after model generation it was just set to "throw new
> UnsupportedOperationException()". I also had to edit the field
> variable so that it wasn't being left un-initialized...
Multi-valued features don't generate a set method. The field is
normally initialized in the getter. Did you mark the feature as
volatile. There's something you're not telling me...
>
> I think that the changes that I made were correct because I wrote some
> test code to check the get method and it returned an EList...
I've already explained that they're not correct.
> I then checked that element 0 was set to an object and it was (the
> test code added an item). But then again I'm a "noob" so I'm probably
> after doing something wrong or haven't done something which I should
> have...
Normally you don't need to write a speck of code for features to work
properly, so there's something going on you've not explained.
icon9.gif  Re: Serialize An Elist [message #496931 is a reply to message #495743] Wed, 11 November 2009 14:07 Go to previous messageGo to next message
Eclipse UserFriend
Apologies for late reply.

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
    xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="Compiler"
    nsURI="http:///Compiler.ecore" nsPrefix="Compiler">
  <eClassifiers xsi:type="ecore:EClass" name="Program">
    <eOperations name="addProcedure" ordered="false" lowerBound="1">
      <eParameters name="procedure" ordered="false" lowerBound="1" eType="#//Procedure"/>
    </eOperations>
    <eStructuralFeatures xsi:type="ecore:EReference" name="procedure" ordered="false"
        lowerBound="1" upperBound="-1" eType="#//Procedure" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Procedure">
    <eOperations name="addNode" ordered="false" lowerBound="1">
      <eParameters name="node" ordered="false" lowerBound="1" eType="#//Node"/>
    </eOperations>
    <eOperations name="setName" ordered="false" lowerBound="1">
      <eParameters name="name" ordered="false" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    </eOperations>
    <eOperations name="getName" ordered="false" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="node" ordered="false" lowerBound="1"
        upperBound="-1" eType="#//ExecutableNode" containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" ordered="false" lowerBound="1"
        eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="ExecutableNode" abstract="true" eSuperTypes="#//Node"/>
  <eClassifiers xsi:type="ecore:EClass" name="Node" abstract="true"/>
  <eClassifiers xsi:type="ecore:EClass" name="PrintNode" eSuperTypes="#//ExecutableNode"/>
  <eClassifiers xsi:type="ecore:EClass" name="InstantiateNode" eSuperTypes="#//ExecutableNode">
    <eOperations name="getName" ordered="false" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eOperations name="setName" ordered="false" lowerBound="1">
      <eParameters name="name" ordered="false" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    </eOperations>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" ordered="false" lowerBound="1"
        eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="OperandNode" eSuperTypes="#//Node"/>
  <eClassifiers xsi:type="ecore:EClass" name="AssignmentNode" eSuperTypes="#//ExecutableNode"/>
</ecore:EPackage>


Above is the eCore for my project. The only thing I've not told you (which I'd forgotten) is that when I generate the model I get some errors about there may not be an operation....with the same signature as..." Perhaps that is linked to the problem... However there was the option to ignore the error by clicking on a tab at the bottom, which is what I did...
Re: Serialize An Elist [message #496936 is a reply to message #496931] Wed, 11 November 2009 14:26 Go to previous messageGo to next message
Eclipse UserFriend
Keith,

These problems cause errors in the generated code so get rid of the
operations it's complaining about. I'm not sure how this relates to the
shop with many items problem you started with...


Keith wrote:
> Apologies for late reply.
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <ecore:EPackage xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="Compiler"
> nsURI="http:///Compiler.ecore" nsPrefix="Compiler">
> <eClassifiers xsi:type="ecore:EClass" name="Program">
> <eOperations name="addProcedure" ordered="false" lowerBound="1">
> <eParameters name="procedure" ordered="false" lowerBound="1"
> eType="#//Procedure"/>
> </eOperations>
> <eStructuralFeatures xsi:type="ecore:EReference" name="procedure"
> ordered="false"
> lowerBound="1" upperBound="-1" eType="#//Procedure"
> containment="true"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Procedure">
> <eOperations name="addNode" ordered="false" lowerBound="1">
> <eParameters name="node" ordered="false" lowerBound="1"
> eType="#//Node"/>
> </eOperations>
> <eOperations name="setName" ordered="false" lowerBound="1">
> <eParameters name="name" ordered="false" lowerBound="1"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> </eOperations>
> <eOperations name="getName" ordered="false" lowerBound="1"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="node"
> ordered="false" lowerBound="1"
> upperBound="-1" eType="#//ExecutableNode" containment="true"/>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
> ordered="false" lowerBound="1"
> eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="ExecutableNode"
> abstract="true" eSuperTypes="#//Node"/>
> <eClassifiers xsi:type="ecore:EClass" name="Node" abstract="true"/>
> <eClassifiers xsi:type="ecore:EClass" name="PrintNode"
> eSuperTypes="#//ExecutableNode"/>
> <eClassifiers xsi:type="ecore:EClass" name="InstantiateNode"
> eSuperTypes="#//ExecutableNode">
> <eOperations name="getName" ordered="false" lowerBound="1"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eOperations name="setName" ordered="false" lowerBound="1">
> <eParameters name="name" ordered="false" lowerBound="1"
> eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> </eOperations>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
> ordered="false" lowerBound="1"
> eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="OperandNode"
> eSuperTypes="#//Node"/>
> <eClassifiers xsi:type="ecore:EClass" name="AssignmentNode"
> eSuperTypes="#//ExecutableNode"/>
> </ecore:EPackage>
>
>
> Above is the eCore for my project. The only thing I've not told you
> (which I'd forgotten) is that when I generate the model I get some
> errors about there may not be an operation....with the same signature
> as..." Perhaps that is linked to the problem... However there was the
> option to ignore the error by clicking on a tab at the bottom, which
> is what I did...
Re: Serialize An Elist [message #496939 is a reply to message #496936] Wed, 11 November 2009 14:45 Go to previous messageGo to next message
Eclipse UserFriend
Thank you for your help and quick replies. I just have one question, if I delete those operations then what will I do without them? They're just get and set methods, which I need.

What I said about the shop applied to what I'm really doing. I'm really doing a compiler but if I said that then I'd just get a load of replies saying that compilers are complex and I shouldn't waste my time trying to write one etc.. (Shop = Root node of abstract syntax tree and shop = node in tree)
Re: Serialize An Elist [message #496954 is a reply to message #496939] Wed, 11 November 2009 15:15 Go to previous messageGo to next message
Eclipse UserFriend
Keith,

Comments below.

Keith wrote:
> Thank you for your help and quick replies. I just have one question,
> if I delete those operations then what will I do without them? They're
> just get and set methods, which I need.
A single-valued feature named "x" will result in an API with getX/setX
methods, so defining operations is redundant. You also don't need add
methods because the list returned by the getter can be modified directly
using the full List API...
> What I said about the shop applied to what I'm really doing. I'm
> really doing a compiler but if I said that then I'd just get a load of
> replies saying that compilers are complex and I shouldn't waste my
> time trying to write one etc.. (Shop = Root node of abstract syntax
> tree and shop = node in tree)
Start by defining just the features you need. That should produce fully
functional code. Worry about adding operations later. They can even be
added just by hand to the generated code without even putting them in
the model.
icon14.gif  Re: Serialize An Elist [message #498773 is a reply to message #496954] Wed, 18 November 2009 10:26 Go to previous messageGo to next message
Eclipse UserFriend
Hi Ed,
Sorry about the slow reply.

Just wanted to say thank you. I tried what you said (i.e. removing the add methods I wrote) and it works now!

Thanks alot for your help,
Keith
icon14.gif  Re: Serialize An Elist [message #498774 is a reply to message #496954] Wed, 18 November 2009 10:30 Go to previous message
Eclipse UserFriend
Hi Ed,
Sorry about the slow reply.

Just wanted to say thank you. I tried what you said (i.e. removing the add methods I wrote) and it works now!

Thanks alot for your help,
Keith
Previous Topic:EPackageRegistry in multi-threaded environment
Next Topic:Re: [EMF Compare] Move of an element
Goto Forum:
  


Current Time: Sat Nov 08 04:33:27 EST 2025

Powered by FUDForum. Page generated in 0.08250 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top