|
Re: Generating sub-models from main model [message #1183370 is a reply to message #1183354] |
Tue, 12 November 2013 20:36 |
Ed Merks Messages: 33137 Registered: July 2009 |
Senior Member |
|
|
Alex,
Comments below.
On 12/11/2013 9:21 PM, Alex Kravets wrote:
> Let's say there is a an EMF model defined by XSD that describes some
> entity - a system. I'd like to have parts of this system in EMF model.
> Right now I just define separate XSD taken from the main XSD and
> generate EMF models off that. However, this means I am breaking away
> from the main XSD and if it changes I need to update my models as
> well, and these models have different namespace than original model
> which means I have adapt my model to main one
>
> I tried creating new EMF model from main XSD and it works for defining
> different types, but since they are all coming from the same main
> model I cannot find how can I define different file extensions for
> each sub-model and create a totally different model that is still
> based on what main model defines.
>
> Consider this example:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
> <!-- definition of simple elements -->
> <xs:element name="orderperson" type="xs:string" />
> <xs:element name="name" type="xs:string" />
> <xs:element name="address" type="xs:string" />
> <xs:element name="city" type="xs:string" />
> <xs:element name="country" type="xs:string" />
> <xs:element name="title" type="xs:string" />
> <xs:element name="note" type="xs:string" />
> <xs:element name="quantity" type="xs:positiveInteger" />
> <xs:element name="price" type="xs:decimal" />
> <!-- definition of attributes -->
> <xs:attribute name="orderid" type="xs:string" />
> <!-- definition of complex elements -->
> <xs:element name="shipto">
> <xs:complexType>
> <xs:sequence>
> <xs:element ref="name" />
> <xs:element ref="address" />
> <xs:element ref="city" />
> <xs:element ref="country" />
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> <xs:element name="item">
> <xs:complexType>
> <xs:sequence>
> <xs:element ref="title" />
> <xs:element ref="note" minOccurs="0" />
> <xs:element ref="quantity" />
> <xs:element ref="price" />
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> <xs:element name="shiporder">
> <xs:complexType>
> <xs:sequence>
> <xs:element ref="orderperson" />
> <xs:element ref="shipto" />
> <xs:element ref="item" maxOccurs="unbounded" />
> </xs:sequence>
> <xs:attribute ref="orderid" use="required" />
> </xs:complexType>
> </xs:element>
> </xs:schema>
>
>
> If I generate EMF model from this schema, I can create Item or Shitorder
I hope I never receive one of those! :-P
> model, but they are going to be part of my order model. I can't for
> example create sampleItem.item from the same model.
Why not? Every global element in the schema can be the root element of
some XML instance.
> Is there a technique I am not aware of that will allow accomplish what
> I am trying to do?
File extensions are independent from what model instances you want to
put in them, so you can define resource factories for as many extensions
as you want (manually). You might even specialize the resources the
factories create to treat a root object it doesn't like as an error
while loading so a shiporder in a *.item's resource would be rejected
during loading...
>
> Thanks,
> Alex
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
|
|
Re: Generating sub-models from main model [message #1203909 is a reply to message #1184497] |
Fri, 22 November 2013 22:28 |
Alex Kravets Messages: 561 Registered: November 2009 |
Senior Member |
|
|
I ended up doing the following, created ResourceFactory that extends base generated ResourceFactory and associated that with my file extension. This worked and I am able to create and open global element from my main model. However, even though DocumentRoot is not serialized I still see it when I set Resource in the TreeViewer. It looks like I am doing something wrong because of this thread. So basically I have:
<extension point="org.eclipse.emf.ecore.extension_parser">
<parser
type="myExtension"
class="/path/to/SpecializedResourceFactoryImpl"/>
</extension>
But how else should I associate file extension with ResourceFactory? If I can't avoid DocumentRoot in my Resource then, as it's being suggested here I need specialized ResourceItemProvider to skip over DocumentRoot, but I am not sure how to tie this provider during model loading.
I also tried adding XMLResource.OPTION_SUPPRESS_DOCUMENT_ROOT set to true in ResourceFactoryImpl, and this did what it promised, but after I created my model and saved it with some elements added I saw that '_._type' was was added to my global element, which seems normal in light of DocumentRoot being supressed, but I don't really want this serialized.
Thanks,
Alex
|
|
|
Re: Generating sub-models from main model [message #1204776 is a reply to message #1203909] |
Sat, 23 November 2013 08:32 |
Ed Merks Messages: 33137 Registered: July 2009 |
Senior Member |
|
|
Alex,
Comments below.
On 22/11/2013 11:28 PM, Alex Kravets wrote:
> I ended up doing the following, created ResourceFactory that extends
> base generated ResourceFactory and associated that with my file
> extension. This worked and I am able to create and open global element
> from my main model. However, even though DocumentRoot is not
> serialized I still see it when I set Resource in the TreeViewer. It
> looks like I am doing something wrong because of this
> http://http://www.eclipse.org/forums/index.php/mv/msg/125914/386310/#msg_386310.
> So basically I have:
>
>
> <extension point="org.eclipse.emf.ecore.extension_parser">
> <parser
> type="myExtension"
> class="/path/to/SpecializedResourceFactoryImpl"/>
> </extension>
>
>
> But how else should I associate file extension with ResourceFactory?
That's the only way.
> If I can't avoid DocumentRoot in my Resource then, as it's being
> suggested
> http://www.eclipse.org/forums/index.php/mv/msg/125914/391583/#msg_391583
> I need specialized ResourceItemProvider to skip over DocumentRoot, but
> I am not sure how to tie this provider during model loading.
You can always specialize methods like doLoad and doSave, but that
shouldn't be necessary.
>
> I also tried adding XMLResource.OPTION_SUPPRESS_DOCUMENT_ROOT set to
> true in ResourceFactoryImpl, and this did what it promised, but after
> I created my model and saved it with some elements added I saw that
> '_._type' was was added to my global element, which seems normal in
> light of DocumentRoot being supressed, but I don't really want this
> serialized.
Did you try it in combination with OPTION_ELEMENT_HANDLER? During
saving, it's important to be able to deduce a global element declaration
(a feature of the document root) that's appropriate for the type of root
object you're serializing so the appropriate root element is serialized
to the resource.
> Thanks,
> Alex
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Powered by
FUDForum. Page generated in 0.02976 seconds