|
Re: Loosing xsi:schemaLocation after serialization [message #423752 is a reply to message #423750] |
Mon, 06 October 2008 22:20 |
Ed Merks Messages: 33113 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>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Powered by
FUDForum. Page generated in 0.02732 seconds