Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » SequenceNode serialization problem?
SequenceNode serialization problem? [message #476743] Wed, 12 December 2007 13:00 Go to next message
Krzysztof Kaczmarski is currently offline Krzysztof KaczmarskiFriend
Messages: 88
Registered: July 2009
Member
Hi All,

I have encountered strange problem with SequenceNodes. I nest them and
to be able to navigate to parent node I use setInStructuredNode()
reference to point one level up. Then I serialize the model. When I
read the model again and try to use this parent node reference by
getInStructuredNode() I get null.
I checked the uml file after serialization. There is no information
about this reference in appropriate SequenceNode. Is this correct?

Thanks for any ideas,
Krzysztof
Re: SequenceNode serialization problem? [message #476746 is a reply to message #476743] Wed, 12 December 2007 18:23 Go to previous messageGo to next message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
Hi Krzysztof,

Would it be possible to provide a sample model and a snippet of code that
demonstrates this issue. I would find it really hard to imagine that the
serialization is getting corrupted or derived collections are not being
properly created.

Cheers,
- James.

"Krzysztof Kaczmarski" <krzysztof_kaczmarski@o2.pl> wrote in message
news:fjom1a$bh5$1@build.eclipse.org...
> Hi All,
>
> I have encountered strange problem with SequenceNodes. I nest them and to
> be able to navigate to parent node I use setInStructuredNode() reference
> to point one level up. Then I serialize the model. When I read the model
> again and try to use this parent node reference by
> getInStructuredNode() I get null.
> I checked the uml file after serialization. There is no information about
> this reference in appropriate SequenceNode. Is this correct?
>
> Thanks for any ideas,
> Krzysztof
Re: SequenceNode serialization problem? [message #476749 is a reply to message #476746] Wed, 12 December 2007 18:56 Go to previous messageGo to next message
Krzysztof Kaczmarski is currently offline Krzysztof KaczmarskiFriend
Messages: 88
Registered: July 2009
Member
Hi James,

I think this is a problem with reverse pointer which I already touched
here:
http://dev.eclipse.org/newslists/news.eclipse.modeling.mdt.u ml2/msg01266.html

I also will try to prepare a simple model and testing code for you.

Thanks,
Krzysztof

James Bruck wrote:
> Hi Krzysztof,
>
> Would it be possible to provide a sample model and a snippet of code that
> demonstrates this issue. I would find it really hard to imagine that the
> serialization is getting corrupted or derived collections are not being
> properly created.
>
> Cheers,
> - James.
>
> "Krzysztof Kaczmarski" <krzysztof_kaczmarski@o2.pl> wrote in message
> news:fjom1a$bh5$1@build.eclipse.org...
>> Hi All,
>>
>> I have encountered strange problem with SequenceNodes. I nest them and to
>> be able to navigate to parent node I use setInStructuredNode() reference
>> to point one level up. Then I serialize the model. When I read the model
>> again and try to use this parent node reference by
>> getInStructuredNode() I get null.
>> I checked the uml file after serialization. There is no information about
>> this reference in appropriate SequenceNode. Is this correct?
>>
>> Thanks for any ideas,
>> Krzysztof
>
>
Re: SequenceNode serialization problem? [message #476750 is a reply to message #476746] Wed, 12 December 2007 19:29 Go to previous messageGo to next message
Krzysztof Kaczmarski is currently offline Krzysztof KaczmarskiFriend
Messages: 88
Registered: July 2009
Member
This is a multi-part message in MIME format.
--------------060808030708010305080301
Content-Type: text/plain; charset=ISO-8859-2; format=flowed
Content-Transfer-Encoding: 7bit

Hi James,

here is sample code and model. I suppose that reverse reference
(inStructuredNode) is not managed by MDT automatically.
In my opinion this code should not return null.

Thanks,
KK


James Bruck wrote:
> Hi Krzysztof,
>
> Would it be possible to provide a sample model and a snippet of code that
> demonstrates this issue. I would find it really hard to imagine that the
> serialization is getting corrupted or derived collections are not being
> properly created.
>
> Cheers,
> - James.
>
> "Krzysztof Kaczmarski" <krzysztof_kaczmarski@o2.pl> wrote in message
> news:fjom1a$bh5$1@build.eclipse.org...
>> Hi All,
>>
>> I have encountered strange problem with SequenceNodes. I nest them and to
>> be able to navigate to parent node I use setInStructuredNode() reference
>> to point one level up. Then I serialize the model. When I read the model
>> again and try to use this parent node reference by
>> getInStructuredNode() I get null.
>> I checked the uml file after serialization. There is no information about
>> this reference in appropriate SequenceNode. Is this correct?
>>
>> Thanks for any ideas,
>> Krzysztof
>
>


--------------060808030708010305080301
Content-Type: text/x-java;
name="SimpleTest.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="SimpleTest.java"

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.common.util.WrappedException;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.uml2.uml.Activity;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.SequenceNode;
import org.eclipse.uml2.uml.UMLFactory;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.resource.UMLResource;


public class SimpleTest
{
public static boolean DEBUG = true;

protected static final ResourceSet RESOURCE_SET = new ResourceSetImpl();

protected static void registerResourceFactories() {
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(
UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
}

protected static org.eclipse.uml2.uml.Package load(URI uri) {
org.eclipse.uml2.uml.Package package_ = null;

try {
Resource resource = RESOURCE_SET.getResource(uri, true);

package_ = (org.eclipse.uml2.uml.Package) EcoreUtil
.getObjectByType(resource.getContents(),
UMLPackage.Literals.PACKAGE);
} catch (WrappedException we) {
err(we.getMessage());
System.exit(1);
}

return package_;
}

protected static void err(String error) {
System.err.println(error);
}


public static void main(String[] args) {

registerResourceFactories();


Model model = UMLFactory.eINSTANCE.createModel();
model.setName("MyModel");

model = (Model) load( URI.createFileURI("sequenceNodeTest.uml"));
org.eclipse.uml2.uml.Class claz = (Class) model.getPackagedElement( "MyClass" );

System.out.println( claz );
Activity a = (Activity) claz.getOwnedBehavior( "MyActivity" );
System.out.println( a );
SequenceNode s1 = (SequenceNode) a.getNode( "nodeLevel1" );
System.out.println( s1 );
SequenceNode s2 = (SequenceNode) s1.getNode( "nodeLevel2" );
System.out.println( s2 );
System.out.println( "Level 2 -> Level 1 (inStructuredNode) = " + s2.getInStructuredNode() );
}
}

--------------060808030708010305080301
Content-Type: text/xml;
name="sequenceNodeTest.uml"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="sequenceNodeTest.uml"

<?xml version="1.0" encoding="UTF-8"?>
<uml:Model xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML" xmi:id="_M8T8cFowEdyn5PgBtndvJg" name="MyModel">
<packagedElement xmi:type="uml:Class" xmi:id="_M8VxoFowEdyn5PgBtndvJg" name="MyClass">
<ownedBehavior xmi:type="uml:Activity" xmi:id="_M8VxoVowEdyn5PgBtndvJg" name="MyActivity">
<node xmi:type="uml:SequenceNode" xmi:id="_M8WYsFowEdyn5PgBtndvJg" name="nodeLevel1">
<executableNode xmi:type="uml:SequenceNode" xmi:id="_WQs5sajkEdy8gcY1EQreGw" name="nodeLevel2"/>
</node>
</ownedBehavior>
</packagedElement>
</uml:Model>

--------------060808030708010305080301--
Re: SequenceNode serialization problem? [message #476761 is a reply to message #476746] Sat, 15 December 2007 09:12 Go to previous messageGo to next message
Krzysztof Kaczmarski is currently offline Krzysztof KaczmarskiFriend
Messages: 88
Registered: July 2009
Member
This is a multi-part message in MIME format.
--------------090005080607090304090207
Content-Type: text/plain; charset=ISO-8859-2; format=flowed
Content-Transfer-Encoding: 7bit

Hi James,

Maybe the previous example was not the best to observe what I am
trying to say.
Here is a better one. It contains four sections:
1. model creation
2. model save
3. model load
4. model check

If you comment out model loading you will see that created model
passes check because setInStructuredNode works properly. Saving
section serializes the model. Then when you uncomment loading and
comment out creation and saving you will see that this model after
loading does not contain inStructuredNode reference which was there
before saving.

Is it normal behavior?
If it is normal how can I navigate from nested StructuredNode to
surrounding node?

Regards,
Krzysztof



James Bruck wrote:
> Hi Krzysztof,
>
> Would it be possible to provide a sample model and a snippet of code that
> demonstrates this issue. I would find it really hard to imagine that the
> serialization is getting corrupted or derived collections are not being
> properly created.
>
> Cheers,
> - James.
>
> "Krzysztof Kaczmarski" <krzysztof_kaczmarski@o2.pl> wrote in message
> news:fjom1a$bh5$1@build.eclipse.org...
>> Hi All,
>>
>> I have encountered strange problem with SequenceNodes. I nest them and to
>> be able to navigate to parent node I use setInStructuredNode() reference
>> to point one level up. Then I serialize the model. When I read the model
>> again and try to use this parent node reference by
>> getInStructuredNode() I get null.
>> I checked the uml file after serialization. There is no information about
>> this reference in appropriate SequenceNode. Is this correct?
>>
>> Thanks for any ideas,
>> Krzysztof
>
>


--------------090005080607090304090207
Content-Type: text/x-java;
name="SimpleTest.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="SimpleTest.java"

import java.io.IOException;
import java.util.Iterator;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.common.util.WrappedException;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.uml2.uml.Activity;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.SequenceNode;
import org.eclipse.uml2.uml.UMLFactory;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.resource.UMLResource;
import org.eclipse.uml2.uml.util.UMLUtil;


public class SimpleTest
{
protected static final ResourceSet RESOURCE_SET = new ResourceSetImpl();

protected static void registerResourceFactories() {
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(
UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
}

protected static void save(org.eclipse.uml2.uml.Package package_, URI uri) {
Resource resource = RESOURCE_SET.createResource(uri);
EList contents = resource.getContents();

contents.add(package_);

for (Iterator allContents = UMLUtil.getAllContents(package_, true,
false); allContents.hasNext();) {

EObject eObject = (EObject) allContents.next();

if (eObject instanceof Element) {
contents
.addAll(((Element) eObject).getStereotypeApplications());
}
}

try {
resource.save(null);
} catch (IOException ioe) {
err(ioe.getMessage());
}
}

protected static org.eclipse.uml2.uml.Package load(URI uri) {
org.eclipse.uml2.uml.Package package_ = null;

try {
Resource resource = RESOURCE_SET.getResource(uri, true);

package_ = (org.eclipse.uml2.uml.Package) EcoreUtil
.getObjectByType(resource.getContents(),
UMLPackage.Literals.PACKAGE);
} catch (WrappedException we) {
err(we.getMessage());
System.exit(1);
}

return package_;
}

protected static void err(String error) {
System.err.println(error);
}


public static void main(String[] args) {

registerResourceFactories();
Activity a;
SequenceNode s1, s2;

// creating model

Model model = UMLFactory.eINSTANCE.createModel();
model.setName("MyModel");
org.eclipse.uml2.uml.Class clazz = model.createOwnedClass("MyClass", false);
a= (Activity) clazz.createOwnedBehavior( "MyActivity", UMLPackage.Literals.ACTIVITY );
s1 = (SequenceNode) a.createNode( "nodeLevel1", UMLPackage.Literals.SEQUENCE_NODE);
s1.setInActivity( a );
s2 = (SequenceNode) s1.createNode( "nodeLevel2", UMLPackage.Literals.SEQUENCE_NODE);
s2.setInStructuredNode( s1 );

// saving

save(model, URI.createFileURI("sequenceNodeTest.uml") );

// loading model

//model = (Model) load( URI.createFileURI("sequenceNodeTest.uml"));

// checking

org.eclipse.uml2.uml.Class claz = (Class) model.getPackagedElement( "MyClass" );
System.out.println( claz );
a = (Activity) claz.getOwnedBehavior( "MyActivity" );
System.out.println( a );
s1 = (SequenceNode) a.getNode( "nodeLevel1" );
System.out.println( s1 );
System.out.println( "Level 1 -> Activity (inActivity) = " + s1.getInActivity() );
s2 = (SequenceNode) s1.getNode( "nodeLevel2" );
System.out.println( s2 );
System.out.println( "Level 2 -> Level 1 (inStructuredNode) = " + s2.getInStructuredNode() );
}
}

--------------090005080607090304090207--
Re: SequenceNode serialization problem? [message #476819 is a reply to message #476761] Thu, 03 January 2008 15:16 Go to previous message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
Hi Krzysztof,

Sorry about the delayed response ... I just got back from vacation. It
looks like your question was answered from your posting of 12/19?

- James.

"Krzysztof Kaczmarski" <krzysztof_kaczmarski@o2.pl> wrote in message
news:fk05pm$1hp$1@build.eclipse.org...
> Hi James,
>
> Maybe the previous example was not the best to observe what I am
> trying to say.
> Here is a better one. It contains four sections:
> 1. model creation
> 2. model save
> 3. model load
> 4. model check
>
> If you comment out model loading you will see that created model
> passes check because setInStructuredNode works properly. Saving
> section serializes the model. Then when you uncomment loading and
> comment out creation and saving you will see that this model after
> loading does not contain inStructuredNode reference which was there
> before saving.
>
> Is it normal behavior?
> If it is normal how can I navigate from nested StructuredNode to
> surrounding node?
>
> Regards,
> Krzysztof
>
>
>
> James Bruck wrote:
>> Hi Krzysztof,
>>
>> Would it be possible to provide a sample model and a snippet of code that
>> demonstrates this issue. I would find it really hard to imagine that the
>> serialization is getting corrupted or derived collections are not being
>> properly created.
>>
>> Cheers,
>> - James.
>>
>> "Krzysztof Kaczmarski" <krzysztof_kaczmarski@o2.pl> wrote in message
>> news:fjom1a$bh5$1@build.eclipse.org...
>>> Hi All,
>>>
>>> I have encountered strange problem with SequenceNodes. I nest them and
>>> to
>>> be able to navigate to parent node I use setInStructuredNode() reference
>>> to point one level up. Then I serialize the model. When I read the model
>>> again and try to use this parent node reference by
>>> getInStructuredNode() I get null.
>>> I checked the uml file after serialization. There is no information
>>> about
>>> this reference in appropriate SequenceNode. Is this correct?
>>>
>>> Thanks for any ideas,
>>> Krzysztof
>>
>>
>
>


------------------------------------------------------------ --------------------


> import java.io.IOException;
> import java.util.Iterator;
>
> import org.eclipse.emf.common.util.EList;
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.emf.common.util.WrappedException;
> import org.eclipse.emf.ecore.EObject;
> import org.eclipse.emf.ecore.resource.Resource;
> import org.eclipse.emf.ecore.resource.ResourceSet;
> import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
> import org.eclipse.emf.ecore.util.EcoreUtil;
> import org.eclipse.uml2.uml.Activity;
> import org.eclipse.uml2.uml.Class;
> import org.eclipse.uml2.uml.Element;
> import org.eclipse.uml2.uml.Model;
> import org.eclipse.uml2.uml.SequenceNode;
> import org.eclipse.uml2.uml.UMLFactory;
> import org.eclipse.uml2.uml.UMLPackage;
> import org.eclipse.uml2.uml.resource.UMLResource;
> import org.eclipse.uml2.uml.util.UMLUtil;
>
>
> public class SimpleTest
> {
> protected static final ResourceSet RESOURCE_SET = new ResourceSetImpl();
>
> protected static void registerResourceFactories() {
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(
> UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
> }
>
> protected static void save(org.eclipse.uml2.uml.Package package_, URI uri)
> {
> Resource resource = RESOURCE_SET.createResource(uri);
> EList contents = resource.getContents();
>
> contents.add(package_);
>
> for (Iterator allContents = UMLUtil.getAllContents(package_, true,
> false); allContents.hasNext();) {
>
> EObject eObject = (EObject) allContents.next();
>
> if (eObject instanceof Element) {
> contents
> .addAll(((Element) eObject).getStereotypeApplications());
> }
> }
>
> try {
> resource.save(null);
> } catch (IOException ioe) {
> err(ioe.getMessage());
> }
> }
>
> protected static org.eclipse.uml2.uml.Package load(URI uri) {
> org.eclipse.uml2.uml.Package package_ = null;
>
> try {
> Resource resource = RESOURCE_SET.getResource(uri, true);
>
> package_ = (org.eclipse.uml2.uml.Package) EcoreUtil
> .getObjectByType(resource.getContents(),
> UMLPackage.Literals.PACKAGE);
> } catch (WrappedException we) {
> err(we.getMessage());
> System.exit(1);
> }
>
> return package_;
> }
>
> protected static void err(String error) {
> System.err.println(error);
> }
>
>
> public static void main(String[] args) {
>
> registerResourceFactories();
> Activity a;
> SequenceNode s1, s2;
>
> // creating model
>
> Model model = UMLFactory.eINSTANCE.createModel();
> model.setName("MyModel");
> org.eclipse.uml2.uml.Class clazz = model.createOwnedClass("MyClass",
> false);
> a= (Activity) clazz.createOwnedBehavior( "MyActivity",
> UMLPackage.Literals.ACTIVITY );
> s1 = (SequenceNode) a.createNode( "nodeLevel1",
> UMLPackage.Literals.SEQUENCE_NODE);
> s1.setInActivity( a );
> s2 = (SequenceNode) s1.createNode( "nodeLevel2",
> UMLPackage.Literals.SEQUENCE_NODE);
> s2.setInStructuredNode( s1 );
>
> // saving
>
> save(model, URI.createFileURI("sequenceNodeTest.uml") );
>
> // loading model
>
> //model = (Model) load( URI.createFileURI("sequenceNodeTest.uml"));
>
> // checking
>
> org.eclipse.uml2.uml.Class claz = (Class) model.getPackagedElement(
> "MyClass" );
> System.out.println( claz );
> a = (Activity) claz.getOwnedBehavior( "MyActivity" );
> System.out.println( a );
> s1 = (SequenceNode) a.getNode( "nodeLevel1" );
> System.out.println( s1 );
> System.out.println( "Level 1 -> Activity (inActivity) = " +
> s1.getInActivity() );
> s2 = (SequenceNode) s1.getNode( "nodeLevel2" );
> System.out.println( s2 );
> System.out.println( "Level 2 -> Level 1 (inStructuredNode) = " +
> s2.getInStructuredNode() );
> }
> }
>
Re: SequenceNode serialization problem? [message #625719 is a reply to message #476743] Wed, 12 December 2007 18:23 Go to previous message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
Hi Krzysztof,

Would it be possible to provide a sample model and a snippet of code that
demonstrates this issue. I would find it really hard to imagine that the
serialization is getting corrupted or derived collections are not being
properly created.

Cheers,
- James.

"Krzysztof Kaczmarski" <krzysztof_kaczmarski@o2.pl> wrote in message
news:fjom1a$bh5$1@build.eclipse.org...
> Hi All,
>
> I have encountered strange problem with SequenceNodes. I nest them and to
> be able to navigate to parent node I use setInStructuredNode() reference
> to point one level up. Then I serialize the model. When I read the model
> again and try to use this parent node reference by
> getInStructuredNode() I get null.
> I checked the uml file after serialization. There is no information about
> this reference in appropriate SequenceNode. Is this correct?
>
> Thanks for any ideas,
> Krzysztof
Re: SequenceNode serialization problem? [message #625722 is a reply to message #476746] Wed, 12 December 2007 18:56 Go to previous message
Krzysztof Kaczmarski is currently offline Krzysztof KaczmarskiFriend
Messages: 88
Registered: July 2009
Member
Hi James,

I think this is a problem with reverse pointer which I already touched
here:
http://dev.eclipse.org/newslists/news.eclipse.modeling.mdt.u ml2/msg01266.html

I also will try to prepare a simple model and testing code for you.

Thanks,
Krzysztof

James Bruck wrote:
> Hi Krzysztof,
>
> Would it be possible to provide a sample model and a snippet of code that
> demonstrates this issue. I would find it really hard to imagine that the
> serialization is getting corrupted or derived collections are not being
> properly created.
>
> Cheers,
> - James.
>
> "Krzysztof Kaczmarski" <krzysztof_kaczmarski@o2.pl> wrote in message
> news:fjom1a$bh5$1@build.eclipse.org...
>> Hi All,
>>
>> I have encountered strange problem with SequenceNodes. I nest them and to
>> be able to navigate to parent node I use setInStructuredNode() reference
>> to point one level up. Then I serialize the model. When I read the model
>> again and try to use this parent node reference by
>> getInStructuredNode() I get null.
>> I checked the uml file after serialization. There is no information about
>> this reference in appropriate SequenceNode. Is this correct?
>>
>> Thanks for any ideas,
>> Krzysztof
>
>
Re: SequenceNode serialization problem? [message #625723 is a reply to message #476746] Wed, 12 December 2007 19:29 Go to previous message
Krzysztof Kaczmarski is currently offline Krzysztof KaczmarskiFriend
Messages: 88
Registered: July 2009
Member
This is a multi-part message in MIME format.
--------------060808030708010305080301
Content-Type: text/plain; charset=ISO-8859-2; format=flowed
Content-Transfer-Encoding: 7bit

Hi James,

here is sample code and model. I suppose that reverse reference
(inStructuredNode) is not managed by MDT automatically.
In my opinion this code should not return null.

Thanks,
KK


James Bruck wrote:
> Hi Krzysztof,
>
> Would it be possible to provide a sample model and a snippet of code that
> demonstrates this issue. I would find it really hard to imagine that the
> serialization is getting corrupted or derived collections are not being
> properly created.
>
> Cheers,
> - James.
>
> "Krzysztof Kaczmarski" <krzysztof_kaczmarski@o2.pl> wrote in message
> news:fjom1a$bh5$1@build.eclipse.org...
>> Hi All,
>>
>> I have encountered strange problem with SequenceNodes. I nest them and to
>> be able to navigate to parent node I use setInStructuredNode() reference
>> to point one level up. Then I serialize the model. When I read the model
>> again and try to use this parent node reference by
>> getInStructuredNode() I get null.
>> I checked the uml file after serialization. There is no information about
>> this reference in appropriate SequenceNode. Is this correct?
>>
>> Thanks for any ideas,
>> Krzysztof
>
>


--------------060808030708010305080301
Content-Type: text/x-java;
name="SimpleTest.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="SimpleTest.java"

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.common.util.WrappedException;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.uml2.uml.Activity;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.SequenceNode;
import org.eclipse.uml2.uml.UMLFactory;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.resource.UMLResource;


public class SimpleTest
{
public static boolean DEBUG = true;

protected static final ResourceSet RESOURCE_SET = new ResourceSetImpl();

protected static void registerResourceFactories() {
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(
UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
}

protected static org.eclipse.uml2.uml.Package load(URI uri) {
org.eclipse.uml2.uml.Package package_ = null;

try {
Resource resource = RESOURCE_SET.getResource(uri, true);

package_ = (org.eclipse.uml2.uml.Package) EcoreUtil
.getObjectByType(resource.getContents(),
UMLPackage.Literals.PACKAGE);
} catch (WrappedException we) {
err(we.getMessage());
System.exit(1);
}

return package_;
}

protected static void err(String error) {
System.err.println(error);
}


public static void main(String[] args) {

registerResourceFactories();


Model model = UMLFactory.eINSTANCE.createModel();
model.setName("MyModel");

model = (Model) load( URI.createFileURI("sequenceNodeTest.uml"));
org.eclipse.uml2.uml.Class claz = (Class) model.getPackagedElement( "MyClass" );

System.out.println( claz );
Activity a = (Activity) claz.getOwnedBehavior( "MyActivity" );
System.out.println( a );
SequenceNode s1 = (SequenceNode) a.getNode( "nodeLevel1" );
System.out.println( s1 );
SequenceNode s2 = (SequenceNode) s1.getNode( "nodeLevel2" );
System.out.println( s2 );
System.out.println( "Level 2 -> Level 1 (inStructuredNode) = " + s2.getInStructuredNode() );
}
}

--------------060808030708010305080301
Content-Type: text/xml;
name="sequenceNodeTest.uml"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="sequenceNodeTest.uml"

<?xml version="1.0" encoding="UTF-8"?>
<uml:Model xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML" xmi:id="_M8T8cFowEdyn5PgBtndvJg" name="MyModel">
<packagedElement xmi:type="uml:Class" xmi:id="_M8VxoFowEdyn5PgBtndvJg" name="MyClass">
<ownedBehavior xmi:type="uml:Activity" xmi:id="_M8VxoVowEdyn5PgBtndvJg" name="MyActivity">
<node xmi:type="uml:SequenceNode" xmi:id="_M8WYsFowEdyn5PgBtndvJg" name="nodeLevel1">
<executableNode xmi:type="uml:SequenceNode" xmi:id="_WQs5sajkEdy8gcY1EQreGw" name="nodeLevel2"/>
</node>
</ownedBehavior>
</packagedElement>
</uml:Model>

--------------060808030708010305080301--
Re: SequenceNode serialization problem? [message #625733 is a reply to message #476746] Sat, 15 December 2007 09:12 Go to previous message
Krzysztof Kaczmarski is currently offline Krzysztof KaczmarskiFriend
Messages: 88
Registered: July 2009
Member
This is a multi-part message in MIME format.
--------------090005080607090304090207
Content-Type: text/plain; charset=ISO-8859-2; format=flowed
Content-Transfer-Encoding: 7bit

Hi James,

Maybe the previous example was not the best to observe what I am
trying to say.
Here is a better one. It contains four sections:
1. model creation
2. model save
3. model load
4. model check

If you comment out model loading you will see that created model
passes check because setInStructuredNode works properly. Saving
section serializes the model. Then when you uncomment loading and
comment out creation and saving you will see that this model after
loading does not contain inStructuredNode reference which was there
before saving.

Is it normal behavior?
If it is normal how can I navigate from nested StructuredNode to
surrounding node?

Regards,
Krzysztof



James Bruck wrote:
> Hi Krzysztof,
>
> Would it be possible to provide a sample model and a snippet of code that
> demonstrates this issue. I would find it really hard to imagine that the
> serialization is getting corrupted or derived collections are not being
> properly created.
>
> Cheers,
> - James.
>
> "Krzysztof Kaczmarski" <krzysztof_kaczmarski@o2.pl> wrote in message
> news:fjom1a$bh5$1@build.eclipse.org...
>> Hi All,
>>
>> I have encountered strange problem with SequenceNodes. I nest them and to
>> be able to navigate to parent node I use setInStructuredNode() reference
>> to point one level up. Then I serialize the model. When I read the model
>> again and try to use this parent node reference by
>> getInStructuredNode() I get null.
>> I checked the uml file after serialization. There is no information about
>> this reference in appropriate SequenceNode. Is this correct?
>>
>> Thanks for any ideas,
>> Krzysztof
>
>


--------------090005080607090304090207
Content-Type: text/x-java;
name="SimpleTest.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="SimpleTest.java"

import java.io.IOException;
import java.util.Iterator;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.common.util.WrappedException;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.uml2.uml.Activity;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.SequenceNode;
import org.eclipse.uml2.uml.UMLFactory;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.resource.UMLResource;
import org.eclipse.uml2.uml.util.UMLUtil;


public class SimpleTest
{
protected static final ResourceSet RESOURCE_SET = new ResourceSetImpl();

protected static void registerResourceFactories() {
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(
UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
}

protected static void save(org.eclipse.uml2.uml.Package package_, URI uri) {
Resource resource = RESOURCE_SET.createResource(uri);
EList contents = resource.getContents();

contents.add(package_);

for (Iterator allContents = UMLUtil.getAllContents(package_, true,
false); allContents.hasNext();) {

EObject eObject = (EObject) allContents.next();

if (eObject instanceof Element) {
contents
.addAll(((Element) eObject).getStereotypeApplications());
}
}

try {
resource.save(null);
} catch (IOException ioe) {
err(ioe.getMessage());
}
}

protected static org.eclipse.uml2.uml.Package load(URI uri) {
org.eclipse.uml2.uml.Package package_ = null;

try {
Resource resource = RESOURCE_SET.getResource(uri, true);

package_ = (org.eclipse.uml2.uml.Package) EcoreUtil
.getObjectByType(resource.getContents(),
UMLPackage.Literals.PACKAGE);
} catch (WrappedException we) {
err(we.getMessage());
System.exit(1);
}

return package_;
}

protected static void err(String error) {
System.err.println(error);
}


public static void main(String[] args) {

registerResourceFactories();
Activity a;
SequenceNode s1, s2;

// creating model

Model model = UMLFactory.eINSTANCE.createModel();
model.setName("MyModel");
org.eclipse.uml2.uml.Class clazz = model.createOwnedClass("MyClass", false);
a= (Activity) clazz.createOwnedBehavior( "MyActivity", UMLPackage.Literals.ACTIVITY );
s1 = (SequenceNode) a.createNode( "nodeLevel1", UMLPackage.Literals.SEQUENCE_NODE);
s1.setInActivity( a );
s2 = (SequenceNode) s1.createNode( "nodeLevel2", UMLPackage.Literals.SEQUENCE_NODE);
s2.setInStructuredNode( s1 );

// saving

save(model, URI.createFileURI("sequenceNodeTest.uml") );

// loading model

//model = (Model) load( URI.createFileURI("sequenceNodeTest.uml"));

// checking

org.eclipse.uml2.uml.Class claz = (Class) model.getPackagedElement( "MyClass" );
System.out.println( claz );
a = (Activity) claz.getOwnedBehavior( "MyActivity" );
System.out.println( a );
s1 = (SequenceNode) a.getNode( "nodeLevel1" );
System.out.println( s1 );
System.out.println( "Level 1 -> Activity (inActivity) = " + s1.getInActivity() );
s2 = (SequenceNode) s1.getNode( "nodeLevel2" );
System.out.println( s2 );
System.out.println( "Level 2 -> Level 1 (inStructuredNode) = " + s2.getInStructuredNode() );
}
}

--------------090005080607090304090207--
Re: SequenceNode serialization problem? [message #625795 is a reply to message #476761] Thu, 03 January 2008 15:16 Go to previous message
james bruck is currently offline james bruckFriend
Messages: 1724
Registered: July 2009
Senior Member
Hi Krzysztof,

Sorry about the delayed response ... I just got back from vacation. It
looks like your question was answered from your posting of 12/19?

- James.

"Krzysztof Kaczmarski" <krzysztof_kaczmarski@o2.pl> wrote in message
news:fk05pm$1hp$1@build.eclipse.org...
> Hi James,
>
> Maybe the previous example was not the best to observe what I am
> trying to say.
> Here is a better one. It contains four sections:
> 1. model creation
> 2. model save
> 3. model load
> 4. model check
>
> If you comment out model loading you will see that created model
> passes check because setInStructuredNode works properly. Saving
> section serializes the model. Then when you uncomment loading and
> comment out creation and saving you will see that this model after
> loading does not contain inStructuredNode reference which was there
> before saving.
>
> Is it normal behavior?
> If it is normal how can I navigate from nested StructuredNode to
> surrounding node?
>
> Regards,
> Krzysztof
>
>
>
> James Bruck wrote:
>> Hi Krzysztof,
>>
>> Would it be possible to provide a sample model and a snippet of code that
>> demonstrates this issue. I would find it really hard to imagine that the
>> serialization is getting corrupted or derived collections are not being
>> properly created.
>>
>> Cheers,
>> - James.
>>
>> "Krzysztof Kaczmarski" <krzysztof_kaczmarski@o2.pl> wrote in message
>> news:fjom1a$bh5$1@build.eclipse.org...
>>> Hi All,
>>>
>>> I have encountered strange problem with SequenceNodes. I nest them and
>>> to
>>> be able to navigate to parent node I use setInStructuredNode() reference
>>> to point one level up. Then I serialize the model. When I read the model
>>> again and try to use this parent node reference by
>>> getInStructuredNode() I get null.
>>> I checked the uml file after serialization. There is no information
>>> about
>>> this reference in appropriate SequenceNode. Is this correct?
>>>
>>> Thanks for any ideas,
>>> Krzysztof
>>
>>
>
>


------------------------------------------------------------ --------------------


> import java.io.IOException;
> import java.util.Iterator;
>
> import org.eclipse.emf.common.util.EList;
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.emf.common.util.WrappedException;
> import org.eclipse.emf.ecore.EObject;
> import org.eclipse.emf.ecore.resource.Resource;
> import org.eclipse.emf.ecore.resource.ResourceSet;
> import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
> import org.eclipse.emf.ecore.util.EcoreUtil;
> import org.eclipse.uml2.uml.Activity;
> import org.eclipse.uml2.uml.Class;
> import org.eclipse.uml2.uml.Element;
> import org.eclipse.uml2.uml.Model;
> import org.eclipse.uml2.uml.SequenceNode;
> import org.eclipse.uml2.uml.UMLFactory;
> import org.eclipse.uml2.uml.UMLPackage;
> import org.eclipse.uml2.uml.resource.UMLResource;
> import org.eclipse.uml2.uml.util.UMLUtil;
>
>
> public class SimpleTest
> {
> protected static final ResourceSet RESOURCE_SET = new ResourceSetImpl();
>
> protected static void registerResourceFactories() {
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(
> UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
> }
>
> protected static void save(org.eclipse.uml2.uml.Package package_, URI uri)
> {
> Resource resource = RESOURCE_SET.createResource(uri);
> EList contents = resource.getContents();
>
> contents.add(package_);
>
> for (Iterator allContents = UMLUtil.getAllContents(package_, true,
> false); allContents.hasNext();) {
>
> EObject eObject = (EObject) allContents.next();
>
> if (eObject instanceof Element) {
> contents
> .addAll(((Element) eObject).getStereotypeApplications());
> }
> }
>
> try {
> resource.save(null);
> } catch (IOException ioe) {
> err(ioe.getMessage());
> }
> }
>
> protected static org.eclipse.uml2.uml.Package load(URI uri) {
> org.eclipse.uml2.uml.Package package_ = null;
>
> try {
> Resource resource = RESOURCE_SET.getResource(uri, true);
>
> package_ = (org.eclipse.uml2.uml.Package) EcoreUtil
> .getObjectByType(resource.getContents(),
> UMLPackage.Literals.PACKAGE);
> } catch (WrappedException we) {
> err(we.getMessage());
> System.exit(1);
> }
>
> return package_;
> }
>
> protected static void err(String error) {
> System.err.println(error);
> }
>
>
> public static void main(String[] args) {
>
> registerResourceFactories();
> Activity a;
> SequenceNode s1, s2;
>
> // creating model
>
> Model model = UMLFactory.eINSTANCE.createModel();
> model.setName("MyModel");
> org.eclipse.uml2.uml.Class clazz = model.createOwnedClass("MyClass",
> false);
> a= (Activity) clazz.createOwnedBehavior( "MyActivity",
> UMLPackage.Literals.ACTIVITY );
> s1 = (SequenceNode) a.createNode( "nodeLevel1",
> UMLPackage.Literals.SEQUENCE_NODE);
> s1.setInActivity( a );
> s2 = (SequenceNode) s1.createNode( "nodeLevel2",
> UMLPackage.Literals.SEQUENCE_NODE);
> s2.setInStructuredNode( s1 );
>
> // saving
>
> save(model, URI.createFileURI("sequenceNodeTest.uml") );
>
> // loading model
>
> //model = (Model) load( URI.createFileURI("sequenceNodeTest.uml"));
>
> // checking
>
> org.eclipse.uml2.uml.Class claz = (Class) model.getPackagedElement(
> "MyClass" );
> System.out.println( claz );
> a = (Activity) claz.getOwnedBehavior( "MyActivity" );
> System.out.println( a );
> s1 = (SequenceNode) a.getNode( "nodeLevel1" );
> System.out.println( s1 );
> System.out.println( "Level 1 -> Activity (inActivity) = " +
> s1.getInActivity() );
> s2 = (SequenceNode) s1.getNode( "nodeLevel2" );
> System.out.println( s2 );
> System.out.println( "Level 2 -> Level 1 (inStructuredNode) = " +
> s2.getInStructuredNode() );
> }
> }
>
Previous Topic:inStructuredNode reference not saved
Next Topic:Transforming UML associations to Ecore
Goto Forum:
  


Current Time: Thu Apr 18 14:48:06 GMT 2024

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

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

Back to the top