Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Dynamic EMF and XSD(How to create editor for model which is known at runtime)
Dynamic EMF and XSD [message #756956] Tue, 15 November 2011 17:33 Go to next message
Michal Swietlik is currently offline Michal SwietlikFriend
Messages: 4
Registered: November 2011
Junior Member
Hello,
I know that topic was discussed many times, but I read all possible post and visited all possible sites, but still cannot find a way to solve my problem.

There is one xsd schema known at compilation time. I generate model, edit and editor code and it works fine. But other teams can contribute other schemas which "extends" base schema at some specified point. They should be supported in generated editor.

Example of base schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="...XMLSchema">
<xs:complexType name="testEquipment">
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="teData" type="equipmentData" />
</xs:sequence>
</xs:complexType>

<xs:complexType name="equipmentData">
<xs:sequence></xs:sequence>
</xs:complexType>

<xs:element name="systemConfiguration">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="testEquipment" type="testEquipment"
minOccurs="0" maxOccurs="unbounded" />
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

There is type "testEquipment" which contains element "teData" of type "equipmentData". Contents of that "equipmentData" is not known at compile time, it is delivered by other teams.

Example of final xml:
<systemConfiguration>
<testEquipment>
<name>PC</name>
<teData>
<ip>192.168.1.1</ip>
</teData>
</testEquipment>
</systemConfiguration>

As you can see "ip" element is taken from another schema.

Let consider that the final format of schemas is not yet defined. What is the best way to do it? Should I use "any" wildcard (I suppose not, because too many elements can be put there)? Or maybe it is possible to extend element from one schema by element in another schema? What should be done to make generated editor support such model (I mean actions "New child" and "New sibling" - I hope they should work as bug related to that topic was closed).

I will be grateful for any help.
Best regards
Michal Swietlik
Re: Dynamic EMF and XSD [message #757727 is a reply to message #756956] Mon, 21 November 2011 11:23 Go to previous messageGo to next message
Michal Swietlik is currently offline Michal SwietlikFriend
Messages: 4
Registered: November 2011
Junior Member
I am trying to extend the schema. The base schema looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="sysCfg" xmlns:xs=".../XMLSchema" xmlns:cfg="sysCfg">

<xs:element name="systemConfiguration">
<xs:complexType>
<xs:sequence>
<xs:element name="testEquipments">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="testEquipment" type="cfg:testEquipment"
minOccurs="0" maxOccurs="unbounded" />
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:complexType name="testEquipment">
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="teData" type="cfg:teData" />
</xs:sequence>
</xs:complexType>

<xs:complexType name="teData">
<xs:sequence>
<xs:element name="teDataContenrs" type="cfg:teDataContents" />
</xs:sequence>
</xs:complexType>

<xs:complexType name="teDataContents" abstract="true">
</xs:complexType>
</xs:schema>

The extending schema looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="ethCrd" xmlns:xs=".../XMLSchema" xmlns:cfg="sysCfg">
<xs:import schemaLocation="sysCfg.xsd" namespace="sysCfg"/>

<xs:complexType name="ethernetCard">
<xs:complexContent>
<xs:extension base="cfg:teDataContents">
<xs:sequence>
<xs:element name="ip" type="xs:string" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>

This works fine if I put everything in one schema. But when I generate code for base schema statically and then create model in runtime for extending schema (using XSDEcoreBuilder), then in editor I don't have possibility to add child from extending schema (ethernetCard) to the parent from base schema (teData).

I tried to modify generated code - I added this code to collectNewChildDescriptors in TeDataItemProvider class:

EPackage pkg = EPackage.Registry.INSTANCE.getEPackage("ethCrd"); newChildDescriptors.add(createChildParameter(CfgPackage.Literals.TE_DATA__TE_DATA_CONTENRS,pkg.getEFactoryInstance().create((EClass) pkg.getEClassifier("EthernetCard"))));

The result is that I can see action "Etherent card" in context menu (in "New child" action), but it is always disabled. I suppose that I should modify also other places in generated code. Can somebody give me any clue where they are?

Best regards
Michal Swietlik
Re: Dynamic EMF and XSD [message #757943 is a reply to message #756956] Tue, 15 November 2011 18:47 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Michal,

Comments below.

On 15/11/2011 6:33 PM, Michal Swietlik wrote:
> Hello,
> I know that topic was discussed many times, but I read all possible
> post and visited all possible sites, but still cannot find a way to
> solve my problem.
> There is one xsd schema known at compilation time. I generate model,
> edit and editor code and it works fine. But other teams can contribute
> other schemas which "extends" base schema at some specified point.
> They should be supported in generated editor.
> Example of base schema:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="...XMLSchema">
> <xs:complexType name="testEquipment">
> <xs:sequence>
> <xs:element name="name" type="xs:string" />
> <xs:element name="teData" type="equipmentData" />
> </xs:sequence>
> </xs:complexType>
>
> <xs:complexType name="equipmentData">
> <xs:sequence></xs:sequence>
> </xs:complexType>
>
> <xs:element name="systemConfiguration">
> <xs:complexType>
> <xs:choice minOccurs="0" maxOccurs="unbounded">
> <xs:element name="testEquipment" type="testEquipment"
> minOccurs="0" maxOccurs="unbounded" />
> </xs:choice>
> </xs:complexType>
> </xs:element>
> </xs:schema>
>
> There is type "testEquipment" which contains element "teData" of type
> "equipmentData". Contents of that "equipmentData" is not known at
> compile time, it is delivered by other teams.
> Example of final xml:
> <systemConfiguration>
> <testEquipment>
> <name>PC</name>
> <teData>
> <ip>192.168.1.1</ip>
> </teData>
> </testEquipment>
> </systemConfiguration>
>
> As you can see "ip" element is taken from another schema.
>
> Let consider that the final format of schemas is not yet defined. What
> is the best way to do it? Should I use "any" wildcard (I suppose not,
> because too many elements can be put there)?
It's kind of a bit broad.
> Or maybe it is possible to extend element from one schema by element
> in another schema?
It's possible to extend complex type (that will involve using xsi:type
in the instance) or you can declare that some element to be part of some
other elements substitution group.
http://ed-merks.blogspot.com/2007/12/winters-icy-grip.html

> What should be done to make generated editor support such model (I
> mean actions "New child" and "New sibling" - I hope they should work
> as bug related to that topic was closed).
This might be useful:
http://ed-merks.blogspot.com/2008/01/creating-children-you-didnt-know.html
>
> I will be grateful for any help.
> Best regards
> Michal Swietlik


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Dynamic EMF and XSD [message #757986 is a reply to message #757727] Mon, 21 November 2011 12:19 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Michal,

Comments below.

On 21/11/2011 12:23 PM, Michal Swietlik wrote:
> I am trying to extend the schema. The base schema looks like this:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema targetNamespace="sysCfg" xmlns:xs=".../XMLSchema"
> xmlns:cfg="sysCfg">
>
> <xs:element name="systemConfiguration">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="testEquipments">
> <xs:complexType>
> <xs:choice minOccurs="0" maxOccurs="unbounded">
> <xs:element name="testEquipment" type="cfg:testEquipment"
> minOccurs="0" maxOccurs="unbounded" />
> </xs:choice>
> </xs:complexType>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
>
> <xs:complexType name="testEquipment">
> <xs:sequence>
> <xs:element name="name" type="xs:string" />
> <xs:element name="teData" type="cfg:teData" />
> </xs:sequence>
> </xs:complexType>
>
> <xs:complexType name="teData">
> <xs:sequence>
> <xs:element name="teDataContenrs" type="cfg:teDataContents" />
> </xs:sequence>
> </xs:complexType>
>
> <xs:complexType name="teDataContents" abstract="true">
> </xs:complexType>
> </xs:schema>
>
> The extending schema looks like this:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema targetNamespace="ethCrd" xmlns:xs=".../XMLSchema"
> xmlns:cfg="sysCfg">
> <xs:import schemaLocation="sysCfg.xsd" namespace="sysCfg"/>
>
> <xs:complexType name="ethernetCard">
> <xs:complexContent>
> <xs:extension base="cfg:teDataContents">
> <xs:sequence>
> <xs:element name="ip" type="xs:string" />
> </xs:sequence>
> </xs:extension>
> </xs:complexContent>
> </xs:complexType>
> </xs:schema>
>
> This works fine if I put everything in one schema. But when I generate
> code for base schema statically and then create model in runtime for
> extending schema (using XSDEcoreBuilder), then in editor I don't have
> possibility to add child from extending schema (ethernetCard) to the
> parent from base schema (teData).
It sounds a bit like you want to do what's described here but only
dynamically:

http://ed-merks.blogspot.com/2008/01/creating-children-you-didnt-know.html

>
> I tried to modify generated code - I added this code to
> collectNewChildDescriptors in TeDataItemProvider class:
>
> EPackage pkg = EPackage.Registry.INSTANCE.getEPackage("ethCrd");
> newChildDescriptors.add(createChildParameter(CfgPackage.Literals.TE_DATA__TE_DATA_CONTENRS,pkg.getEFactoryInstance().create((EClass)
> pkg.getEClassifier("EthernetCard"))));
>
> The result is that I can see action "Etherent card" in context menu
> (in "New child" action), but it is always disabled. I suppose that I
> should modify also other places in generated code. Can somebody give
> me any clue where they are?
Do you really need this other schema to be dynamic or is another schema
like this something you could generate code for and install in the
application?
>
> Best regards
> Michal Swietlik


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Dynamic EMF and XSD [message #758083 is a reply to message #757986] Mon, 21 November 2011 20:50 Go to previous messageGo to next message
Michal Swietlik is currently offline Michal SwietlikFriend
Messages: 4
Registered: November 2011
Junior Member
Hi Ed,
thank you for reply.


Quote:
It sounds a bit like you want to do what's described here but only
dynamically:

http...ed-merks.blogspot.com/2008/01/creating-children-you-didnt-know.html


Yes, that's correct. I saw your article, but it describes how to do it for "static" EMF. Unfortunately the other schema cannot be static - I will have access to it only during runtime. But it can have types which extends types from my first (known during compilation) schema. In other words - I don't know the part of model which will be delivered by others, but they know my part. Is it possible to make generated editor handle it?
Re: Dynamic EMF and XSD [message #758105 is a reply to message #758083] Mon, 21 November 2011 21:36 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Michal,

Can't they deliver these extensions by installing generated bundles into
the base IDE? You can look at
ReflectiveItemProvider.collectNewChildDescriptors to see how child
descriptors can be created dynamically.



On 21/11/2011 9:50 PM, Michal Swietlik wrote:
> Hi Ed,
> thank you for reply.
>
>
> Quote:
>> It sounds a bit like you want to do what's described here but only
>> dynamically:
>>
>> http...ed-merks.blogspot.com/2008/01/creating-children-you-didnt-know.html
>>
>
>
> Yes, that's correct. I saw your article, but it describes how to do it
> for "static" EMF. Unfortunately the other schema cannot be static - I
> will have access to it only during runtime. But it can have types
> which extends types from my first (known during compilation) schema.
> In other words - I don't know the part of model which will be
> delivered by others, but they know my part. Is it possible to make
> generated editor handle it?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Dynamic EMF and XSD [message #758193 is a reply to message #758105] Tue, 22 November 2011 09:54 Go to previous messageGo to next message
Michal Swietlik is currently offline Michal SwietlikFriend
Messages: 4
Registered: November 2011
Junior Member
Ed,
no they can't deliver generated bundles. Does it mean it cannot be done in dynamic way?

I will look at the ReflectiveItemProvider class, but any other advice will be also useful.

Best regards
Michal Swietlik
Re: Dynamic EMF and XSD [message #758200 is a reply to message #758193] Tue, 22 November 2011 10:14 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Michal,

As you'll see in that class, you need logic that will analyze all
relevant models for subclasses (and substitution groups) and then create
descriptors base on those. So your generated item providers will need
logic much like you see in ReflectiveItemProvider.


On 22/11/2011 10:54 AM, Michal Swietlik wrote:
> Ed,
> no they can't deliver generated bundles. Does it mean it cannot be
> done in dynamic way?
>
> I will look at the ReflectiveItemProvider class, but any other advice
> will be also useful.
>
> Best regards
> Michal Swietlik


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Not all labels for enumeration values are shown in property sheet view
Next Topic:[CDO] How to get the userId of the user who locks a given CDO object
Goto Forum:
  


Current Time: Fri Apr 26 15:43:25 GMT 2024

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

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

Back to the top