Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Creating my on derived feature based on a "mixed" feature
Creating my on derived feature based on a "mixed" feature [message #423834] Tue, 07 October 2008 18:18 Go to next message
Cameron Bateman is currently offline Cameron BatemanFriend
Messages: 481
Registered: July 2009
Senior Member
I have an EClass called ShortNameType that was generated based on the
following schema:

<xs:element name="short-name">
<xs:complexType mixed="true">
<xs:attribute name="id" type="xs:ID"/>
</xs:complexType>
</xs:element>

This produces the expected "mixed" feature on ShortNameType per section
3.4 of XSD2Ecore mapping doc (NOTE: the official link to the PDF sems to
link a corrupt file; I had to use the Google cached version).

Most of the time, the text content of the mixed will simple a single text
string like this:

<short-name>foobar</short-name>

So I'd like to map a derived feature called "value" to "mixed" that gets
the "ecore.xml.type:text" feature data from "mixed" when called from the
generated getValue method on the generated class.

I am able to do this manually by annotating my "value" feature with
(group->"#:mixed, name="ecore.xml.type:text") and then overriding the template
to generate (it uses the name="ecore..." part to decide if it should change
what would be generated by default for a delegated type):

public String getValue()
{
return IBindingAdapter.UTIL.compressTextContent(this,
eClass().getEStructuralFeature(DescriptorPackage.SHORT_NAME_ TYPE__MIXED),
org.eclipse.emf.ecore.xml.type.XMLTypePackage.Literals.XML_T YPE_DOCUMENT_ROOT__TEXT);
}

Here, the "compressTextContent" method acquires the EList of text content
from the "mixed" efeature and then concat's them together if there's more
than one (an unlikely corner case). I might add additional policy options
for concatentation that tries to preserve whitespace and order relative to
anything else like comments that might be there.

My question is, is there a better way to get what I want?


Thanks,

Cameron
Re: Creating my on derived feature based on a "mixed" feature [message #423837 is a reply to message #423834] Tue, 07 October 2008 18:55 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.
--------------050008030208080308080906
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Cameron,

Comments below.


Cameron Bateman wrote:
> I have an EClass called ShortNameType that was generated based on the
> following schema:
>
> <xs:element name="short-name">
> <xs:complexType mixed="true">
> <xs:attribute name="id" type="xs:ID"/>
> </xs:complexType>
> </xs:element>
>
> This produces the expected "mixed" feature on ShortNameType per
> section 3.4 of XSD2Ecore mapping doc (NOTE: the official link to the
> PDF sems to link a corrupt file; I had to use the Google cached version).
It worked fine for me... Maybe a network glitch...
>
> Most of the time, the text content of the mixed will simple a single
> text string like this:
>
> <short-name>foobar</short-name>
>
> So I'd like to map a derived feature called "value" to "mixed" that
> gets the "ecore.xml.type:text" feature data from "mixed" when called
> from the generated getValue method on the generated class.
Very similar to what SimpleAnyType.getRawValue does... And to what
you'd get if you just gave it simple content...
>
> I am able to do this manually by annotating my "value" feature with
> (group->"#:mixed, name="ecore.xml.type:text") and then overriding the
> template to generate (it uses the name="ecore..." part to decide if it
> should change what would be generated by default for a delegated type):
>
> public String getValue()
> {
> return IBindingAdapter.UTIL.compressTextContent(this,
> eClass().getEStructuralFeature(DescriptorPackage.SHORT_NAME_ TYPE__MIXED),
> org.eclipse.emf.ecore.xml.type.XMLTypePackage.Literals.XML_T YPE_DOCUMENT_ROOT__TEXT);
>
> }
>
> Here, the "compressTextContent" method acquires the EList of text
> content from the "mixed" efeature and then concat's them together if
> there's more than one (an unlikely corner case). I might add
> additional policy options for concatentation that tries to preserve
> whitespace and order relative to anything else like comments that
> might be there.
I don't suppose you can change the schema? Restricting anyType to have
simple content will produce the identical API compared to what you've shown.

/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public String getRawValue()
{
return
(String)getMixed().get(XMLTypePackage.Literals.SIMPLE_ANY_TY PE__RAW_VALUE,
true);
}

>
> My question is, is there a better way to get what I want?
The XML instances you'd support for the above content model are
equivalent to what you'd get for simple content of type xsd:string...

The raw value feature is annotated like this:

* @model dataType="org.eclipse.emf.ecore.xml.type.String"
transient="true" volatile="true" derived="true"
* extendedMetaData="name=':3' kind='simple'"

The kind='simple' is what helps generated the above method...
>
>
> Thanks,
>
> Cameron
>

--------------050008030208080308080906
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Cameron,<br>
<br>
Comments below.<br>
<br>
<br>
Cameron Bateman wrote:
<blockquote
cite="mid:fbd93d0bcbe898961680f4525266a3e9$1@www.eclipse.org"
type="cite">I have an EClass called ShortNameType that was generated
based on the following schema:
<br>
<br>
&lt;xs:element name="short-name"&gt;
<br>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[CDO] SQLException
Next Topic:Generated editor for XSD generated Ecore model
Goto Forum:
  


Current Time: Fri Apr 26 00:19:05 GMT 2024

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

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

Back to the top