|
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 |
Ed Merks 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> /**
<br> * <!-- begin-user-doc -->
<br> * <!-- end-user-doc -->
<br> * @generated
<br> */
<br> public short getX()
<br> {
<br> return ((Short)getMixed().get(TestPackage.eINSTANCE.getDocumentRoot _X(),
true)).shortValue();
<br> }
<p> /**
<br> * <!-- begin-user-doc -->
<br> * <!-- end-user-doc -->
<br> * @generated
<br> */
<br> public void setX(short newX)
<br> {
<br> ((FeatureMap.Internal)getMixed()).set(TestPackage.eINSTANCE. getDocumentRoot_X(),
new Short(newX));
<br> }
<br> </blockquote>
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....
<br>
<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><xs:element name = "weight" type = "xs:unsignedByte">
<br> <xs:annotation>
<br>
<xs:documentation>
<br>
The relative weighting the rule should be given
<br>
</xs:documentation>
<br> </xs:annotation>
<br></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> /**
<br> * <!-- begin-user-doc
-->
<br> * <!-- end-user-doc
-->
<br> * @generated
<br> */
<br> public short getWeight()
{
<br>
return
<br> (short)getMixed().get(RbmlPackage.eINSTANCE.getDocumentRoot_ Weight(),
<br>true);
<br> }
<p> /**
<br> * <!-- begin-user-doc
-->
<br> * <!-- end-user-doc
-->
<br> * @generated
<br> */
<br> public void setWeight(short
newWeight) {
<br>
((FeatureMap.Internal)getMixed()).set(RbmlPackage.eINSTANCE. getDocumentRoot_Weight(),
<br>newWeight);
<br> }
<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/
|
|
|
Powered by
FUDForum. Page generated in 0.06078 seconds