Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EDataType creation
EDataType creation [message #636770] Tue, 02 November 2010 17:45 Go to next message
Arun  is currently offline Arun Friend
Messages: 16
Registered: October 2010
Junior Member
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] Wed, 03 November 2010 01:33 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30550
Registered: July 2009
Senior Member
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 12:09 Go to previous message
Arun  is currently offline Arun Friend
Messages: 16
Registered: October 2010
Junior Member
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
Previous Topic:[Teneo] PersistenceOptions.MAXIMUM_SQL_NAME_LENGTH and @Table or @Column
Next Topic:Reload-refresh resource supporting opened editor
Goto Forum:
  


Current Time: Wed Oct 16 21:36:51 GMT 2019

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

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

Back to the top