|
Re: EDataType creation [message #636827 is a reply to message #636770] |
Wed, 03 November 2010 01:33 |
Ed Merks Messages: 33136 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
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Powered by
FUDForum. Page generated in 0.02303 seconds