Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » saving objects
saving objects [message #407399] Fri, 23 February 2007 21:21 Go to next message
Aleksandr Kravets is currently offline Aleksandr KravetsFriend
Messages: 55
Registered: July 2009
Member
Hello,

Before I load my XML document it looks like this:

<iway xmlns="http://www.iwaysoftware.com/designer/model"
creation_date="02/21/07 10:54:35">
....
....
</iway>

But when I save the document, the root element is saved as:

<iway xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.iwaysoftware.com/designer/model"
creation_date="02/21/07 10:54:35">

My schema does have a target namespace:

xs:schema targetNamespace="http://www.iwaysoftware.com/designer/model">

So why is noNamespaceSchemaLocation inserted?

thanks,
Alex
Re: saving objects [message #407400 is a reply to message #407399] Fri, 23 February 2007 21:28 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------030505030604040202090309
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Alex,

Stepping through XMLSaveImpl.addNamespaceDeclarations should be
informative.

protected void addNamespaceDeclarations()
{
EPackage *noNamespacePackage *= helper.getNoNamespacePackage();


Using OPTION_SCHEMA_LOCATION will be partly to blame, but the instance
serialization as you show it really does have a null namespace, so I
suspect that you've specialized something to make the system think that
your package should be treated as the no namespace package.


Aleksandr Kravets wrote:
> Hello,
>
> Before I load my XML document it looks like this:
>
> <iway xmlns="http://www.iwaysoftware.com/designer/model"
> creation_date="02/21/07 10:54:35">
> ....
> ....
> </iway>
>
> But when I save the document, the root element is saved as:
>
> <iway xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="http://www.iwaysoftware.com/designer/model"
> creation_date="02/21/07 10:54:35">
>
> My schema does have a target namespace:
>
> xs:schema targetNamespace="http://www.iwaysoftware.com/designer/model">
>
> So why is noNamespaceSchemaLocation inserted?
>
> thanks,
> Alex
>


--------------030505030604040202090309
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Alex,<br>
<br>
Stepping through XMLSaveImpl.addNamespaceDeclarations should be
informative.&nbsp; <br>
<blockquote>&nbsp; protected void addNamespaceDeclarations()<br>
&nbsp; {<br>
&nbsp;&nbsp;&nbsp; EPackage <b>noNamespacePackage </b>=
helper.getNoNamespacePackage();<br>
</blockquote>
<br>
Using OPTION_SCHEMA_LOCATION will be partly to blame, but the instance
serialization as you show it really does have a null namespace, so I
suspect that you've specialized something to make the system think that
your package should be treated as the no namespace package.<br>
<br>
<br>
Aleksandr Kravets wrote:
<blockquote cite="midernlti$tuf$1@utils.eclipse.org" type="cite">Hello,
<br>
<br>
Before I load my XML document it looks like this:
<br>
<br>
&lt;iway xmlns=<a class="moz-txt-link-rfc2396E" href="http://www.iwaysoftware.com/designer/model">"http://www.iwaysoftware.com/designer/model"</a>
creation_date="02/21/07&nbsp; 10:54:35"&gt;
<br>
.....
<br>
.....
<br>
&lt;/iway&gt;
<br>
<br>
But when I save the document, the root element is saved as:
<br>
<br>
&lt;iway xmlns:xsi=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a>
xsi:noNamespaceSchemaLocation=<a class="moz-txt-link-rfc2396E" href="http://www.iwaysoftware.com/designer/model">"http://www.iwaysoftware.com/designer/model"</a>
creation_date="02/21/07&nbsp; 10:54:35"&gt;
<br>
<br>
My schema does have a target namespace:
<br>
<br>
xs:schema
targetNamespace=<a class="moz-txt-link-rfc2396E" href="http://www.iwaysoftware.com/designer/model">"http://www.iwaysoftware.com/designer/model"</a>&gt;
<br>
<br>
So why is noNamespaceSchemaLocation inserted?
<br>
<br>
thanks,
<br>
Alex
<br>
<br>
</blockquote>
<br>
</body>
</html>

--------------030505030604040202090309--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: saving objects [message #407401 is a reply to message #407400] Fri, 23 February 2007 21:56 Go to previous messageGo to next message
Aleksandr Kravets is currently offline Aleksandr KravetsFriend
Messages: 55
Registered: July 2009
Member
You're right, I created specialized BasicExtendedMetaData class and
overridden String getNamespace(EPackage ePackage) and just returned
null...my mistake.

Another question if I can without starting another thread. I asked
similar question earlier where I needed to load XML file converting
upper case element names to lower. I did that by creating class from
BasicExtendedMetaData, so now I need to save the data converting lower
case letters to upper again. I tried doing it with similar specialized
class but it doesn't work. Are there other methods that I should
override other than getLocalAttribute, getLocalElement and getType. I
tried debugging XMLSaveImpl but can't seem to pinpoint where
ExtendedMetaData is used.

thanks,
Alex

Ed Merks wrote:
> Alex,
>
> Stepping through XMLSaveImpl.addNamespaceDeclarations should be
> informative.
>
> protected void addNamespaceDeclarations()
> {
> EPackage *noNamespacePackage *= helper.getNoNamespacePackage();
>
>
> Using OPTION_SCHEMA_LOCATION will be partly to blame, but the instance
> serialization as you show it really does have a null namespace, so I
> suspect that you've specialized something to make the system think that
> your package should be treated as the no namespace package.
>
>
> Aleksandr Kravets wrote:
>> Hello,
>>
>> Before I load my XML document it looks like this:
>>
>> <iway xmlns="http://www.iwaysoftware.com/designer/model"
>> creation_date="02/21/07 10:54:35">
>> ....
>> ....
>> </iway>
>>
>> But when I save the document, the root element is saved as:
>>
>> <iway xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xsi:noNamespaceSchemaLocation="http://www.iwaysoftware.com/designer/model"
>> creation_date="02/21/07 10:54:35">
>>
>> My schema does have a target namespace:
>>
>> xs:schema targetNamespace="http://www.iwaysoftware.com/designer/model">
>>
>> So why is noNamespaceSchemaLocation inserted?
>>
>> thanks,
>> Alex
>>
>
Re: saving objects [message #407402 is a reply to message #407401] Fri, 23 February 2007 22:12 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Alex,

You'll want to override getName(EStructuralFeature) and possibly
getName(EClassifier) if there are any xsi:types being written.


Aleksandr Kravets wrote:
> You're right, I created specialized BasicExtendedMetaData class and
> overridden String getNamespace(EPackage ePackage) and just returned
> null...my mistake.
>
> Another question if I can without starting another thread. I asked
> similar question earlier where I needed to load XML file converting
> upper case element names to lower. I did that by creating class from
> BasicExtendedMetaData, so now I need to save the data converting lower
> case letters to upper again. I tried doing it with similar specialized
> class but it doesn't work. Are there other methods that I should
> override other than getLocalAttribute, getLocalElement and getType. I
> tried debugging XMLSaveImpl but can't seem to pinpoint where
> ExtendedMetaData is used.
>
> thanks,
> Alex
>
> Ed Merks wrote:
>> Alex,
>>
>> Stepping through XMLSaveImpl.addNamespaceDeclarations should be
>> informative.
>> protected void addNamespaceDeclarations()
>> {
>> EPackage *noNamespacePackage *= helper.getNoNamespacePackage();
>>
>>
>> Using OPTION_SCHEMA_LOCATION will be partly to blame, but the
>> instance serialization as you show it really does have a null
>> namespace, so I suspect that you've specialized something to make the
>> system think that your package should be treated as the no namespace
>> package.
>>
>>
>> Aleksandr Kravets wrote:
>>> Hello,
>>>
>>> Before I load my XML document it looks like this:
>>>
>>> <iway xmlns="http://www.iwaysoftware.com/designer/model"
>>> creation_date="02/21/07 10:54:35">
>>> ....
>>> ....
>>> </iway>
>>>
>>> But when I save the document, the root element is saved as:
>>>
>>> <iway xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>> xsi:noNamespaceSchemaLocation="http://www.iwaysoftware.com/designer/model"
>>> creation_date="02/21/07 10:54:35">
>>>
>>> My schema does have a target namespace:
>>>
>>> xs:schema targetNamespace="http://www.iwaysoftware.com/designer/model">
>>>
>>> So why is noNamespaceSchemaLocation inserted?
>>>
>>> thanks,
>>> Alex
>>>
>>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: saving objects [message #407403 is a reply to message #407402] Fri, 23 February 2007 22:17 Go to previous messageGo to next message
Aleksandr Kravets is currently offline Aleksandr KravetsFriend
Messages: 55
Registered: July 2009
Member
Thank you.

Ed Merks wrote:
> Alex,
>
> You'll want to override getName(EStructuralFeature) and possibly
> getName(EClassifier) if there are any xsi:types being written.
>
>
> Aleksandr Kravets wrote:
>> You're right, I created specialized BasicExtendedMetaData class and
>> overridden String getNamespace(EPackage ePackage) and just returned
>> null...my mistake.
>>
>> Another question if I can without starting another thread. I asked
>> similar question earlier where I needed to load XML file converting
>> upper case element names to lower. I did that by creating class from
>> BasicExtendedMetaData, so now I need to save the data converting lower
>> case letters to upper again. I tried doing it with similar specialized
>> class but it doesn't work. Are there other methods that I should
>> override other than getLocalAttribute, getLocalElement and getType. I
>> tried debugging XMLSaveImpl but can't seem to pinpoint where
>> ExtendedMetaData is used.
>>
>> thanks,
>> Alex
>>
>> Ed Merks wrote:
>>> Alex,
>>>
>>> Stepping through XMLSaveImpl.addNamespaceDeclarations should be
>>> informative.
>>> protected void addNamespaceDeclarations()
>>> {
>>> EPackage *noNamespacePackage *= helper.getNoNamespacePackage();
>>>
>>>
>>> Using OPTION_SCHEMA_LOCATION will be partly to blame, but the
>>> instance serialization as you show it really does have a null
>>> namespace, so I suspect that you've specialized something to make the
>>> system think that your package should be treated as the no namespace
>>> package.
>>>
>>>
>>> Aleksandr Kravets wrote:
>>>> Hello,
>>>>
>>>> Before I load my XML document it looks like this:
>>>>
>>>> <iway xmlns="http://www.iwaysoftware.com/designer/model"
>>>> creation_date="02/21/07 10:54:35">
>>>> ....
>>>> ....
>>>> </iway>
>>>>
>>>> But when I save the document, the root element is saved as:
>>>>
>>>> <iway xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>> xsi:noNamespaceSchemaLocation="http://www.iwaysoftware.com/designer/model"
>>>> creation_date="02/21/07 10:54:35">
>>>>
>>>> My schema does have a target namespace:
>>>>
>>>> xs:schema targetNamespace="http://www.iwaysoftware.com/designer/model">
>>>>
>>>> So why is noNamespaceSchemaLocation inserted?
>>>>
>>>> thanks,
>>>> Alex
>>>>
>>>
Re: saving objects [message #529250 is a reply to message #407399] Fri, 23 April 2010 15:22 Go to previous messageGo to next message
Claus Kricke is currently offline Claus KrickeFriend
Messages: 5
Registered: July 2009
Junior Member
Hello,

I'm having kind of the inverse problem of what's described below.
May I hijack the thread briefly ?

I want my EMF editor to include the noNamespaceSchemaLocation in the root element of the edited XML file but is doesn't do.

If I manually (with a text editor) include this information, it is preserved across edits. So the question is rather how can I get
the Model creation wizard to include it right from the start ?

Any hints ?
Thank you.

Claus
Re: saving objects [message #529253 is a reply to message #529250] Fri, 23 April 2010 15:24 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Claus,

A DocumentRoot has a getXSISchemaLocation EMap that can be populated
directly.


Claus Kricke wrote:
> Hello,
>
> I'm having kind of the inverse problem of what's described below.
> May I hijack the thread briefly ?
>
> I want my EMF editor to include the noNamespaceSchemaLocation in the
> root element of the edited XML file but is doesn't do.
>
> If I manually (with a text editor) include this information, it is
> preserved across edits. So the question is rather how can I get
> the Model creation wizard to include it right from the start ?
>
> Any hints ?
> Thank you.
>
> Claus
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: saving objects [message #529256 is a reply to message #529253] Fri, 23 April 2010 15:46 Go to previous messageGo to next message
Claus Kricke is currently offline Claus KrickeFriend
Messages: 5
Registered: July 2009
Junior Member
Thanks so far.

But what do you mean by "populated".

Can I do that in the ecore model or even in the schema file ?
Or would I need to edit the generated java code ?

Re: saving objects [message #529282 is a reply to message #529256] Fri, 23 April 2010 16:52 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------000308070901010903090209
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Claus,

In the generated model wizard you'll see it creates DocumentRoot; you
could modify that code. There's also the FAQ:
< http://wiki.eclipse.org/index.php/EMF-FAQ#How_can_I_ensure_t hat_an_xsi:schemaLocation_is_serialized_for_my_packages.3F>


http://wiki.eclipse.org/index.php/EMF-FAQ#How_can_I_ensure_t hat_an_xsi:schemaLocation_is_serialized_for_my_packages.3F

I think that works for the noSchemaLocation as well.


Claus Kricke wrote:
> Thanks so far.
>
> But what do you mean by "populated".
>
> Can I do that in the ecore model or even in the schema file ?
> Or would I need to edit the generated java code ?
>
>

--------------000308070901010903090209
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">
Claus,<br>
<br>
In the generated model wizard you'll see it creates DocumentRoot; you
could modify that code.  There's also the FAQ:<a
href=" http://wiki.eclipse.org/index.php/EMF-FAQ#How_can_I_ensure_t hat_an_xsi:schemaLocation_is_serialized_for_my_packages.3F"><br>
</a>
<blockquote><a
href=" http://wiki.eclipse.org/index.php/EMF-FAQ#How_can_I_ensure_t hat_an_xsi:schemaLocation_is_serialized_for_my_packages.3F"> http://wiki.eclipse.org/index.php/EMF-FAQ#How_can_I_ensure_t hat_an_xsi:schemaLocation_is_serialized_for_my_packages.3F</a><br>
</blockquote>
I think that works for the noSchemaLocation as well.<br>
<br>
<br>
Claus Kricke wrote:
<blockquote cite="mid:hqsfcm$3pf$1@build.eclipse.org" type="cite">Thanks
so far.
<br>
<br>
But what do you mean by "populated".
<br>
<br>
Can I do that in the ecore model or even in the schema file ?
<br>
Or would I need to edit the generated java code ?
<br>
<br>
<br>
</blockquote>
</body>
</html>

--------------000308070901010903090209--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: saving objects [message #529762 is a reply to message #407399] Tue, 27 April 2010 07:13 Go to previous messageGo to next message
Claus Kricke is currently offline Claus KrickeFriend
Messages: 5
Registered: July 2009
Junior Member
I implemented the method of the FAQ as described but with no luck (still no noNamespaceSchemaLocation in the result).

I found the getXSISchemaLocation EMap readily

public EMap<?, ?> getXSISchemaLocation() {
if (xSISchemaLocation == null) {
xSISchemaLocation = new EcoreEMap(EcorePackage.Literals.ESTRING_TO_STRING_MAP_ENTRY, EStringToStringMapEntryImpl.class, this, MyPackage.MYP__XSI_SCHEMA_LOCATION);
}
return xSISchemaLocation;
}

but it returns an empty xSISchemaLocation. This is why the XMLHandler will not write the location to the file. From the code of the XMLHandler, it seams that it'll write the noNamespaceSchemaLocation when the key in the <key ,value > pair is null and the value is !null.

So I'd like to do something like this in the getXSISchemaLocation():

if ( xSISchemaLocation.isEmpty()) {
Map<?,String> map = null;
map.put(null, "MyPack.xsd");
xSISchemaLocation.set(map);
}

but can't get it to work ( I'm not familiar enough with the EMF data types).

Any hints ?
Re: saving objects [message #529821 is a reply to message #529762] Tue, 27 April 2010 11:03 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Claus,

Comments below.

Claus Kricke wrote:
> I implemented the method of the FAQ as described but with no luck
> (still no noNamespaceSchemaLocation in the result).
>
> I found the getXSISchemaLocation EMap readily
>
> public EMap<?, ?> getXSISchemaLocation() {
> if (xSISchemaLocation == null) {
> xSISchemaLocation = new
> EcoreEMap(EcorePackage.Literals.ESTRING_TO_STRING_MAP_ENTRY,
> EStringToStringMapEntryImpl.class, this,
> MyPackage.MYP__XSI_SCHEMA_LOCATION);
> }
> return xSISchemaLocation;
> }
>
> but it returns an empty xSISchemaLocation.
It's always empty at first.
> This is why the XMLHandler will not write the location to the file.
> From the code of the XMLHandler, it seams that it'll write the
> noNamespaceSchemaLocation when the key in the <key ,value > pair is
> null and the value is !null.
Yes, I'd expect that.
>
> So I'd like to do something like this in the getXSISchemaLocation():
>
> if ( xSISchemaLocation.isEmpty()) {
> Map<?,String> map = null;
> map.put(null, "MyPack.xsd");
I assume this causes a null pointer exception.
> xSISchemaLocation.set(map);
> }
>
> but can't get it to work ( I'm not familiar enough with the EMF data
> types).
Did you try modifying the generated wizard?

Modifying the generated XyzExample.java like this:

Resource resource =
resourceSet.createResource(URI.createURI("http:///My.library"));
DocumentRoot documentRoot =
LibraryFactory.eINSTANCE.createDocumentRoot();
documentRoot.getXSISchemaLocation().put(null, "foo");
Library root = LibraryFactory.eINSTANCE.createLibrary();
documentRoot.setLibrary(root);
resource.getContents().add(documentRoot);
resource.save(System.out, null);

produces

<?xml version="1.0" encoding="ASCII"?>
<library xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="foo"/>

so I know that works.
>
> Any hints ?
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: saving objects [message #529886 is a reply to message #407399] Tue, 27 April 2010 14:56 Go to previous messageGo to next message
Claus Kricke is currently offline Claus KrickeFriend
Messages: 5
Registered: July 2009
Junior Member
Thanks Ed so far.

I followed you advice exactly as recommended, but the line

documentRoot.getXSISchemaLocation().put(null,"foo");

gives me headache casting the error message:

"The method put(capture#7-of ?, capture#8-of ?) in the type EMap<capture#7-of ?,capture#8-of ?> is not applicable for the arguments (null, String)"

I work with eclipse Version: 3.5.2.R35x_v20100119-7Q7bARBPWUHM_CSjz-8bF1f7_n8rLSyWHoiKoyx BQSGT4
Build id: M20100211-1343
Re: saving objects [message #529909 is a reply to message #529886] Tue, 27 April 2010 16:11 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Claus,

Cast the null to String if necessary. I don't see how it's possible to
get that message for this use of EMap in DocumentRoot:

EMap<String, String> getXSISchemaLocation();



Claus Kricke wrote:
> Thanks Ed so far.
>
> I followed you advice exactly as recommended, but the line
>
> documentRoot.getXSISchemaLocation().put(null,"foo");
>
> gives me headache casting the error message:
>
> "The method put(capture#7-of ?, capture#8-of ?) in the type
> EMap<capture#7-of ?,capture#8-of ?> is not applicable for the
> arguments (null, String)"
>
> I work with eclipse Version:
> 3.5.2.R35x_v20100119-7Q7bARBPWUHM_CSjz-8bF1f7_n8rLSyWHoiKoyx BQSGT4
> Build id: M20100211-1343


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: saving objects [message #529936 is a reply to message #529909] Tue, 27 April 2010 18:34 Go to previous message
Claus Kricke is currently offline Claus KrickeFriend
Messages: 5
Registered: July 2009
Junior Member
Thank you Ed,

works just fine now.
On earlier versions of eclipse(3.4.0) / EMF (2.4) the cast isn't needed.
Thank you for the prompt support

Claus
Previous Topic:[Announce] Webinar: CDO Model Repository - Apr. 29
Next Topic:Temporarily add structural features to existent metamodel
Goto Forum:
  


Current Time: Thu Apr 25 06:10:59 GMT 2024

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

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

Back to the top