Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » inStructuredNode reference not saved
inStructuredNode reference not saved [message #625762] Wed, 19 December 2007 14:44
Krzysztof Kaczmarski is currently offline Krzysztof KaczmarskiFriend
Messages: 88
Registered: July 2009
This is a multi-part message in MIME format.
Content-Type: text/plain; charset=ISO-8859-2; format=flowed
Content-Transfer-Encoding: 7bit

Hi All,

I have to ask this question once again. I create several
SequenceNodes. I set inStructuredNode reference. Then I serialize the
model. When I load it again this reference is lost.

Is this normal behavior? Why it is not recreated when model is loaded?

I attach sample code to test it.
(after first run and model creation comment out saving and creation
and uncomment loading)


Content-Type: text/x-java;
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;

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(

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


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

EObject eObject = (EObject);

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

try {;
} catch (IOException ioe) {

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
} catch (WrappedException we) {

return package_;

protected static void err(String error) {

public static void main(String[] args) {

Activity a;
SequenceNode s1, s2;

// creating model

Model model = UMLFactory.eINSTANCE.createModel();
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:UML2 / Sequence diagram / MessageKind
Next Topic:how to generate EMF from UML.ecore
Goto Forum:

Current Time: Sat Aug 13 01:17:18 GMT 2022

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

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

Back to the top