Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF serialize custom xml
EMF serialize custom xml [message #498520] Tue, 17 November 2009 10:41 Go to next message
robin Missing name is currently offline robin Missing nameFriend
Messages: 16
Registered: November 2009
Junior Member
hi,master,
I come from China,I like emf.

I create Ecore file and define my model.
Control1 Control2
| |
| |
V V
ControlObject

ControlObject is parent class and Control1 and Control2 is ControlObject's subclass.

In Container the ControlObject is EReference.

In my tree editor I create Control1 and Control2 in Container node and save.

The xml is:
<Container>
<ControlObject xsi:type="Control1"/>
<ControlObject xsi:type="Control2"/>
</Container>
I want to serialize:
<Container>
<Control1/>
<Control2/>
</Container>

what can I do?
Thanks.

[Updated on: Tue, 17 November 2009 13:43]

Report message to a moderator

Re: EMF serialize cutomer xml [message #498573 is a reply to message #498520] Tue, 17 November 2009 14:46 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33145
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------090304060105050700010303
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Robin,

Comments below.

robin wrote:
> hi,master,
> I come from China,I like emf.
>
> I create Ecore file and define my model.
> Control1 Control2
> | |
> | |
> V V
> ControlObject
>
> ControlObject is parent
super class/type
> class and Control1 and Control2 is ControlObject's subclass.
>
> In Container the ControlObject is EReference.
>
> In my tree editor I create Control1 and Control2 in Container node and
> save.
>
> The xml is:
> <Container>
> <ControlObject xsi:type="Control1"/>
> <ControlObject xsi:type="Control2"/>
> </Container>
> I want to serialize:
> <Container>
> <Control1/>
> <Control2/>
> </Container>
>
> what can I do?
Serialization always uses the names of features, not the names of types,
except for the root element of an XMI serialization. If you defined the
model with XML Schema, you could make use of element substitution
groups. This blog has some details:
<http://ed-merks.blogspot.com/2007/12/winters-icy-grip.html>

http://ed-merks.blogspot.com/2007/12/winters-icy-grip.html


> Thanks.
>

--------------090304060105050700010303
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Robin,<br>
<br>
Comments below.<br>
<br>
robin wrote:
<blockquote cite="mid:hdtukc$2bj$1@build.eclipse.org" type="cite">hi,master,
<br>
I come from China,I like emf.
<br>
<br>
I create Ecore file and define my model.
<br>
Control1  Control2
<br>
      |             |
<br>
      |             |
<br>
     V           V
<br>
 ControlObject
<br>
<br>
ControlObject is parent </blockquote>
super class/type<br>
<blockquote cite="mid:hdtukc$2bj$1@build.eclipse.org" type="cite">class
and Control1 and Control2 is ControlObject's subclass.
<br>
<br>
In  Container the ControlObject is EReference.
<br>
<br>
In my tree editor I create Control1 and Control2 in Container node and
save.
<br>
<br>
The xml is:
<br>
&lt;Container&gt;
<br>
   &lt;ControlObject xsi:type="Control1"/&gt;
<br>
   &lt;ControlObject xsi:type="Control2"/&gt;
<br>
&lt;/Container&gt;
<br>
I want to serialize:
<br>
&lt;Container&gt;
<br>
   &lt;Control1/&gt;
<br>
   &lt;Control2/&gt;
<br>
&lt;/Container&gt;
<br>
<br>
what can I do?
<br>
</blockquote>
Serialization always uses the names of features, not the names of
types, except for the root element of an XMI serialization.  If you
defined the model with XML Schema, you could make use of element
substitution groups. This blog has some details:<a
href="http://ed-merks.blogspot.com/2007/12/winters-icy-grip.html"><br>
</a>
<blockquote><a
href="http://ed-merks.blogspot.com/2007/12/winters-icy-grip.html">http://ed-merks.blogspot.com/2007/12/winters-icy-grip.html</a><br>
</blockquote>
<br>
<blockquote cite="mid:hdtukc$2bj$1@build.eclipse.org" type="cite">Thanks.
<br>
<br>
</blockquote>
</body>
</html>

--------------090304060105050700010303--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF serialize custom xml [message #498949 is a reply to message #498520] Thu, 19 November 2009 10:19 Go to previous messageGo to next message
robin Missing name is currently offline robin Missing nameFriend
Messages: 16
Registered: November 2009
Junior Member
Thanks you very much.
Successed.
Re: EMF serialize custom xml [message #510901 is a reply to message #498520] Fri, 29 January 2010 04:46 Go to previous messageGo to next message
robin Missing name is currently offline robin Missing nameFriend
Messages: 16
Registered: November 2009
Junior Member
Hi Ed,
Thanks for your help last time.
But My model has bean changer Dynamic EMF model and created that.
But How to programmatically do my dynamic emf model with substitution groups?

Thanks. Very Happy
Re: EMF serialize custom xml [message #510910 is a reply to message #510901] Fri, 29 January 2010 06:54 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33145
Registered: July 2009
Senior Member
Robin,

The behavior is completely driven by the extended meta data EAnnotations
so if you look at the generated model you had working, you'd need to add
the same types of annotations as you saw there. You might look at
XSDEcoreBuilder to see how it builds up a dynamic model from an XML Schema.


robin wrote:
> Hi Ed,
> Thanks for your help last time.
> But My model has bean changer Dynamic EMF model and created that.
> But How to programmatically do my dynamic emf model with substitution
> groups?
> Thanks. :d


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF serialize custom xml [message #510913 is a reply to message #498520] Fri, 29 January 2010 07:21 Go to previous messageGo to next message
robin Missing name is currently offline robin Missing nameFriend
Messages: 16
Registered: November 2009
Junior Member
Thanks,I have been understand meta data EAnnotations.
But my model info exist in a xml file.
....
<Rule name="View" ></Rule>
<Rule name="Button"></Rule>
<Rule name="HtmlContainer"></Rule>
..

I parse this xml file and Create my emf model
ePackage = ecoreFactory.createEPackage();
ePackage.setName(PACKAGE_NAME);
ePackage.setNsURI(NS_URI);

parsexml()

for(xmlobject) {

createEClasses()
      addAttributes()
      addReference()
}
EList classifiers = ePackage.getEClassifiers();
addClassifier(classifiers, eClasses);


In addReference() I add Button and HtmlContainer object.

So I create My editor include TreeViewer.

This TreeViewer's root is View.

I add Button and HtmlContainer. But there can't transposition

+View
   --Button
   --Button
   --HtmlContainer


The Button can't move down the HtmlContainer.

How can I create my model so that the childNode can be moved random?
+View
   --Button
   --HtmlContainer
   --Button


[Updated on: Fri, 29 January 2010 07:41]

Report message to a moderator

Re: EMF serialize custom xml [message #510920 is a reply to message #510913] Fri, 29 January 2010 02:52 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33145
Registered: July 2009
Senior Member
Robin,

There are no question marks in this posting.


robin wrote:
> Thanks, I have been understand meta data EAnnotations.
> But my model info exist in a xml file.
>
> ...
> <Rule name="View" ></Rule>
> <Rule name="Button" parents="ControlObject"></Rule>
> <Rule name="HtmlContainer" parents="ControlObject"</Rule>
> .
>
> I parse this xml file.
>
> ePackage = ecoreFactory.createEPackage();
> ePackage.setName(PACKAGE_NAME);
> ePackage.setNsURI(NS_URI);
>
> createEClasses()
> addAttributes()
>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF serialize custom xml [message #510923 is a reply to message #510913] Fri, 29 January 2010 08:03 Go to previous messageGo to next message
robin Missing name is currently offline robin Missing nameFriend
Messages: 16
Registered: November 2009
Junior Member
Sorry.Just send question with the wrong key.

Thanks,I have been understand meta data EAnnotations.
But my model info exist in a xml file.
....
<Rule name="View" ></Rule>
<Rule name="Button"></Rule>
<Rule name="HtmlContainer"></Rule>
..

I parse this xml file and Create my emf model
ePackage = ecoreFactory.createEPackage();
ePackage.setName(PACKAGE_NAME);
ePackage.setNsURI(NS_URI);

parsexml()

for(xmlobject) {

createEClasses()
      addAttributes()
      addReference()
}
EList classifiers = ePackage.getEClassifiers();
addClassifier(classifiers, eClasses);


In addReference() I add Button and HtmlContainer object.

So I create My editor include TreeViewer.

This TreeViewer's root is View.

I add Button and HtmlContainer. But there can't transposition

+View
   --Button
   --Button
   --HtmlContainer


The Button can't move down the HtmlContainer.

How can I create my model so that the childNode can be moved random?
+View
   --Button
   --HtmlContainer
   --Button

Re: EMF serialize custom xml [message #510930 is a reply to message #510923] Fri, 29 January 2010 03:42 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33145
Registered: July 2009
Senior Member
Robin,

Either you need a single feature with a type general enough to hold all
possible children, or you'd need something similar to what you'd get if
you had an XML Schema with <xsd:choice maxOccurrs="unbounded">, i.e.,
you'd end up with a feature map into which all the other features would
delegate.


robin wrote:
> Sorry.Just send question with the wrong key.
>
> Thanks,I have been understand meta data EAnnotations.
> But my model info exist in a xml file.
>
> ...
> <Rule name="View" ></Rule>
> <Rule name="Button"></Rule>
> <Rule name="HtmlContainer"></Rule>
> .
>
> I parse this xml file and Create my emf model
>
> ePackage = ecoreFactory.createEPackage();
> ePackage.setName(PACKAGE_NAME);
> ePackage.setNsURI(NS_URI);
>
> parsexml()
>
> for(xmlobject) {
>
> createEClasses()
> addAttributes()
> addReference()
> }
> EList classifiers = ePackage.getEClassifiers();
> addClassifier(classifiers, eClasses);
>
>
> In addReference() I add Button and HtmlContainer object.
>
> So I create My editor include TreeViewer.
>
> This TreeViewer's root is View.
>
> I add Button and HtmlContainer. But there can't transposition
>
>
> +View
> --Button
> --Button
> --HtmlContainer
>
>
> The Button can't move down the HtmlContainer.
>
> How can I create my model so that the childNode can be moved random?
>
> +View
> --Button
> --HtmlContainer
> --Button
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF serialize custom xml [message #511588 is a reply to message #498520] Tue, 02 February 2010 08:18 Go to previous messageGo to next message
robin Missing name is currently offline robin Missing nameFriend
Messages: 16
Registered: November 2009
Junior Member
I choice No.1 solution.
Create a single feature.

controls = ecoreFactory.createEReference();
		complexEClass.getEStructuralFeatures().add(controls);
		controls.setName("controls");
		controls.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY);
		controls.setEType(EcorePackage.Literals.EFEATURE_MAP_ENTRY);
		ExtendedMetaData.INSTANCE.setFeatureKind(controls,
				ExtendedMetaData.GROUP_FEATURE);


Hold all children
EReference reference = ecoreFactory.createEReference();
ExtendedMetaData.INSTANCE.setGroup(reference, controls);

So in TreeViewer I can not inset any child(button,container).
Can you give me some i.e. about example code snippet?
Sorry I'am a slow learner. Sad
Thanks.
Re: EMF serialize custom xml [message #511592 is a reply to message #511588] Tue, 02 February 2010 08:25 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33145
Registered: July 2009
Senior Member
Robin,

Look closely at a schema with repeating choice elements and try to match
that. It's important to mark things derived, volatile, and to ensure
containment is set if you want to support children.


robin wrote:
> I choice No.1 solution. Create a single feature.
>
>
> controls = ecoreFactory.createEReference();
> complexEClass.getEStructuralFeatures().add(controls);
> controls.setName("controls");
> controls.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY) ;
> controls.setEType(EcorePackage.Literals.EFEATURE_MAP_ENTRY);
> ExtendedMetaData.INSTANCE.setFeatureKind(controls,
> ExtendedMetaData.GROUP_FEATURE);
>
>
> Hold all children
>
> EReference reference = ecoreFactory.createEReference();
> ExtendedMetaData.INSTANCE.setGroup(reference, controls);
>
> So in TreeViewer I can not inset any child(button,container).
> Can you give me some i.e. about example code snippet?
> Sorry I'am a slow learner. :( Thanks.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF serialize custom xml [message #511606 is a reply to message #498520] Tue, 02 February 2010 09:07 Go to previous messageGo to next message
robin Missing name is currently offline robin Missing nameFriend
Messages: 16
Registered: November 2009
Junior Member
I have been changed my code.
reference.setVolatile(true);
reference.setDerived(true);
reference.setContainment(true);


But... Sad
Please help me.
How can implement below recipes solution with programmatically emf model?
http://wiki.eclipse.org/EMF/Recipes#Recipe:_Exploiting_Subst itution_Groups_Without_Polluting_Your_Generated_API
Thank you very much.
Re: EMF serialize custom xml [message #511659 is a reply to message #511606] Tue, 02 February 2010 13:20 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33145
Registered: July 2009
Senior Member
Robin,

I've explained how to help yourself. Look at the XSDEcoreBuilder as an
example and write a schema with a repeating choice so you can look
closely at the feature map along with the features that delegate to it.
Don't know how to write a schema? Modify the Library tutorials XSD so
the sequence is a choice and add maxOccurs=:"unbounded"


robin wrote:
> I have been changed my code.
>
> reference.setVolatile(true);
> reference.setDerived(true);
> reference.setContainment(true);
>
>
> But... :( Please help me.
> How can implement below recipes solution with programmatically emf model?
> http://wiki.eclipse.org/EMF/Recipes#Recipe:_Exploiting_Subst itution_Groups_Without_Polluting_Your_Generated_API
>
> Thank you very much.
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF serialize custom xml [message #512136 is a reply to message #498520] Thu, 04 February 2010 06:07 Go to previous messageGo to next message
robin Missing name is currently offline robin Missing nameFriend
Messages: 16
Registered: November 2009
Junior Member
Hi,ed
Thanks for your help.I debug my code.I change my model and override XMLResourceImpl,XMLSaveImpl,XMLLoadImpl and SAXXMLHandler,XMLHelperImpl for my model.
So I succeed. Very Happy
But I can't find more specifically knowledge about xmlload xmlsave,xmlhandler.
Can you give some suggestion for some example?
Re: EMF serialize custom xml [message #512196 is a reply to message #512136] Thu, 04 February 2010 11:23 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33145
Registered: July 2009
Senior Member
Robin,

For what you've described, you'd not need to specialize any of these
things. There's really no significant body of documentation for these
low level implementation classes so you're best to use the debugger to
analyze the dynamic behavior of the source in action.


robin wrote:
> Hi,ed
> Thanks for your help.I debug my code.I change my model and override
> XMLResourceImpl,XMLSaveImpl,XMLLoadImpl and
> SAXXMLHandler,XMLHelperImpl for my model.
> So I succeed. :d But I can't find more specifically knowledge about
> xmlload xmlsave,xmlhandler.
> Can you give some suggestion for some example?


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:The RESTful EMF containment paradox
Next Topic:[DataBinding] FeaturePath for "many" features?
Goto Forum:
  


Current Time: Tue May 07 19:28:31 GMT 2024

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

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

Back to the top