Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » <appinfo> tag not generated during model export to XSD
<appinfo> tag not generated during model export to XSD [message #1706581] Thu, 27 August 2015 19:56 Go to next message
Jim Boone is currently offline Jim BooneFriend
Messages: 15
Registered: August 2015
Location: North Carolina
Junior Member
Hi,

I am new to EMF and an attempting to define a domin model using EMF. I have defined an eAttribute and documented it with an eAnnotation. I want to be able to generate a XSD that has both a documentation and appinfo tag like this:

<xsd:annotation>
  <xsd:documentation> attribute information</xsd:documentation>
  <xsd:appinfo> application specific info for attribute  <xsd:appinfo>
</xsd:annotation>


The following shows the excerpt from the ecore file the way I would expect the eAnnotation to be defined in EMF:

      <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
        <details key="documentation" value="attribute information"/>
        <details key="appinfo" value="application specific info for attribute"/>
      </eAnnotations>


The problem is, when I generate the XSD from the ecore file, I do not see the appinfo information. Only the documentation tag is generated (e.g.
<xsd:annotation>
  <xsd:documentation> attribute information</xsd:documentation>
</xsd:annotation>


The book "EMF: Eclipse Modeling Framework, Second Edition" says
Quote:

"An xsd:appinfo element in a schema component's xsd:annotation maps to an EAnnotation whose source is the same as the source attribute of the xsd:appinfo, or null if none is provided. The EAnnotation's details map contains a single entry:

•key = "appinfo", value = the contents of the xsd:appinfo element"


The book implies that it is a no-brainer to create an appinfo tag in the XSD. I have tried to define the appinfo annotation in almost every combination but with no luck. Is this a bug or am is missing something? Thanks in advance for the help.

Regards,

--Jim

Re: &lt;appinfo&gt; tag not generated during model export to XSD [message #1706720 is a reply to message #1706581] Sat, 29 August 2015 07:11 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30553
Registered: July 2009
Senior Member
Jim,

For the purpose of converting to XML Schema, these two annotations
sources are ignored:

protected boolean isIgnoredAnnotationSource(String sourceURI)
{
return
EcorePackage.eNS_URI.equals(sourceURI) ||
ExtendedMetaData.ANNOTATION_URI.equals(sourceURI) ||
GEN_MODEL_PACKAGE_NS_URI.equals(sourceURI);
}

Otherwise the behavior is quite subtle. If the value has no newlines
it's coverted to a non-schema namespace attribute:

<eAnnotations source="foo">
<details key="appinfo" value="Foo"/>
</eAnnotations>

->

<xsd:schema xmlns:foo="foo" foo:appinfo="Foo" ...


If it contains a newline, it's converted to an appinfo.
<eAnnotations source="bar">
<details key="appinfo" value="&#xA;Bar"/>
</eAnnotations>

->

<xsd:annotation>
<xsd:appinfo ecore:key="appinfo" source="bar">
Bar</xsd:appinfo>


On 28/08/2015 3:02 PM, Jim Boone wrote:
> Hi,
>
> I am new to EMF and an attempting to define a domin model using EMF.
> I have defined an eAttribute and documented it with an eAnnotation. I
> want to be able to generate a XSD that has both a documentation and
> appinfo tag like this:
>
>
> <xsd:annotation>
> <xsd:documentation> attribute information</xsd:documentation>
> <xsd:appinfo> application specific info for attribute <xsd:appinfo>
> </xsd:annotation>
>
>
> The following shows the excerpt from the ecore file the way I would
> expect the eAnnotation to be defined in EMF:
>
>
> <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
> <details key="documentation" value="attribute information"/>
> <details key="appinfo" value="application specific info for
> attribute"/>
> </eAnnotations>
>
>
> The problem is, when I generate the XSD from the ecore file, I do not
> see the appinfo information. Only the documentation tag is generated
> (e.g.
> <xsd:annotation>
> <xsd:documentation> attribute information</xsd:documentation>
> </xsd:annotation>
>
>
> The book "EMF: Eclipse Modeling Framework, Second Edition" says Quote:
>> "An xsd:appinfo element in a schema component's xsd:annotation maps
>> to an EAnnotation whose source is the same as the source attribute of
>> the xsd:appinfo, or null if none is provided. The EAnnotation's
>> details map contains a single entry:
>>
>> •key = "appinfo", value = the contents of the xsd:appinfo element"
>
>
> The book implies that it is a no-brainer to create an appinfo tag in
> the XSD. I have tried to define the appinfo annotation in almost every
> combination but with no luck. Is this a bug or am is missing
> something? Thanks in advance for the help.
>
> Regards,
> --Jim
>
>
Re: &lt;appinfo&gt; tag not generated during model export to XSD [message #1707028 is a reply to message #1706720] Tue, 01 September 2015 15:03 Go to previous messageGo to next message
Jim Boone is currently offline Jim BooneFriend
Messages: 15
Registered: August 2015
Location: North Carolina
Junior Member
Ed,

This is almost perfect! The secret is a unique source the newline character.

Quote:


If it contains a newline, it's converted to an appinfo.
<eAnnotations source="bar">
<details key="appinfo" value="&#xA;Bar"/>
</eAnnotations>


Unfortunately, there is still a problem. Now that I a getting my annotation, the output string is still escaped so none of the XML code I have included can be found using XPath (the GUI escapes the code when you save the annotation). For example, the appinfo text output is:

&lt;ecore:NPILevel&gt;Blocked&lt;/ecore:NPILevel&gt;

when what I really need is:

<ecore:NPILevel>Blocked</ecore:NPILevel>

Is there an easy way to un-escape the appinfo element text? The simplest way would be to unescape it while the appinfo text is being generated (e.g. StringEscapeUtils.unescapeXml(text)). If there is no easy way, then it looks like my options are


  1. Run the schema through a XSL transform
  2. Modify the code to include the unescape logic


Any other thoughts or ideas! Thanks!

--Jim
Re: &lt;appinfo&gt; tag not generated during model export to XSD [message #1707048 is a reply to message #1707028] Tue, 01 September 2015 20:16 Go to previous message
Jim Boone is currently offline Jim BooneFriend
Messages: 15
Registered: August 2015
Location: North Carolina
Junior Member
I considered the options and decided that the XSLT transform option was the best one since I was already running my schemas through transforms as part of the Maven build process. I looked at the source and it would have been a trivial change but the following xslt file is less hassle. Thanks for the prompt feedback!

<xsl:stylesheet version="3.0" xmlns:xsl="htt://www.w3.org/1999/XSL/Transform" xmlns:xs="htt://www.w3.org/2001/XMLSchema" xmlns:fn="htt://www.w3.org/2005/xpath-functions" xmlns:xsd="htt://www.w3.org/2001/XMLSchema">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
	<xsl:template match="@* | node()">
		<xsl:copy>
			<xsl:apply-templates select="@* | node()"/>
		</xsl:copy>
	</xsl:template>
	<xsl:template match="xsd:appinfo">
		<xsl:copy>
			<xsl:apply-templates select="@*"/>
			<xsl:value-of select="." disable-output-escaping="yes"/>
		</xsl:copy>
	</xsl:template>
</xsl:stylesheet>
Previous Topic:Vaadin implementation of EMF Edit
Next Topic:ChangeCommand.getAffectedObjects()
Goto Forum:
  


Current Time: Tue Oct 22 14:18:58 GMT 2019

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

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

Back to the top