|
Re: EAttribute to Java datatype [message #1273089 is a reply to message #1273063] |
Wed, 19 March 2014 13:30 |
|
Hi,
The Java type of the attribute is just getEType().getInstanceClass().
Asking for the class of that gives you java.lang.Class, which is the
class of every run-time class.
HTH,
Christian
On 2014-03-19 12:34:05 +0000, Sudharshan Ravi said:
> Hi
>
> If i have an EAttribute that got converted from xsd:boolean for example
> what is the easiest way to determine the corresponding Java type of
> this attribute without using a long list of switch case ?
>
> I tried EAttribute.getEType().getInstanceClass().getClass() To find out
> the type but this returns a generic Class<? extends type> not the
> actual "type"
|
|
|
|
|
Re: EAttribute to Java datatype [message #1273115 is a reply to message #1273111] |
Wed, 19 March 2014 14:38 |
|
Hi,
Yes, that's why you need the getEType().getInstanceClass() only. I was
explaining why asking further for the getClass() was giving you the
wrong result.
For your particular attribute, this returns boolean.class, not
Boolean.class, probably because the attribute's type is
EcorePackage.Literals.EBOOLEAN (which represents Java's boolean), not
EcorePackage.Literals.EBOOLEAN_OBJECT (which represents Java's
java.lang.Boolean).
Cheers,
Christian
On 2014-03-19 14:30:43 +0000, Sudharshan Ravi said:
> Hi
>
> Quote:
>> Hi,
>>
>> The Java type of the attribute is just getEType().getInstanceClass().
>> Asking for the class of that gives you java.lang.Class, which is the
>> class of every run-time class.
>>
>> HTH,
>>
>> Christian
>
>
> But we want the specific Java class which was used for the mapping, not
> the class of every run-time class.
>
> Quote:
>> To get the java type, you could use
>> EAttribute.getEAttributeType().getInstanceClass().
>>
>> ex: to test if the attribute type is a boolean
>>
>> EAttribute.getEAttributeType().getInstanceClass().equals(Boolean.class)
>>
>>
>> If the datatype is predefined in ecore (like EString, EBoolean, ....),
>> then you can use the EcorePackage.Literals ex :
>> getEAttributeType().equals(EcorePackage.Literals.EBoolean)
>
>
> This is the output of the type of the attribute
>
> System.out.println("attr.getEAttributeType().getInstanceClass() : " +
> attr.getEAttributeType().getInstanceClass());
> System.out.println("attr.getEType().getInstanceClass() : " +
> attr.getEType().getInstanceClass());
>
>
> attr.getEAttributeType().getInstanceClass() : boolean
> attr.getEType().getInstanceClass() : boolean
>
>
>
> System.out.println("attr.getEAttributeType().getInstanceClass().equals(Boolean.class)
> : " +
> attr.getEAttributeType().getInstanceClass().equals(Boolean.class));
>
> attr.getEAttributeType().getInstanceClass().equals(Boolean.class) : false
|
|
|
|
|
Re: EAttribute to Java datatype [message #1273140 is a reply to message #1273130] |
Wed, 19 March 2014 15:26 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Hessein,
It could also be XMLTypePackage.Literals.BOOLEAN (and will be if the
model is derived from an XSD) so one should be careful about the purpose
of the test, which isn't clear. Of course == can be used for testing
EObjects equality...
On 19/03/2014 8:07 AM, Hussein MHANNA wrote:
> I think with this
> getEAttributeType().equals(EcorePackage.Literals.EBoolean), it will
> work in your case (EBoolean is the equivalent of the boolean java
> primitive type and EBOOLEAN_OBJECT is the equivalent of the Boolean
> object java.lang.Boolean).
>
> Hussein
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03307 seconds