Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EDataType and Resource
EDataType and Resource [message #425643] Wed, 03 December 2008 16:28 Go to next message
Marc-Philippe Huget is currently offline Marc-Philippe HugetFriend
Messages: 9
Registered: July 2009
Junior Member
Hello all,

I asked by the past how to use Java classes such as java.util.Vector in my
dynamic model, and as proposed I used a EDataType, it works well for every
type but now, I have to save the model and in this case, the program
triggers the frustrating IOWrappedException, here are two excerpts:

//creating an attribute
EAttribute eAttribute = ecoreFactory.createEAttribute();
eAttribute.setName(attributeName);
EDataType dt = ecoreFactory.createEDataType();
dt.setInstanceClassName(attributeType);
eAttribute.setEType(dt);

//Saving the model
ResourceSet resourceSet = new ResourceSetImpl();

// Register XML Factory implementation to handle .ecore files
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap()
.put("ecore", new XMLResourceFactoryImpl());

// Create empty resource with the given URI
Resource resource = resourceSet.createResource(URI.createURI("./"
+ name + ".ecore"));

for (Enumeration<PackageType> elements = packages.elements(); elements
.hasMoreElements();) {
PackageType aPackage = elements.nextElement();
resource.getContents().add(aPackage.getPackage());
}

try {
// Save the resource
Map<String, String> options = new HashMap<String, String>();
options.put(XMLResource.OPTION_ENCODING, "UTF-8");
resource.save(options);
} catch (IOException e) {
e.printStackTrace();
}

How can I come up with the DanglingHrefException? If I understand well, it
comes from the fact, the class is not serialized but I don't understand
why we need that since we generate an XMI file. Thanks in advance for your
help

Regards,
M.
Re: EDataType and Resource [message #425649 is a reply to message #425643] Wed, 03 December 2008 17:41 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 31164
Registered: July 2009
Senior Member
Marc-Philippe,

Comments below.

Marc-Philippe Huget wrote:
> Hello all,
> I asked by the past how to use Java classes such as java.util.Vector
> in my dynamic model, and as proposed I used a EDataType, it works well
> for every type but now, I have to save the model and in this case, the
> program triggers the frustrating IOWrappedException, here are two
> excerpts:
> //creating an attribute
> EAttribute eAttribute = ecoreFactory.createEAttribute();
> eAttribute.setName(attributeName);
> EDataType dt = ecoreFactory.createEDataType();
> dt.setInstanceClassName(attributeType);
> eAttribute.setEType(dt);
>
> //Saving the model
> ResourceSet resourceSet = new ResourceSetImpl();
>
> // Register XML Factory implementation to handle .ecore files
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap()
> .put("ecore", new XMLResourceFactoryImpl());
>
> // Create empty resource with the given URI
> Resource resource = resourceSet.createResource(URI.createURI("./"
> + name + ".ecore"));
>
> for (Enumeration<PackageType> elements = packages.elements(); elements
> .hasMoreElements();) {
> PackageType aPackage = elements.nextElement();
> resource.getContents().add(aPackage.getPackage());
> }
>
> try {
> // Save the resource
> Map<String, String> options = new HashMap<String, String>();
> options.put(XMLResource.OPTION_ENCODING, "UTF-8");
> resource.save(options);
> } catch (IOException e) {
> e.printStackTrace();
> }
>
> How can I come up with the DanglingHrefException?
The debugger is a good friend. If you use resource.getAllContents() and
then iterate over the eCrossReferences of each EObject, anyone for which
eResource is null, that's a dangling reference.
> If I understand well, it comes from the fact, the class is not
> serialized but I don't understand why we need that since we generate
> an XMI file. Thanks in advance for your help
>
> Regards, M.
>
Re: EDataType and Resource [message #425664 is a reply to message #425649] Thu, 04 December 2008 12:49 Go to previous messageGo to next message
Marc-Philippe Huget is currently offline Marc-Philippe HugetFriend
Messages: 9
Registered: July 2009
Junior Member
Hello Ed,

Thanks for this answer, that's right, the eCrossReferences is null but I
found no example treating this kind of problem: considering new EDataType
from classes not provided by EcorePackage. Do I have to populate
eCrossReferences? Which values do I add in it since it is waiting for
objects? An instance of a class, say java.util.Vector if I want a
EDataType for Vector? Thanks again for your answers

Regards,
M.


Ed Merks wrote:

> The debugger is a good friend. If you use resource.getAllContents() and
> then iterate over the eCrossReferences of each EObject, anyone for which
> eResource is null, that's a dangling reference.
Re: EDataType and Resource [message #425667 is a reply to message #425664] Thu, 04 December 2008 13:01 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 31164
Registered: July 2009
Senior Member
Marc-Philippe,

Comments below.


Marc-Philippe Huget wrote:
> Hello Ed,
> Thanks for this answer, that's right, the eCrossReferences is null but
> I found no example treating this kind of problem: considering new
> EDataType from classes not provided by EcorePackage. Do I have to
> populate eCrossReferences? Which values do I add in it since it is
> waiting for objects? An instance of a class, say java.util.Vector if I
> want a EDataType for Vector? Thanks again for your answers
An EDataType must be in an EPackage to be meaningful, and that EPackage
must be in a Resource with a non-null URI in order to be able to
serialize reference to the package or anything it contains.

I'm really not sure what you're trying to accomplish so my answers will
generally be a tiny snip that addresses only the little bit you've told me.
>
> Regards,
> M.
>
>
> Ed Merks wrote:
>
>> The debugger is a good friend. If you use resource.getAllContents()
>> and then iterate over the eCrossReferences of each EObject, anyone
>> for which eResource is null, that's a dangling reference.
>
>
Previous Topic:EDataTypeImpl equality?
Next Topic:Saving emfresource while updating references
Goto Forum:
  


Current Time: Sat Jun 06 06:03:27 GMT 2020

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

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

Back to the top