Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Papyrus for Real Time » Method for determining whether a capsule part is plugin
Method for determining whether a capsule part is plugin [message #1775828] Mon, 06 November 2017 21:52 Go to next message
Nicolas Hili is currently offline Nicolas HiliFriend
Messages: 40
Registered: March 2017
Member
Hi,

There is a method to determine whether a capsule part is an optional capsule. It is defined in RTPropertyUtils.

public static boolean isOptional(Property property) {
	return isZero(property.getLowerValue());
}


Would a similar method exist for determining that a capsule part is a plugin capsule?

Nicolas
Re: Method for determining whether a capsule part is plugin [message #1775830 is a reply to message #1775828] Mon, 06 November 2017 22:30 Go to previous messageGo to next message
Ernesto Posse is currently offline Ernesto PosseFriend
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 #1775834 is a reply to message #1775830] Mon, 06 November 2017 22:43 Go to previous messageGo to next message
Nicolas Hili is currently offline Nicolas HiliFriend
Messages: 40
Registered: March 2017
Member
[edit]: sorry for the duplicate message. some bug occurred on the Eclipse forum.

[Updated on: Mon, 06 November 2017 22:45]

Report message to a moderator

Re: Method for determining whether a capsule part is plugin [message #1775835 is a reply to message #1775830] Mon, 06 November 2017 22:44 Go to previous messageGo to next message
Nicolas Hili is currently offline Nicolas HiliFriend
Messages: 40
Registered: March 2017
Member
[edit]: sorry for the duplicate message. some bug occurred on the Eclipse forum.

[Updated on: Mon, 06 November 2017 22:46]

Report message to a moderator

Re: Method for determining whether a capsule part is plugin [message #1775836 is a reply to message #1775830] Mon, 06 November 2017 22:44 Go to previous messageGo to next message
Nicolas Hili is currently offline Nicolas HiliFriend
Messages: 40
Registered: March 2017
Member
Thanks Ernesto for your reply :)

I am in the first case. I have not noticed that we can retrieve the capsule part from the UML property. That simplifies a lot.

I suppose then that I should also avoid to use:
CapsulePartUtils.isCapsulePart( p );
for checking that a property is a capsule part, is not it? Instead, I should just check whether
UMLRTCapsulePart.getInstance( p );
returns a capsule part or null, right?

Nicolas
Re: Method for determining whether a capsule part is plugin [message #1775838 is a reply to message #1775834] Mon, 06 November 2017 23:07 Go to previous messageGo to next message
Ernesto Posse is currently offline Ernesto PosseFriend
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 #1775898 is a reply to message #1775838] Tue, 07 November 2017 21:29 Go to previous messageGo to next message
Nicolas Hili is currently offline Nicolas HiliFriend
Messages: 40
Registered: March 2017
Member
Hello Ernesto,

I have tried and yes, I can use getInstance to heck whether a UML property is a capsule part or not (it is is not, null is returned). Very helpful :)

Thanks,

Nicolas
Re: Method for determining whether a capsule part is plugin [message #1775982 is a reply to message #1775898] Wed, 08 November 2017 20:31 Go to previous messageGo to next message
Nicolas Hili is currently offline Nicolas HiliFriend
Messages: 40
Registered: March 2017
Member
I've had the time to look inside the org.eclipse.papyrusrt.umlrt.uml plugin, and the façade code seems really robust :)

One question though. I could not find any façade for the UMLRTPassiveClassProperties. Is that intended like this? How can I find whether a class in my element is a PassiveClass?

Nicolas
Re: Method for determining whether a capsule part is plugin [message #1775988 is a reply to message #1775982] Wed, 08 November 2017 21:42 Go to previous messageGo to next message
Ernesto Posse is currently offline Ernesto PosseFriend
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.




Re: Method for determining whether a capsule part is plugin [message #1775990 is a reply to message #1775988] Wed, 08 November 2017 22:44 Go to previous messageGo to next message
Nicolas Hili is currently offline Nicolas HiliFriend
Messages: 40
Registered: March 2017
Member
Hello Ernesto and thanks for your reply,

I realize my question was silly. Actually, I do not want to get all elements that are annotated with the PassiveClassProperties . As you mentioned, it is C++ specific. What I was actually looking for was a way for getting all passive classes in the system, that is, all classes that are not annotated with the Capsule stereotype. I guess in that context, it is better for me to get all classes and check whether a class is a capsule (using UMLRTCapsule.getInstance()) is not it?

Nicolas
Re: Method for determining whether a capsule part is plugin [message #1776044 is a reply to message #1775990] Thu, 09 November 2017 17:39 Go to previous message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 438
Registered: March 2011
Senior Member
Yes, you could get all classes and check whether they are a capsule with the façade method, or you could do something equivalent, by using the UMLRTProfileUtil like this:

import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Model;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.eclipse.papyrusrt.xtumlrt.external.predefined.UMLRTProfileUtil;

public class PassiveClassUtils {

	static boolean isPassiveClass(Element el) {
		return el instanceof Class && !UMLRTProfileUtil.isCapsule(el);
	}
	
	static List<Class> getAllPassiveClasses(Model model) {
		return model.allOwnedElements()
				.stream()
				.filter(element -> isPassiveClass(element))
				.collect(Collectors.toCollection(ArrayList<Class>::new));
	}
}


The UMLRTProfileUtil is a light-weight façade, and doesn't pose the problems of the other *Utils classes like RTPropertyUtils that you found.
Previous Topic:Understanding the behaviour of the code generator
Next Topic:recall timeouts?
Goto Forum:
  


Current Time: Thu Dec 12 01:48:03 GMT 2024

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

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

Back to the top