EDataType creation [message #636770] |
Tue, 02 November 2010 13:45  |
Eclipse User |
|
|
|
Hi Guys,
I have a strange problem. Probably, this was already solved in some previous thread (i checked through most of the forum discussion on this issue).
I do the following in my code.
EcoreFactory theCoreFactory = EcoreFactory.eINSTANCE;
theCoreFactory.setEPackage(EcorePackage.eINSTANCE);
EAttribute tempEAttribute = theCoreFactory.createEAttribute();
EDataType tempEDataType = theCoreFactory.createEDataType();
tempEAttribute.setName(strAttributeName);
tempEDataType.setName("String");
/*The method returns me a Class object*/
Class<?> temp = getMetaGMEElementFieldType(ProjectTypeImpl.class, strAttributeName);
tempEDataType.setInstanceClass(temp);
tempEDataType.setInstanceTypeName("java.lang.String");
tempEDataType.setInstanceClassName("java.lang.String");
tempEDataType.setSerializable(true);
tempEAttribute.setDefaultValue(tempNode.getNodeValue());
Now the setDefaultValue() method throws me a NullPointerException.
I researched a bit, and found that it is the following piece of code
EFactory factory = eType.getEPackage().getEFactoryInstance();
in the setDefaultValue() (defined in EStructuralFeatureImpl class) that throws the exception.
I inspected the eType (EClassifier object) and found that the ePackage=NULL.
How can I solve this problem?
Regards
Arun
|
|
|
Re: EDataType creation [message #636827 is a reply to message #636770] |
Tue, 02 November 2010 21:33   |
Eclipse User |
|
|
|
Arun,
Comments below.
Arun wrote:
> Hi Guys,
>
> I have a strange problem. Probably, this was already solved in some
> previous thread (i checked through most of the forum discussion on
> this issue).
>
> I do the following in my code.
>
>
>
> EcoreFactory theCoreFactory = EcoreFactory.eINSTANCE;
> theCoreFactory.setEPackage(EcorePackage.eINSTANCE);
Why would you do such a thing?
>
> EAttribute tempEAttribute = theCoreFactory.createEAttribute();
> EDataType tempEDataType = theCoreFactory.createEDataType();
>
> tempEAttribute.setName(strAttributeName);
>
> tempEDataType.setName("String");
>
> /*The method returns me a Class object*/
> Class<?> temp = getMetaGMEElementFieldType(ProjectTypeImpl.class,
> strAttributeName);
Mystery method that returns an Class....
> tempEDataType.setInstanceClass(temp);
> tempEDataType.setInstanceTypeName("java.lang.String");
Setting the instance class petty much determines the instance type name,
doesn't it?
> tempEDataType.setInstanceClassName("java.lang.String");
Given that there are no type arguments, is there any point in setting both?
> tempEDataType.setSerializable(true);
This is already the default.
>
> tempEAttribute.setDefaultValue(tempNode.getNodeValue());
What might tempNode be? Is it really the default value, or is it a literal?
>
>
>
> Now the setDefaultValue() method throws me a NullPointerException.
You know how to use the debugger, right?
>
> I researched a bit, and found that it is the following piece of code
>
> EFactory factory = eType.getEPackage().getEFactoryInstance();
>
> in the setDefaultValue() (defined in EStructuralFeatureImpl class)
> that throws the exception.
An EDataType that's not in an EPackage is not in a meaningful/complete
context where you should expect to be able to use it. Similarly an
EAttribute that's not in an EClass in an EPackage is also kind of a free
floating bit of meaninglessness.
>
> I inspected the eType (EClassifier object) and found that the
> ePackage=NULL.
Yep, that's what I'd expect.
>
> How can I solve this problem?
What exactly are you trying to accomplish? A complete Ecore model will
definitely require everything to be rooted in an EPackage....
>
> Regards
> Arun
|
|
|
Re: EDataType creation [message #636931 is a reply to message #636827] |
Wed, 03 November 2010 08:09  |
Eclipse User |
|
|
|
Hi Ed,
Thanks for the reply. I found the answer in your reply
Quote: |
An EDataType that's not in an EPackage is not in a meaningful / complete context where you should expect to be able to use it. Similarly an EAttribute that's not in an EClass in an EPackage is also kind of a free floating bit of meaninglessness.
|
I just added the eDataType to a package and it works perfectly.
Thanks again
Regards
Arun
|
|
|
Powered by
FUDForum. Page generated in 0.04092 seconds