Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Problems in creating code generated from EMF Model created from XSD
Problems in creating code generated from EMF Model created from XSD [message #384542] Fri, 30 April 2004 15:38 Go to next message
Vijay is currently offline VijayFriend
Messages: 14
Registered: July 2009
Junior Member
Hi All,

I have an XSD that describes my model. I have defined the following
element in it:

<xs:element name = "weight" type = "xs:unsignedByte">
<xs:annotation>
<xs:documentation>
The relative weighting the rule should be given
</xs:documentation>
</xs:annotation>
</xs:element>

I used XML Schema Infoset model to generate the EMF model from my schema.

I then used the ecore model to create the genmodel file and then generate
my class files. I have the following problems:

The following getter and setter for weight was generated:

/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public short getWeight() {
return
(short)getMixed().get(RbmlPackage.eINSTANCE.getDocumentRoot_ Weight(),
true);
}

/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setWeight(short newWeight) {
((FeatureMap.Internal)getMixed()).set(RbmlPackage.eINSTANCE. getDocumentRoot_Weight(),
newWeight);
}

However both these methods give the following compile errors:

getWeight: cannot case from object to short
setWeight: The method set(EStructuralFeature, int, Object) in the type
FeatureMap.Internal is not applicable for the arguments (EAttribute, short)

I am not sure why some code with compilation errors would be generated.
How am I to fix this problem

Another thing I observed is that these methods are present in the class
DocumentRootImpl. I dont have any such element called DocumentRoot in my
schema file. I am totally clueless why such a class was generated.

It will be really helpful if somebody could throw some light into why
these problems occur.

Thanks a lot,
Vijay
Re: Problems in creating code generated from EMF Model created from XSD [message #384543 is a reply to message #384542] Fri, 30 April 2004 16:15 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
--------------B015E74D4D0B24BE4485D433
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Vijay,

I remember fixing that a quite while back; the problem was the handling of primitives. The latest driver
generates this:

/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public short getX()
{
return ((Short)getMixed().get(TestPackage.eINSTANCE.getDocumentRoot _X(),
true)).shortValue();
}

/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setX(short newX)
{
((FeatureMap.Internal)getMixed()).set(TestPackage.eINSTANCE. getDocumentRoot_X(), new
Short(newX));
}


The DocumentRoot EClass is generated with one feature for each global element and attribute
declaration. The document root instance acts as the one root object in a Resource, and it is used to
control/record the QName for that root to make it correspond to a global element declaration's QName.
Complex/simple types always map to EClass/EDataType and element/attribute declarations always map to
EStructuralFeatures....


Vijay wrote:

> Hi All,
>
> I have an XSD that describes my model. I have defined the following
> element in it:
>
> <xs:element name = "weight" type = "xs:unsignedByte">
> <xs:annotation>
> <xs:documentation>
> The relative weighting the rule should be given
> </xs:documentation>
> </xs:annotation>
> </xs:element>
>
> I used XML Schema Infoset model to generate the EMF model from my schema.
>
> I then used the ecore model to create the genmodel file and then generate
> my class files. I have the following problems:
>
> The following getter and setter for weight was generated:
>
> /**
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> public short getWeight() {
> return
> (short)getMixed().get(RbmlPackage.eINSTANCE.getDocumentRoot_ Weight(),
> true);
> }
>
> /**
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> public void setWeight(short newWeight) {
> ((FeatureMap.Internal)getMixed()).set(RbmlPackage.eINSTANCE. getDocumentRoot_Weight(),
> newWeight);
> }
>
> However both these methods give the following compile errors:
>
> getWeight: cannot case from object to short
> setWeight: The method set(EStructuralFeature, int, Object) in the type
> FeatureMap.Internal is not applicable for the arguments (EAttribute, short)
>
> I am not sure why some code with compilation errors would be generated.
> How am I to fix this problem
>
> Another thing I observed is that these methods are present in the class
> DocumentRootImpl. I dont have any such element called DocumentRoot in my
> schema file. I am totally clueless why such a class was generated.
>
> It will be really helpful if somebody could throw some light into why
> these problems occur.
>
> Thanks a lot,
> Vijay

--------------B015E74D4D0B24BE4485D433
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Vijay,
<p>I remember fixing that a quite while back; the problem was the handling
of primitives. The latest driver generates this:
<blockquote>&nbsp; /**
<br>&nbsp;&nbsp; * &lt;!-- begin-user-doc -->
<br>&nbsp;&nbsp; * &lt;!-- end-user-doc -->
<br>&nbsp;&nbsp; * @generated
<br>&nbsp;&nbsp; */
<br>&nbsp; public short getX()
<br>&nbsp; {
<br>&nbsp;&nbsp;&nbsp; return ((Short)getMixed().get(TestPackage.eINSTANCE.getDocumentRoot _X(),
true)).shortValue();
<br>&nbsp; }
<p>&nbsp; /**
<br>&nbsp;&nbsp; * &lt;!-- begin-user-doc -->
<br>&nbsp;&nbsp; * &lt;!-- end-user-doc -->
<br>&nbsp;&nbsp; * @generated
<br>&nbsp;&nbsp; */
<br>&nbsp; public void setX(short newX)
<br>&nbsp; {
<br>&nbsp;&nbsp;&nbsp; ((FeatureMap.Internal)getMixed()).set(TestPackage.eINSTANCE. getDocumentRoot_X(),
new Short(newX));
<br>&nbsp; }
<br>&nbsp;</blockquote>
The DocumentRoot EClass is generated with one feature for each&nbsp; global
element and attribute declaration.&nbsp; The document root instance acts
as the one root object in a Resource, and it is used to control/record
the QName for that root to make it correspond to a global element declaration's
QName.&nbsp; Complex/simple types always map to EClass/EDataType and element/attribute
declarations always map to EStructuralFeatures....
<br>&nbsp;
<p>Vijay wrote:
<blockquote TYPE=CITE>Hi All,
<p>I have an XSD that describes my model. I have defined the following
<br>element in it:
<p>&lt;xs:element name = "weight" type = "xs:unsignedByte">
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;xs:annotation>
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&lt;xs:documentation>
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
The relative weighting the rule should be given
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&lt;/xs:documentation>
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &lt;/xs:annotation>
<br>&lt;/xs:element>
<p>I used XML Schema Infoset model to generate the EMF model from my schema.
<p>I then used the ecore model to create the genmodel file and then generate
<br>my class files. I have the following problems:
<p>The following getter and setter for weight was generated:
<p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; /**
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; * &lt;!-- begin-user-doc
-->
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; * &lt;!-- end-user-doc
-->
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; * @generated
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; */
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; public short getWeight()
{
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
return
<br> (short)getMixed().get(RbmlPackage.eINSTANCE.getDocumentRoot_ Weight(),
<br>true);
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; }
<p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; /**
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; * &lt;!-- begin-user-doc
-->
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; * &lt;!-- end-user-doc
-->
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; * @generated
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; */
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; public void setWeight(short
newWeight) {
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
((FeatureMap.Internal)getMixed()).set(RbmlPackage.eINSTANCE. getDocumentRoot_Weight(),
<br>newWeight);
<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; }
<p>However both these methods give the following compile errors:
<p>getWeight: cannot case from object to short
<br>setWeight: The method set(EStructuralFeature, int, Object) in the type
<br>FeatureMap.Internal is not applicable for the arguments (EAttribute,
short)
<p>I am not sure why some code with compilation errors would be generated.
<br>How am I to fix this problem
<p>Another thing I observed is that these methods are present in the class
<br>DocumentRootImpl. I dont have any such element called DocumentRoot
in my
<br>schema file. I am totally clueless why such a class was generated.
<p>It will be really helpful if somebody could throw some light into why
<br>these problems occur.
<p>Thanks a lot,
<br>Vijay</blockquote>
</html>

--------------B015E74D4D0B24BE4485D433--


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Enforcing acyclic graph constraint
Next Topic:Importing from an XMI file?
Goto Forum:
  


Current Time: Fri Mar 29 14:23:21 GMT 2024

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

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

Back to the top