|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
| Ed Merks
Registered: July 2009
This is a multi-part message in MIME format.|
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
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"/>
> 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:
> 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 -->
public String getRawValue()
> 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...
Content-Type: text/html; charset=ISO-8859-15
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<body bgcolor="#ffffff" text="#000000">
Cameron Bateman wrote:
type="cite">I have an EClass called ShortNameType that was generated
based on the following schema:
Powered by FUDForum
. Page generated in 0.02056 seconds