Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Obtaining a value of a property defined in a profile
Obtaining a value of a property defined in a profile [message #1018006] Wed, 13 March 2013 00:11 Go to next message
Missing name Mising name is currently offline Missing name Mising name
Messages: 1
Registered: August 2010
Junior Member
Hi, I'm new to eclipse UML2 and get stuck in the following problem.

I defined a profile with two stereotypes: ServiceRequest and TransitionEdge. ServiceRequest extends the Action metaclass with two additional properties (cpu, memory), and TransitionEdge extends the ActivityEdge metaclass with the additional property called "probability". All these properties are of type float defined as a PrimitiveType.

The I created an activity diagram that have the profile and stereotypes applied. In the activity diagram, each edge is a TransitionEdge defined in the profile, and a value has been assigned to the probability property.

Having the profile and the activity model, I use the following Java code to load them.

// Load the profile
URI profileUri = URI.createURI(PROFILE_NAME);
ResourceSet profileSet = new ResourceSetImpl();
profileSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
profileSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
profileSet.createResource(profileUri);
Resource profileResource = profileSet.getResource(profileUri, true);
Profile profile = (Profile)EcoreUtil.getObjectByType(profileResource.getContents(), UMLPackage.Literals.PROFILE);
Profile sopraProfile = (Profile)profile.getOwnedMember(PROFILE_NAME);
Stereotype serviceRequestStereotype = (Stereotype)sopraProfile.getOwnedMember(STEREOTYPE_SERVICE_REQUEST); 
Stereotype transitionEdgeStereotype = (Stereotype)sopraProfile.getOwnedMember(STEREOTYPE_TRANSITION_EDGE); 
		
// Load the model
URI modelUri = URI.createURI(MODEL_NAME);
ResourceSet modelSet = new ResourceSetImpl();
modelSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
modelSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
modelSet.createResource(modelUri);
Resource modelResource = modelSet.getResource(modelUri, true);
Model model = (Model)EcoreUtil.getObjectByType(modelResource.getContents(), UMLPackage.Literals.MODEL);

EList<Element> elements = model.getOwnedElements();
for(Element e : elements){
     if(e instanceof Activity){
	Activity activity = (Activity)e;
	EList<ActivityEdge> edges = activity.getEdges();
	for(ActivityEdge edge : edges){
		System.out.println(edge.getValue(transitionEdgeStereotype, "probability"));
	}
     }
}


An exception is thrown when the getValue method is called upon an element.
The following is the error message:

org.eclipse.uml2.uml.internal.impl.PropertyImpl@7a6d6a3f (name: base_ActivityEdge, visibility: <unset>) (isLeaf: false) (isStatic: false) (isOrdered: false, isUnique: true, isReadOnly: false) (aggregation: none, isDerived: false, isDerivedUnion: false, isID: false)

org.eclipse.uml2.uml.internal.impl.PropertyImpl@255a8ce4 (name: probability, visibility: public) (isLeaf: false) (isStatic: false) (isOrdered: false, isUnique: true, isReadOnly: false) (aggregation: none, isDerived: false, isDerivedUnion: false, isID: false)

Exception in thread "main" java.lang.IllegalArgumentException: org.eclipse.uml2.uml.internal.impl.StereotypeImpl@442f4161 (name: TransitionEdge, visibility: <unset>) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isActive: false)
	at org.eclipse.uml2.uml.internal.operations.ElementOperations.getValue(ElementOperations.java:527)
	at org.eclipse.uml2.uml.internal.impl.ElementImpl.getValue(ElementImpl.java:296)
	at test.Test.main(Test.java:68)


I couldn't figure out what was going on. Any suggestions? Thanks a lot!!
Re: Obtaining a value of a property defined in a profile [message #1018236 is a reply to message #1018006] Wed, 13 March 2013 13:13 Go to previous message
Christian W. Damus is currently offline Christian W. Damus
Messages: 789
Registered: July 2009
Senior Member
Hi,

If you want to use your own data types in a profile for stereotype
attributes, you have to tell EMF how to load and save values of those
data types. UML stereotypes are converted to Ecore EClasses (from EMF)
for persistence in your model.

If you want a floating-point value, the easiest approach is to use the
Real primitive type in the standard UML Primitive Types library.
Otherwise, you could use the EFloat or EDouble primitive type from the
Ecore Primitive Types library.

If you define your own data types in a profile, I think they will have to

* be stereotyped as <<eDataType>> (from the Ecore profile)
* have the instanceClassName stereotype attribute set to the
name of a Java type that is convertible to and from Strings
(the basic primitive types and wrappers are supported by
default, I think)

If you generate your profile as a static EPackage (rather than rely on
the dynamic profile definitions), then you can implement the data type
string conversion methods in the factory class for even more
flexibility.

HTH,

Christian

On 2013-03-13 12:43:56 +0000, Missing name Mising name said:

> Hi, I'm new to eclipse UML2 and get stuck in the following problem.
>
> I defined a profile with two stereotypes: ServiceRequest and
> TransitionEdge. ServiceRequest extends the Action metaclass with two
> additional properties (cpu, memory), and TransitionEdge extends the
> ActivityEdge metaclass with the additional property called
> "probability". All these properties are of type float defined as a
> PrimitiveType.
> The I created an activity diagram that have the profile and stereotypes
> applied. In the activity diagram, each edge is a TransitionEdge defined
> in the profile, and a value has been assigned to the probability
> property.
> Having the profile and the activity model, I use the following Java
> code to load them.
>
>
> // Load the profile
> URI profileUri = URI.createURI(PROFILE_NAME);
> ResourceSet profileSet = new ResourceSetImpl();
> profileSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
> profileSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
> profileSet.createResource(profileUri);
> Resource profileResource = profileSet.getResource(profileUri, true);
> Profile profile =
> (Profile)EcoreUtil.getObjectByType(profileResource.getContents(),
> UMLPackage.Literals.PROFILE);
> Profile sopraProfile = (Profile)profile.getOwnedMember(PROFILE_NAME);
> Stereotype serviceRequestStereotype =
> (Stereotype)sopraProfile.getOwnedMember(STEREOTYPE_SERVICE_REQUEST);
> Stereotype transitionEdgeStereotype =
> (Stereotype)sopraProfile.getOwnedMember(STEREOTYPE_TRANSITION_EDGE);
> // Load the model
> URI modelUri = URI.createURI(MODEL_NAME);
> ResourceSet modelSet = new ResourceSetImpl();
> modelSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
> modelSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION,
> UMLResource.Factory.INSTANCE);
> modelSet.createResource(modelUri);
> Resource modelResource = modelSet.getResource(modelUri, true);
> Model model =
> (Model)EcoreUtil.getObjectByType(modelResource.getContents(),
> UMLPackage.Literals.MODEL);
>
> EList<Element> elements = model.getOwnedElements();
> for(Element e : elements){
> if(e instanceof Activity){
> Activity activity = (Activity)e;
> EList<ActivityEdge> edges = activity.getEdges();
> for(ActivityEdge edge : edges){
> System.out.println(edge.getValue(transitionEdgeStereotype, "probability"));
> }
> }
> }
>
> An exception is thrown when the getValue method is called upon an
> element. The following is the error message:
>
>
> org.eclipse.uml2.uml.internal.impl.PropertyImpl@7a6d6a3f (name:
> base_ActivityEdge, visibility: <unset>) (isLeaf: false) (isStatic:
> false) (isOrdered: false, isUnique: true, isReadOnly: false)
> (aggregation: none, isDerived: false, isDerivedUnion: false, isID:
> false)
>
> org.eclipse.uml2.uml.internal.impl.PropertyImpl@255a8ce4 (name:
> probability, visibility: public) (isLeaf: false) (isStatic: false)
> (isOrdered: false, isUnique: true, isReadOnly: false) (aggregation:
> none, isDerived: false, isDerivedUnion: false, isID: false)
>
> Exception in thread "main" java.lang.IllegalArgumentException:
> org.eclipse.uml2.uml.internal.impl.StereotypeImpl@442f4161 (name:
> TransitionEdge, visibility: <unset>) (isLeaf: false, isAbstract: false,
> isFinalSpecialization: false) (isActive: false)
> at
> org.eclipse.uml2.uml.internal.operations.ElementOperations.getValue(ElementOperations.java:527)
>
> at
> org.eclipse.uml2.uml.internal.impl.ElementImpl.getValue(ElementImpl.java:296)
>
> at test.Test.main(Test.java:68)
>
>
> I couldn't figure out what was going on. Any suggestions? Thanks a lot!!
Previous Topic:Create Papyrus Project From UML file Using Java
Next Topic:[uml2ecore] UML2EcoreConvertor::ProcessInvariantConstraint
Goto Forum:
  


Current Time: Mon Sep 22 04:18:11 GMT 2014

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

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