Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Loosing xsi:schemaLocation after serialization
Loosing xsi:schemaLocation after serialization [message #423750] Mon, 06 October 2008 21:07 Go to next message
Abdel  is currently offline Abdel Friend
Messages: 10
Registered: July 2009
Junior Member
Hi All
I'm loading a resource using the following method,

public Resource loadDynamicResource(String url) throws IOException {
// Create a resource set.
ResourceSet resourceSet = new ResourceSetImpl();

// Register the resource factory as Global
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(
"xmi", new XMIResourceFactoryImpl());

// Register the BP package
BpPackage.eINSTANCE.eClass();

// create the URI
URI uri = URI.createURI(url, true);

resourceSet.getLoadOptions().put(XMIResource.OPTION_SCHEMA_L OCATION,
Boolean.TRUE);

// Demand load the resource for this file.
return resourceSet.getResource(uri, true);

}

The resource I want to load was created in different location than the
package using Create Dynamic Resource from the editor and it looks like :

<?xml version="1.0" encoding="ASCII"?>
<bp:Process xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:bp="ca.uqam.latece.bpc4s.metamodel"
xsi:schemaLocation="ca.uqam.latece.bpc4s.metamodel ../../../bp.ecore"
name="Ordering">
<succession nextStep="//@ownedCoursePart.0" name="Succession0">
<previousStep href="../../resource/shared/changePart/Start.xmi#/"/>
<successorEvent href="../../resource/shared/event/Event_Start.xmi#/"/>
</succession>
.......
</bp:Process>

My question is :
When I serialize this resource again using resource.save(io, options); I
loose the xsi:schemaLocation.
What I should do the keep the xsi:schemaLocation ?
If I want to serialize this resource in a different location than the
original resource, what is the simple way to change the href attribute
of all referenced resource inside ?

Thanks in advance
Re: Loosing xsi:schemaLocation after serialization [message #423752 is a reply to message #423750] Mon, 06 October 2008 22:20 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30810
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------010502090109070307030309
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Abdel,

Comments below.


Abdel wrote:
> Hi All
> I'm loading a resource using the following method,
>
> public Resource loadDynamicResource(String url) throws IOException {
> // Create a resource set.
> ResourceSet resourceSet = new ResourceSetImpl();
> // Register the resource factory as Global
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put(
> "xmi", new XMIResourceFactoryImpl());
>
> // Register the BP package
> BpPackage.eINSTANCE.eClass();
>
> // create the URI
> URI uri = URI.createURI(url, true);
>
> resourceSet.getLoadOptions().put(XMIResource.OPTION_SCHEMA_L OCATION,
> Boolean.TRUE);
> // Demand load the resource for this file.
Note that it's a save option:

/**
* Produce an xsi:schemaLocation/xsi:noNamespaceSchemaLocation in
the *saved *result.
*/
String OPTION_SCHEMA_LOCATION = "SCHEMA_LOCATION";


> return resourceSet.getResource(uri, true);
>
> }
>
> The resource I want to load was created in different location than the
> package using Create Dynamic Resource from the editor and it looks like :
>
> <?xml version="1.0" encoding="ASCII"?>
> <bp:Process xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:bp="ca.uqam.latece.bpc4s.metamodel"
> xsi:schemaLocation="ca.uqam.latece.bpc4s.metamodel ../../../bp.ecore"
> name="Ordering">
> <succession nextStep="//@ownedCoursePart.0" name="Succession0">
> <previousStep href="../../resource/shared/changePart/Start.xmi#/"/>
Hmmm. A bit odd that "resource" is in the path. To me it implies that
URI used to save this wasn't of the form
platform:/resource/<project-name>/..
> <successorEvent href="../../resource/shared/event/Event_Start.xmi#/"/>
> </succession>
> .......
> </bp:Process>
>
> My question is :
> When I serialize this resource again using resource.save(io, options);
> I loose the xsi:schemaLocation.
The schema location is saved iff ePackage.getNsURI() is different from
ePackage.eResource().getURI()...
> What I should do the keep the xsi:schemaLocation ?
The static package when it's initialized calls
EPackageImpl.createResource which by default passes in the nsURI. You
could specialize that method in the generated XyzPackageImpl to replace
the nsURI with a location URI.
> If I want to serialize this resource in a different location than the
> original resource, what is the simple way to change the href attribute
> of all referenced resource inside ?
The locations of hrefs within the resource will be relative to the URI
of the containing resource at the time that it's saved. So you'd need
to use resource.setURI to be what you want the hrefs to be relative to.
Or use OPTION_URI_HANDLER to specialize the behavior...

>
> Thanks in advance
>

--------------010502090109070307030309
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Abdel,<br>
<br>
Comments below.<br>
<br>
<br>
Abdel wrote:
<blockquote
cite="mid:3b3d9318a2186276bf899c5bf604ed5c$1@www.eclipse.org"
type="cite">Hi All
<br>
I'm loading a resource using the following method,
<br>
<br>
public Resource loadDynamicResource(String url) throws IOException {
<br>
Re: Loosing xsi:schemaLocation after serialization [message #423754 is a reply to message #423752] Tue, 07 October 2008 03:36 Go to previous message
Abdel  is currently offline Abdel Friend
Messages: 10
Registered: July 2009
Junior Member
Thanks Ed,
Every thing works fine now.

Thanks again
Previous Topic:multiple namespaces in one editor supported?
Next Topic:XSD ID -> EMF ID -> hibernate id
Goto Forum:
  


Current Time: Tue Jan 21 16:32:36 GMT 2020

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

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

Back to the top