Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » programmatically create RSA Comments
programmatically create RSA Comments [message #477548] Mon, 23 June 2008 17:30 Go to next message
Jinhui is currently offline JinhuiFriend
Messages: 42
Registered: July 2009
Member
Hi everyone,

I am having some difficulties with RSA7 comments/documentations:

I programmatically created a new Model with the Eclipse-UML2 API, and now
I want to programmatically create the "Documentation information" (which
will be displayed in the "Documentation Tab of the Properties View") for
some model element.

but the problem is:
the newly created Comments must be stereotyped with
"Default:Documentation" from RSA, in order to be displayed in the
"Documentation Tab".
and I don't know how to achieve all this programmatically.


I saw in this thread
( http://dev.eclipse.org/newslists/news.eclipse.modeling.mdt.u ml2/msg02351.html)
the same problem.

Can anyone show me some ideas?

Thanks.
Jinhui
Re: programmatically create RSA Comments [message #477549 is a reply to message #477548] Mon, 23 June 2008 20:57 Go to previous messageGo to next message
Dave Carlson is currently offline Dave CarlsonFriend
Messages: 402
Registered: July 2009
Senior Member
Jinhui,

Sorry, I saw this question a few weeks ago and intended to reply, but forgot
to post a response.

This snippet works for me:

public static final String RSM_DOCUMENTATION_STEREOTYPE_QNAME =
"Default::Documentation";

Stereotype rsaDocStereotype =
comment.getApplicableStereotype(RSM_DOCUMENTATION_STEREOTYPE _QNAME);
if (rsaDocStereotype != null &&
!comment.isStereotypeApplied(rsaDocStereotype)) {
UMLUtil.safeApplyStereotype(comment, rsaDocStereotype);
}

Depending on how your code is set up, you may need to load the profile
before you can get the stereotype, use the profile URI:

public static final String RSM_DEFAULT_PROFILE_URI =
"pathmap://UML2_MSL_PROFILES/Default.epx";


"Jinhui" <zhuj@in.tum.de> wrote in message
news:a06def84ac24eb40a8beb14e8534e7ab$1@www.eclipse.org...
> Hi everyone,
> I am having some difficulties with RSA7 comments/documentations:
> I programmatically created a new Model with the Eclipse-UML2 API, and now
> I want to programmatically create the "Documentation information" (which
> will be displayed in the "Documentation Tab of the Properties View") for
> some model element.
>
> but the problem is: the newly created Comments must be stereotyped with
> "Default:Documentation" from RSA, in order to be displayed in the
> "Documentation Tab". and I don't know how to achieve all this
> programmatically.
>
>
> I saw in this thread
> ( http://dev.eclipse.org/newslists/news.eclipse.modeling.mdt.u ml2/msg02351.html)
> the same problem.
>
> Can anyone show me some ideas?
>
> Thanks.
> Jinhui
>
>
>
Re: programmatically create RSA Comments [message #477551 is a reply to message #477549] Tue, 24 June 2008 08:49 Go to previous message
Jinhui is currently offline JinhuiFriend
Messages: 42
Registered: July 2009
Member
Thanks, Dave.

I know I should apply that stereotype.
have you created the model in a standalone application?
if yes, can you show me how to load the profile and how to persist the
newly created model?

I used the following snippet to load the profile, apply the stereotype and
persist the model, but what I get is only a "ProfileApplication" in the
model, but not Stereotype-information.

thanks.




1) load profile:
ResourceSet resSet = new ResourceSetImpl();
resSet.getPackageRegistry().put(UMLPackage.eNS_URI,
UMLPackage.eINSTANCE);
resSet.getResourceFactoryRegistry().getExtensionToFactoryMap ().put(UMLResource.FILE_EXTENSION,
UMLResource.Factory.INSTANCE);
Map uriMap = resSet.getURIConverter().getURIMap();
// for UML resource
URI uriUML =
URI.createURI(" jar:file:/D:/Programme/IBM/SDP70Shared/plugins/org.eclipse.u ml2.uml.resources_2.0.3.v200707041607.jar!/ ");
uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
uriUML.appendSegment("libraries").appendSegment(""));
uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
uriUML.appendSegment("metamodels").appendSegment(""));
uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
uriUML.appendSegment("profiles").appendSegment(""));
resSet.getResourceFactoryRegistry().getExtensionToFactoryMap ().put( "epx",
UMLResource.Factory.INSTANCE);
resSet.getResourceFactoryRegistry().getExtensionToFactoryMap ().put(UMLResource.FILE_EXTENSION,
UMLResource.Factory.INSTANCE);
resSet.getResourceFactoryRegistry().getExtensionToFactoryMap ().put(UMLResource.METAMODELS_PATHMAP,
UMLResource.Factory.INSTANCE);
// the Defautl-Profile
URI uri =
URI.createURI(" jar:file:/D:/Programme/IBM/SDP70Shared/plugins/com.ibm.xtool s.uml.msl_7.0.120.v20070802_1920.jar!/profiles/Default.epx ");
Resource resource = resSet.getResource(uri, true);
return (Profile)resource.getContents().get(0);


2) apply stereotype:
Profile p = getRsaDefaultProfile(); // ref to 1)
m.applyProfile(p);
UseCase uc = UMLFactory.eINSTANCE.createUseCase();

uc.setName(nodes.item(i).getAttributes().getNamedItem("name ").getNodeValue());
useCasePkg.getPackagedElements().add(uc);
Comment c = uc.createOwnedComment();
Stereotype st = p.getOwnedStereotype("Documentation");
// I did get the stereotype here.
c.setBody(...);
c.getAnnotatedElements().add(uc);
UMLUtil.safeApplyStereotype(c, st);


3) persisting the model
logger.info("psersisting model...");
String fileExtension="emx";

ResourceSetImpl rsImpl = new ResourceSetImpl();
rsImpl.getResourceFactoryRegistry().getExtensionToFactoryMap ().put(
fileExtension, UMLResource.Factory.INSTANCE);

final URI fileURI = URI.createFileURI(this.rsaModelPath + fileName + "."
+ fileExtension);
Resource r = rsImpl.createResource(fileURI);
r.getContents().add(m);
try {
r.save(null);
} catch (IOException e) {
e.printStackTrace();
}
Re: programmatically create RSA Comments [message #626739 is a reply to message #477548] Mon, 23 June 2008 20:57 Go to previous message
Dave Carlson is currently offline Dave CarlsonFriend
Messages: 402
Registered: July 2009
Senior Member
Jinhui,

Sorry, I saw this question a few weeks ago and intended to reply, but forgot
to post a response.

This snippet works for me:

public static final String RSM_DOCUMENTATION_STEREOTYPE_QNAME =
"Default::Documentation";

Stereotype rsaDocStereotype =
comment.getApplicableStereotype(RSM_DOCUMENTATION_STEREOTYPE _QNAME);
if (rsaDocStereotype != null &&
!comment.isStereotypeApplied(rsaDocStereotype)) {
UMLUtil.safeApplyStereotype(comment, rsaDocStereotype);
}

Depending on how your code is set up, you may need to load the profile
before you can get the stereotype, use the profile URI:

public static final String RSM_DEFAULT_PROFILE_URI =
"pathmap://UML2_MSL_PROFILES/Default.epx";


"Jinhui" <zhuj@in.tum.de> wrote in message
news:a06def84ac24eb40a8beb14e8534e7ab$1@www.eclipse.org...
> Hi everyone,
> I am having some difficulties with RSA7 comments/documentations:
> I programmatically created a new Model with the Eclipse-UML2 API, and now
> I want to programmatically create the "Documentation information" (which
> will be displayed in the "Documentation Tab of the Properties View") for
> some model element.
>
> but the problem is: the newly created Comments must be stereotyped with
> "Default:Documentation" from RSA, in order to be displayed in the
> "Documentation Tab". and I don't know how to achieve all this
> programmatically.
>
>
> I saw in this thread
> ( http://dev.eclipse.org/newslists/news.eclipse.modeling.mdt.u ml2/msg02351.html)
> the same problem.
>
> Can anyone show me some ideas?
>
> Thanks.
> Jinhui
>
>
>
Re: programmatically create RSA Comments [message #626741 is a reply to message #477549] Tue, 24 June 2008 08:49 Go to previous message
Jinhui is currently offline JinhuiFriend
Messages: 42
Registered: July 2009
Member
Thanks, Dave.

I know I should apply that stereotype.
have you created the model in a standalone application?
if yes, can you show me how to load the profile and how to persist the
newly created model?

I used the following snippet to load the profile, apply the stereotype and
persist the model, but what I get is only a "ProfileApplication" in the
model, but not Stereotype-information.

thanks.




1) load profile:
ResourceSet resSet = new ResourceSetImpl();
resSet.getPackageRegistry().put(UMLPackage.eNS_URI,
UMLPackage.eINSTANCE);
resSet.getResourceFactoryRegistry().getExtensionToFactoryMap ().put(UMLResource.FILE_EXTENSION,
UMLResource.Factory.INSTANCE);
Map uriMap = resSet.getURIConverter().getURIMap();
// for UML resource
URI uriUML =
URI.createURI(" jar:file:/D:/Programme/IBM/SDP70Shared/plugins/org.eclipse.u ml2.uml.resources_2.0.3.v200707041607.jar!/ ");
uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP),
uriUML.appendSegment("libraries").appendSegment(""));
uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP),
uriUML.appendSegment("metamodels").appendSegment(""));
uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP),
uriUML.appendSegment("profiles").appendSegment(""));
resSet.getResourceFactoryRegistry().getExtensionToFactoryMap ().put( "epx",
UMLResource.Factory.INSTANCE);
resSet.getResourceFactoryRegistry().getExtensionToFactoryMap ().put(UMLResource.FILE_EXTENSION,
UMLResource.Factory.INSTANCE);
resSet.getResourceFactoryRegistry().getExtensionToFactoryMap ().put(UMLResource.METAMODELS_PATHMAP,
UMLResource.Factory.INSTANCE);
// the Defautl-Profile
URI uri =
URI.createURI(" jar:file:/D:/Programme/IBM/SDP70Shared/plugins/com.ibm.xtool s.uml.msl_7.0.120.v20070802_1920.jar!/profiles/Default.epx ");
Resource resource = resSet.getResource(uri, true);
return (Profile)resource.getContents().get(0);


2) apply stereotype:
Profile p = getRsaDefaultProfile(); // ref to 1)
m.applyProfile(p);
UseCase uc = UMLFactory.eINSTANCE.createUseCase();

uc.setName(nodes.item(i).getAttributes().getNamedItem("name ").getNodeValue());
useCasePkg.getPackagedElements().add(uc);
Comment c = uc.createOwnedComment();
Stereotype st = p.getOwnedStereotype("Documentation");
// I did get the stereotype here.
c.setBody(...);
c.getAnnotatedElements().add(uc);
UMLUtil.safeApplyStereotype(c, st);


3) persisting the model
logger.info("psersisting model...");
String fileExtension="emx";

ResourceSetImpl rsImpl = new ResourceSetImpl();
rsImpl.getResourceFactoryRegistry().getExtensionToFactoryMap ().put(
fileExtension, UMLResource.Factory.INSTANCE);

final URI fileURI = URI.createFileURI(this.rsaModelPath + fileName + "."
+ fileExtension);
Resource r = rsImpl.createResource(fileURI);
r.getContents().add(m);
try {
r.save(null);
} catch (IOException e) {
e.printStackTrace();
}
Previous Topic:programmatically create RSA Comments
Next Topic:Use a UML model with a profile
Goto Forum:
  


Current Time: Tue Apr 16 11:07:11 GMT 2024

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

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

Back to the top