Home » Modeling » EMF » Loading resource interception...(Intercept DOM while loading a resource)
Loading resource interception... [message #528547] |
Tue, 20 April 2010 22:08 |
Babloo Messages: 12 Registered: September 2009 |
Junior Member |
|
|
Hello there,
I am trying to load a xml file into XMLResource using a resourceset.
The following code snippet works fine...
//code fragment in init a resourceSet.
ResourceSet resourceSet;
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new ModelXMLResourceFactory());
resourceSet.getPackageRegistry().put(CommonPackage.eNS_URI, CommonPackage.eINSTANCE);
resourceSet.setURIConverter(new ModelURNConverter());
public EObject loadEObject(URI uri) {
Resource resource = resourceSet.createResource(uri);
try {
resource.load(null);
} catch (IOException e) {
throw new RuntimeException("Error occured while reading EObject to file", e);
}
return resource.getContents().get(0);
}
I have some persisted XML in filesystem that can load fine.
Now, I have some changes made to the ECore file where I have moved some attributes around. Is there a way I could transform this persisted XML file, while the resource is being loaded?
Also wondering, if I could do the reverse, where I might be able to transform the newly generated XML back to another file.
I could write some XSLs to do load & save. But, I would need some advice on the hooks where I could do the load resource / save resource transformation.
Thanks,
Babloo
|
|
|
Re: Loading resource interception... [message #528683 is a reply to message #528547] |
Wed, 21 April 2010 13:04 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------090708030807020401010308
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Babloo,
This is likely useful:
5.1 Recipe: Data Migration
<http://wiki.eclipse.org/EMF/Recipes#Recipe:_Data_Migration>
Babloo wrote:
> Hello there,
>
> I am trying to load a xml file into XMLResource using a resourceset.
> The following code snippet works fine...
>
>
> //code fragment in init a resourceSet.
> ResourceSet resourceSet;
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "*",
> new ModelXMLResourceFactory());
> resourceSet.getPackageRegistry().put(CommonPackage.eNS_URI,
> CommonPackage.eINSTANCE);
> resourceSet.setURIConverter(new ModelURNConverter());
>
> public EObject loadEObject(URI uri) {
> Resource resource = resourceSet.createResource(uri);
> try {
> resource.load(null);
> } catch (IOException e) {
> throw new RuntimeException("Error occured while reading
> EObject to file", e);
> }
> return resource.getContents().get(0);
> }
>
>
> I have some persisted XML in filesystem that can load fine.
> Now, I have some changes made to the ECore file where I have moved
> some attributes around. Is there a way I could transform this
> persisted XML file, while the resource is being loaded?
> Also wondering, if I could do the reverse, where I might be able to
> transform the newly generated XML back to another file.
> I could write some XSLs to do load & save. But, I would need some
> advice on the hooks where I could do the load resource / save resource
> transformation.
>
> Thanks,
> Babloo
>
--------------090708030807020401010308
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">
Babloo,<br>
<br>
This is likely useful:<br>
<blockquote><a
href="http://wiki.eclipse.org/EMF/Recipes#Recipe:_Data_Migration"><span
class="tocnumber">5.1</span> <span class="toctext">Recipe: Data
Migration</span></a><br>
</blockquote>
<br>
Babloo wrote:
<blockquote cite="mid:hql8kt$ofe$1@build.eclipse.org" type="cite">Hello
there,
<br>
<br>
I am trying to load a xml file into XMLResource using a resourceset.
The following code snippet works fine...
<br>
<br>
<br>
//code fragment in init a resourceSet.
<br>
ResourceSet resourceSet;
<br>
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "*",
new ModelXMLResourceFactory());
<br>
resourceSet.getPackageRegistry().put(CommonPackage.eNS_URI,
CommonPackage.eINSTANCE);
<br>
resourceSet.setURIConverter(new ModelURNConverter());
<br>
<br>
public EObject loadEObject(URI uri) {
<br>
Resource resource = resourceSet.createResource(uri);
<br>
try {
<br>
resource.load(null);
<br>
} catch (IOException e) {
<br>
throw new RuntimeException("Error occured while reading
EObject to file", e);
<br>
}
<br>
return resource.getContents().get(0);
<br>
}
<br>
<br>
<br>
I have some persisted XML in filesystem that can load fine.
<br>
Now, I have some changes made to the ECore file where I have moved some
attributes around. Is there a way I could transform this persisted XML
file, while the resource is being loaded?
<br>
Also wondering, if I could do the reverse, where I might be able to
transform the newly generated XML back to another file.
<br>
I could write some XSLs to do load & save. But, I would need some
advice on the hooks where I could do the load resource / save resource
transformation.
<br>
<br>
Thanks,
<br>
Babloo
<br>
<br>
</blockquote>
</body>
</html>
--------------090708030807020401010308--
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| |
Re: Loading resource interception... [message #528761 is a reply to message #528753] |
Wed, 21 April 2010 16:39 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Babloo,
Likely you'd have to specialize XMLHandler and XMLSaveImpl.
OPTION_RECORD_UNKNOWN_FEATURES might allow you to post process/ pre
process what you load/save.
Babloo wrote:
> Thanks for the response Ed. In my case I have the same namespace URN
> for the old and new ecore model. In general, I may not be having the
> old ecore model around.
> Do you think, I could override...
> public void doLoad(InputStream inputStream, Map<?, ?> map) throws
> IOException
>
> to get do some kind of XSLT?
>
> Thanks,
> Babloo
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Goto Forum:
Current Time: Tue Apr 23 13:28:31 GMT 2024
Powered by FUDForum. Page generated in 0.03276 seconds
|