|
|
Re: Strange URI format [message #417046 is a reply to message #417027] |
Sun, 24 February 2008 19:02 |
AlesD Messages: 12 Registered: July 2009 |
Junior Member |
|
|
Ed Merks wrote:
> AlesD wrote:
>> Hello,
>>
>> I have problem with serialization to XML. When I have attribute with
>> type xsd:anyURI and ecore:reference to type that is common abstract
>> type for other types then URIs generated by EMF have following format
>>
>> realType resourceURI#ID
> This is expected. EMF needs to create a proxy object to hold this
> reference until its resolved and since the type of the feature is
> abstract, it needs to know about the non-abstract derived type that it
> can actually create for the proxy.
Why it is not possible for EMF code generator to create proxy for abstract
type? Or interface? All methods of the proxy first resolve the reference
and then invoked the method on real object. So the proxy can implement
abstract methods or interface, because it know that the resolved object
can't be abstract - it must be some subtype of the abstract type or some
type implementing the interface.
=> Looking at my example the EMF could generate "PersonProxy" that would
resolve either to Man or Woman.
>> How can I get rid of the type prefix (people:Man)?
> If you got rid of it, EMF couldn't deserialize it anymore. Make Person
> be not abstract, at least in the Ecore model, would eliminate the issue.
I do not need (actually I don't want) implementation of the abstract type.
It is all because XSD does not allow multiple inferitance.
In my real project I also mark it with ecore:interface so it can be
"mixed" into other types. The XSD type does not have any attribtes or
elements I just add methods to it. Here is another short example.
<xsd:attributeGroup name="commonAttribs">
<xsd:attribute name="attr" type="xsd:string"/>
</xsd:attributeGroup>
<xsd:complexType name="Common" abstract="true" ecore:interface="true"/>
<xsd:complexType name="One" ecore:implements="Common">
<xsd:complexContent>
<xsd:extension base="OneBase">
<xsd:attributeGroup ref="commonAttribs"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="Two" ecore:implements="Common">
<xsd:complexContent>
<xsd:extension base="TwoBase">
<xsd:attributeGroup ref="commonAttribs"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
The types One and Two have different superTypes so I create abstract
type Common and let One and Two implement it. The Common should have
attribute "attr", but I can't add it directly to Common - it would not
make sense for the XML Schema since it does not know about
ecore:implements and would not allow "attr" for One and Two. Instead I
create attributeGrou and add it to every Type that implements Common.
The I add method "String getAttr()" to generated Common interface and
have interface for One and Two common attributes/elements.
Any reference to Common, however, will be in the "strange URI format".
But if there was "CommonProxy" it wouldn't be necessary.
Maybe if I could convince the Ecore generator to delegate to super type
attribute/element if the interface/class specified by "ecore:implements"
contains attribute/element already present in the super Type.
> Or you could use IDREF instead of anyURI, if it's okay that references
> will all have to be in the same resource.
Unfortunatelly I need them in different resources.
Hello
|
|
|
Re: Strange URI format [message #417047 is a reply to message #417046] |
Sun, 24 February 2008 20:30 |
Ed Merks Messages: 33137 Registered: July 2009 |
Senior Member |
|
|
AlesD,
Comments below.
AlesD wrote:
> Ed Merks wrote:
>> AlesD wrote:
>>> Hello,
>>>
>>> I have problem with serialization to XML. When I have attribute
>>> with type xsd:anyURI and ecore:reference to type that is common
>>> abstract type for other types then URIs generated by EMF have
>>> following format
>>>
>>> realType resourceURI#ID
>> This is expected. EMF needs to create a proxy object to hold this
>> reference until its resolved and since the type of the feature is
>> abstract, it needs to know about the non-abstract derived type that
>> it can actually create for the proxy.
>
> Why it is not possible for EMF code generator to create proxy for
> abstract
> type? Or interface?
Because, it's abstract and you can't create an instance of an abstract.
There's no generated create method for it.
> All methods of the proxy first resolve the reference
> and then invoked the method on real object. So the proxy can implement
> abstract methods or interface, because it know that the resolved object
> can't be abstract - it must be some subtype of the abstract type or some
> type implementing the interface.
Don't mix the concept of a Java proxy with EMF's analog. For EMF we
need to be able to use EcoreUtil.create to create an instance and for an
abstract type, that's not possible.
>
> => Looking at my example the EMF could generate "PersonProxy" that would
> resolve either to Man or Woman.
It doesn't though. In an EClass is abstract, the AbcImpl for it will
also be abstract, and there will be no possibility to create an instance.
>
>>> How can I get rid of the type prefix (people:Man)?
>> If you got rid of it, EMF couldn't deserialize it anymore. Make
>> Person be not abstract, at least in the Ecore model, would eliminate
>> the issue.
>
> I do not need (actually I don't want) implementation of the abstract
> type.
>
> It is all because XSD does not allow multiple inferitance.
>
> In my real project I also mark it with ecore:interface so it can be
> "mixed" into other types. The XSD type does not have any attribtes or
> elements I just add methods to it. Here is another short example.
>
> <xsd:attributeGroup name="commonAttribs">
> <xsd:attribute name="attr" type="xsd:string"/>
> </xsd:attributeGroup>
>
> <xsd:complexType name="Common" abstract="true" ecore:interface="true"/>
>
> <xsd:complexType name="One" ecore:implements="Common">
> <xsd:complexContent>
> <xsd:extension base="OneBase">
> <xsd:attributeGroup ref="commonAttribs"/>
> </xsd:extension>
> </xsd:complexContent>
> </xsd:complexType>
>
> <xsd:complexType name="Two" ecore:implements="Common">
> <xsd:complexContent>
> <xsd:extension base="TwoBase">
> <xsd:attributeGroup ref="commonAttribs"/>
> </xsd:extension>
> </xsd:complexContent>
> </xsd:complexType>
>
> The types One and Two have different superTypes so I create abstract
> type Common and let One and Two implement it. The Common should have
> attribute "attr", but I can't add it directly to Common - it would not
> make sense for the XML Schema since it does not know about
> ecore:implements and would not allow "attr" for One and Two. Instead I
> create attributeGrou and add it to every Type that implements Common.
>
> The I add method "String getAttr()" to generated Common interface and
> have interface for One and Two common attributes/elements.
>
> Any reference to Common, however, will be in the "strange URI format".
> But if there was "CommonProxy" it wouldn't be necessary.
There isn't though.
>
> Maybe if I could convince the Ecore generator to delegate to super type
> attribute/element if the interface/class specified by "ecore:implements"
> contains attribute/element already present in the super Type.
I don't really understand...
>
>> Or you could use IDREF instead of anyURI, if it's okay that
>> references will all have to be in the same resource.
>
> Unfortunatelly I need them in different resources.
Maybe it's best then not to make the type abstract. Ecore supports
multiple inheritance (though obviously Java itself doesn't for classes).
>
> Hello
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Re: Strange URI format [message #417049 is a reply to message #417048] |
Mon, 25 February 2008 00:43 |
Ed Merks Messages: 33137 Registered: July 2009 |
Senior Member |
|
|
AlesD,
The only way is to make the type not be abstract so that a proxy of that
type can be created. If you serialize as an element, the type QName
will appear in the xsi:type instead of as part of the URI, so if that's
not a problem, that seems like a good compromise.
AlesD wrote:
> Ed Merks wrote:
>> AlesD wrote:
>>> Unfortunatelly I need them in different resources.
>> Maybe it's best then not to make the type abstract. Ecore supports
>> multiple inheritance (though obviously Java itself doesn't for classes).
>
> Thanks for your patience and explaintation Ed.
>
> I know that I can do it with Ecore, but I start with XML Schema and XSD
> unfortunatelly does not allow multiple inheritance. Any good way how to
> define it in XSD - except the one I outlined in previous example?
>
> The schema still changes from time to time - so I need to regenerate the
> Ecore. Is the XML to Ecore Map used for it?
>
> Mean time I used element instead of attribute the URL looks normal
> now. It
> is not so clean from design point of view, but the extra xsi:type does
> not
> cause problems to 3rd party tools working with XML documents generated by
> my application.
>
> AlesD
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03369 seconds