Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » How to manipulate UML Class Diagram Elements
How to manipulate UML Class Diagram Elements [message #1733029] Mon, 23 May 2016 13:04 Go to next message
Mohammadreza Sharbaf is currently offline Mohammadreza SharbafFriend
Messages: 17
Registered: February 2016
Junior Member

Hi all,

I want to modify an UML Class Diagram by java code, for this purpose first, I load an UML model by below java code, But I don't know how to change elements of "UMLModel" in run method. (for example change name of "Person" class to "Human").

package example ; 

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EPackage;
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.epsilon.emc.emf.InMemoryEmfModel;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.resource.UMLResource;
import org.eclipse.uml2.uml.resources.util.UMLResourcesUtil;

public class MinimalExample {
	
	public static void main(String[] args) throws Exception {
		new MinimalExample().run();
	}
	
	public void run() throws Exception {
		InMemoryEmfModel Model = getUmlModel("UMLModel", new File("src/models/Dev1.uml"));
		
	}
	
	public InMemoryEmfModel getUmlModel(String name, File file) throws Exception {
		ResourceSet set = new ResourceSetImpl();
		UMLResourcesUtil.init(set);
		set.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
		set.getResourceFactoryRegistry().getExtensionToFactoryMap().
		         put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
		Resource r = set.getResource(URI.createFileURI(file.getAbsolutePath()), true);
		r.load(null);
		
		Collection<EPackage> ePackages = new ArrayList<EPackage>();
		for (Object ePackage : set.getPackageRegistry().values()) {
			ePackages.add((EPackage) ePackage);
		}
		return new InMemoryEmfModel(name, r, ePackages);
	}
}



Can one help me?

I used emc and eol epsilon plugin for this project and attached a minimal example to this post.

Best regards,
Mohammadreza
  • Attachment: Minimal.rar
    (Size: 5.22KB, Downloaded 65 times)
Re: How to manipulate UML Class Diagram Elements [message #1733142 is a reply to message #1733029] Tue, 24 May 2016 17:56 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. DamusFriend
Messages: 1174
Registered: July 2009
Location: Canada
Senior Member

Hi,

Mohammadreza,

I don't know what emc and eol are.

But the UML2 project provides an API that has all of the tools
necessary for manipulation of UML models, including modification of all
of the attributes and associations defined by the language
specification. For example, to change the name of a class from
"Person" to "Human", you would simply use the
org.eclipse.uml2.uml.NamedElement::setName method, as the Java class
implementing the UML Class metaclass conforms to the NamedElement Java
interface.

HTH,

Christian


On 2016-05-23 13:04:35 +0000, Mohammadreza Sharbaf said:

> Hi all,
>
> I want to modify an UML Class Diagram by java code, for this purpose
> first, I load an UML model by below java code, But I don't know how to
> change elements of "UMLModel" in run method. (for example change name
> of "Person" class to "Human").
>
>
> package example ;
>
> import java.io.File;
> import java.util.ArrayList;
> import java.util.Collection;
>
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.emf.ecore.EPackage;
> 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.epsilon.emc.emf.InMemoryEmfModel;
> import org.eclipse.uml2.uml.UMLPackage;
> import org.eclipse.uml2.uml.resource.UMLResource;
> import org.eclipse.uml2.uml.resources.util.UMLResourcesUtil;
>
> public class MinimalExample {
>
> public static void main(String[] args) throws Exception {
> new MinimalExample().run();
> }
>
> public void run() throws Exception {
> InMemoryEmfModel Model = getUmlModel("UMLModel", new
> File("src/models/Dev1.uml"));
>
> }
>
> public InMemoryEmfModel getUmlModel(String name, File file) throws Exception {
> ResourceSet set = new ResourceSetImpl();
> UMLResourcesUtil.init(set);
> set.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
> set.getResourceFactoryRegistry().getExtensionToFactoryMap().
> put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
> Resource r =
> set.getResource(URI.createFileURI(file.getAbsolutePath()), true);
> r.load(null);
>
> Collection<EPackage> ePackages = new ArrayList<EPackage>();
> for (Object ePackage : set.getPackageRegistry().values()) {
> ePackages.add((EPackage) ePackage);
> }
> return new InMemoryEmfModel(name, r, ePackages);
> }
> }
>
>
>
> Can one help me?
>
> I used emc and eol epsilon plugin for this project and attached a
> minimal example to this post.
>
> Best regards,
> Mohammadreza
> <image>
Re: How to manipulate UML Class Diagram Elements [message #1733148 is a reply to message #1733142] Tue, 24 May 2016 18:19 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5981
Registered: July 2009
Senior Member
Hi

It's best to ask Epsilon questions on the Epsilon newsgroup.

Regards

Ed Willink


On 24/05/2016 18:56, Christian W. Damus wrote:
> Hi,
>
> Mohammadreza,
>
> I don't know what emc and eol are.
>
> But the UML2 project provides an API that has all of the tools
> necessary for manipulation of UML models, including modification of
> all of the attributes and associations defined by the language
> specification. For example, to change the name of a class from
> "Person" to "Human", you would simply use the
> org.eclipse.uml2.uml.NamedElement::setName method, as the Java class
> implementing the UML Class metaclass conforms to the NamedElement Java
> interface.
>
> HTH,
>
> Christian
>
>
> On 2016-05-23 13:04:35 +0000, Mohammadreza Sharbaf said:
>
>> Hi all,
>>
>> I want to modify an UML Class Diagram by java code, for this purpose
>> first, I load an UML model by below java code, But I don't know how
>> to change elements of "UMLModel" in run method. (for example change
>> name of "Person" class to "Human").
>>
>>
>> package example ;
>>
>> import java.io.File;
>> import java.util.ArrayList;
>> import java.util.Collection;
>>
>> import org.eclipse.emf.common.util.URI;
>> import org.eclipse.emf.ecore.EPackage;
>> 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.epsilon.emc.emf.InMemoryEmfModel;
>> import org.eclipse.uml2.uml.UMLPackage;
>> import org.eclipse.uml2.uml.resource.UMLResource;
>> import org.eclipse.uml2.uml.resources.util.UMLResourcesUtil;
>>
>> public class MinimalExample {
>>
>> public static void main(String[] args) throws Exception {
>> new MinimalExample().run();
>> }
>>
>> public void run() throws Exception {
>> InMemoryEmfModel Model = getUmlModel("UMLModel", new
>> File("src/models/Dev1.uml"));
>>
>> }
>>
>> public InMemoryEmfModel getUmlModel(String name, File file)
>> throws Exception {
>> ResourceSet set = new ResourceSetImpl();
>> UMLResourcesUtil.init(set);
>> set.getPackageRegistry().put(UMLPackage.eNS_URI,
>> UMLPackage.eINSTANCE);
>> set.getResourceFactoryRegistry().getExtensionToFactoryMap().
>> put(UMLResource.FILE_EXTENSION,
>> UMLResource.Factory.INSTANCE);
>> Resource r =
>> set.getResource(URI.createFileURI(file.getAbsolutePath()), true);
>> r.load(null);
>>
>> Collection<EPackage> ePackages = new ArrayList<EPackage>();
>> for (Object ePackage : set.getPackageRegistry().values()) {
>> ePackages.add((EPackage) ePackage);
>> }
>> return new InMemoryEmfModel(name, r, ePackages);
>> }
>> }
>>
>>
>>
>> Can one help me?
>>
>> I used emc and eol epsilon plugin for this project and attached a
>> minimal example to this post.
>>
>> Best regards,
>> Mohammadreza
>> <image>
>
>
Re: How to manipulate UML Class Diagram Elements [message #1733237 is a reply to message #1733148] Wed, 25 May 2016 15:55 Go to previous message
Mohammadreza Sharbaf is currently offline Mohammadreza SharbafFriend
Messages: 17
Registered: February 2016
Junior Member

Hi all,

Thanks for your help, my problem was solved.

Kind regards,
Mohammadreza
Previous Topic:Get the file (.uml) generated
Next Topic:How to use UML2 with Maven
Goto Forum:
  


Current Time: Mon Jul 23 09:44:40 GMT 2018

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

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

Back to the top