Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Problem Applying Stereotype(works manually, not working programmatically, even when following documentation)
Problem Applying Stereotype [message #497425] Fri, 13 November 2009 05:46 Go to next message
Vikram Sjn is currently offline Vikram SjnFriend
Messages: 39
Registered: July 2009
Member
I am doing my first UML profile.

Following the article 'Introduction to UML2 Profiles', I tried everything manually. It all went fine, and the article was very useful.

Now when doing it programmatically, I am facing a problem when applying stereotype.

When the stereotype is applied, there is no exception, and everything seems to go fine - but on opening the .uml file in model editor, the stereotype is not there.

On close inspection I found that saving the model just before applying the stereotype, and after applying the stereotype, resulted in no difference.

When I use this file (which has everything fine and in place, except the stereotype), and apply stereotype manually, then on saving, the content of .uml file changes, and the entire uml node becomes child of xmi node.

What am I missing? What am I doing incorrect?



.uml file start when stereotype was applied, but did not have any effect...

<?xml version="1.0" encoding="UTF-8"?>
<uml:Model xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML" xmi:id="_w25RsM-UEd6ARaBEQDTKaA" name="WWCUSTS">
  <ownedComment xmi:id="_w25Rsc-UEd6ARaBEQDTKaA">
    <body>WWCUSTS Model Comment</body>
  </ownedComment>
  <packagedElement xmi:type="uml:Package" xmi:id="_w25Rss-UEd6ARaBEQDTKaA" name="Types">
...
...



.uml file start when stereotype was applied manually, and resulted in changed xml structure...

<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML" xmlns:xanalysis="http:///schemas/xanalysis/_xm39IM-UEd6ARaBEQDTKaA/0" xsi:schemaLocation="http:///schemas/xanalysis/_xm39IM-UEd6ARaBEQDTKaA/0 file:/G:/vikram-admin/Documents/Adhoc/xanalysis.profile.uml#_yNeDEs-UEd6ARaBEQDTKaA">
  <uml:Model xmi:id="_w25RsM-UEd6ARaBEQDTKaA" name="WWCUSTS">
    <ownedComment xmi:id="_w25Rsc-UEd6ARaBEQDTKaA">
      <body>WWCUSTS Model Comment</body>
    </ownedComment>
    <packagedElement xmi:type="uml:Package" xmi:id="_w25Rss-UEd6ARaBEQDTKaA" name="Types">
...
...
Re: Problem Applying Stereotype [message #498066 is a reply to message #497425] Sat, 14 November 2009 02:14 Go to previous messageGo to next message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 362
Registered: July 2009
Senior Member
Vikram,

Are you:

1) defining your profile?
2) applying the profile to the package
3) only then aplying the stereotype?

You might want to attach your code/models.

Cheers,

Rafael
http://abstratt.com/blog/

Vikram wrote:
> I am doing my first UML profile.
>
> Following the article 'Introduction to UML2 Profiles', I tried
> everything manually. It all went fine, and the article was very useful.
>
> Now when doing it programmatically, I am facing a problem when applying
> stereotype.
>
> When the stereotype is applied, there is no exception, and everything
> seems to go fine - but on opening the .uml file in model editor, the
> stereotype is not there.
>
> On close inspection I found that saving the model just before applying
> the stereotype, and after applying the stereotype, resulted in no
> difference.
>
> When I use this file (which has everything fine and in place, except the
> stereotype), and apply stereotype manually, then on saving, the content
> of .uml file changes, and the entire uml node becomes child of xmi node.
>
> What am I missing? What am I doing incorrect?
>
>
>
> uml file start when stereotype was applied, but did not have any effect...
>
> <?xml version="1.0" encoding="UTF-8"?>
> <uml:Model xmi:version="2.1"
> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
> xmi:id="_w25RsM-UEd6ARaBEQDTKaA" name="WWCUSTS">
> <ownedComment xmi:id="_w25Rsc-UEd6ARaBEQDTKaA">
> <body>WWCUSTS Model Comment</body>
> </ownedComment>
> <packagedElement xmi:type="uml:Package"
> xmi:id="_w25Rss-UEd6ARaBEQDTKaA" name="Types">
> ..
> ..
>
>
> uml file start when stereotype was applied manually, and resulted in
> changed xml structure...
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xmi:XMI xmi:version="2.1"
> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
> xmlns:xanalysis="http:///schemas/xanalysis/_xm39IM-UEd6ARaBEQDTKaA/0"
> xsi:schemaLocation="http:///schemas/xanalysis/_xm39IM-UEd6ARaBEQDTKaA/0
> file:/G:/vikram-admin/Documents/Adhoc/xanalysis.profile.uml# _yNeDEs-UEd6ARaBEQDTKaA ">
>
> <uml:Model xmi:id="_w25RsM-UEd6ARaBEQDTKaA" name="WWCUSTS">
> <ownedComment xmi:id="_w25Rsc-UEd6ARaBEQDTKaA">
> <body>WWCUSTS Model Comment</body>
> </ownedComment>
> <packagedElement xmi:type="uml:Package"
> xmi:id="_w25Rss-UEd6ARaBEQDTKaA" name="Types">
> ..
> ..
>
Re: Problem Applying Stereotype [message #498069 is a reply to message #498066] Sat, 14 November 2009 04:25 Go to previous messageGo to next message
Vikram Sjn is currently offline Vikram SjnFriend
Messages: 39
Registered: July 2009
Member
Thanks for replying.

Yes the profile is being defined, and the applied to the package, and then the stereotype is applied.

I am unable to attach files to the post (tried upload twice, but page refreshes, but file is not attached).

Will try in another post (may be sharing somewhere else on net)

Regards
Vikram
Re: Problem Applying Stereotype [message #498070 is a reply to message #498066] Sat, 14 November 2009 04:46 Go to previous messageGo to next message
Vikram Sjn is currently offline Vikram SjnFriend
Messages: 39
Registered: July 2009
Member
Since I am unable to attach files to post, I have shared the files here:
http://www.mediafire.com/file/m4nkn2jj2ez/profile-and-model. zip

zip has the saved uml files at various stages, and also the xanalysis profile generated in the process.

IntroductionToUML2Profiles.mainfunc() is called from another class, and the modified package is saved using the following code:

	public static boolean save(org.eclipse.uml2.uml.Package package_, URI uri)
	{
		Resource resource = new ResourceSetImpl().createResource(uri);
		resource.getContents().add(package_);

		try
		{
			resource.save(null);
			out("Done.");
			return true;
		}
		catch (IOException ioe)
		{
			err(ioe.getMessage());
		}

		return false;
	}

[Updated on: Sat, 14 November 2009 05:24]

Report message to a moderator

Re: Problem Applying Stereotype [message #498072 is a reply to message #498070] Sat, 14 November 2009 05:53 Go to previous messageGo to next message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 362
Registered: July 2009
Senior Member
Hi Vikram,

Sorry, that link did not work for me. If you use a nntp client (such as
Thunderbird) you should be able to attach.

Also, if you reduced your example to a very small Java program that
reproduced the issue, you could just paste the source code here (and the
source of your profile as well), inline.

Cheers,

Rafael

Vikram wrote:
> Since I am unable to attach files to post, I have shared the files here:
> http://www.mediafire.com/file/zaenvvmmuxm/profile-and-model. zip
Re: Problem Applying Stereotype [message #498149 is a reply to message #498072] Sun, 15 November 2009 04:01 Go to previous messageGo to next message
Vikram Sjn is currently offline Vikram SjnFriend
Messages: 39
Registered: July 2009
Member
Actually I missed .java file in the zip. So I updated the zip, and then updated link in the post --- that new link will work.

However in the meantime you must have accessed the old link which was then invalid.

Sorry for all the confusion.
Kindly use the link in this post.

I repeat the post again here...

Since I am unable to attach files to post, from Firefox, I have shared the files here:
http://www.mediafire.com/file/m4nkn2jj2ez/profile-and-model.zip

zip has the saved uml files at various stages, and also the profile generated in the process.

IntroductionToUML2Profiles.mainfunc() is called from another class, and the modified package is saved using the following code:


public static boolean save(org.eclipse.uml2.uml.Package package_, URI uri)
{
	Resource resource = new ResourceSetImpl().createResource(uri);
	resource.getContents().add(package_);

	try
	{
		resource.save(null);
		out("Done.");
		return true;
	}
	catch (IOException ioe)
	{
		err(ioe.getMessage());
	}

	return false;
}

Re: Problem Applying Stereotype [message #498158 is a reply to message #498149] Sun, 15 November 2009 08:27 Go to previous messageGo to next message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 362
Registered: July 2009
Senior Member
Vikram,

You are saving the model before applying stereotypes, and that is not
what you want. The example code from the article shows stereotypes have
to be applied first, and then the model can be saved.

As a side note, you will ae morelikely to get help if the code you send
can be executed on its own and has the minimum amount of code required
to reproduce your problem. As a nice side-effect, from my experience,
the exercise of crafting a standalone test case usually leads to one
figuring out the problem on their own.

Cheers,

Rafael
http://abstratt.com/blog/

Vikram wrote:
> Actually I missed .java file in the zip. So I updated the zip, and then
> updated link in the post --- that new link will work.
>
> However in the meantime you must have accessed the old link which was
> then invalid.
>
> Sorry for all the confusion.
> Kindly use the link in this post.
>
> I repeat the post again here...
>
> Since I am unable to attach files to post, from Firefox, I have shared
> the files here:
> http://www.mediafire.com/file/m4nkn2jj2ez/profile-and-model. zip
>
> zip has the saved uml files at various stages, and also the profile
> generated in the process.
>
> IntroductionToUML2Profiles.mainfunc() is called from another class, and
> the modified package is saved using the following code:
>
>
>
> public static boolean save(org.eclipse.uml2.uml.Package package_, URI uri)
> {
> Resource resource = new ResourceSetImpl().createResource(uri);
> resource.getContents().add(package_);
>
> try
> {
> resource.save(null);
> out("Done.");
> return true;
> }
> catch (IOException ioe)
> {
> err(ioe.getMessage());
> }
>
> return false;
> }
>
>
Re: Problem Applying Stereotype [message #498384 is a reply to message #498158] Mon, 16 November 2009 17:09 Go to previous messageGo to next message
Vikram Sjn is currently offline Vikram SjnFriend
Messages: 39
Registered: July 2009
Member
Thanks for advice.

I have arranged the code to be executable. Now this has minimum code to reproduce the problem.

The entire thing has been arranged into a Eclipse plugin project, which will contribute 'Sample Menu', with 'Sample Action'.

Selecting Sample Action will run this code. The files (profile and model files) will be generated in 'user.dir'.

The generated files (profile & model) are also bundled in the zip.

The project is shared here:
http://www.mediafire.com/file/myidynngwmz/UMLStereotypePlugi n1.zip

As I previously stated - everything seems to work fine, except the applyStereotype. Manually the stereotype application is working fine.

Thanks for all the help.
Kindly help resolve.

[Updated on: Tue, 17 November 2009 02:20]

Report message to a moderator

Re: Problem Applying Stereotype [message #498388 is a reply to message #498384] Mon, 16 November 2009 17:20 Go to previous messageGo to next message
Vikram Sjn is currently offline Vikram SjnFriend
Messages: 39
Registered: July 2009
Member
Forgot to mention in previous post...

1. The starter method is SampleAction.run()
2. From there umlstereotypeplugin1.actions.UML2Profile.mainfunc() is called, which does all the work, and has the code which has the problem.
Re: Problem Applying Stereotype [message #498453 is a reply to message #498388] Tue, 17 November 2009 02:51 Go to previous messageGo to next message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 362
Registered: July 2009
Senior Member
Vikram, I think you missed my reply above where I point out the problem
with your code:

"You are saving the model before applying stereotypes, and that is not
what you want. The example code from the article shows stereotypes have
to be applied first, and then the model can be saved."

Got it?

Cheers,

Rafael
http://abstratt.com/blog/

Vikram wrote:
> Forgot to mention in previous post...
>
> 1. The starter method is SampleAction.run()
> 2. From there umlstereotypeplugin1.actions.UML2Profile.mainfunc() is
> called, which does all the work, and has the code which has the problem.
Re: Problem Applying Stereotype [message #498463 is a reply to message #498453] Tue, 17 November 2009 05:07 Go to previous messageGo to next message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 362
Registered: July 2009
Senior Member
Ok, I see now that in the new code you fixed that problem. The new
problem is that even though profile applications are serialized, the
stereotype application is not.

The thing is that if you apply a stereotype to an element that is in a
resource, the stereotype application is automatically added to the
resource. But if you apply a stereotype to an element that is not part
of a resource, the application is not added anywhere - it is your
responsibility to add it to a resource.

You can address this issue in your code by moving these lines:

String modelPath = folder + "XMODEL-classdiagram";
URI modelURI = URI.createURI("file:///")
.appendSegment(modelPath)
.appendFileExtension(UMLResource.FILE_EXTENSION);
Resource resource = new ResourceSetImpl().createResource(modelURI);
resource.getContents().add(model);

to right after you create the model so the model will be part of the
resource, and so will the class when you apply the stereotype.

You should also get rid of these lines:

Resource resource = new ResourceSetImpl().createResource(uri);
resource.getContents().add(model);
resource.save(null);

as they don't do you any good - this just saves an empty model.

HTH,

Rafael
http://absratt.com/blog/


Rafael Chaves wrote:
> Vikram, I think you missed my reply above where I point out the problem
> with your code:
>
> "You are saving the model before applying stereotypes, and that is not
> what you want. The example code from the article shows stereotypes have
> to be applied first, and then the model can be saved."
>
> Got it?
>
> Cheers,
>
> Rafael
> http://abstratt.com/blog/
>
> Vikram wrote:
>> Forgot to mention in previous post...
>>
>> 1. The starter method is SampleAction.run()
>> 2. From there umlstereotypeplugin1.actions.UML2Profile.mainfunc() is
>> called, which does all the work, and has the code which has the problem.
Re: Problem Applying Stereotype [message #498525 is a reply to message #498463] Tue, 17 November 2009 10:48 Go to previous messageGo to next message
Vikram Sjn is currently offline Vikram SjnFriend
Messages: 39
Registered: July 2009
Member
Actually this saving code is at two locations - first after creating the class, and later after applying stereotype.

Commenting the one after applying stereotype got it working.
Thanks for helping resolve.

However this code was exactly same to the one above, and in both case was adding the model to resource - so why did the one after apply stereotype was not working?

Could you kindly give some hint, or point to some article.

[Updated on: Tue, 17 November 2009 10:50]

Report message to a moderator

Re: Problem Applying Stereotype [message #498591 is a reply to message #498525] Tue, 17 November 2009 15:41 Go to previous messageGo to next message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 362
Registered: July 2009
Senior Member
Vikram wrote:
> Actually this saving code is at two locations - first after creating the
> class, and later after applying stereotype.

Yes, that is why I suggested you got rid of the first save which had no
use.

>
> Commenting the one after applying stereotype got it working.

Sorry, that doesn't make sense - if you don't save after applying a
stereotype, how can the stereotype application possibly be saved?

> However this code was exactly same to the one above, and in both case
> was adding the model to resource - so why did the one after apply
> stereotype was not working?

The one you submitted before had other problem - please see my response
in a previous post.

Rafael
Re: Problem Applying Stereotype [message #498983 is a reply to message #498591] Thu, 19 November 2009 12:41 Go to previous messageGo to next message
Vikram Sjn is currently offline Vikram SjnFriend
Messages: 39
Registered: July 2009
Member
Sorry I made a mistake in the previous post.

I stated 'Commenting the one, after applying stereotype got it working.'
whereas what I actually did was that I commented most of the 2nd saving code, except the save statement.


I have copied below, to show what I actually did:
(... indicates code at that location, that is removed to give a concise veiw)


...

org.eclipse.uml2.uml.Class class_ = model.createOwnedClass("Purchases", false);
Comment classComment = class_.createOwnedComment();
classComment.setBody("CUSTS");

Property prop = class_.createOwnedAttribute("customer_id", type);
prop.setVisibility(VisibilityKind.PRIVATE_LITERAL);

//------------------------------------------------------------------
String filePath = folder + "XMODEL-classdiagram";

URI uri = URI.createURI("file:///").appendSegment(filePath).appendFileExtension(UMLResource.FILE_EXTENSION);

Resource resource = new ResourceSetImpl().createResource(uri);
resource.getContents().add(model);
//resource.save(null);
//==================================================================

// Register Resource Factory
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);

...
...

// Apply Stereotype
class_.applyStereotype(stereotype);

// Setting stereotype property values
class_.setValue(stereotype, attribute.getName(), "prop-name");

//------------------------------------------------------------------
// Save Model
//String modelPath = folder + "XMODEL-classdiagram";
//URI modelURI = URI.createURI("file:///").appendSegment(modelPath).appendFileExtension(UMLResource.FILE_EXTENSION);

//resource = new ResourceSetImpl().createResource(modelURI);
//resource.getContents().add(model);
resource.save(null);
//==================================================================


However, if I commented the entire 1st saving code block, and uncommented the 2nd saving block - the file was saved without strereotype applied, and was starting with

<?xml version="1.0" encoding="UTF-8"?>
<uml:Model xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML" xmi:id="_w25RsM-UEd6ARaBEQDTKaA" name="WWCUSTS">


What is the reason for this? - that even when model/resource is saved after applying the stereotype, still the stereotype application is not saved?
Re: Problem Applying Stereotype [message #499142 is a reply to message #498983] Fri, 20 November 2009 05:10 Go to previous messageGo to next message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 362
Registered: July 2009
Senior Member
Vikram, I wrote the explanation before in this thread, you must have
missed it:

"The thing is that if you apply a stereotype to an element that is in a
resource, the stereotype application is automatically added to the
resource. But if you apply a stereotype to an element that is not part
of a resource, the application is not added anywhere - it is your
responsibility to add it to a resource. "

Rafael
http://abstratt.com/blog/

Vikram wrote:
> Sorry I made a mistake in the previous post.
>
> I stated 'Commenting the one, after applying stereotype got it working.'
> whereas what I actually did was that I commented most of the 2nd saving
> code, except the save statement.
>
>
> I have copied below, to show what I actually did:
> (... indicates code at that location, that is removed to give a concise
> veiw)
>
>
>
> ..
>
> org.eclipse.uml2.uml.Class class_ = model.createOwnedClass("Purchases",
> false);
> Comment classComment = class_.createOwnedComment();
> classComment.setBody("CUSTS");
>
> Property prop = class_.createOwnedAttribute("customer_id", type);
> prop.setVisibility(VisibilityKind.PRIVATE_LITERAL);
>
> //---------------------------------------------------------- --------
> String filePath = folder + "XMODEL-classdiagram";
>
> URI uri =
> URI.createURI("file:///" ).appendSegment(filePath).appendFileExtension(UMLResource.FI LE_EXTENSION);
>
>
> Resource resource = new ResourceSetImpl().createResource(uri);
> resource.getContents().add(model);
> //resource.save(null);
> //========================================================== ========
>
> // Register Resource Factory
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
>
> ..
> ..
>
> // Apply Stereotype
> class_.applyStereotype(stereotype);
>
> // Setting stereotype property values
> class_.setValue(stereotype, attribute.getName(), "prop-name");
>
> //---------------------------------------------------------- --------
> // Save Model
> //String modelPath = folder + "XMODEL-classdiagram";
> //URI modelURI =
> URI.createURI("file:///" ).appendSegment(modelPath).appendFileExtension(UMLResource.F ILE_EXTENSION);
>
>
> //resource = new ResourceSetImpl().createResource(modelURI);
> //resource.getContents().add(model);
> resource.save(null);
> //========================================================== ========
>
>
> However, if I commented the entire 1st saving code block, and
> uncommented the 2nd saving block - the file was saved without
> strereotype applied, and was starting with
>
> <?xml version="1.0" encoding="UTF-8"?>
> <uml:Model xmi:version="2.1"
> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
> xmi:id="_w25RsM-UEd6ARaBEQDTKaA" name="WWCUSTS">
>
>
> What is the reason for this? - that even when model/resource is saved
> after applying the stereotype, still the stereotype application is not
> saved?
Re: Problem Applying Stereotype [message #499143 is a reply to message #499142] Fri, 20 November 2009 05:52 Go to previous messageGo to next message
Vikram Sjn is currently offline Vikram SjnFriend
Messages: 39
Registered: July 2009
Member
Thanks Rafael and Eclipse forum for all the help.

Best wishes
Vikram
Re: Problem Applying Stereotype [message #628058 is a reply to message #498066] Sat, 14 November 2009 04:25 Go to previous messageGo to next message
Vikram Sjn is currently offline Vikram SjnFriend
Messages: 39
Registered: July 2009
Member
Thanks for replying.

Yes the profile is being defined, and the applied to the package, and then the stereotype is applied.

I am unable to attach files to the post (tried upload twice, but page refreshes, but file is not attached).

Will try in another post (may be sharing somewhere else on net)

Regards
Vikram
Re: Problem Applying Stereotype [message #628059 is a reply to message #498066] Sat, 14 November 2009 04:46 Go to previous messageGo to next message
Vikram Sjn is currently offline Vikram SjnFriend
Messages: 39
Registered: July 2009
Member
Since I am unable to attach files to post, I have shared the files here:
http://www.mediafire.com/file/zaenvvmmuxm/profile-and-model. zip
Re: Problem Applying Stereotype [message #628060 is a reply to message #628059] Sat, 14 November 2009 05:53 Go to previous messageGo to next message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 362
Registered: July 2009
Senior Member
Hi Vikram,

Sorry, that link did not work for me. If you use a nntp client (such as
Thunderbird) you should be able to attach.

Also, if you reduced your example to a very small Java program that
reproduced the issue, you could just paste the source code here (and the
source of your profile as well), inline.

Cheers,

Rafael

Vikram wrote:
> Since I am unable to attach files to post, I have shared the files here:
> http://www.mediafire.com/file/zaenvvmmuxm/profile-and-model. zip
Re: Problem Applying Stereotype [message #628061 is a reply to message #498072] Sun, 15 November 2009 04:01 Go to previous messageGo to next message
Vikram Sjn is currently offline Vikram SjnFriend
Messages: 39
Registered: July 2009
Member
Actually I missed .java file in the zip. So I updated the zip, and then updated link in the post --- that new link will work.

However in the meantime you must have accessed the old link which was then invalid.

Sorry for all the confusion.
Kindly use the link in this post.

I repeat the post again here...

Since I am unable to attach files to post, from Firefox, I have shared the files here:
http://www.mediafire.com/file/m4nkn2jj2ez/profile-and-model. zip

zip has the saved uml files at various stages, and also the profile generated in the process.

IntroductionToUML2Profiles.mainfunc() is called from another class, and the modified package is saved using the following code:



public static boolean save(org.eclipse.uml2.uml.Package package_, URI uri)
{
Resource resource = new ResourceSetImpl().createResource(uri);
resource.getContents().add(package_);

try
{
resource.save(null);
out("Done.");
return true;
}
catch (IOException ioe)
{
err(ioe.getMessage());
}

return false;
}
Re: Problem Applying Stereotype [message #628062 is a reply to message #628061] Sun, 15 November 2009 08:27 Go to previous messageGo to next message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 362
Registered: July 2009
Senior Member
Vikram,

You are saving the model before applying stereotypes, and that is not
what you want. The example code from the article shows stereotypes have
to be applied first, and then the model can be saved.

As a side note, you will ae morelikely to get help if the code you send
can be executed on its own and has the minimum amount of code required
to reproduce your problem. As a nice side-effect, from my experience,
the exercise of crafting a standalone test case usually leads to one
figuring out the problem on their own.

Cheers,

Rafael
http://abstratt.com/blog/

Vikram wrote:
> Actually I missed .java file in the zip. So I updated the zip, and then
> updated link in the post --- that new link will work.
>
> However in the meantime you must have accessed the old link which was
> then invalid.
>
> Sorry for all the confusion.
> Kindly use the link in this post.
>
> I repeat the post again here...
>
> Since I am unable to attach files to post, from Firefox, I have shared
> the files here:
> http://www.mediafire.com/file/m4nkn2jj2ez/profile-and-model. zip
>
> zip has the saved uml files at various stages, and also the profile
> generated in the process.
>
> IntroductionToUML2Profiles.mainfunc() is called from another class, and
> the modified package is saved using the following code:
>
>
>
> public static boolean save(org.eclipse.uml2.uml.Package package_, URI uri)
> {
> Resource resource = new ResourceSetImpl().createResource(uri);
> resource.getContents().add(package_);
>
> try
> {
> resource.save(null);
> out("Done.");
> return true;
> }
> catch (IOException ioe)
> {
> err(ioe.getMessage());
> }
>
> return false;
> }
>
>
Re: Problem Applying Stereotype [message #628066 is a reply to message #498158] Mon, 16 November 2009 17:09 Go to previous messageGo to next message
Vikram Sjn is currently offline Vikram SjnFriend
Messages: 39
Registered: July 2009
Member
Thanks for advice.

I have arranged the code to be executable. Now this has minimum code to reproduce the problem.

The entire thing has been arranged into a Eclipse plugin, which will contribute 'Sample Menu', with 'Sample Action'.

Selecting Sample Action will run this code. The files (profile and model files) will be generated in 'user.dir'.

The generated files (profile & model) are also bundled in the zip.

The project is shared here:
http://www.mediafire.com/file/myidynngwmz/UMLStereotypePlugi n1.zip

As I previously stated - everything seems to work fine, except the applyStereotype. Manually the stereotype application is working fine.

Thanks for all the help.
Kindly help resolve.
Re: Problem Applying Stereotype [message #628067 is a reply to message #628066] Mon, 16 November 2009 17:20 Go to previous messageGo to next message
Vikram Sjn is currently offline Vikram SjnFriend
Messages: 39
Registered: July 2009
Member
Forgot to mention in previous post...

1. The starter method is SampleAction.run()
2. From there umlstereotypeplugin1.actions.UML2Profile.mainfunc() is called, which does all the work, and has the code which has the problem.
Re: Problem Applying Stereotype [message #628068 is a reply to message #498388] Tue, 17 November 2009 02:51 Go to previous messageGo to next message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 362
Registered: July 2009
Senior Member
Vikram, I think you missed my reply above where I point out the problem
with your code:

"You are saving the model before applying stereotypes, and that is not
what you want. The example code from the article shows stereotypes have
to be applied first, and then the model can be saved."

Got it?

Cheers,

Rafael
http://abstratt.com/blog/

Vikram wrote:
> Forgot to mention in previous post...
>
> 1. The starter method is SampleAction.run()
> 2. From there umlstereotypeplugin1.actions.UML2Profile.mainfunc() is
> called, which does all the work, and has the code which has the problem.
Re: Problem Applying Stereotype [message #628069 is a reply to message #498453] Tue, 17 November 2009 05:07 Go to previous messageGo to next message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 362
Registered: July 2009
Senior Member
Ok, I see now that in the new code you fixed that problem. The new
problem is that even though profile applications are serialized, the
stereotype application is not.

The thing is that if you apply a stereotype to an element that is in a
resource, the stereotype application is automatically added to the
resource. But if you apply a stereotype to an element that is not part
of a resource, the application is not added anywhere - it is your
responsibility to add it to a resource.

You can address this issue in your code by moving these lines:

String modelPath = folder + "XMODEL-classdiagram";
URI modelURI = URI.createURI("file:///")
.appendSegment(modelPath)
.appendFileExtension(UMLResource.FILE_EXTENSION);
Resource resource = new ResourceSetImpl().createResource(modelURI);
resource.getContents().add(model);

to right after you create the model so the model will be part of the
resource, and so will the class when you apply the stereotype.

You should also get rid of these lines:

Resource resource = new ResourceSetImpl().createResource(uri);
resource.getContents().add(model);
resource.save(null);

as they don't do you any good - this just saves an empty model.

HTH,

Rafael
http://absratt.com/blog/


Rafael Chaves wrote:
> Vikram, I think you missed my reply above where I point out the problem
> with your code:
>
> "You are saving the model before applying stereotypes, and that is not
> what you want. The example code from the article shows stereotypes have
> to be applied first, and then the model can be saved."
>
> Got it?
>
> Cheers,
>
> Rafael
> http://abstratt.com/blog/
>
> Vikram wrote:
>> Forgot to mention in previous post...
>>
>> 1. The starter method is SampleAction.run()
>> 2. From there umlstereotypeplugin1.actions.UML2Profile.mainfunc() is
>> called, which does all the work, and has the code which has the problem.
Re: Problem Applying Stereotype [message #628071 is a reply to message #498463] Tue, 17 November 2009 10:48 Go to previous messageGo to next message
Vikram Sjn is currently offline Vikram SjnFriend
Messages: 39
Registered: July 2009
Member
Actually this saving code is at two locations - first after creating the class, and later after applying stereotype.

Commenting the one after applying stereotype got it working.

However this code was exactly same to the one above, and in both case was adding the model to resource - so why did the one after apply stereotype was not working?

Could you kindly give some hint, or point to some article.
Re: Problem Applying Stereotype [message #628072 is a reply to message #498525] Tue, 17 November 2009 15:41 Go to previous messageGo to next message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 362
Registered: July 2009
Senior Member
Vikram wrote:
> Actually this saving code is at two locations - first after creating the
> class, and later after applying stereotype.

Yes, that is why I suggested you got rid of the first save which had no
use.

>
> Commenting the one after applying stereotype got it working.

Sorry, that doesn't make sense - if you don't save after applying a
stereotype, how can the stereotype application possibly be saved?

> However this code was exactly same to the one above, and in both case
> was adding the model to resource - so why did the one after apply
> stereotype was not working?

The one you submitted before had other problem - please see my response
in a previous post.

Rafael
Re: Problem Applying Stereotype [message #628077 is a reply to message #498591] Thu, 19 November 2009 12:41 Go to previous messageGo to next message
Vikram Sjn is currently offline Vikram SjnFriend
Messages: 39
Registered: July 2009
Member
Sorry I made a mistake in the previous post.

I stated 'Commenting the one, after applying stereotype got it working.'
whereas what I actually did was that I commented most of the 2nd saving code, except the save statement.


I have copied below, to show what I actually did:
(... indicates code at that location, that is removed to give a concise veiw)



...

org.eclipse.uml2.uml.Class class_ = model.createOwnedClass("Purchases", false);
Comment classComment = class_.createOwnedComment();
classComment.setBody("CUSTS");

Property prop = class_.createOwnedAttribute("customer_id", type);
prop.setVisibility(VisibilityKind.PRIVATE_LITERAL);

//---------------------------------------------------------- --------
String filePath = folder + "XMODEL-classdiagram";

URI uri = URI.createURI("file:///" ).appendSegment(filePath).appendFileExtension(UMLResource.FI LE_EXTENSION);

Resource resource = new ResourceSetImpl().createResource(uri);
resource.getContents().add(model);
//resource.save(null);
//========================================================== ========

// Register Resource Factory
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);

...
...

// Apply Stereotype
class_.applyStereotype(stereotype);

// Setting stereotype property values
class_.setValue(stereotype, attribute.getName(), "prop-name");

//---------------------------------------------------------- --------
// Save Model
//String modelPath = folder + "XMODEL-classdiagram";
//URI modelURI = URI.createURI("file:///" ).appendSegment(modelPath).appendFileExtension(UMLResource.F ILE_EXTENSION);

//resource = new ResourceSetImpl().createResource(modelURI);
//resource.getContents().add(model);
resource.save(null);
//========================================================== ========


However, if I commented the entire 1st saving code block, and uncommented the 2nd saving block - the file was saved without strereotype applied, and was starting with


<?xml version="1.0" encoding="UTF-8"?>
<uml:Model xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML" xmi:id="_w25RsM-UEd6ARaBEQDTKaA" name="WWCUSTS">


What is the reason for this? - that even when model/resource is saved after applying the stereotype, still the stereotype application is not saved?
Re: Problem Applying Stereotype [message #628079 is a reply to message #628077] Fri, 20 November 2009 05:10 Go to previous messageGo to next message
Rafael Chaves is currently offline Rafael ChavesFriend
Messages: 362
Registered: July 2009
Senior Member
Vikram, I wrote the explanation before in this thread, you must have
missed it:

"The thing is that if you apply a stereotype to an element that is in a
resource, the stereotype application is automatically added to the
resource. But if you apply a stereotype to an element that is not part
of a resource, the application is not added anywhere - it is your
responsibility to add it to a resource. "

Rafael
http://abstratt.com/blog/

Vikram wrote:
> Sorry I made a mistake in the previous post.
>
> I stated 'Commenting the one, after applying stereotype got it working.'
> whereas what I actually did was that I commented most of the 2nd saving
> code, except the save statement.
>
>
> I have copied below, to show what I actually did:
> (... indicates code at that location, that is removed to give a concise
> veiw)
>
>
>
> ..
>
> org.eclipse.uml2.uml.Class class_ = model.createOwnedClass("Purchases",
> false);
> Comment classComment = class_.createOwnedComment();
> classComment.setBody("CUSTS");
>
> Property prop = class_.createOwnedAttribute("customer_id", type);
> prop.setVisibility(VisibilityKind.PRIVATE_LITERAL);
>
> //---------------------------------------------------------- --------
> String filePath = folder + "XMODEL-classdiagram";
>
> URI uri =
> URI.createURI("file:///" ).appendSegment(filePath).appendFileExtension(UMLResource.FI LE_EXTENSION);
>
>
> Resource resource = new ResourceSetImpl().createResource(uri);
> resource.getContents().add(model);
> //resource.save(null);
> //========================================================== ========
>
> // Register Resource Factory
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
>
> ..
> ..
>
> // Apply Stereotype
> class_.applyStereotype(stereotype);
>
> // Setting stereotype property values
> class_.setValue(stereotype, attribute.getName(), "prop-name");
>
> //---------------------------------------------------------- --------
> // Save Model
> //String modelPath = folder + "XMODEL-classdiagram";
> //URI modelURI =
> URI.createURI("file:///" ).appendSegment(modelPath).appendFileExtension(UMLResource.F ILE_EXTENSION);
>
>
> //resource = new ResourceSetImpl().createResource(modelURI);
> //resource.getContents().add(model);
> resource.save(null);
> //========================================================== ========
>
>
> However, if I commented the entire 1st saving code block, and
> uncommented the 2nd saving block - the file was saved without
> strereotype applied, and was starting with
>
> <?xml version="1.0" encoding="UTF-8"?>
> <uml:Model xmi:version="2.1"
> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
> xmi:id="_w25RsM-UEd6ARaBEQDTKaA" name="WWCUSTS">
>
>
> What is the reason for this? - that even when model/resource is saved
> after applying the stereotype, still the stereotype application is not
> saved?
Re: Problem Applying Stereotype [message #628080 is a reply to message #499142] Fri, 20 November 2009 05:52 Go to previous message
Vikram Sjn is currently offline Vikram SjnFriend
Messages: 39
Registered: July 2009
Member
Thanks Rafael and Eclipse forum for all the help.

Best wishes
Vikram
Previous Topic:need clarification about "package import"
Next Topic:need clarification about "package import"
Goto Forum:
  


Current Time: Fri Apr 19 03:47:01 GMT 2024

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

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

Back to the top