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
Member
This is a multi-part message in MIME format.
--------------070205090204010205000104
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)

Regards,
Krzysztof

--------------070205090204010205000104
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() );
}
}

--------------070205090204010205000104--
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