Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » generating xml-structured file beside the generated xmi file
generating xml-structured file beside the generated xmi file [message #839844] Mon, 09 April 2012 05:27 Go to next message
Eclipse UserFriend
Hello All,

I'm trying to generate xml-structured file beside the already generated xmi file, the problem is i got lots of nested elements...so i need to loop for all the created elements and create the file accordingly.

Is there any way that i could loop for all the created elements after saving the file not while writing and modifying it? (because while writing is going to be kinda messy)

below you can find the generated XMI structure, my structure should be quite similar too:

<?xml version="1.0" encoding="UTF-8"?>
<umlt:ModelUMLT>
<packagedElement xsi:type="umlt:PackageUMLT">
<packagedElement xsi:type="umlt:TransformationActivity">
<node xsi:type="umlt:StructuredTransformation">
<node xsi:type="umlt:TransformationAction">
<ownedMapping>
<ownedAssignmentDef name="a.b:=7">
<ownedExpression xsi:type="uml:Expression">
<name xsi:nil="true"/>
<symbol xsi:nil="true"/>
<operand xsi:type="uml:OpaqueExpression">
<name xsi:nil="true"/>
</operand>
<operand xsi:type="uml:OpaqueExpression">
<body xsi:nil="true"/>
</operand>
</ownedExpression>
</ownedAssignmentDef>
<ownedAssignmentDef name="a.b.c:=3">
<ownedExpression xsi:type="uml:Expression">
<name xsi:nil="true"/>
<symbol xsi:nil="true"/>
<operand xsi:type="uml:OpaqueExpression">
<name xsi:nil="true"/>
</operand>
<operand xsi:type="uml:OpaqueExpression">
<body xsi:nil="true"/>
</operand>
</ownedExpression>
</ownedAssignmentDef>
</ownedMapping>
</node>
<node xsi:type="umlt:TransformationAction">
<ownedMapping>
<ownedAssignmentDef name="a.b.c.d:=15">
<ownedExpression xsi:type="uml:Expression">
<name xsi:nil="true"/>
<symbol xsi:nil="true"/>
<operand xsi:type="uml:OpaqueExpression">
<name xsi:nil="true"/>
</operand>
<operand xsi:type="uml:OpaqueExpression">
<body xsi:nil="true"/>
</operand>
</ownedExpression>
</ownedAssignmentDef>
</ownedMapping>
</node>
</node>
</packagedElement>
</packagedElement>
</umlt:ModelUMLT>

Thanks in Advance and happy easter:)
Mostafa.
Re: generating xml-structured file beside the generated xmi file [message #839858 is a reply to message #839844] Mon, 09 April 2012 05:49 Go to previous messageGo to next message
Eclipse UserFriend
Mostafa,

Comments below.

On 09/04/2012 11:27 AM, Mostafa Fouly wrote:
> Hello All,
>
> I'm trying to generate xml-structured file beside the already
> generated xmi file, the problem is i got lots of nested elements...so
> i need to loop for all the created elements and create the file
> accordingly.
Resource.eAllContents will walk the whole tree...
>
> Is there any way that i could loop for all the created elements after
> saving the file not while writing and modifying it? (because while
> writing is going to be kinda messy)
I don't follow what you're asking...
>
> below you can find the generated XMI structure, my structure should be
> quite similar too:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <umlt:ModelUMLT>
> <packagedElement xsi:type="umlt:PackageUMLT">
> <packagedElement xsi:type="umlt:TransformationActivity">
> <node xsi:type="umlt:StructuredTransformation">
> <node xsi:type="umlt:TransformationAction">
> <ownedMapping>
> <ownedAssignmentDef name="a.b:=7">
> <ownedExpression xsi:type="uml:Expression">
> <name xsi:nil="true"/>
> <symbol xsi:nil="true"/>
> <operand xsi:type="uml:OpaqueExpression">
> <name xsi:nil="true"/>
> </operand>
> <operand xsi:type="uml:OpaqueExpression">
> <body xsi:nil="true"/>
> </operand>
> </ownedExpression>
> </ownedAssignmentDef>
> <ownedAssignmentDef name="a.b.c:=3">
> <ownedExpression xsi:type="uml:Expression">
> <name xsi:nil="true"/>
> <symbol xsi:nil="true"/>
> <operand xsi:type="uml:OpaqueExpression">
> <name xsi:nil="true"/>
> </operand>
> <operand xsi:type="uml:OpaqueExpression">
> <body xsi:nil="true"/>
> </operand>
> </ownedExpression>
> </ownedAssignmentDef>
> </ownedMapping>
> </node>
> <node xsi:type="umlt:TransformationAction">
> <ownedMapping>
> <ownedAssignmentDef name="a.b.c.d:=15">
> <ownedExpression xsi:type="uml:Expression">
> <name xsi:nil="true"/>
> <symbol xsi:nil="true"/>
> <operand xsi:type="uml:OpaqueExpression">
> <name xsi:nil="true"/>
> </operand>
> <operand xsi:type="uml:OpaqueExpression">
> <body xsi:nil="true"/>
> </operand>
> </ownedExpression>
> </ownedAssignmentDef>
> </ownedMapping>
> </node>
> </node>
> </packagedElement>
> </packagedElement>
> </umlt:ModelUMLT>
>
> Thanks in Advance and happy easter:)
> Mostafa.
Re: generating xml-structured file beside the generated xmi file [message #840626 is a reply to message #839858] Tue, 10 April 2012 06:06 Go to previous messageGo to next message
Eclipse UserFriend
well, thanks for your quick reply...

let me show you the complete scenario:

-Create the diagram
-create the elements inside that diagram.
-saving the diagram should fire the event for looping for all the elements and creating the xml-structured file accordingly.

i have checked the eAllContents method and googled it and indeed that's what i need according to the online documentation!
TreeIterator<EObject> treeIterator = diagram.eAllContents();

but the point is i couldn't retrieve all the elements in my diagram...below is a code snippet i created for retrieving the diagram's elements:

org.eclipse.emf.ecore.resource.Resource diagramResource = umlt.diagram.part.UMLTCreationWizard.getDiagram();

TreeIterator<EObject> treeIterator = diagramResource.getAllContents();

while (treeIterator.hasNext()) {

EObject diagramEl = treeIterator.next();

String name = diagramEl.eClass().getName();

System.out.println("diagramEl.eClass().getName(): " + name);

}

the expected output was all the elements' names within that diagram, while the current output ist:
diagramEl.eClass().getName(): Diagram
diagramEl.eClass().getName(): DiagramStyle

please have a look over the attached snapshot to get a clearer idea on how to diagram looks like
index.php/fa/7842/0/

thx!
mostafa.
  • Attachment: diagram.JPG
    (Size: 143.27KB, Downloaded 570 times)
Re: generating xml-structured file beside the generated xmi file [message #840734 is a reply to message #840626] Tue, 10 April 2012 08:59 Go to previous messageGo to next message
Eclipse UserFriend
Moustafa,

Comments below.

On 10/04/2012 12:06 PM, Mostafa Fouly wrote:
> well, thanks for your quick reply...
>
> let me show you the complete scenario:
>
> -Create the diagram
> -create the elements inside that diagram.
> -saving the diagram should fire the event for looping for all the elements and creating the xml-structured file accordingly.
>
> i have checked the eAllContents method and googled it and indeed that's what i need according to the online documentation!
> TreeIterator<EObject> treeIterator = diagram.eAllContents();
>
> but the point is i couldn't retrieve all the elements in my diagram...below is a code snippet i created for retrieving the diagram's elements:
>
> org.eclipse.emf.ecore.resource.Resource diagramResource = umlt.diagram.part.UMLTCreationWizard.getDiagram();
>
> TreeIterator<EObject> treeIterator = diagramResource.getAllContents();
>
> while (treeIterator.hasNext()) {
>
> EObject diagramEl = treeIterator.next();
>
> String name = diagramEl.eClass().getName();
>
> System.out.println("diagramEl.eClass().getName(): " + name);
>
> }
>
> the expected output was all the elements' names within that diagram, while the current output ist:
> diagramEl.eClass().getName(): Diagram
> diagramEl.eClass().getName(): DiagramStyle
What does the XML for this resource look like? I imagine it only has
these two levels of nesting...
>
> please have a look over the attached snapshot to get a clearer idea on how to diagram looks like
>
>
> thx!
> mostafa.
Re: generating xml-structured file beside the generated xmi file [message #840740 is a reply to message #840734] Tue, 10 April 2012 09:07 Go to previous messageGo to next message
Eclipse UserFriend
Hi Ed,

do you think a model2text transformation language could help moustafa further? This could take care of a lot of things which he would need to do by hand otherwise.

Ralph
Re: generating xml-structured file beside the generated xmi file [message #840747 is a reply to message #840740] Tue, 10 April 2012 09:11 Go to previous messageGo to next message
Eclipse UserFriend
Ralph,

I suspect that he wants to create some model and serialize it as
XML/XMI, but it's all been pretty vague so far...


On 10/04/2012 3:07 PM, Ralph Gerbig wrote:
> Hi Ed,
>
> do you think a model2text transformation language could help moustafa
> further? This could take care of a lot of things which he would need
> to do by hand otherwise.
>
> Ralph
Re: generating xml-structured file beside the generated xmi file [message #845718 is a reply to message #840734] Sun, 15 April 2012 06:44 Go to previous messageGo to next message
Eclipse UserFriend
Hey Ed,

the model looks like the snap shot below:
index.php/fa/7899/0/

and for the xmi structure:

<?xml version="1.0" encoding="UTF-8"?>
<umlt:ModelUMLT xmlns:xsi="" xmlns:uml="" xmlns:umlt="">
<packagedElement xsi:type="umlt:PackageUMLT">
<packagedElement xsi:type="umlt:TransformationActivity">
<node xsi:type="umlt:StructuredTransformation">
<node xsi:type="umlt:TransformationAction">
<ownedMapping>
<ownedAssignmentDef name="a.b.c.d:=7">
<ownedExpression xsi:type="uml:Expression">
<name xsi:nil="true"/>
<symbol xsi:nil="true"/>
<operand xsi:type="uml:OpaqueExpression">
<name xsi:nil="true"/>
</operand>
<operand xsi:type="uml:OpaqueExpression">
<body xsi:nil="true"/>
</operand>
</ownedExpression>
</ownedAssignmentDef>
</ownedMapping>
</node>
</node>
</packagedElement>
</packagedElement>
</umlt:ModelUMLT>

for the xml:

<?xml version="1.0" encoding="UTF-8"?>
<notation:Diagram xmi:version="2.0" xmlns:xmi="" xmlns:notation="" xmlns:umlt="" xmi:id="_ODQmAYblEeGF2rapLL5tLQ" type="UMLT" name="default21.umlt_diagram" measurementUnit="Pixel">
<children xmi:type="notation:Node" xmi:id="_PFFPYIblEeGF2rapLL5tLQ" type="2001">
<children xmi:type="notation:DecorationNode" xmi:id="_PFKH4IblEeGF2rapLL5tLQ" type="5013"/>
<children xmi:type="notation:DecorationNode" xmi:id="_PFL9EIblEeGF2rapLL5tLQ" type="7001">
<styles xmi:type="notation:SortingStyle" xmi:id="_PFL9EYblEeGF2rapLL5tLQ"/>
<styles xmi:type="notation:FilteringStyle" xmi:id="_PFL9EoblEeGF2rapLL5tLQ"/>
</children>
<children xmi:type="notation:DecorationNode" xmi:id="_PFMkIIblEeGF2rapLL5tLQ" type="7002">
<children xmi:type="notation:Shape" xmi:id="_Q4DB0IblEeGF2rapLL5tLQ" type="3001" fontName="Segoe UI">
<children xmi:type="notation:DecorationNode" xmi:id="_Q4Do4IblEeGF2rapLL5tLQ" type="5012"/>
<children xmi:type="notation:DecorationNode" xmi:id="_Q4Do4YblEeGF2rapLL5tLQ" type="7003">
<children xmi:type="notation:Node" xmi:id="_ShXJAIblEeGF2rapLL5tLQ" type="3002">
<children xmi:type="notation:DecorationNode" xmi:id="_ShXwEIblEeGF2rapLL5tLQ" type="5011"/>
<children xmi:type="notation:DecorationNode" xmi:id="_ShXwEYblEeGF2rapLL5tLQ" type="7004">
<children xmi:type="notation:Node" xmi:id="_S-z6AIblEeGF2rapLL5tLQ" type="3009">
<children xmi:type="notation:DecorationNode" xmi:id="_S-1IIIblEeGF2rapLL5tLQ" type="5007"/>
<children xmi:type="notation:DecorationNode" xmi:id="_S-1IIYblEeGF2rapLL5tLQ" type="7005">
<children xmi:type="notation:Node" xmi:id="_YGwrQIblEeGF2rapLL5tLQ" type="3012">
<children xmi:type="notation:DecorationNode" xmi:id="_YGxSUIblEeGF2rapLL5tLQ" type="5006"/>
<children xmi:type="notation:DecorationNode" xmi:id="_YGxSUYblEeGF2rapLL5tLQ" type="7006">
<styles xmi:type="notation:SortingStyle" xmi:id="_YGxSUoblEeGF2rapLL5tLQ"/>
<styles xmi:type="notation:FilteringStyle" xmi:id="_YGx5YIblEeGF2rapLL5tLQ"/>
</children>
<styles xmi:type="notation:DescriptionStyle" xmi:id="_YGwrQYblEeGF2rapLL5tLQ"/>
<styles xmi:type="notation:FontStyle" xmi:id="_YGwrQoblEeGF2rapLL5tLQ" fontName="Segoe UI"/>
<styles xmi:type="notation:FillStyle" xmi:id="_YGwrQ4blEeGF2rapLL5tLQ"/>
<element xmi:type="umlt:MappingRule" href="default24.umlt#//@packagedElement.0/@packagedElement.0/@node.0/@node.0/@ownedMapping.0"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_YGwrRIblEeGF2rapLL5tLQ" x="269" y="11" height="77"/>
</children>
</children>
<styles xmi:type="notation:DescriptionStyle" xmi:id="_S-z6AYblEeGF2rapLL5tLQ"/>
<styles xmi:type="notation:FontStyle" xmi:id="_S-z6AoblEeGF2rapLL5tLQ" fontName="Segoe UI"/>
<styles xmi:type="notation:FillStyle" xmi:id="_S-z6A4blEeGF2rapLL5tLQ"/>
<element xmi:type="umlt:TransformationAction" href="default24.umlt#//@packagedElement.0/@packagedElement.0/@node.0/@node.0"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_S-z6BIblEeGF2rapLL5tLQ" x="235" y="5" height="210"/>
</children>
</children>
<styles xmi:type="notation:DescriptionStyle" xmi:id="_ShXJAYblEeGF2rapLL5tLQ"/>
<styles xmi:type="notation:FontStyle" xmi:id="_ShXJAoblEeGF2rapLL5tLQ" fontName="Segoe UI"/>
<styles xmi:type="notation:FillStyle" xmi:id="_ShXJA4blEeGF2rapLL5tLQ"/>
<element xmi:type="umlt:StructuredTransformation" href="default24.umlt#//@packagedElement.0/@packagedElement.0/@node.0"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_ShXJBIblEeGF2rapLL5tLQ" x="157" y="2"/>
</children>
</children>
<element xmi:type="umlt:TransformationActivity" href="default24.umlt#//@packagedElement.0/@packagedElement.0"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_Q4DB0YblEeGF2rapLL5tLQ" x="225"/>
</children>
</children>
<styles xmi:type="notation:DescriptionStyle" xmi:id="_PFFPYYblEeGF2rapLL5tLQ"/>
<styles xmi:type="notation:FontStyle" xmi:id="_PFFPYoblEeGF2rapLL5tLQ" fontName="Segoe UI"/>
<styles xmi:type="notation:LineStyle" xmi:id="_PFFPY4blEeGF2rapLL5tLQ"/>
<element xmi:type="umlt:PackageUMLT" href="default24.umlt#//@packagedElement.0"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_PFFPZIblEeGF2rapLL5tLQ" x="133" y="42"/>
</children>
<styles xmi:type="notation:DiagramStyle" xmi:id="_ODRNEIblEeGF2rapLL5tLQ"/>
<element xmi:type="umlt:ModelUMLT" href="default24.umlt#/"/>
</notation:Diagram>

=========================================================

i've also tried working with some other way for showing the view but it only shows the hierarchy and not all the contents...
So for example if i got a schema like the following:

ModelUMLT --> PackageUMLT --> TransformationActivity --> Structured Transformation Activity --> Mapping Rules --> Assignment Definition

if i got single Assignment Definition the result will be the same as if we got a couple of Assignment Definitions...

  • Attachment: Model.JPG
    (Size: 50.89KB, Downloaded 544 times)
Re: generating xml-structured file beside the generated xmi file [message #845774 is a reply to message #845718] Sun, 15 April 2012 08:12 Go to previous messageGo to next message
Eclipse UserFriend
may i ask another piece of question?
at what event/method exactly does the xml/xmi file is generated? when we add new elements to our diagram and save the file, the xml/xmi file is updated accordingly, which event is called then?

Mostafa
Re: generating xml-structured file beside the generated xmi file [message #845844 is a reply to message #845774] Sun, 15 April 2012 09:26 Go to previous messageGo to next message
Eclipse UserFriend
well to make it clearer i am trying to find where and how does the editor itself generate the xml/xmi structure...
Re: generating xml-structured file beside the generated xmi file [message #848466 is a reply to message #845844] Wed, 18 April 2012 04:51 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

take a look at the generated xxxDiagramEditor and its performSave method.

Cheers,

Ralph
Re: generating xml-structured file beside the generated xmi file [message #856049 is a reply to message #848466] Wed, 25 April 2012 06:17 Go to previous message
Eclipse UserFriend
Hey Ralph,

I checked that class but i didn't find that method, i found: "performSaveAs" and "doSaveAs" methods though!

at the xxxDocumentProvider class there's another method performing the same functionality which is "doSaveDocument"

Thanks a lot for your help!

mostafa.
Previous Topic:Extension point has stopped working
Next Topic:Adding buttons to the elements
Goto Forum:
  


Current Time: Fri Jul 04 11:29:43 EDT 2025

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

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

Back to the top