EDataType and Resource [message #425643] |
Wed, 03 December 2008 16:28 |
Marc-Philippe Huget 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 |
Ed Merks Messages: 33216 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.
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Re: EDataType and Resource [message #425667 is a reply to message #425664] |
Thu, 04 December 2008 13:01 |
Ed Merks Messages: 33216 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.
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.02970 seconds