Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Identify unset/undefined attributes in Entities
Identify unset/undefined attributes in Entities [message #1431149] Thu, 25 September 2014 09:17 Go to next message
Richard Gross is currently offline Richard GrossFriend
Messages: 9
Registered: September 2014
Junior Member
I am using Epsilon/EMF to read an xml file and transform it to a different model. Some Entities inside my model contain attributes which might be unset/undefined/.

Normally I can use the ETL Statement entity.attribute.isDefined(). This correctly returns true for integer or string Attributes which are not set. But long or double and sometimes enum Attributes, are always identified as defined, even though they are not. Is this the intended behavior?

I originally asked this question in the Epsilon Forum and was advised to ask this question again here, since Epsilon uses EMF to load XSD-based XML documents.

My minimal example is:

1) Check out https://dev.eclipse.org/svnroot/modeling/org.eclipse.epsilon/trunk/examples/org.eclipse.epsilon.examples.xsdxml
2) Add <xs:attribute name="unusedInt" type="xs:integer"/> to the complex type in note.xsd
3) Attribute <xs:attribute name="unusedLong" type="xs:long"/> to the complex type in note.xsd
4) Add the following line to note.eol: note.unusedInt.isDefined().println();
5) Add the following line to note.eol: note.unusedLong.isDefined().println();
6) Right-click note.launch and launch it (the first line of the console output should be "false" but the second is interestingly "true")

[Updated on: Thu, 25 September 2014 09:18]

Report message to a moderator

Re: Identify unset/undefined attributes in Entities [message #1431197 is a reply to message #1431149] Thu, 25 September 2014 10:29 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30351
Registered: July 2009
Senior Member
Richard,

Comments below.

On 25/09/2014 11:17 AM, Richard Gross wrote:
> I am using Epsilon/EMF to read an xml file and transform it to a
> different model. Some Entities inside my model contain attributes
> which might be unset/undefined/.
I'm not sure what undefined means...
> Normally I can use the ETL Statement entity.attribute.isDefined().
> This correctly returns true for integer or string Attributes which are
> not set. But long or double and sometimes enum Attributes, are always
> identified as defined, even though they are not. Ist this the intended
> behavior?
Perhaps isDefine just tests if o.eGet(f) != null and for primitives and
enums that's always true.
>
> I originally asked this question in the Epsilon Forum and was advised
> to ask this question again here, since Epsilon uses EMF to load
> XSD-based XML documents.
> My minimal example is:
>
> 1) Check out
> https://dev.eclipse.org/svnroot/modeling/org.eclipse.epsilon/trunk/examples/org.eclipse.epsilon.examples.xsdxml
> 2) Add <xs:attribute name="unusedInt" type="xs:integer"/> to the
> complex type in note.xsd
> 3) Attribute <xs:attribute name="unusedLong" type="xs:long"/> to the
> complex type in note.xsd
> 4) Add the following line to note.eol:
> note.unusedInt.isDefined().println();
> 5) Add the following line to note.eol:
> note.unusedLong.isDefined().println();
> 6) Right-click note.launch and launch it (the first line of the
> console output should be "false" but the second is interestingly "true")
For XML Schema-based models, elements and attributes of primitive type
are generally mapped to unsettable features and that essentially adds
one value to the value space for that feature.

For example if you have an object o with a feature f of type boolean and
you just created a new o, o.eIsSet(f) will be false (unless someone has
butchered the generated code). If you call o.eSet(f, false), you'll
still find that o.eIsSet(f) is false, because false is the intrinsic
default value. If you call o.eSet(f, true), you'll find o.eIsSet(f) is
true because false != true. However, if f is an unsettable feature and
you call o.eSet(f, false), you'll find that o.eIsSet() is true. This
behavior, eIsSet being true no matter what value you've passed to eSet,
is what's special about an unsettable feature, and as I said, XML
Schema-based models will generally map to unsettable feature for
primitive types so that you can tell the difference between the
attribute being present in the XML with what happens to be the default
value, verses the attribute being absent, in which case eIsSet is false.

I hope that helps. I can't answer specific questions about ETL...
Re: Identify unset/undefined attributes in Entities [message #1433754 is a reply to message #1431197] Mon, 29 September 2014 07:48 Go to previous messageGo to next message
Richard Gross is currently offline Richard GrossFriend
Messages: 9
Registered: September 2014
Junior Member
Hello Ed,
Our Code uses Epsilon which in turn includes the org.eclipse.xsd.source_2.10.0.v20140519-0339.jar.

But I can also use the Eclipse Epsilon 1.2 Extensions to generate an Ecore Model and get the same problems:
When I look at the generated Ecore Model in the Exceed or the Sample Ecore Model Editor almost all primitive Entity Attributes are Unsettable=True. Integer and String are unsettable=false. Decimal, Double, Enum, Long etc. are all Unsettable=True. None of these primitive Attributes are required in the xsd.

Are you sure there is no bug in the generation code?

Cheers
Richard
Re: Identify unset/undefined attributes in Entities [message #1433856 is a reply to message #1433754] Mon, 29 September 2014 10:24 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30351
Registered: July 2009
Senior Member
Richard,

Comments below.

On 29/09/2014 9:48 AM, Richard Gross wrote:
> Hello Ed,
> Our Code uses Epsilon which in turn includes the
> org.eclipse.xsd.source_2.10.0.v20140519-0339.jar.
> But I can also use the Eclipse Epsilon 1.2 Extensions to generate an
> Ecore Model and get the same problems: When I look at the generated
> Ecore Model in the Exceed or the Sample Ecore Model Editor almost all
> primitive Entity Attributes are Unsettable=True.
That's generally what I'd expect.
> Integer and String are unsettable=false.
The names you're using here are the names in the XMLTypePackage?
> Decimal, Double, Enum, Long etc. are all Unsettable=True. None of
> these primitive Attributes are required in the xsd.
You mean the xsd:attribute specifies the attributes as option?
>
> Are you sure there is no bug in the generation code?
You can look at the generated code to see if it looks correct, but yes,
given it's the same pattern (from the template) in all places it will
always be right or always be wrong...

So have a look at the generated code and if you think something is
wrong, phrase the problem in terms of something I can reproduce without
Epsilon...
>
> Cheers
> Richard
Re: Identify unset/undefined attributes in Entities [message #1433995 is a reply to message #1433856] Mon, 29 September 2014 14:22 Go to previous messageGo to next message
Richard Gross is currently offline Richard GrossFriend
Messages: 9
Registered: September 2014
Junior Member
Hi Ed,
- I use Eclipse Kepler SP2, prepackaged with Eclipse Modeling Tools.
- I create a new xsd file (note.xsd) that has attributes that are not required (see below). One not-required integer, one not-required long.
- In my Eclipse Project Exloper I select New->Other->Eclipse Modeling Framwork -> EMF Project
- I pick a project name; next XML-Schema; next use the created xsd file (note.xsd); finish
- Then I select note.genmodel
- I navigate to Note->Xsdxml->NoteType
- I look at the NoteType Attributes unusedLong and unusedInteger
- unusedLong is Unsettable=True
- unusedInteger is Unsetttable=False



--- Here is the note.xsd ---
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xs:schema xmlns="xsdxml" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="xsdxml">

<xs:element name="note">
<xs:complexType mixed="true">
<xs:attribute name="unusedInteger" type="xs:integer"/>
<xs:attribute name="unusedLong" type="xs:long"/>
</xs:complexType>
</xs:element>

</xs:schema>

[Updated on: Mon, 29 September 2014 14:23]

Report message to a moderator

Re: Identify unset/undefined attributes in Entities [message #1434009 is a reply to message #1433995] Mon, 29 September 2014 14:40 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30351
Registered: July 2009
Senior Member
Richard,

Pay close attention to the XML Schema definitions for these types. Note
in particular that http://www.w3.org/TR/xmlschema-2/#integer has no
upper/lower bounds on the value space so the EDataType for this maps to
java.math.BigInteger and as such, it's not a primitive type. Compare
that to http://www.w3.org/TR/xmlschema-2/#long which is bounded exactly
such that Java's primitive long can represent all the value, so the
EDataType for this maps to long. Similarly
http://www.w3.org/TR/xmlschema-2/#int is bounded so that Java's int can
represent all values. Perhaps you want to be using int and not integer...


On 29/09/2014 4:22 PM, Richard Gross wrote:
> Hi Ed,
> - I use Eclipse Kepler SP2, prepackaged with Eclipse Modeling Tools. -
> Then I create a new xsd file (note.xsd) that has attributes that are
> not required (see below). One not-required integer, one not-required
> long.
> - In my Eclipse Project Exloper I select New->Other->Eclipse Modeling
> Framwork -> EMF Project
> - I pick a project name; next XML-Schema; next use the created xsd
> file (note.xsd); finish
> - Then I select note.genmodel
> - I navigate to Note->Xsdxml->NoteType
> - I look at the NoteType Attributes unusedLong and unusedInteger
> - unusedLong is Unsettable=True
> - unusedInteger is Unsetttable=False
>
>
>
> --- Here is the note.xsd ---
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <xs:schema xmlns="xsdxml" xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified" targetNamespace="xsdxml">
>
> <xs:element name="note">
> <xs:complexType mixed="true">
> <xs:attribute name="unusedInteger" type="xs:integer"/>
> <xs:attribute name="unusedLong" type="xs:long"/>
> </xs:complexType>
> </xs:element>
>
> </xs:schema>
Previous Topic:Opening an EMF-Editor
Next Topic:[Xcore] What is the advantage of "derived feature" from "operation"
Goto Forum:
  


Current Time: Mon Aug 19 00:03:17 GMT 2019

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

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

Back to the top