Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Getting Enumeration literals, DataType on Property
Getting Enumeration literals, DataType on Property [message #627052] Mon, 20 October 2008 14:20
Eric is currently offline EricFriend
Messages: 77
Registered: July 2009
Member
This is a multi-part message in MIME format.

------=_NextPart_000_0023_01C9329D.6F2352D0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hello,
What is the best way to get enumeration literals while using UML2 =
models?
a) For enumeration literals, the actual literal value, seems to be an =
"ownedElement" of type "LiteralValue" under the EnumerationLiteral =
object.=20
This is what I'm doing:

Iterator iRes =3D res.getAllContents();
while (iRes.hasNext())
{
EObject obj =3D (EObject) iRes.next();
if (obj instanceof org.eclipse.uml2.uml.Enumeration)
{ =20
org.eclipse.uml2.uml.Enumeration enumeration =3D =
(org.eclipse.uml2.uml.Enumeration) obj;
System.out.println (">>>Enumeration: " + =
enumeration.getQualifiedName());
Iterator<org.eclipse.uml2.uml.EnumerationLiteral> iLiterals =3D =
enumeration.getOwnedLiterals().iterator();

while (iLiterals.hasNext())
{
org.eclipse.uml2.uml.EnumerationLiteral literal =3D =
iLiterals.next();
System.out.println (" " + literal.getName());
Iterator<org.eclipse.uml2.uml.Element> iValue =3D =
literal.getOwnedElements().iterator();
while (iValue.hasNext())
{
org.eclipse.uml2.uml.Element elem =3D iValue.next();
if (elem instanceof org.eclipse.uml2.uml.LiteralString)
{
System.out.println (" Value: " + =
((org.eclipse.uml2.uml.LiteralString)elem).getValue());
}
}
}
}

It seems I am only picking up any "OwnedElement" which is of the type =
LiteralString (for example, should I only ever expect 1 owned element of =
this type?). Is this the best way of getting at the value of the =
literal?

b) In the same token, I can go through a resource, picking out all the =
Classes, and for each get their attributes (through the getAttributes() =
call, which gets an Elist of "Property"s) At this point, however, the =
getDataType() method on Property, always returns null. Why is that? How =
can i get their datatypes?

Thank you for your help.
------=_NextPart_000_0023_01C9329D.6F2352D0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.6000.16674" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>Hello,</DIV>
<DIV><FONT face=3DVerdana size=3D2>What is the best way to get =
enumeration literals=20
while using UML2 models?</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2>a) For enumeration literals, the =
actual literal=20
value, seems to be an</FONT><FONT face=3D"Tms Rmn"> </FONT><FONT =
face=3DVerdana=20
size=3D2>"ownedElement" of type</FONT><FONT face=3D"Tms Rmn"> =
</FONT><FONT=20
face=3DVerdana size=3D2>"LiteralValue"</FONT><FONT face=3D"Tms Rmn"> =
</FONT><FONT=20
face=3DVerdana size=3D2>under</FONT><FONT face=3D"Tms Rmn"> </FONT><FONT =
face=3DVerdana=20
size=3D2>the EnumerationLiteral object.</FONT><FONT face=3D"Tms Rmn"> =
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>This is what I'm doing:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D1>Iterator iRes =3D =
res.getAllContents();<BR>while=20
(iRes.hasNext())</FONT></DIV>
<DIV><FONT face=3DArial size=3D1>{</FONT></DIV>
<DIV><FONT face=3DArial size=3D1>&nbsp;&nbsp;&nbsp; EObject obj =3D =
(EObject)=20
iRes.next();</FONT></DIV>
<DIV><FONT face=3DArial size=3D1>&nbsp;&nbsp;&nbsp; if (obj instanceof=20
org.eclipse.uml2.uml.Enumeration)</FONT></DIV>
<DIV><FONT face=3DArial size=3D1>&nbsp;&nbsp;&nbsp; {&nbsp; =
</FONT></DIV>
<DIV><FONT face=3DArial size=3D1>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
org.eclipse.uml2.uml.Enumeration enumeration =3D=20
(org.eclipse.uml2.uml.Enumeration) obj;</FONT></DIV>
<DIV><FONT face=3DArial size=3D1>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
System.out.println ("&gt;&gt;&gt;Enumeration: " +=20
enumeration.getQualifiedName());</FONT><FONT face=3DArial><BR><FONT=20
size=3D1>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
Iterator&lt;org.eclipse.uml2.uml.EnumerationLiteral& gt; iLiterals =3D=20
enumeration.getOwnedLiterals().iterator();</FONT></DIV>
<DIV><FONT size=3D1></FONT>&nbsp;</DIV>
<DIV><FONT size=3D1>&nbsp;&nbsp;&nbsp; while =
(iLiterals.hasNext())</FONT></DIV>
<DIV><FONT size=3D1>&nbsp;&nbsp;&nbsp; {</FONT></DIV>
<DIV><FONT size=3D1>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
org.eclipse.uml2.uml.EnumerationLiteral literal =3D =
iLiterals.next();</FONT></DIV>
<DIV><FONT size=3D1>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
System.out.println (" "=20
+ literal.getName());</FONT></DIV>
<DIV><FONT size=3D1>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
Iterator&lt;org.eclipse.uml2.uml.Element&gt; iValue =3D=20
literal.getOwnedElements().iterator();</FONT></DIV>
<DIV><FONT size=3D1>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; while=20
(iValue.hasNext())</FONT></DIV>
<DIV><FONT size=3D1>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</FONT></DIV>
<DIV><FONT size=3D1>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; org.eclipse.uml2.uml.Element elem =3D=20
iValue.next();</FONT></DIV>
<DIV><FONT size=3D1>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; if (elem instanceof=20
org.eclipse.uml2.uml.LiteralString)</FONT></DIV>
<DIV><FONT size=3D1>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; {</FONT></DIV>
<DIV><FONT size=3D1>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println (" Value: " +=20
((org.eclipse.uml2.uml.LiteralString)elem).getValue());</FONT ></DIV>
<DIV><FONT size=3D1>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; }</FONT></DIV>
<DIV><FONT size=3D1>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</FONT></DIV>
<DIV><FONT size=3D1>&nbsp;&nbsp;&nbsp; }<BR>}</FONT></DIV>
<DIV><FONT size=3D1></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>It seems I am only picking up =
any</FONT><FONT=20
face=3D"Tms Rmn"> </FONT><FONT face=3DVerdana size=3D2>"OwnedElement" =
which is of the=20
type LiteralString (for example, should I only ever expect 1 owned =
element of=20
this type?).</FONT><FONT face=3D"Tms Rmn"> </FONT><FONT face=3DVerdana =
size=3D2>Is=20
this the best way of getting at the</FONT><FONT face=3D"Tms Rmn"> =
</FONT><FONT=20
face=3DVerdana size=3D2>value of the literal</FONT><FONT face=3DVerdana=20
size=3D2>?</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>b) In the same token, <FONT =
face=3DVerdana size=3D2>I=20
can go through a resource, picking out all the</FONT><FONT face=3D"Tms =
Rmn"=20
size=3D3> </FONT><FONT face=3DVerdana size=3D2>Classes, and for each get =
their=20
attributes (through the</FONT><FONT face=3D"Tms Rmn" size=3D3> =
</FONT><FONT=20
face=3DVerdana size=3D2>getAttributes() call, which gets an Elist =
of</FONT><FONT=20
face=3D"Tms Rmn" size=3D3> </FONT><FONT face=3DVerdana =
size=3D2>"Property"s) At this=20
point, however,</FONT><FONT face=3D"Tms Rmn" size=3D3> </FONT><FONT =
face=3DVerdana=20
size=3D2>the getDataType() method on Property, always returns =
null.</FONT><FONT=20
face=3D"Tms Rmn" size=3D3> <FONT face=3DVerdana size=3D2>Why is that? =
How can i get=20
their datatypes?</FONT></FONT></FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT><FONT face=3DVerdana=20
size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thank you for your help.</FONT><FONT=20
face=3DHelv></DIV></FONT></BODY></HTML>

------=_NextPart_000_0023_01C9329D.6F2352D0--
Previous Topic:Main intention of PackageMerge
Next Topic:Getting Enumeration literals, DataType on Property
Goto Forum:
  


Current Time: Fri Apr 03 09:16:27 GMT 2020

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

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

Back to the top