Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to annotate attribute of type xsd:long to be of type LongObject in Ecore model
How to annotate attribute of type xsd:long to be of type LongObject in Ecore model [message #427650] Wed, 25 February 2009 12:11 Go to next message
koloale is currently offline koloaleFriend
Messages: 41
Registered: July 2009
Member
Hello, newsgroup

I import Ecore model from xsd, where there is an attribute of type
xsd:long. By default this attribute corresponds to long property in the
generated code, but I want it to be java.lang.Long. Is there any way to
annotate source xsd to achieve the desired result? I searched for
newsgroups, but ecore:instanceClass, ecore:type don't solve the problem,
Also source schema should be used as standalone without ecore one to
validate xml documents, i.e. type of attribute in xsd should be xsd:long.

Thanks, Alexey.
Re: How to annotate attribute of type xsd:long to be of type LongObject in Ecore model [message #427662 is a reply to message #427650] Wed, 25 February 2009 15:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Alexey,

Comments below.

koloale wrote:
> Hello, newsgroup
>
> I import Ecore model from xsd, where there is an attribute of type
> xsd:long. By default this attribute corresponds to long property in
> the generated code, but I want it to be java.lang.Long. Is there any
> way to annotate source xsd to achieve the desired result?
Hmmm. An xsd:element with nil="true" would do the trick, but you said
attribute.
> I searched for newsgroups, but ecore:instanceClass, ecore:type don't
> solve the problem, Also source schema should be used as standalone
> without ecore one to validate xml documents, i.e. type of attribute in
> xsd should be xsd:long.
You could use ecore:type, but you'd have to use ecore:ELongObject as the
type, and unfortunately you'd have to change the schema to import
Ecore.xsd from location
platform:/plugins/org.eclipse.emf.ecore/model/Ecore.xsd.
>
> Thanks, Alexey.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to annotate attribute of type xsd:long to be of type LongObject in Ecore model [message #427683 is a reply to message #427662] Thu, 26 February 2009 11:05 Go to previous messageGo to next message
koloale is currently offline koloaleFriend
Messages: 41
Registered: July 2009
Member
Hello, Ed!
Ed Merks wrote:
> You could use ecore:type, but you'd have to use ecore:ELongObject as the
> type, and unfortunately you'd have to change the schema to import
> Ecore.xsd from location
> platform:/plugins/org.eclipse.emf.ecore/model/Ecore.xsd.

I get failure of source xsd validation when I use ecore extensions, e.g.
for <xsd:appinfo ecore:key="appinfo" source="teneo.jpa"> I get:
"Attribute 'ecore:key' cannot appear in element 'appinfo'"). Maybe I
need to set some special option in the validator. I use SAX parser for
validation like that:
// Create a JAXP SAXParserFactory and configure it
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
spf.setValidating(true);

SAXParser saxParser = spf.newSAXParser();
saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
saxParser.setProperty(JAXP_SCHEMA_SOURCE, xmlSchema);

XMLReader xmlReader = saxParser.getXMLReader();
xmlReader.setContentHandler(new DefaultHandler());
xmlReader.setErrorHandler(errHandler);

String xmlToValidate = ...
xmlReader.parse(xmlToValidate );
Re: How to annotate attribute of type xsd:long to be of type LongObject in Ecore model [message #427685 is a reply to message #427683] Thu, 26 February 2009 12:56 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------030806050400000904000001
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Koloale,

Given that the specification defines it like this:

XML Representation Summary: |annotation| Element Information Item

<annotation
id = ID
< http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes .html#ID>
/{any attributes with non-schema namespace . . .}/>
/ Content: /(appinfo
<http://www.w3.org/TR/xmlschema-1/#element-appinfo> | documentation
<http://www.w3.org/TR/xmlschema-1/#element-documentation>)*
</annotation>

<appinfo
source = anyURI
< http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes .html#anyURI>
/{any attributes with non-schema namespace . . .}/>
/ Content: /(/{any}/)*
</appinfo>

<documentation
source = anyURI
< http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes .html#anyURI>
xml:lang = language
< http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes .html#language>
/{any attributes with non-schema namespace . . .}/>
/ Content: /(/{any}/)*
</documentation>

And that the schema for schemas has this:

<xs:element name="appinfo" id="appinfo">
<xs:annotation>
<xs:documentation
source="http://www.w3.org/TR/xmlschema-1/#element-appinfo"/>
</xs:annotation>
<xs:complexType mixed="true">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:any processContents="lax"/>
</xs:sequence>
<xs:attribute name="source" type="xs:anyURI"/>
<xs:anyAttribute namespace="##other" processContents="lax"/>
</xs:complexType>
</xs:element>

I'd say that validation error is bogus since clearly an appinfo is
allowed to have any attribute from any other namespace.

In other words, it sounds like a bug in the JAXP implementation you're
using.



koloale wrote:
> Hello, Ed!
> Ed Merks wrote:
>> You could use ecore:type, but you'd have to use ecore:ELongObject as
>> the type, and unfortunately you'd have to change the schema to import
>> Ecore.xsd from location
>> platform:/plugins/org.eclipse.emf.ecore/model/Ecore.xsd.
>
> I get failure of source xsd validation when I use ecore extensions,
> e.g. for <xsd:appinfo ecore:key="appinfo" source="teneo.jpa"> I get:
> "Attribute 'ecore:key' cannot appear in element 'appinfo'"). Maybe I
> need to set some special option in the validator. I use SAX parser for
> validation like that:
> // Create a JAXP SAXParserFactory and configure it
> SAXParserFactory spf = SAXParserFactory.newInstance();
> spf.setNamespaceAware(true);
> spf.setValidating(true);
>
> SAXParser saxParser = spf.newSAXParser();
> saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
> saxParser.setProperty(JAXP_SCHEMA_SOURCE, xmlSchema);
>
> XMLReader xmlReader = saxParser.getXMLReader();
> xmlReader.setContentHandler(new DefaultHandler());
> xmlReader.setErrorHandler(errHandler);
>
> String xmlToValidate = ...
> xmlReader.parse(xmlToValidate );

--------------030806050400000904000001
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Koloale,<br>
<br>
Given that the specification defines it like this:<br>
<br>
<div class="reprHeader"><span class="reprdef">XML Representation Summary</span>: <code >annotation</code> Element
Information Item</div>
<blockquote>
<p class="element-syntax-1"><a name="element-annotation"
id="element-annotation">&lt;annotation</a><br>
  id = <a
href=" http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes .html#ID">ID</a><br>
  <em>{any attributes with non-schema namespace . . .}</em>&gt;<br>
<em>  Content: </em>(<a class="eltref"
href="http://www.w3.org/TR/xmlschema-1/#element-appinfo">appinfo</a> |
<a class="eltref"
href="http://www.w3.org/TR/xmlschema-1/#element-documentation">documentation</a>)*<br>
&lt;/annotation&gt;</p>
<p class="element-syntax"><a name="element-appinfo"
id="element-appinfo">&lt;appinfo</a><br>
  source = <a
href=" http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes .html#anyURI">anyURI</a><br>
  <em>{any attributes with non-schema namespace . . .}</em>&gt;<br>
<em>  Content: </em>(<em>{any}</em>)*<br>
&lt;/appinfo&gt;</p>
<a name="element-documentation" id="element-documentation">&lt;documentation</a><br>
  source = <a
href=" http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes .html#anyURI">anyURI</a><br>
  xml:lang = <a
href=" http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes .html#language">language</a><br>
  <em>{any attributes with non-schema namespace . . .}</em>&gt;<br>
<em>  Content: </em>(<em>{any}</em>)*<br>
&lt;/documentation&gt;<br>
</blockquote>
<p class="element-syntax">And that the schema for schemas has this:<br>
</p>
<p class="element-syntax"> &lt;xs:element name="appinfo"
id="appinfo"&gt;<br>
   &lt;xs:annotation&gt;<br>
     &lt;xs:documentation
source=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/TR/xmlschema-1/#element-appinfo">"http://www.w3.org/TR/xmlschema-1/#element-appinfo"</a>/&gt;<br>

   &lt;/xs:annotation&gt;<br>
   &lt;xs:complexType mixed="true"&gt;<br>
    &lt;xs:sequence minOccurs="0" maxOccurs="unbounded"&gt;<br>
     &lt;xs:any processContents="lax"/&gt;<br>
    &lt;/xs:sequence&gt;<br>
    &lt;xs:attribute name="source" type="xs:anyURI"/&gt;<br>
    &lt;xs:anyAttribute namespace="##other" processContents="lax"/&gt;<br>
   &lt;/xs:complexType&gt;<br>
 &lt;/xs:element&gt;<br>
</p>
<p class="element-syntax">I'd say that validation error is bogus since
clearly an appinfo is allowed to have any attribute from any other
namespace.<br>
</p>
<p class="element-syntax">In other words, it sounds like a bug in the
JAXP implementation you're using.<br>
</p>
<br>
<br>
koloale wrote:
<blockquote cite="mid:go5t1m$c27$1@build.eclipse.org" type="cite">Hello,
Ed!
<br>
Ed Merks wrote:
<br>
<blockquote type="cite">You could use ecore:type, but you'd have to
use ecore:ELongObject as the type, and unfortunately you'd have to
change the schema to import Ecore.xsd from location
platform:/plugins/org.eclipse.emf.ecore/model/Ecore.xsd.
<br>
</blockquote>
<br>
I get failure of source xsd validation when I use ecore extensions,
e.g. for &lt;xsd:appinfo ecore:key="appinfo" source="teneo.jpa"&gt; I
get: "Attribute 'ecore:key' cannot appear in element 'appinfo'"). Maybe
I need to set some special option in the validator. I use SAX parser
for validation like that:
<br>
// Create a JAXP SAXParserFactory and configure it
<br>
SAXParserFactory spf = SAXParserFactory.newInstance();
<br>
spf.setNamespaceAware(true);
<br>
spf.setValidating(true);
<br>
<br>
SAXParser saxParser = spf.newSAXParser();
<br>
saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
<br>
saxParser.setProperty(JAXP_SCHEMA_SOURCE, xmlSchema);
<br>
<br>
XMLReader xmlReader = saxParser.getXMLReader();
<br>
xmlReader.setContentHandler(new DefaultHandler());
<br>
xmlReader.setErrorHandler(errHandler);
<br>
<br>
String xmlToValidate = ...
<br>
xmlReader.parse(xmlToValidate );
<br>
</blockquote>
</body>
</html>

--------------030806050400000904000001--


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[Teneo] Annotation required to stop cascade updates
Next Topic:Testing the emf commands on a command stack?
Goto Forum:
  


Current Time: Fri Apr 26 00:51:09 GMT 2024

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

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

Back to the top