Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » in memory XML representation
in memory XML representation [message #420826] Fri, 11 July 2008 12:28 Go to next message
Nicola Salvo is currently offline Nicola SalvoFriend
Messages: 42
Registered: July 2009
Member
From salvo.nicola@gmail.com Fri Jul 11 13:26:12 2008
Subject: in memory XML representation
From: Nicola Salvo <salvo.nicola@gmail.com>
X-Evolution-PostTo:
nntp://exquisitus@news.eclipse.org:119/eclipse.tools.emf
In-Reply-To: <g56s8q$9f2$1@build.eclipse.org>
References: <g56s8q$9f2$1@build.eclipse.org>
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
X-Evolution-Format: text/plain
X-Evolution-Account: 1215424214.5117.1@deepthought.gt4
X-Evolution-Transport:
smtp://salvo.nicola%40gmail.com;auth=PLAIN@smpt.gmail.com:587/;use_ssl=always
X-Evolution-Fcc: mbox:/home/rootto/.evolution/mail/local#Sent
X-Mailer: Evolution 2.22.2
Date: Fri, 11 Jul 2008 13:26:12 +0100
Message-Id: <1215779172.2758.18.camel@deepthought.gt4>
Mime-Version: 1.0

Hello,

I'm back with another problem. I need to obtain a in memory
representation, of the workflow modelled with GMF/EMF in order to deploy
it on a server. Searching on the archive I found this:
http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg1 8706.html

that answer to my question building a org.w3c.dom.Document. I wrapped
the code in a subMenu action, and in the selectionChanged method, I get
the WorkflowTypeEditPart in order receive the editingDomain (am I
right?). This is the run method:


public void run(IAction action) {

DocumentBuilderFactory documentBuilderFactory =
DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder documentBuilder;
try {
documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.newDocument();

ResourceSet resourceSet =
mySelectedElement.getEditingDomain().getResourceSet();
for(Resource resource:resourceSet.getResources()){
((XMLResource)resource).save (document, null, null);
}
TransformerFactory transformerFactory =
TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();

transformer.transform(new DOMSource(document), new
StreamResult(System.out));

}

and this it the error I receive:

org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to
insert a node where it is not permitted.
at org.apache.xerces.dom.CoreDocumentImpl.insertBefore(Unknown Source)
at org.apache.xerces.dom.NodeImpl.appendChild(Unknown Source)
at
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSa veImpl.java:1139)
at
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSa veImpl.java:1017)
at
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementFeatur eMap(XMLSaveImpl.java:2417)
at
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1480)
at
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XM LSaveImpl.java:725)
at
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveI mpl.java:588)
at
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:206)
at
org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.save(XMLResou rceImpl.java:282)
at
gsoc.ogsdai.custom.actions.DeployWorkflowAction.run(DeployWo rkflowAction.java:74)

I suppose is something wrong with the ResourceSet (debugging I notice
that the exception is raised after few iterations), but I don't know how
to solve the problem. Any help would be more than appreciated :)
Cheers

Nicola
Re: in memory XML representation [message #420829 is a reply to message #420826] Fri, 11 July 2008 13:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Nicola,

If you just tried to save to an string writer and checked the result, is
it well formed XML?

currentNode =
currentNode.appendChild(document.createElementNS(nameInfo.ge tNamespaceURI(),
nameInfo.getQualifiedName()));

Given the above line, I'm suspicious that there aren't perhaps two
features set on the document root and hence it's trying to create two
root elements...


Nicola Salvo wrote:
> From salvo.nicola@gmail.com Fri Jul 11 13:26:12 2008
> Subject: in memory XML representation
> From: Nicola Salvo <salvo.nicola@gmail.com>
> X-Evolution-PostTo:
> nntp://exquisitus@news.eclipse.org:119/eclipse.tools.emf
> In-Reply-To: <g56s8q$9f2$1@build.eclipse.org>
> References: <g56s8q$9f2$1@build.eclipse.org>
> Content-Type: text/plain
> Content-Transfer-Encoding: 7bit
> X-Evolution-Format: text/plain
> X-Evolution-Account: 1215424214.5117.1@deepthought.gt4
> X-Evolution-Transport:
> smtp://salvo.nicola%40gmail.com;auth=PLAIN@smpt.gmail.com:587/;use_ssl=always
>
> X-Evolution-Fcc: mbox:/home/rootto/.evolution/mail/local#Sent
> X-Mailer: Evolution 2.22.2 Date: Fri, 11 Jul 2008 13:26:12 +0100
> Message-Id: <1215779172.2758.18.camel@deepthought.gt4>
> Mime-Version: 1.0
>
> Hello,
>
> I'm back with another problem. I need to obtain a in memory
> representation, of the workflow modelled with GMF/EMF in order to deploy
> it on a server. Searching on the archive I found this:
> http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg1 8706.html
>
> that answer to my question building a org.w3c.dom.Document. I wrapped
> the code in a subMenu action, and in the selectionChanged method, I get
> the WorkflowTypeEditPart in order receive the editingDomain (am I
> right?). This is the run method:
>
>
> public void run(IAction action) {
>
> DocumentBuilderFactory documentBuilderFactory =
> DocumentBuilderFactory.newInstance();
> documentBuilderFactory.setNamespaceAware(true);
> DocumentBuilder documentBuilder;
> try {
> documentBuilder = documentBuilderFactory.newDocumentBuilder();
> Document document = documentBuilder.newDocument();
>
> ResourceSet resourceSet =
> mySelectedElement.getEditingDomain().getResourceSet();
> for(Resource resource:resourceSet.getResources()){
> ((XMLResource)resource).save (document, null, null);
> }
> TransformerFactory transformerFactory =
> TransformerFactory.newInstance();
> Transformer transformer = transformerFactory.newTransformer();
>
> transformer.transform(new DOMSource(document), new
> StreamResult(System.out));
>
> }
>
> and this it the error I receive:
>
> org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to
> insert a node where it is not permitted. at
> org.apache.xerces.dom.CoreDocumentImpl.insertBefore(Unknown Source)
> at org.apache.xerces.dom.NodeImpl.appendChild(Unknown Source)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSa veImpl.java:1139)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSa veImpl.java:1017)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementFeatur eMap(XMLSaveImpl.java:2417)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1480)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XM LSaveImpl.java:725)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveI mpl.java:588)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:206)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.save(XMLResou rceImpl.java:282)
>
> at
> gsoc.ogsdai.custom.actions.DeployWorkflowAction.run(DeployWo rkflowAction.java:74)
>
>
> I suppose is something wrong with the ResourceSet (debugging I notice
> that the exception is raised after few iterations), but I don't know how
> to solve the problem. Any help would be more than appreciated :)
> Cheers
>
> Nicola
>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: in memory XML representation [message #420830 is a reply to message #420829] Fri, 11 July 2008 14:06 Go to previous messageGo to next message
Nicola Salvo is currently offline Nicola SalvoFriend
Messages: 42
Registered: July 2009
Member
Hello Ed,

thanks for the hint! I solved the problem following your hint. The
resourceSet contains two resources thus in the second iteration the
Document class was complaining. I solved changing the code in this way:

for(Resource resource: resourceSet.getResources()){
if(resource instanceof ModelResourceImpl)
((XMLResource)resource).save (document, null, null);
}

Even if I struggled for a while with GMF/EMF for a while, some concepts
are still mysterious:)
Again thank you!

Ed Merks wrote:

> Nicola,

> If you just tried to save to an string writer and checked the result, is
> it well formed XML?

> currentNode =
> currentNode.appendChild(document.createElementNS(nameInfo.ge tNamespaceURI(),
> nameInfo.getQualifiedName()));

> Given the above line, I'm suspicious that there aren't perhaps two
> features set on the document root and hence it's trying to create two
> root elements...


> Nicola Salvo wrote:
>> From salvo.nicola@gmail.com Fri Jul 11 13:26:12 2008
>> Subject: in memory XML representation
>> From: Nicola Salvo <salvo.nicola@gmail.com>
>> X-Evolution-PostTo:
>> nntp://exquisitus@news.eclipse.org:119/eclipse.tools.emf
>> In-Reply-To: <g56s8q$9f2$1@build.eclipse.org>
>> References: <g56s8q$9f2$1@build.eclipse.org>
>> Content-Type: text/plain
>> Content-Transfer-Encoding: 7bit
>> X-Evolution-Format: text/plain
>> X-Evolution-Account: 1215424214.5117.1@deepthought.gt4
>> X-Evolution-Transport:
>>
smtp://salvo.nicola%40gmail.com;auth=PLAIN@smpt.gmail.com:587/;use_ssl=always
>>
>> X-Evolution-Fcc: mbox:/home/rootto/.evolution/mail/local#Sent
>> X-Mailer: Evolution 2.22.2 Date: Fri, 11 Jul 2008 13:26:12 +0100
>> Message-Id: <1215779172.2758.18.camel@deepthought.gt4>
>> Mime-Version: 1.0
>>
>> Hello,
>>
>> I'm back with another problem. I need to obtain a in memory
>> representation, of the workflow modelled with GMF/EMF in order to deploy
>> it on a server. Searching on the archive I found this:
>> http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg1 8706.html
>>
>> that answer to my question building a org.w3c.dom.Document. I wrapped
>> the code in a subMenu action, and in the selectionChanged method, I get
>> the WorkflowTypeEditPart in order receive the editingDomain (am I
>> right?). This is the run method:
>>
>>
>> public void run(IAction action) {
>>
>> DocumentBuilderFactory documentBuilderFactory =
>> DocumentBuilderFactory.newInstance();
>> documentBuilderFactory.setNamespaceAware(true);
>> DocumentBuilder documentBuilder;
>> try {
>> documentBuilder = documentBuilderFactory.newDocumentBuilder();
>> Document document = documentBuilder.newDocument();
>>
>> ResourceSet resourceSet =
>> mySelectedElement.getEditingDomain().getResourceSet();
>> for(Resource resource:resourceSet.getResources()){
>> ((XMLResource)resource).save (document, null, null);
>> }
>> TransformerFactory transformerFactory =
>> TransformerFactory.newInstance();
>> Transformer transformer = transformerFactory.newTransformer();
>>
>> transformer.transform(new DOMSource(document), new
>> StreamResult(System.out));
>>
>> }
>>
>> and this it the error I receive:
>>
>> org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to
>> insert a node where it is not permitted. at
>> org.apache.xerces.dom.CoreDocumentImpl.insertBefore(Unknown Source)
>> at org.apache.xerces.dom.NodeImpl.appendChild(Unknown Source)
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSa veImpl.java:1139)
>>
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSa veImpl.java:1017)
>>
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementFeatur eMap(XMLSaveImpl.java:2417)
>>
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1480)
>>
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XM LSaveImpl.java:725)
>>
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveI mpl.java:588)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:206)
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.save(XMLResou rceImpl.java:282)
>>
>> at
>>
gsoc.ogsdai.custom.actions.DeployWorkflowAction.run(DeployWo rkflowAction.java:74)
>>
>>
>> I suppose is something wrong with the ResourceSet (debugging I notice
>> that the exception is raised after few iterations), but I don't know how
>> to solve the problem. Any help would be more than appreciated :)
>> Cheers
>>
>> Nicola
>>
>>
>>
>>
Re: in memory XML representation [message #420831 is a reply to message #420830] Fri, 11 July 2008 14:39 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Nicola,

Oh, I see the problem now. You might and do end up calling this for
multiple resources so you really ought to have a break statement or not
be doing it in a loop.


Nicola Salvo wrote:
> Hello Ed,
>
> thanks for the hint! I solved the problem following your hint. The
> resourceSet contains two resources thus in the second iteration the
> Document class was complaining. I solved changing the code in this way:
>
> for(Resource resource: resourceSet.getResources()){
> if(resource instanceof ModelResourceImpl)
> ((XMLResource)resource).save (document, null, null);
> }
>
> Even if I struggled for a while with GMF/EMF for a while, some
> concepts are still mysterious:) Again thank you!
>
> Ed Merks wrote:
>
>> Nicola,
>
>> If you just tried to save to an string writer and checked the result,
>> is it well formed XML?
>
>> currentNode =
>> currentNode.appendChild(document.createElementNS(nameInfo.ge tNamespaceURI(),
>> nameInfo.getQualifiedName()));
>
>> Given the above line, I'm suspicious that there aren't perhaps two
>> features set on the document root and hence it's trying to create two
>> root elements...
>
>
>> Nicola Salvo wrote:
>>> From salvo.nicola@gmail.com Fri Jul 11 13:26:12 2008
>>> Subject: in memory XML representation
>>> From: Nicola Salvo <salvo.nicola@gmail.com>
>>> X-Evolution-PostTo:
>>> nntp://exquisitus@news.eclipse.org:119/eclipse.tools.emf
>>> In-Reply-To: <g56s8q$9f2$1@build.eclipse.org>
>>> References: <g56s8q$9f2$1@build.eclipse.org>
>>> Content-Type: text/plain
>>> Content-Transfer-Encoding: 7bit
>>> X-Evolution-Format: text/plain
>>> X-Evolution-Account: 1215424214.5117.1@deepthought.gt4
>>> X-Evolution-Transport:
>>>
> smtp://salvo.nicola%40gmail.com;auth=PLAIN@smpt.gmail.com:587/;use_ssl=always
>
>>>
>>> X-Evolution-Fcc: mbox:/home/rootto/.evolution/mail/local#Sent
>>> X-Mailer: Evolution 2.22.2 Date: Fri, 11 Jul 2008 13:26:12 +0100
>>> Message-Id: <1215779172.2758.18.camel@deepthought.gt4>
>>> Mime-Version: 1.0
>>>
>>> Hello,
>>>
>>> I'm back with another problem. I need to obtain a in memory
>>> representation, of the workflow modelled with GMF/EMF in order to
>>> deploy
>>> it on a server. Searching on the archive I found this:
>>> http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg1 8706.html
>>>
>>> that answer to my question building a org.w3c.dom.Document. I wrapped
>>> the code in a subMenu action, and in the selectionChanged method, I get
>>> the WorkflowTypeEditPart in order receive the editingDomain (am I
>>> right?). This is the run method:
>>>
>>>
>>> public void run(IAction action) {
>>> DocumentBuilderFactory documentBuilderFactory =
>>> DocumentBuilderFactory.newInstance();
>>> documentBuilderFactory.setNamespaceAware(true);
>>> DocumentBuilder documentBuilder;
>>> try {
>>> documentBuilder = documentBuilderFactory.newDocumentBuilder();
>>> Document document = documentBuilder.newDocument();
>>> ResourceSet resourceSet =
>>> mySelectedElement.getEditingDomain().getResourceSet();
>>> for(Resource resource:resourceSet.getResources()){
>>> ((XMLResource)resource).save (document, null, null);
>>> }
>>> TransformerFactory transformerFactory =
>>> TransformerFactory.newInstance();
>>> Transformer transformer = transformerFactory.newTransformer();
>>> transformer.transform(new DOMSource(document), new
>>> StreamResult(System.out));
>>> }
>>>
>>> and this it the error I receive:
>>>
>>> org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to
>>> insert a node where it is not permitted. at
>>> org.apache.xerces.dom.CoreDocumentImpl.insertBefore(Unknown Source)
>>> at org.apache.xerces.dom.NodeImpl.appendChild(Unknown Source)
>>> at
>>>
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSa veImpl.java:1139)
>
>>>
>>> at
>>>
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSa veImpl.java:1017)
>
>>>
>>> at
>>>
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementFeatur eMap(XMLSaveImpl.java:2417)
>
>>>
>>> at
>>>
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1480)
>
>>>
>>> at
>>>
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XM LSaveImpl.java:725)
>
>>>
>>> at
>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveI mpl.java:588)
>>>
>>> at
>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:206)
>>> at
>>>
> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.save(XMLResou rceImpl.java:282)
>
>>>
>>> at
>>>
> gsoc.ogsdai.custom.actions.DeployWorkflowAction.run(DeployWo rkflowAction.java:74)
>
>>>
>>>
>>> I suppose is something wrong with the ResourceSet (debugging I notice
>>> that the exception is raised after few iterations), but I don't know
>>> how
>>> to solve the problem. Any help would be more than appreciated :)
>>> Cheers
>>>
>>> Nicola
>>>
>>>
>>>
>>>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:tree editors with different structures
Next Topic:Ecore vs XML
Goto Forum:
  


Current Time: Thu Apr 25 11:28:37 GMT 2024

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

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

Back to the top