|
Re: Method for determining whether a capsule part is plugin [message #1775830 is a reply to message #1775828] |
Mon, 06 November 2017 22:30 |
Ernesto Posse Messages: 438 Registered: March 2011 |
Senior Member |
|
|
Is this for code generation? I don't recommend using that method. That method is from the org.eclipse.papyrusrt.umlrt.core plugin, which is associated with the tooling, and depends on the Papyrus element-types so it cannot be used in stand-alone. Even if you don't care if you bring the full Papyrus in code-generation, a lot of that API is incomplete, as you have noticed.
There are several alternatives, depending on whether you are doing this during code generation or not, and when in code generation you are doing this.
First, in the general case, not just code generation, or pre-code-generation (when you still have access to UML elements), you can use the UML-RT façade from org.eclipse.papyrusrt.umlrt.uml. In particular the UMLRTCapsulePart class. For example, if you already have access to the (UML) property p that represents the part, you can write:
import org.eclipse.papyrusrt.umlrt.uml.UMLRTCapsulePart;
import org.eclipse.papyrusrt.umlrt.uml.UMLRTCapsulePartKind;
...
Property p = ...;
UMLRTCapsulePart part = UMLRTCapsulePart.getInstance( p );
if (part.getKind().equals(UMLRTCapsulePartKind.PLUG_IN)) {
...
}
In this case, p is a UML Property.
If you are doing this later in code generation, for example in a custom Capsule generator, then you are handling XtUML-RT objects instead of UML-RT objects. In that case, a CapsulePart object already has a getKind method so you could write
CapsulePart part = ...;
if (part.getKind().equals(CapsuleKind.PLUGIN)) { ... }
where "CapsuleKind" is the XtUML-RT equivalent of CapsulePartKind.
|
|
|
|
|
|
Re: Method for determining whether a capsule part is plugin [message #1775838 is a reply to message #1775834] |
Mon, 06 November 2017 23:07 |
Ernesto Posse Messages: 438 Registered: March 2011 |
Senior Member |
|
|
Yes, in general, if you are working with UML elements you should be using the façade from org.eclipse.papyrusrt.umlrt.uml, rather than working directly with the UML model elements or other utilities. The façade allows you to see UML objects as UML-RT objects, at the right level of abstraction, (partially) hiding their "UMLness" and implementing UML-RT specific concepts, such as the way inheritance is dealt-with.
Basically you should use all the UMLRT* classes in that package, one for each UML-RT construct.
Of the top of my head I don't remember if the getInstance methods could return null or not. Maybe it returns null if the Property doesn't have the CapsulePart stereotype, but I'm not sure. But the façade code is pretty robust. (Thank Christian for that ;)) In any case, you have access to the sources, so you could check there ;)
|
|
|
|
|
Re: Method for determining whether a capsule part is plugin [message #1775988 is a reply to message #1775982] |
Wed, 08 November 2017 21:42 |
Ernesto Posse Messages: 438 Registered: March 2011 |
Senior Member |
|
|
Well, the façade as a UML-RT façade so it only provides an interface to UML-RT constructs. PassiveClassProperties is a stereotype in the RtCppProperties profile, a profile which is not UML-RT per-se, but an extension intended to be used with C++ only, and therefore the façade doesn't provide any such functionality. However, if your intention is to access properties of passive class (not the stereotype), then you can use the UML API directly, as UML-RT passive classes are just UML classes.
If you do need to access the PassiveClass stereotype properties from a given UML class, you would do something similar to the pseudo-façade provided by org.eclipse.papyrusrt.xtumlrt.external.predefined.UMLRTProfileUtil. For example,
/** Name of the capsule part stereotype. */
private static final String UML_REAL_TIME_CAPSULE_PART = "UMLRealTime::CapsulePart";
/**
* Determine whether el is a capsule part.
*
* @param el
* - An {@link Element}.
* @return True iff el has the {@link CapsulePart} stereotype applied.
*/
public static boolean isCapsulePart(Element el) {
Stereotype s = el.getAppliedStereotype(UML_REAL_TIME_CAPSULE_PART);
return s != null;
}
/**
* Get the CapsulePart stereotype for el.
*
* @param el
* - An {@link Element}.
* @return The {@link CapsulePart} stereotype.
*/
public static CapsulePart getCapsulePart(Element el) {
Stereotype s = el.getAppliedStereotype(UML_REAL_TIME_CAPSULE_PART);
return s == null ? null : (CapsulePart) el.getStereotypeApplication(s);
}
The getCapsulePart method expects a UML Element and returns the CapsulePart stereotype (if it has one, null otherwise) and from the stereotype you can access directly its properties.
You could write something similar for the RtCppProperties profile. There is such a façade for this profile at org.eclipse.papyrusrt.codegen.cpp.profile.facade.RTCppGenerationProperties, but it is for use with XtUML-RT elements, not with UML elements.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04888 seconds