Home » Modeling » UML2 » programmatically create RSA Comments
|
Re: programmatically create RSA Comments [message #477549 is a reply to message #477548] |
Mon, 23 June 2008 20:57 |
Dave Carlson 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 |
Jinhui 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 |
Dave Carlson 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 |
Jinhui 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();
}
|
|
|
Goto Forum:
Current Time: Thu Apr 25 17:39:26 GMT 2024
Powered by FUDForum. Page generated in 0.03297 seconds
|