|
Re: Problem serialization of own UML ModelImpl [message #1090348 is a reply to message #1090028] |
Tue, 20 August 2013 02:38 |
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03106 seconds