Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Problem serialization of own UML ModelImpl
icon5.gif  Problem serialization of own UML ModelImpl [message #1090028] Mon, 19 August 2013 15:59 Go to next message
Gabby Jay is currently offline Gabby JayFriend
Messages: 2
Registered: August 2013
Junior Member
Hello,

I wanted to create my own little UML tool. For that I extended the already existing Model class (from org.eclipse.uml2.uml.Model) and added some functionality to it.

e.g. I implemented an observer interface
and I added some attributes like an Icon which gets displayed in a JTree.

Here is the mimimized code for the Model interface/class

/* Model interface*/
import org.eclipse.uml2.uml.Model;
import uml2.visual.model.VisualElement;


public interface VisualModel extends Model, VisualElement
{
}

/* Model class */
public class VisualModelImpl extends ModelImpl implements VisualModel
{
	private Icon umlIcon;
}


So I want now to serielize and deserialize my own created UML Model with the new Icon attribute.

I use the following code to serialize:

/* Controller */
public void serializeModel(String xmlFilePath)
{
    Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
    Map<String, Object> m = reg.getExtensionToFactoryMap();
    m.put("xml", new XMLResourceFactoryImpl());

    ResourceSet resSet = new ResourceSetImpl();

    Resource resource = resSet.createResource(URI.createFileURI(xmlFilePath));

    /*umlToolModel.getUmlModel() returns the VisualModel*/
    resource.getContents().add(umlToolModel.getUmlModel());

    try
    {
	resource.save(null);
    }
    catch (IOException ex)
    {
	ex.printStackTrace();
    }
}


The problem is that I am not able to serialize my VisualModel. Only the super class provided by eclipse gets serialized. So I loose all my new added attributes in VisualModel.

I think I have to overwrite some operation of the Model class in order to bring the serialization to work. I also had a look at the source code of the Model implementattion. But as I am no expert with EMF object serialization I don't know how to do it or where to look exactly.

Mabe someone can help me or provide me some information where I can look to solve this problem.

Thanks in advance

Re: Problem serialization of own UML ModelImpl [message #1090348 is a reply to message #1090028] Tue, 20 August 2013 02:38 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi,

If you want to extend an EMF-based model, then you need to model your
extensions so that EMF has all of the metadata required for
serialization and other operations. There are numerous tutorials on
the subject of defining models that extend other EMF models; indeed,
the UML model itself is an example because the Element metaclass
extends EModelElement from Ecore.

However, in the case of extending UML, life is more complicated than
usual because:

* you would have to use the UML2 code generator, not EMF's, to generate
your extended model
* the UML implementation does not officially support this kind of
extension. Do it at your own risk. The next release of UML is likely
to break your extension

Far better for your purpose, since you are extending UML, is to use
UML's own built-in metamodel extension facility: Stereotypes, defined
in Profiles. There are numerous tutorials on that subject, too. In
fact, the UML metamodel provides an Image metaclass that the Stereotype
metaclass uses for its icon property. You can model a
<<VisualElement>> stereotype having a property of type Image to
similarly attach icons to your model elements (including the Model).

HTH,

Christian


On 2013-08-19 19:01:02 +0000, Gabby Jay said:

> Hello,
>
> I wanted to create my own little UML tool. For that I extended the
> already existing Model class (from org.eclipse.uml2.uml.Model) and
> added some functionality to it.
> e.g. I implemented an observer interface and I added some attributes
> like an Icon which gets displayed in a JTree.
>
> Here is the mimimized code for the Model interface/class
>
>
> /* Model interface*/
> import org.eclipse.uml2.uml.Model;
> import uml2.visual.model.VisualElement;
>
>
> public interface VisualModel extends Model, VisualElement
> {
> }
>
> /* Model class */
> public class VisualModelImpl extends ModelImpl implements VisualModel
> {
> private Icon umlIcon;
> }
>
>
> So I want now to serielize and deserialize my own created UML Model
> with the new Icon attribute.
>
> I use the following code to serialize:
>
>
> /* Controller */
> public void serializeModel(String xmlFilePath)
> {
> Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
> Map<String, Object> m = reg.getExtensionToFactoryMap();
> m.put("xml", new XMLResourceFactoryImpl());
>
> ResourceSet resSet = new ResourceSetImpl();
>
> Resource resource = resSet.createResource(URI.createFileURI(xmlFilePath));
>
> /*umlToolModel.getUmlModel() returns the VisualModel*/
> resource.getContents().add(umlToolModel.getUmlModel());
>
> try
> {
> resource.save(null);
> }
> catch (IOException ex)
> {
> ex.printStackTrace();
> }
> }
>
>
> The problem is that I am not able to serialize my VisualModel. Only the
> super class provided by eclipse gets serialized. So I loose all my new
> added attributes in VisualModel.
>
> I think I have to overwrite some operation of the Model class in order
> to bring the serialization to work. I also had a look at the source
> code of the Model implementattion. But as I am no expert with EMF
> object serialization I don't know how to do it or where to look exactly.
>
> Mabe someone can help me or provide me some information where I can
> look to solve this problem.
>
> Thanks in advance
Re: Problem serialization of own UML ModelImpl [message #1091603 is a reply to message #1090028] Wed, 21 August 2013 18:35 Go to previous message
Gabby Jay is currently offline Gabby JayFriend
Messages: 2
Registered: August 2013
Junior Member
okay I got your point. I understand how the stereotype extensions works.
So I think I will go in that direction.
Thank you

Previous Topic:Error when using getValue(): Illegal argument exception
Next Topic:Extract a Subset of Communication Diagram
Goto Forum:
  


Current Time: Fri Apr 19 08:34:32 GMT 2024

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

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

Back to the top