Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Multiple Serializations
Multiple Serializations [message #506251] Wed, 06 January 2010 17:10 Go to next message
Eclipse UserFriend
Originally posted by: jseng.valen.trick.gov

I am new to EMF and am trying to find documentation on how to do something
not mentioned in the tutorials.

As background, I need to generate classes that serialize to/de-serialize
from a specific schema.

The toolkit manages serialization of all objects for me; however, it does
so by managing child objects separate from object data. This means that I
need to do the following:
a) keep the toolkit's child list in sync with the EMF child list, and
b) provide a second serialization method that serializes the object
identical to the schema, but without its children.

Where should I look in the documentation for serializing/de-serializing
with and without children? And is this compatible with generation from a
schema?

Thank you.
Re: Multiple Serializations [message #506258 is a reply to message #506251] Wed, 06 January 2010 17:17 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------070800090202060508040700
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Jonathan,

Comments below.

Jonathan Seng wrote:
> I am new to EMF and am trying to find documentation on how to do something
> not mentioned in the tutorials.
>
> As background, I need to generate classes that serialize to/de-serialize
> from a specific schema.
Like this?

Tutorial: Generating an EMF Model using XML Schema
< http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.emf.doc/tutorials/xlibmod/xlibmod.html>

> The toolkit manages serialization of all objects for me; however, it does
> so by managing child objects separate from object data. This means that I
> need to do the following:
> a) keep the toolkit's child list in sync with the EMF child list,
What toolkit are you referring to?
> and
> b) provide a second serialization method that serializes the object
> identical to the schema, but without its children.
>
You could specialize methods like XMLSaveImpl.shouldSaveFeature to omit
certain ones.
> Where should I look in the documentation for serializing/de-serializing
> with and without children? And is this compatible with generation from a
> schema?
>
There's not much detailed documentation of these low level aspects of
the framework. Best to look at the source code, which is often done
best by setting breakpoints and watching the live behavior; setting a
breakpoint in the method I mentioned above would be a good start.
> Thank you.
>

--------------070800090202060508040700
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">
Jonathan,<br>
<br>
Comments below.<br>
<br>
Jonathan Seng wrote:
<blockquote cite="mid:pan.2010.01.06.17.10.14.182348@valen.trick.gov"
type="cite">
<pre wrap="">I am new to EMF and am trying to find documentation on how to do something
not mentioned in the tutorials.

As background, I need to generate classes that serialize to/de-serialize
from a specific schema.</pre>
</blockquote>
Like this? <br>
<blockquote><a
href=" http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.emf.doc/tutorials/xlibmod/xlibmod.html">Tutorial:
Generating an EMF Model using XML Schema</a><br>
</blockquote>
<blockquote cite="mid:pan.2010.01.06.17.10.14.182348@valen.trick.gov"
type="cite">
<pre wrap="">
The toolkit manages serialization of all objects for me; however, it does
so by managing child objects separate from object data. This means that I
need to do the following:
a) keep the toolkit's child list in sync with the EMF child list,</pre>
</blockquote>
What toolkit are you referring to?<br>
<blockquote cite="mid:pan.2010.01.06.17.10.14.182348@valen.trick.gov"
type="cite">
<pre wrap=""> and
b) provide a second serialization method that serializes the object
identical to the schema, but without its children.
</pre>
</blockquote>
You could specialize methods like XMLSaveImpl.shouldSaveFeature to omit
certain ones.<br>
<blockquote cite="mid:pan.2010.01.06.17.10.14.182348@valen.trick.gov"
type="cite">
<pre wrap="">
Where should I look in the documentation for serializing/de-serializing
with and without children? And is this compatible with generation from a
schema?
</pre>
</blockquote>
There's not much detailed documentation of these low level aspects of
the framework.&nbsp; Best to look at the source code, which is often done
best by setting breakpoints and watching the live behavior; setting a
breakpoint in the method I mentioned above would be a good start.<br>
<blockquote cite="mid:pan.2010.01.06.17.10.14.182348@valen.trick.gov"
type="cite">
<pre wrap="">
Thank you.
</pre>
</blockquote>
</body>
</html>

--------------070800090202060508040700--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Multiple Serializations [message #506284 is a reply to message #506258] Wed, 06 January 2010 18:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jseng.valen.trick.gov

The toolkit in question is a proprietary toolkit not released publicly
that I cannot even provide documentation for.

>> You could specialize methods like XMLSaveImpl.shouldSaveFeature to omit
>> certain ones.

Let me try to follow this...

When EMF generates my model and classes from my schema, it should generate
an XMLSaveImpl derived class to do the serialization. This works when I
want to serialize everything. I would then create a class derived from
this serializer and override shouldSaveFeature() to return false to block
all contained elements. I would follow the debugger to find how/when to
specify the correct serializer.

In the general case, one would check per object and feature in
shouldSaveFeature() possibly deferring to the super class. Since I do not
want any child elements, I would return false for all EStructuralFeatures.

Please let me know if I did not follow correctly.

Thank you,

Jonathan






On Wed, 06 Jan 2010 12:17:25 -0500, Ed Merks wrote:

> Jonathan,
>
> Comments below.
>
> Jonathan Seng wrote:
>> I am new to EMF and am trying to find documentation on how to do something
>> not mentioned in the tutorials.
>>
>> As background, I need to generate classes that serialize to/de-serialize
>> from a specific schema.
> Like this?
>
> Tutorial: Generating an EMF Model using XML Schema
> < http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.emf.doc/tutorials/xlibmod/xlibmod.html>
>
>> The toolkit manages serialization of all objects for me; however, it does
>> so by managing child objects separate from object data. This means that I
>> need to do the following:
>> a) keep the toolkit's child list in sync with the EMF child list,
> What toolkit are you referring to?
>> and
>> b) provide a second serialization method that serializes the object
>> identical to the schema, but without its children.
>>
> You could specialize methods like XMLSaveImpl.shouldSaveFeature to omit
> certain ones.
>> Where should I look in the documentation for serializing/de-serializing
>> with and without children? And is this compatible with generation from a
>> schema?
>>
> There's not much detailed documentation of these low level aspects of
> the framework. Best to look at the source code, which is often done
> best by setting breakpoints and watching the live behavior; setting a
> breakpoint in the method I mentioned above would be a good start.
>> Thank you.
>>
Re: Multiple Serializations [message #506286 is a reply to message #506284] Wed, 06 January 2010 19:02 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------090407030100000508050202
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Jonathan,

Comments below.

Jonathan Seng wrote:
> The toolkit in question is a proprietary toolkit not released publicly
> that I cannot even provide documentation for.
>
>
>>> You could specialize methods like XMLSaveImpl.shouldSaveFeature to omit
>>> certain ones.
>>>
>
> Let me try to follow this...
>
> When EMF generates my model and classes from my schema, it should generate
> an XMLSaveImpl derived class to do the serialization.
No, it's not generated. It's a reusable component of the framework that
works using EMF reflection for all models.
> This works when I
> want to serialize everything. I would then create a class derived from
> this serializer and override shouldSaveFeature() to return false to block
> all contained elements. I would follow the debugger to find how/when to
> specify the correct serializer.
>
No, you'd specialize your own derived XMLResourceImpl and use that to
create a derived XMLSaveImpl and in there add your logic. A model
generated from an XML schema will already have an XyzResourceImpl as the
basis for this work.
> In the general case, one would check per object and feature in
> shouldSaveFeature() possibly deferring to the super class. Since I do not
> want any child elements, I would return false for all EStructuralFeatures.
>
Likely you'll compare against things like XyzPackage.Literals.ABC__DEF.
> Please let me know if I did not follow correctly.
>
So often it's easier to use the debugger to answer questions. Set a
breakpoint, serialize your instance (i.e., save the generated editor or
run the generated XyzExample.java in the *.test project when you invoke
Generate Test Code), and see what's going on.
> Thank you,
>
> Jonathan
>
>
>
>
>
>
> On Wed, 06 Jan 2010 12:17:25 -0500, Ed Merks wrote:
>
>
>> Jonathan,
>>
>> Comments below.
>>
>> Jonathan Seng wrote:
>>
>>> I am new to EMF and am trying to find documentation on how to do something
>>> not mentioned in the tutorials.
>>>
>>> As background, I need to generate classes that serialize to/de-serialize
>>> from a specific schema.
>>>
>> Like this?
>>
>> Tutorial: Generating an EMF Model using XML Schema
>> < http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.emf.doc/tutorials/xlibmod/xlibmod.html>
>>
>>
>>> The toolkit manages serialization of all objects for me; however, it does
>>> so by managing child objects separate from object data. This means that I
>>> need to do the following:
>>> a) keep the toolkit's child list in sync with the EMF child list,
>>>
>> What toolkit are you referring to?
>>
>>> and
>>> b) provide a second serialization method that serializes the object
>>> identical to the schema, but without its children.
>>>
>>>
>> You could specialize methods like XMLSaveImpl.shouldSaveFeature to omit
>> certain ones.
>>
>>> Where should I look in the documentation for serializing/de-serializing
>>> with and without children? And is this compatible with generation from a
>>> schema?
>>>
>>>
>> There's not much detailed documentation of these low level aspects of
>> the framework. Best to look at the source code, which is often done
>> best by setting breakpoints and watching the live behavior; setting a
>> breakpoint in the method I mentioned above would be a good start.
>>
>>> Thank you.
>>>
>>>

--------------090407030100000508050202
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">
Jonathan,<br>
<br>
Comments below.<br>
<br>
Jonathan Seng wrote:
<blockquote cite="mid:pan.2010.01.06.18.54.29.122644@valen.trick.gov"
type="cite">
<pre wrap="">The toolkit in question is a proprietary toolkit not released publicly
that I cannot even provide documentation for.

</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">You could specialize methods like XMLSaveImpl.shouldSaveFeature to omit
certain ones.
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->
Let me try to follow this...

When EMF generates my model and classes from my schema, it should generate
an XMLSaveImpl derived class to do the serialization. </pre>
</blockquote>
No, it's not generated.&nbsp; It's a reusable component of the framework
that works using EMF reflection for all models.<br>
<blockquote cite="mid:pan.2010.01.06.18.54.29.122644@valen.trick.gov"
type="cite">
<pre wrap=""> This works when I
want to serialize everything. I would then create a class derived from
this serializer and override shouldSaveFeature() to return false to block
all contained elements. I would follow the debugger to find how/when to
specify the correct serializer.
</pre>
</blockquote>
No, you'd specialize your own derived XMLResourceImpl and use that to
create a derived XMLSaveImpl and in there add your logic.&nbsp; A model
generated from an XML schema will already have an XyzResourceImpl as
the basis for this work.<br>
<blockquote cite="mid:pan.2010.01.06.18.54.29.122644@valen.trick.gov"
type="cite">
<pre wrap="">
In the general case, one would check per object and feature in
shouldSaveFeature() possibly deferring to the super class. Since I do not
want any child elements, I would return false for all EStructuralFeatures.
</pre>
</blockquote>
Likely you'll compare against things like XyzPackage.Literals.ABC__DEF.<br>
<blockquote cite="mid:pan.2010.01.06.18.54.29.122644@valen.trick.gov"
type="cite">
<pre wrap="">
Please let me know if I did not follow correctly.
</pre>
</blockquote>
So often it's easier to use the debugger to answer questions.&nbsp; Set a
breakpoint, serialize your instance (i.e., save the generated editor or
run the generated XyzExample.java in the *.test project when you invoke
Generate Test Code), and see what's going on.<br>
<blockquote cite="mid:pan.2010.01.06.18.54.29.122644@valen.trick.gov"
type="cite">
<pre wrap="">
Thank you,

Jonathan






On Wed, 06 Jan 2010 12:17:25 -0500, Ed Merks wrote:

</pre>
<blockquote type="cite">
<pre wrap="">Jonathan,

Comments below.

Jonathan Seng wrote:
</pre>
<blockquote type="cite">
<pre wrap="">I am new to EMF and am trying to find documentation on how to do something
not mentioned in the tutorials.

As background, I need to generate classes that serialize to/de-serialize
from a specific schema.
</pre>
</blockquote>
<pre wrap="">Like this?

Tutorial: Generating an EMF Model using XML Schema
<a class="moz-txt-link-rfc2396E" href=" http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.emf.doc/tutorials/xlibmod/xlibmod.html">&lt; http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.emf.doc/tutorials/xlibmod/xlibmod.html&gt;</a>

</pre>
<blockquote type="cite">
<pre wrap="">The toolkit manages serialization of all objects for me; however, it does
so by managing child objects separate from object data. This means that I
need to do the following:
a) keep the toolkit's child list in sync with the EMF child list,
</pre>
</blockquote>
<pre wrap="">What toolkit are you referring to?
</pre>
<blockquote type="cite">
<pre wrap=""> and
b) provide a second serialization method that serializes the object
identical to the schema, but without its children.

</pre>
</blockquote>
<pre wrap="">You could specialize methods like XMLSaveImpl.shouldSaveFeature to omit
certain ones.
</pre>
<blockquote type="cite">
<pre wrap="">Where should I look in the documentation for serializing/de-serializing
with and without children? And is this compatible with generation from a
schema?

</pre>
</blockquote>
<pre wrap="">There's not much detailed documentation of these low level aspects of
the framework. Best to look at the source code, which is often done
best by setting breakpoints and watching the live behavior; setting a
breakpoint in the method I mentioned above would be a good start.
</pre>
<blockquote type="cite">
<pre wrap="">Thank you.

</pre>
</blockquote>
</blockquote>
</blockquote>
</body>
</html>

--------------090407030100000508050202--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Multiple Serializations [message #516440 is a reply to message #506286] Tue, 23 February 2010 17:52 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jseng.valen.trick.gov

I was able to implement and use my own XMLSaveImpl with some debugger
tracing.

This EMF project is based on a schema file; however, the output does not
follow the schema -- the XML tags are wrong. I am using the new / special
resourceFactoryImpl to not save children -- verified by the debugger.

Further, reading fails with a Feature not found exception. Changing the
in the debugger to the right tag fails the same (though listing the tag
name it was changed to).

The only thing strange I noticed was that I am using
an empty URI in the resourceSet.createResource() call
and then using resource.save(stream, null). When saving to a file, I use
a file name with the right extension and resource.save(null).

Any ideas?

Jonathan
Re: Multiple Serializations [message #516441 is a reply to message #516440] Tue, 23 February 2010 17:52 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Jonathan,

Comments below.

Jonathan Seng wrote:
> I was able to implement and use my own XMLSaveImpl with some debugger
> tracing.
>
> This EMF project is based on a schema file; however, the output does not
> follow the schema -- the XML tags are wrong. I am using the new / special
> resourceFactoryImpl to not save children -- verified by the debugger.
>
Are you using the load and save options that are in the generated
resource factory? It looks like this:

public Resource createResource(URI uri)
{
XMLResource result = new LibraryResourceImpl(uri);

result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
Boolean.TRUE);

result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
Boolean.TRUE);


result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION,
Boolean.TRUE);


result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
Boolean.TRUE);

result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
Boolean.TRUE);


result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LE XICAL_HANDLER,
Boolean.TRUE);
return result;
}

> Further, reading fails with a Feature not found exception. Changing the
> in the debugger to the right tag fails the same (though listing the tag
> name it was changed to).
>
It's hard to comment without something more specific, i.e., what's
wrong? What would be right?
> The only thing strange I noticed was that I am using
> an empty URI in the resourceSet.createResource() call
> and then using resource.save(stream, null). When saving to a file, I use
> a file name with the right extension and resource.save(null).
>
> Any ideas?
>
I don't really understand what's wrong with the XML. An example would
likely help.
> Jonathan
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Multiple Serializations [message #516669 is a reply to message #516441] Wed, 24 February 2010 17:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jseng.valen.trick.gov

Ed,

Right vs. wrong: When I first tried EMF, I copied example code which used
XmlResourceFactoryImpl. This produced different output (XML tags like
prl:ObjectiveInstructionType) than using the generated
PrlResourceFactoryImpl (XML tags like prl:Objective as specified in the
schema used to generate the EMF classes).

My first thought was that the following code sets a factory for the
default extension "*", which might not match the empty URI I use when
setting up to write to a string:
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(
Resource.Factory.Registry.DEFAULT_EXTENSION, resourceFactoryImpl);

Code follows.

Thank you,

Jonathan



Replacement Factory Impl to replace the XMLSaveImpl:

public class ChildlessPrlResourceFactoryImpl extends PrlResourceFactoryImpl {

/**
* Creates an instance of the resource factory.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public ChildlessPrlResourceFactoryImpl() {
super();
}

/**
* Creates an instance of the resource.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Resource createResource(URI uri) {
XMLResource result = new ChildlessPrlResourceImpl(uri);
result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA, Boolean.TRUE);
result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA, Boolean.TRUE);

result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION, Boolean.TRUE);

result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE, Boolean.TRUE);
result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE, Boolean.TRUE);

result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LE XICAL_HANDLER, Boolean.TRUE);
return result;
}

public class ChildlessPrlResourceImpl extends PrlResourceImpl {
/**
* Creates an instance of the resource.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @param uri the URI of the new resource.
* @generated
*/
public ChildlessPrlResourceImpl(URI uri) {
super(uri);
}

@Override
protected XMLSave createXMLSave()
{
return new ChildlessPRLSaveImpl(createXMLHelper());
}

public class ChildlessPRLSaveImpl extends XMLSaveImpl {
public ChildlessPRLSaveImpl(XMLHelper helper) {
super(helper);
}

@Override
protected boolean shouldSaveFeature(EObject o, EStructuralFeature f)
{
if(!super.shouldSaveFeature(o, f)) {
return false;
}

return f instanceof EAttribute;
}
}
}
}

The following is a chop-up of the tutorial to do full tree file
serialization / deserialization and childless save to / load from a
string:

public class EMFResourceUtil {
private static Logger logger = LoggerFactory.getLogger(EMFResourceUtil.class);

private final ResourceSet resourceSet;
private Resource resource = null;

public EMFResourceUtil(ResourceFactoryImpl resourceFactoryImpl) {
// Create a resource set.
resourceSet = new ResourceSetImpl();

// Register the default resource factory -- only needed for stand-alone!
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(
Resource.Factory.Registry.DEFAULT_EXTENSION, resourceFactoryImpl);
}

private URI makeURI(String filename) {
// Get the URI of the model file.
return URI.createFileURI(new File(filename).getAbsolutePath());
}

public EList<EObject> read(String filename) {
URI fileURI = makeURI(filename);

resource = resourceSet.getResource(fileURI, true);

if(null == resource) {
return null;
}
return resource.getContents();
}

public EList<EObject> loadWithoutChildren(String value) {
resource = resourceSet.createResource(URI.createURI(""));

if(null == resource) {
return null;
}

// Save the contents of the resource to the file system.
try
{
ByteArrayInputStream stream = new ByteArrayInputStream(value.getBytes());
resource.load(stream, null);
// TODO: improve this hack
return resource.getContents();
}
catch (IOException e) {
logger.error(e.getMessage());
e.printStackTrace();
return null;
}
}

public void write(EObject data, String filename) {
URI fileURI = makeURI(filename);

// Create a resource for this file.
resource = resourceSet.createResource(fileURI);

// Add the book and writer objects to the contents.
resource.getContents().add(data);

// Save the contents of the resource to the file system.
try
{
resource.save(null);
}
catch (IOException e) {}
}

public String saveWithoutChildren(EObject data) {
// Create a resource for this file.
resource = resourceSet.createResource(URI.createURI(""));

// Add the book and writer objects to the contents.
resource.getContents().add(data);

// Save the contents of the resource to the file system.
try
{
ByteArrayOutputStream stream = new ByteArrayOutputStream();
resource.save(stream, null);
// TODO: improve this hack
return stream.toString();
}
catch (IOException e) {
return "";
}
}

public void close() {
if(null != resource) {
resource.unload();
}
}
}

Save to file usage:
EMFResourceUtil util = new EMFResourceUtil(new PrlResourceFactoryImpl());
util.write(eObject, pathname);
util.close();

Load from file usage:
EMFResourceUtil util = new EMFResourceUtil(new PrlResourceFactoryImpl());
EList<EObject> contents = util.read(pathname);
...
EObject newEObject = contents.get(0);
util.close();

Save without children to string:
EMFResourceUtil util = new EMFResourceUtil(new ChildlessPrlResourceFactoryImpl());
String contents = util.saveWithoutChildren(eObject);
util.close();

Load from string:
EMFResourceUtil util = new EMFResourceUtil(new ChildlessPrlResourceFactoryImpl());
EList<EObject> contents = util.loadWithoutChildren(value);
...
EObject newEObject = contents.get(0);
util.close();


On Tue, 23 Feb 2010 17:44:05 -0500, Ed Merks wrote:

> Jonathan,
>
> Comments below.
>
> Jonathan Seng wrote:
>> I was able to implement and use my own XMLSaveImpl with some debugger
>> tracing.
>>
>> This EMF project is based on a schema file; however, the output does not
>> follow the schema -- the XML tags are wrong. I am using the new / special
>> resourceFactoryImpl to not save children -- verified by the debugger.
>>
> Are you using the load and save options that are in the generated
> resource factory? It looks like this:
>
> public Resource createResource(URI uri)
> {
> XMLResource result = new LibraryResourceImpl(uri);
>
> result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
> Boolean.TRUE);
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
> Boolean.TRUE);
>
>
> result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION,
> Boolean.TRUE);
>
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
> Boolean.TRUE);
>
> result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
> Boolean.TRUE);
>
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LE XICAL_HANDLER,
> Boolean.TRUE);
> return result;
> }
>
>> Further, reading fails with a Feature not found exception. Changing the
>> in the debugger to the right tag fails the same (though listing the tag
>> name it was changed to).
>>
> It's hard to comment without something more specific, i.e., what's
> wrong? What would be right?
>> The only thing strange I noticed was that I am using
>> an empty URI in the resourceSet.createResource() call
>> and then using resource.save(stream, null). When saving to a file, I use
>> a file name with the right extension and resource.save(null).
>>
>> Any ideas?
>>
> I don't really understand what's wrong with the XML. An example would
> likely help.
>> Jonathan
>>
>>
>>
Re: Multiple Serializations [message #516711 is a reply to message #516669] Wed, 24 February 2010 21:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jseng.valen.trick.gov

Further investigation reveals that saving to file is saving with the
correct tags, but with href=... instead of actual data, where value of the
href attribute is the URI provided to the create resource.

In context, I have an application where the data is implemented in EMF and
the application serializes the objects from time to time maintaining
parent/child in a different mechanism than attribute data. This
serialization is returned as a byte array or String. When creating the
resource for this, I am specifying a URI when there really isn't one...
This is used to select the right factory implementation and, apparently,
as references when later saving to a file. And the saved string has tags
not agreeing with the schema used to generate the EMF project.

Thank you,

Jonathan

On Wed, 24 Feb 2010 11:33:18 -0600, Jonathan Seng wrote:

> Ed,
>
> Right vs. wrong: When I first tried EMF, I copied example code which used
> XmlResourceFactoryImpl. This produced different output (XML tags like
> prl:ObjectiveInstructionType) than using the generated
> PrlResourceFactoryImpl (XML tags like prl:Objective as specified in the
> schema used to generate the EMF classes).
>
> My first thought was that the following code sets a factory for the
> default extension "*", which might not match the empty URI I use when
> setting up to write to a string:
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(
> Resource.Factory.Registry.DEFAULT_EXTENSION, resourceFactoryImpl);
>
> Code follows.
>
> Thank you,
>
> Jonathan
>
>
>
> Replacement Factory Impl to replace the XMLSaveImpl:
>
> public class ChildlessPrlResourceFactoryImpl extends PrlResourceFactoryImpl {
>
> /**
> * Creates an instance of the resource factory.
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> public ChildlessPrlResourceFactoryImpl() {
> super();
> }
>
> /**
> * Creates an instance of the resource.
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated
> */
> @Override
> public Resource createResource(URI uri) {
> XMLResource result = new ChildlessPrlResourceImpl(uri);
> result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA, Boolean.TRUE);
> result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA, Boolean.TRUE);
>
> result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION, Boolean.TRUE);
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE, Boolean.TRUE);
> result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE, Boolean.TRUE);
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LE XICAL_HANDLER, Boolean.TRUE);
> return result;
> }
>
> public class ChildlessPrlResourceImpl extends PrlResourceImpl {
> /**
> * Creates an instance of the resource.
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @param uri the URI of the new resource.
> * @generated
> */
> public ChildlessPrlResourceImpl(URI uri) {
> super(uri);
> }
>
> @Override
> protected XMLSave createXMLSave()
> {
> return new ChildlessPRLSaveImpl(createXMLHelper());
> }
>
> public class ChildlessPRLSaveImpl extends XMLSaveImpl {
> public ChildlessPRLSaveImpl(XMLHelper helper) {
> super(helper);
> }
>
> @Override
> protected boolean shouldSaveFeature(EObject o, EStructuralFeature f)
> {
> if(!super.shouldSaveFeature(o, f)) {
> return false;
> }
>
> return f instanceof EAttribute;
> }
> }
> }
> }
>
> The following is a chop-up of the tutorial to do full tree file
> serialization / deserialization and childless save to / load from a
> string:
>
> public class EMFResourceUtil {
> private static Logger logger = LoggerFactory.getLogger(EMFResourceUtil.class);
>
> private final ResourceSet resourceSet;
> private Resource resource = null;
>
> public EMFResourceUtil(ResourceFactoryImpl resourceFactoryImpl) {
> // Create a resource set.
> resourceSet = new ResourceSetImpl();
>
> // Register the default resource factory -- only needed for stand-alone!
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(
> Resource.Factory.Registry.DEFAULT_EXTENSION, resourceFactoryImpl);
> }
>
> private URI makeURI(String filename) {
> // Get the URI of the model file.
> return URI.createFileURI(new File(filename).getAbsolutePath());
> }
>
> public EList<EObject> read(String filename) {
> URI fileURI = makeURI(filename);
>
> resource = resourceSet.getResource(fileURI, true);
>
> if(null == resource) {
> return null;
> }
> return resource.getContents();
> }
>
> public EList<EObject> loadWithoutChildren(String value) {
> resource = resourceSet.createResource(URI.createURI(""));
>
> if(null == resource) {
> return null;
> }
>
> // Save the contents of the resource to the file system.
> try
> {
> ByteArrayInputStream stream = new ByteArrayInputStream(value.getBytes());
> resource.load(stream, null);
> // TODO: improve this hack
> return resource.getContents();
> }
> catch (IOException e) {
> logger.error(e.getMessage());
> e.printStackTrace();
> return null;
> }
> }
>
> public void write(EObject data, String filename) {
> URI fileURI = makeURI(filename);
>
> // Create a resource for this file.
> resource = resourceSet.createResource(fileURI);
>
> // Add the book and writer objects to the contents.
> resource.getContents().add(data);
>
> // Save the contents of the resource to the file system.
> try
> {
> resource.save(null);
> }
> catch (IOException e) {}
> }
>
> public String saveWithoutChildren(EObject data) {
> // Create a resource for this file.
> resource = resourceSet.createResource(URI.createURI(""));
>
> // Add the book and writer objects to the contents.
> resource.getContents().add(data);
>
> // Save the contents of the resource to the file system.
> try
> {
> ByteArrayOutputStream stream = new ByteArrayOutputStream();
> resource.save(stream, null);
> // TODO: improve this hack
> return stream.toString();
> }
> catch (IOException e) {
> return "";
> }
> }
>
> public void close() {
> if(null != resource) {
> resource.unload();
> }
> }
> }
>
> Save to file usage:
> EMFResourceUtil util = new EMFResourceUtil(new PrlResourceFactoryImpl());
> util.write(eObject, pathname);
> util.close();
>
> Load from file usage:
> EMFResourceUtil util = new EMFResourceUtil(new PrlResourceFactoryImpl());
> EList<EObject> contents = util.read(pathname);
> ...
> EObject newEObject = contents.get(0);
> util.close();
>
> Save without children to string:
> EMFResourceUtil util = new EMFResourceUtil(new ChildlessPrlResourceFactoryImpl());
> String contents = util.saveWithoutChildren(eObject);
> util.close();
>
> Load from string:
> EMFResourceUtil util = new EMFResourceUtil(new ChildlessPrlResourceFactoryImpl());
> EList<EObject> contents = util.loadWithoutChildren(value);
> ...
> EObject newEObject = contents.get(0);
> util.close();
>
>
Re: Multiple Serializations [message #516712 is a reply to message #516711] Wed, 24 February 2010 21:30 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Jonathan,

I'm not sure if you're still asking question. I see no question marks
in this post or the previous one, nor do any of the sentence look like
questions, so I'll just comment.

Jonathan Seng wrote:
> Further investigation reveals that saving to file is saving with the
> correct tags, but with href=... instead of actual data, where value of the
> href attribute is the URI provided to the create resource.
>
That sounds like an XMI serialization, i.e., one that's using
XMIResourceImpl.
> In context, I have an application where the data is implemented in EMF and
> the application serializes the objects from time to time maintaining
> parent/child in a different mechanism than attribute data. This
> serialization is returned as a byte array or String. When creating the
> resource for this, I am specifying a URI when there really isn't one...
> This is used to select the right factory implementation and, apparently,
> as references when later saving to a file.
Yes, cross file references will use the URI of the resource containing
the referenced object.
> And the saved string has tags
> not agreeing with the schema used to generate the EMF project.
>
The only reasons for this is using different options or a different
resource implementation.
> Thank you,
>
> Jonathan
>
> On Wed, 24 Feb 2010 11:33:18 -0600, Jonathan Seng wrote:
>
>
>> Ed,
>>
>> Right vs. wrong: When I first tried EMF, I copied example code which used
>> XmlResourceFactoryImpl. This produced different output (XML tags like
>> prl:ObjectiveInstructionType) than using the generated
>> PrlResourceFactoryImpl (XML tags like prl:Objective as specified in the
>> schema used to generate the EMF classes).
>>
>> My first thought was that the following code sets a factory for the
>> default extension "*", which might not match the empty URI I use when
>> setting up to write to a string:
>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(
>> Resource.Factory.Registry.DEFAULT_EXTENSION, resourceFactoryImpl);
>>
>> Code follows.
>>
>> Thank you,
>>
>> Jonathan
>>
>>
>>
>> Replacement Factory Impl to replace the XMLSaveImpl:
>>
>> public class ChildlessPrlResourceFactoryImpl extends PrlResourceFactoryImpl {
>>
>> /**
>> * Creates an instance of the resource factory.
>> * <!-- begin-user-doc -->
>> * <!-- end-user-doc -->
>> * @generated
>> */
>> public ChildlessPrlResourceFactoryImpl() {
>> super();
>> }
>>
>> /**
>> * Creates an instance of the resource.
>> * <!-- begin-user-doc -->
>> * <!-- end-user-doc -->
>> * @generated
>> */
>> @Override
>> public Resource createResource(URI uri) {
>> XMLResource result = new ChildlessPrlResourceImpl(uri);
>> result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA, Boolean.TRUE);
>> result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA, Boolean.TRUE);
>>
>> result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION, Boolean.TRUE);
>>
>> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE, Boolean.TRUE);
>> result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE, Boolean.TRUE);
>>
>> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LE XICAL_HANDLER, Boolean.TRUE);
>> return result;
>> }
>>
>> public class ChildlessPrlResourceImpl extends PrlResourceImpl {
>> /**
>> * Creates an instance of the resource.
>> * <!-- begin-user-doc -->
>> * <!-- end-user-doc -->
>> * @param uri the URI of the new resource.
>> * @generated
>> */
>> public ChildlessPrlResourceImpl(URI uri) {
>> super(uri);
>> }
>>
>> @Override
>> protected XMLSave createXMLSave()
>> {
>> return new ChildlessPRLSaveImpl(createXMLHelper());
>> }
>>
>> public class ChildlessPRLSaveImpl extends XMLSaveImpl {
>> public ChildlessPRLSaveImpl(XMLHelper helper) {
>> super(helper);
>> }
>>
>> @Override
>> protected boolean shouldSaveFeature(EObject o, EStructuralFeature f)
>> {
>> if(!super.shouldSaveFeature(o, f)) {
>> return false;
>> }
>>
>> return f instanceof EAttribute;
>> }
>> }
>> }
>> }
>>
>> The following is a chop-up of the tutorial to do full tree file
>> serialization / deserialization and childless save to / load from a
>> string:
>>
>> public class EMFResourceUtil {
>> private static Logger logger = LoggerFactory.getLogger(EMFResourceUtil.class);
>>
>> private final ResourceSet resourceSet;
>> private Resource resource = null;
>>
>> public EMFResourceUtil(ResourceFactoryImpl resourceFactoryImpl) {
>> // Create a resource set.
>> resourceSet = new ResourceSetImpl();
>>
>> // Register the default resource factory -- only needed for stand-alone!
>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(
>> Resource.Factory.Registry.DEFAULT_EXTENSION, resourceFactoryImpl);
>> }
>>
>> private URI makeURI(String filename) {
>> // Get the URI of the model file.
>> return URI.createFileURI(new File(filename).getAbsolutePath());
>> }
>>
>> public EList<EObject> read(String filename) {
>> URI fileURI = makeURI(filename);
>>
>> resource = resourceSet.getResource(fileURI, true);
>>
>> if(null == resource) {
>> return null;
>> }
>> return resource.getContents();
>> }
>>
>> public EList<EObject> loadWithoutChildren(String value) {
>> resource = resourceSet.createResource(URI.createURI(""));
>>
>> if(null == resource) {
>> return null;
>> }
>>
>> // Save the contents of the resource to the file system.
>> try
>> {
>> ByteArrayInputStream stream = new ByteArrayInputStream(value.getBytes());
>> resource.load(stream, null);
>> // TODO: improve this hack
>> return resource.getContents();
>> }
>> catch (IOException e) {
>> logger.error(e.getMessage());
>> e.printStackTrace();
>> return null;
>> }
>> }
>>
>> public void write(EObject data, String filename) {
>> URI fileURI = makeURI(filename);
>>
>> // Create a resource for this file.
>> resource = resourceSet.createResource(fileURI);
>>
>> // Add the book and writer objects to the contents.
>> resource.getContents().add(data);
>>
>> // Save the contents of the resource to the file system.
>> try
>> {
>> resource.save(null);
>> }
>> catch (IOException e) {}
>> }
>>
>> public String saveWithoutChildren(EObject data) {
>> // Create a resource for this file.
>> resource = resourceSet.createResource(URI.createURI(""));
>>
>> // Add the book and writer objects to the contents.
>> resource.getContents().add(data);
>>
>> // Save the contents of the resource to the file system.
>> try
>> {
>> ByteArrayOutputStream stream = new ByteArrayOutputStream();
>> resource.save(stream, null);
>> // TODO: improve this hack
>> return stream.toString();
>> }
>> catch (IOException e) {
>> return "";
>> }
>> }
>>
>> public void close() {
>> if(null != resource) {
>> resource.unload();
>> }
>> }
>> }
>>
>> Save to file usage:
>> EMFResourceUtil util = new EMFResourceUtil(new PrlResourceFactoryImpl());
>> util.write(eObject, pathname);
>> util.close();
>>
>> Load from file usage:
>> EMFResourceUtil util = new EMFResourceUtil(new PrlResourceFactoryImpl());
>> EList<EObject> contents = util.read(pathname);
>> ...
>> EObject newEObject = contents.get(0);
>> util.close();
>>
>> Save without children to string:
>> EMFResourceUtil util = new EMFResourceUtil(new ChildlessPrlResourceFactoryImpl());
>> String contents = util.saveWithoutChildren(eObject);
>> util.close();
>>
>> Load from string:
>> EMFResourceUtil util = new EMFResourceUtil(new ChildlessPrlResourceFactoryImpl());
>> EList<EObject> contents = util.loadWithoutChildren(value);
>> ...
>> EObject newEObject = contents.get(0);
>> util.close();
>>
>>
>>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Multiple Serializations [message #516715 is a reply to message #516712] Wed, 24 February 2010 21:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jseng.valen.trick.gov

Ed,

How do I get my schema-based serialization from my derived factory instead
of the XMI serialization? I believe that all of my created classes derive
from the schema generated classes....

The cross-references I am seeing are not appropriate as they are
referencing URIs inserted to create OutputStreams -- not files. How can I
override them?

Thank you,

Jonathan

On Wed, 24 Feb 2010 16:30:31 -0500, Ed Merks wrote:

> Jonathan,
>
> I'm not sure if you're still asking question. I see no question marks
> in this post or the previous one, nor do any of the sentence look like
> questions, so I'll just comment.
>
> Jonathan Seng wrote:
>> Further investigation reveals that saving to file is saving with the
>> correct tags, but with href=... instead of actual data, where value of the
>> href attribute is the URI provided to the create resource.
>>
> That sounds like an XMI serialization, i.e., one that's using
> XMIResourceImpl.
>> In context, I have an application where the data is implemented in EMF and
>> the application serializes the objects from time to time maintaining
>> parent/child in a different mechanism than attribute data. This
>> serialization is returned as a byte array or String. When creating the
>> resource for this, I am specifying a URI when there really isn't one...
>> This is used to select the right factory implementation and, apparently,
>> as references when later saving to a file.
> Yes, cross file references will use the URI of the resource containing
> the referenced object.
>> And the saved string has tags
>> not agreeing with the schema used to generate the EMF project.
>>
> The only reasons for this is using different options or a different
> resource implementation.
>> Thank you,
>>
>> Jonathan
>>
Re: Multiple Serializations [message #516726 is a reply to message #516715] Wed, 24 February 2010 22:14 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------000406090209010700090700
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Jonathan,

Be sure you're extending XMLResourceImpl, not XMIResourceImpl, and
XMLSaveImpl,not XMISaveImpl. and be sure you're using the right
options. I'm pretty sure that hrefs can come only from XMI
implementation classes.


Jonathan Seng wrote:
> Ed,
>
> How do I get my schema-based serialization from my derived factory instead
> of the XMI serialization? I believe that all of my created classes derive
> from the schema generated classes....
>
> The cross-references I am seeing are not appropriate as they are
> referencing URIs inserted to create OutputStreams -- not files. How can I
> override them?
>
> Thank you,
>
> Jonathan
>
> On Wed, 24 Feb 2010 16:30:31 -0500, Ed Merks wrote:
>
>
>> Jonathan,
>>
>> I'm not sure if you're still asking question. I see no question marks
>> in this post or the previous one, nor do any of the sentence look like
>> questions, so I'll just comment.
>>
>> Jonathan Seng wrote:
>>
>>> Further investigation reveals that saving to file is saving with the
>>> correct tags, but with href=... instead of actual data, where value of the
>>> href attribute is the URI provided to the create resource.
>>>
>>>
>> That sounds like an XMI serialization, i.e., one that's using
>> XMIResourceImpl.
>>
>>> In context, I have an application where the data is implemented in EMF and
>>> the application serializes the objects from time to time maintaining
>>> parent/child in a different mechanism than attribute data. This
>>> serialization is returned as a byte array or String. When creating the
>>> resource for this, I am specifying a URI when there really isn't one...
>>> This is used to select the right factory implementation and, apparently,
>>> as references when later saving to a file.
>>>
>> Yes, cross file references will use the URI of the resource containing
>> the referenced object.
>>
>>> And the saved string has tags
>>> not agreeing with the schema used to generate the EMF project.
>>>
>>>
>> The only reasons for this is using different options or a different
>> resource implementation.
>>
>>> Thank you,
>>>
>>> Jonathan
>>>
>>>
>
>
>

--------------000406090209010700090700
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">
Jonathan,<br>
<br>
Be sure you're extending XMLResourceImpl, not XMIResourceImpl, and
XMLSaveImpl,not XMISaveImpl. and be sure you're using the right
options.&nbsp;&nbsp; I'm pretty sure that hrefs can come only from XMI
implementation classes.<br>
<br>
<br>
Jonathan Seng wrote:
<blockquote cite="mid:pan.2010.02.24.21.35.28.82176@valen.trick.gov"
type="cite">
<pre wrap="">Ed,

How do I get my schema-based serialization from my derived factory instead
of the XMI serialization? I believe that all of my created classes derive
from the schema generated classes....

The cross-references I am seeing are not appropriate as they are
referencing URIs inserted to create OutputStreams -- not files. How can I
override them?

Thank you,

Jonathan

On Wed, 24 Feb 2010 16:30:31 -0500, Ed Merks wrote:

</pre>
<blockquote type="cite">
<pre wrap="">Jonathan,

I'm not sure if you're still asking question. I see no question marks
in this post or the previous one, nor do any of the sentence look like
questions, so I'll just comment.

Jonathan Seng wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Further investigation reveals that saving to file is saving with the
correct tags, but with href=... instead of actual data, where value of the
href attribute is the URI provided to the create resource.

</pre>
</blockquote>
<pre wrap="">That sounds like an XMI serialization, i.e., one that's using
XMIResourceImpl.
</pre>
<blockquote type="cite">
<pre wrap="">In context, I have an application where the data is implemented in EMF and
the application serializes the objects from time to time maintaining
parent/child in a different mechanism than attribute data. This
serialization is returned as a byte array or String. When creating the
resource for this, I am specifying a URI when there really isn't one...
This is used to select the right factory implementation and, apparently,
as references when later saving to a file.
</pre>
</blockquote>
<pre wrap="">Yes, cross file references will use the URI of the resource containing
the referenced object.
</pre>
<blockquote type="cite">
<pre wrap=""> And the saved string has tags
not agreeing with the schema used to generate the EMF project.

</pre>
</blockquote>
<pre wrap="">The only reasons for this is using different options or a different
resource implementation.
</pre>
<blockquote type="cite">
<pre wrap="">Thank you,

Jonathan

</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
</body>
</html>

--------------000406090209010700090700--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Multiple Serializations [message #516730 is a reply to message #516726] Wed, 24 February 2010 22:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jseng.valen.trick.gov

Ed,

The generated code extends XMLResourceImpl. My code extends the generated
code. In the event that the package my code was in (the project using the
generated project) was the problem, I moved it into the generated code's
package.

I continue to have the childless string saves using the wrong tags and the
less frequent disk saves using hrefs to the URI used for the childless
string saves.

Is there anything else I can check or do?

Thank you,

Jonathan



On Wed, 24 Feb 2010 17:14:36 -0500, Ed Merks wrote:

> Jonathan,
>
> Be sure you're extending XMLResourceImpl, not XMIResourceImpl, and
> XMLSaveImpl,not XMISaveImpl. and be sure you're using the right
> options. I'm pretty sure that hrefs can come only from XMI
> implementation classes.
>
>
Re: Multiple Serializations [message #516735 is a reply to message #516730] Wed, 24 February 2010 22:46 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------090508000809050104020704
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Jonathan,

My psychic abilities only extend so far...

Presumably the original unaltered resource implementation was working
correctly, right?


Jonathan Seng wrote:
> Ed,
>
> The generated code extends XMLResourceImpl. My code extends the generated
> code. In the event that the package my code was in (the project using the
> generated project) was the problem, I moved it into the generated code's
> package.
>
> I continue to have the childless string saves using the wrong tags and the
> less frequent disk saves using hrefs to the URI used for the childless
> string saves.
>
> Is there anything else I can check or do?
>
> Thank you,
>
> Jonathan
>
>
>
> On Wed, 24 Feb 2010 17:14:36 -0500, Ed Merks wrote:
>
>
>> Jonathan,
>>
>> Be sure you're extending XMLResourceImpl, not XMIResourceImpl, and
>> XMLSaveImpl,not XMISaveImpl. and be sure you're using the right
>> options. I'm pretty sure that hrefs can come only from XMI
>> implementation classes.
>>
>>
>>
>
>

--------------090508000809050104020704
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">
Jonathan,<br>
<br>
My psychic abilities only extend so far... <br>
<br>
Presumably the original unaltered resource implementation was working
correctly, right?<br>
<br>
<br>
Jonathan Seng wrote:
<blockquote cite="mid:pan.2010.02.24.22.27.22.871097@valen.trick.gov"
type="cite">
<pre wrap="">Ed,

The generated code extends XMLResourceImpl. My code extends the generated
code. In the event that the package my code was in (the project using the
generated project) was the problem, I moved it into the generated code's
package.

I continue to have the childless string saves using the wrong tags and the
less frequent disk saves using hrefs to the URI used for the childless
string saves.

Is there anything else I can check or do?

Thank you,

Jonathan



On Wed, 24 Feb 2010 17:14:36 -0500, Ed Merks wrote:

</pre>
<blockquote type="cite">
<pre wrap="">Jonathan,

Be sure you're extending XMLResourceImpl, not XMIResourceImpl, and
XMLSaveImpl,not XMISaveImpl. and be sure you're using the right
options. I'm pretty sure that hrefs can come only from XMI
implementation classes.


</pre>
</blockquote>
<pre wrap=""><!---->
</pre>
</blockquote>
</body>
</html>

--------------090508000809050104020704--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Multiple Serializations [message #516742 is a reply to message #516735] Wed, 24 February 2010 23:06 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jseng.valen.trick.gov

Ed,

Disabling the code that does the stream saves/loads, the files save
correctly the first time. The second save gets hrefs for items saved
similarly the first time such as: <prl:Objective href="#11"/> Note that
the href lacks the file part of the URI reference, yet a file URI was used
to write this to disk.

I recall that before I started with the childless string saves, if I
opened a file, then saved it as another name, I saw hrefs for the content.
So, apparently, it recognizes that a previous save occurred and writes
refs -- even if it crosses resource sets.

Thank you,

Jonathan


On Wed, 24 Feb 2010 17:46:47 -0500, Ed Merks wrote:

> Jonathan,
>
> My psychic abilities only extend so far...
>
> Presumably the original unaltered resource implementation was working
> correctly, right?
>
Re: Multiple Serializations [message #516744 is a reply to message #516742] Wed, 24 February 2010 23:17 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Jonathan,

Comments below.

Jonathan Seng wrote:
> Ed,
>
> Disabling the code that does the stream saves/loads, the files save
> correctly the first time. The second save gets hrefs for items saved
> similarly the first time such as: <prl:Objective href="#11"/> Note that
> the href lacks the file part of the URI reference, yet a file URI was used
> to write this to disk.
>
I have a hard time believing this. I've never know save to change the
state in such a way. References to other parts of the same document will
deresolve to what you are showing; that's normal.
> I recall that before I started with the childless string saves, if I
> opened a file, then saved it as another name, I saw hrefs for the content.
> So, apparently, it recognizes that a previous save occurred and writes
> refs -- even if it crosses resource sets.
>
No, I don't think so. All these problems sound vague. I'm at a loss for
what to say. Notice again your lack of questions...
> Thank you,
>
> Jonathan
>
>
> On Wed, 24 Feb 2010 17:46:47 -0500, Ed Merks wrote:
>
>
>> Jonathan,
>>
>> My psychic abilities only extend so far...
>>
>> Presumably the original unaltered resource implementation was working
>> correctly, right?
>>
>>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Multiple Serializations [message #516888 is a reply to message #516744] Thu, 25 February 2010 08:22 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jseng.valen.trick.gov

Ed,

Clearly, I'm doing something wrong as I am getting results you are
having a hard time believing. None the less, I am getting them and it is
a problem.

What am I doing wrong?

Thank you,

Jonathan

On Wed, 24 Feb 2010 18:17:17 -0500, Ed Merks wrote:

> Jonathan,
>
> Comments below.
>
> Jonathan Seng wrote:
>> Ed,
>>
>> Disabling the code that does the stream saves/loads, the files save
>> correctly the first time. The second save gets hrefs for items saved
>> similarly the first time such as: <prl:Objective href="#11"/> Note that
>> the href lacks the file part of the URI reference, yet a file URI was used
>> to write this to disk.
>>
> I have a hard time believing this. I've never know save to change the
> state in such a way. References to other parts of the same document will
> deresolve to what you are showing; that's normal.
>> I recall that before I started with the childless string saves, if I
>> opened a file, then saved it as another name, I saw hrefs for the content.
>> So, apparently, it recognizes that a previous save occurred and writes
>> refs -- even if it crosses resource sets.
>>
> No, I don't think so. All these problems sound vague. I'm at a loss for
> what to say. Notice again your lack of questions...
>> Thank you,
>>
>> Jonathan
>>
>>
>> On Wed, 24 Feb 2010 17:46:47 -0500, Ed Merks wrote:
>>
>>
>>> Jonathan,
>>>
>>> My psychic abilities only extend so far...
>>>
>>> Presumably the original unaltered resource implementation was working
>>> correctly, right?
>>>
>>>
Re: Multiple Serializations [message #516895 is a reply to message #516888] Thu, 25 February 2010 13:27 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------070701080508030600020908
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Jonathan,

If you spell out a set or reproducible steps so I can see the problem
locally, then I'll be able to help better.

One possible issue with saving to a different name is that the model may
have unresolved proxies references to the original name.
EcoreUtil.resolveAll can be used to ensure that all proxies are resolved
so that no knowledge of the original resource URIs is retained within
the model itself. Within the UI, invoking Validate... will similarly
ensure that all references are visited and resolved.


Jonathan Seng wrote:
> Ed,
>
> Clearly, I'm doing something wrong as I am getting results you are
> having a hard time believing. None the less, I am getting them and it is
> a problem.
>
> What am I doing wrong?
>
> Thank you,
>
> Jonathan
>
> On Wed, 24 Feb 2010 18:17:17 -0500, Ed Merks wrote:
>
>
>> Jonathan,
>>
>> Comments below.
>>
>> Jonathan Seng wrote:
>>
>>> Ed,
>>>
>>> Disabling the code that does the stream saves/loads, the files save
>>> correctly the first time. The second save gets hrefs for items saved
>>> similarly the first time such as: <prl:Objective href="#11"/> Note that
>>> the href lacks the file part of the URI reference, yet a file URI was used
>>> to write this to disk.
>>>
>>>
>> I have a hard time believing this. I've never know save to change the
>> state in such a way. References to other parts of the same document will
>> deresolve to what you are showing; that's normal.
>>
>>> I recall that before I started with the childless string saves, if I
>>> opened a file, then saved it as another name, I saw hrefs for the content.
>>> So, apparently, it recognizes that a previous save occurred and writes
>>> refs -- even if it crosses resource sets.
>>>
>>>
>> No, I don't think so. All these problems sound vague. I'm at a loss for
>> what to say. Notice again your lack of questions...
>>
>>> Thank you,
>>>
>>> Jonathan
>>>
>>>
>>> On Wed, 24 Feb 2010 17:46:47 -0500, Ed Merks wrote:
>>>
>>>
>>>
>>>> Jonathan,
>>>>
>>>> My psychic abilities only extend so far...
>>>>
>>>> Presumably the original unaltered resource implementation was working
>>>> correctly, right?
>>>>
>>>>
>>>>
>
>

--------------070701080508030600020908
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">
Jonathan,<br>
<br>
If you spell out a set or reproducible steps so I can see the problem
locally, then I'll be able to help better.&nbsp; <br>
<br>
One possible issue with saving to a different name is that the model
may have unresolved proxies references to the original name.&nbsp;
EcoreUtil.resolveAll can be used to ensure that all proxies are
resolved so that no knowledge of the original resource URIs is retained
within the model itself.&nbsp; Within the UI, invoking Validate... will
similarly ensure that all references are visited and resolved.<br>
<br>
<br>
Jonathan Seng wrote:
<blockquote cite="mid:pan.2010.02.25.13.13.54.696897@valen.trick.gov"
type="cite">
<pre wrap="">Ed,

Clearly, I'm doing something wrong as I am getting results you are
having a hard time believing. None the less, I am getting them and it is
a problem.

What am I doing wrong?

Thank you,

Jonathan

On Wed, 24 Feb 2010 18:17:17 -0500, Ed Merks wrote:

</pre>
<blockquote type="cite">
<pre wrap="">Jonathan,

Comments below.

Jonathan Seng wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Ed,

Disabling the code that does the stream saves/loads, the files save
correctly the first time. The second save gets hrefs for items saved
similarly the first time such as: &lt;prl:Objective href="#11"/&gt; Note that
the href lacks the file part of the URI reference, yet a file URI was used
to write this to disk.

</pre>
</blockquote>
<pre wrap="">I have a hard time believing this. I've never know save to change the
state in such a way. References to other parts of the same document will
deresolve to what you are showing; that's normal.
</pre>
<blockquote type="cite">
<pre wrap="">I recall that before I started with the childless string saves, if I
opened a file, then saved it as another name, I saw hrefs for the content.
So, apparently, it recognizes that a previous save occurred and writes
refs -- even if it crosses resource sets.

</pre>
</blockquote>
<pre wrap="">No, I don't think so. All these problems sound vague. I'm at a loss for
what to say. Notice again your lack of questions...
</pre>
<blockquote type="cite">
<pre wrap="">Thank you,

Jonathan


On Wed, 24 Feb 2010 17:46:47 -0500, Ed Merks wrote:


</pre>
<blockquote type="cite">
<pre wrap="">Jonathan,

My psychic abilities only extend so far...

Presumably the original unaltered resource implementation was working
correctly, right?


</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->
</pre>
</blockquote>
</body>
</html>

--------------070701080508030600020908--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Multiple Serializations [message #516896 is a reply to message #516895] Thu, 25 February 2010 13:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jseng.valen.trick.gov

Ed,

I will try the resolveAll() next; however, I just found an issue that may
render this moot.

In order to save an EObject (to file or stream), I must put it in a
Resopurce's contents and save the resource. However, this removes the
object from its parent. (That is, in the debugger,
resource.getContents().add(eobject) leaves eobject with eobject.eContainer
== null first observed by the application losing the parent/child).

Is there a way to save just an object (without its children) without
putting it by itself in a resource?

If not, then I have to change my implementation from keeping a full EMF
tree and saving each object individually, to only assmebling a full EMF
tree for saving the whole file and validating.

Thank you,

Jonathan

On Thu, 25 Feb 2010 08:27:00 -0500, Ed Merks wrote:

> Jonathan,
>
> If you spell out a set or reproducible steps so I can see the problem
> locally, then I'll be able to help better.
>
> One possible issue with saving to a different name is that the model may
> have unresolved proxies references to the original name.
> EcoreUtil.resolveAll can be used to ensure that all proxies are resolved
> so that no knowledge of the original resource URIs is retained within
> the model itself. Within the UI, invoking Validate... will similarly
> ensure that all references are visited and resolved.
>
Re: Multiple Serializations [message #516908 is a reply to message #516895] Thu, 25 February 2010 14:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jseng.valen.trick.gov

Ed,

When writing to a file, I do the following:

....

resource.getContents().add(data);
EcoreUtil.resolveAll(resource);

try
{
resource.save(null);
} ...

The file continues to write hrefs.

Any other thoughts to force these references not to occur? Or, any other
issues to look for as I hunt through the documentation for similar issues?

Thank you,

Jonathan


On Thu, 25 Feb 2010 08:27:00 -0500, Ed Merks wrote:

> Jonathan,
>
> If you spell out a set or reproducible steps so I can see the problem
> locally, then I'll be able to help better.
>
> One possible issue with saving to a different name is that the model may
> have unresolved proxies references to the original name.
> EcoreUtil.resolveAll can be used to ensure that all proxies are resolved
> so that no knowledge of the original resource URIs is retained within
> the model itself. Within the UI, invoking Validate... will similarly
> ensure that all references are visited and resolved.
>
>
Re: Multiple Serializations [message #516925 is a reply to message #516896] Thu, 25 February 2010 14:13 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050404090007040602010002
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Jonathan,

Comments below.

Jonathan Seng wrote:
> Ed,
>
> I will try the resolveAll() next; however, I just found an issue that may
> render this moot.
>
> In order to save an EObject (to file or stream), I must put it in a
> Resopurce's contents and save the resource. However, this removes the
> object from its parent. (That is, in the debugger,
> resource.getContents().add(eobject) leaves eobject with eobject.eContainer
> == null first observed by the application losing the parent/child).
>
Yes, but proxy resolving containments that's not the case.
EcoreUtil.copy could be used to save a copy instead of the original. It
copies the full tree, but you can specialize the EcoreUtil.Copier not to
do that.
> Is there a way to save just an object (without its children) without
> putting it by itself in a resource?
>
No.
> If not, then I have to change my implementation from keeping a full EMF
> tree and saving each object individually, to only assmebling a full EMF
> tree for saving the whole file and validating.
>
Copying an object without copying any contained children should be
relatively simple and cheap.
> Thank you,
>
> Jonathan
>
> On Thu, 25 Feb 2010 08:27:00 -0500, Ed Merks wrote:
>
>
>> Jonathan,
>>
>> If you spell out a set or reproducible steps so I can see the problem
>> locally, then I'll be able to help better.
>>
>> One possible issue with saving to a different name is that the model may
>> have unresolved proxies references to the original name.
>> EcoreUtil.resolveAll can be used to ensure that all proxies are resolved
>> so that no knowledge of the original resource URIs is retained within
>> the model itself. Within the UI, invoking Validate... will similarly
>> ensure that all references are visited and resolved.
>>
>>
>
>
>

--------------050404090007040602010002
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">
Jonathan,<br>
<br>
Comments below.<br>
<br>
Jonathan Seng wrote:
<blockquote cite="mid:pan.2010.02.25.13.42.37.329488@valen.trick.gov"
type="cite">
<pre wrap="">Ed,

I will try the resolveAll() next; however, I just found an issue that may
render this moot.

In order to save an EObject (to file or stream), I must put it in a
Resopurce's contents and save the resource. However, this removes the
object from its parent. (That is, in the debugger,
resource.getContents().add(eobject) leaves eobject with eobject.eContainer
== null first observed by the application losing the parent/child).
</pre>
</blockquote>
Yes, but proxy resolving containments that's not the case.&nbsp;
EcoreUtil.copy could be used to save a copy instead of the original.&nbsp;
It copies the full tree, but you can specialize the EcoreUtil.Copier
not to do that.<br>
<blockquote cite="mid:pan.2010.02.25.13.42.37.329488@valen.trick.gov"
type="cite">
<pre wrap="">
Is there a way to save just an object (without its children) without
putting it by itself in a resource?
</pre>
</blockquote>
No.<br>
<blockquote cite="mid:pan.2010.02.25.13.42.37.329488@valen.trick.gov"
type="cite">
<pre wrap="">
If not, then I have to change my implementation from keeping a full EMF
tree and saving each object individually, to only assmebling a full EMF
tree for saving the whole file and validating.
</pre>
</blockquote>
Copying an object without copying any contained children should be
relatively simple and cheap.<br>
<blockquote cite="mid:pan.2010.02.25.13.42.37.329488@valen.trick.gov"
type="cite">
<pre wrap="">
Thank you,

Jonathan

On Thu, 25 Feb 2010 08:27:00 -0500, Ed Merks wrote:

</pre>
<blockquote type="cite">
<pre wrap="">Jonathan,

If you spell out a set or reproducible steps so I can see the problem
locally, then I'll be able to help better.

One possible issue with saving to a different name is that the model may
have unresolved proxies references to the original name.
EcoreUtil.resolveAll can be used to ensure that all proxies are resolved
so that no knowledge of the original resource URIs is retained within
the model itself. Within the UI, invoking Validate... will similarly
ensure that all references are visited and resolved.

</pre>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
</body>
</html>

--------------050404090007040602010002--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Multiple Serializations [message #516926 is a reply to message #516908] Thu, 25 February 2010 14:15 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------090108040806060607070409
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Jonathan,

Comments below.

Jonathan Seng wrote:
> Ed,
>
> When writing to a file, I do the following:
>
> ...
>
> resource.getContents().add(data);
> EcoreUtil.resolveAll(resource);
>
> try
> {
> resource.save(null);
> } ...
>
> The file continues to write hrefs.
>
> Any other thoughts to force these references not to occur? Or, any other
> issues to look for as I hunt through the documentation for similar issues?
>
The original generated resource implementation for your schema derived
model didn't do that though, right?
> Thank you,
>
> Jonathan
>
>
> On Thu, 25 Feb 2010 08:27:00 -0500, Ed Merks wrote:
>
>
>> Jonathan,
>>
>> If you spell out a set or reproducible steps so I can see the problem
>> locally, then I'll be able to help better.
>>
>> One possible issue with saving to a different name is that the model may
>> have unresolved proxies references to the original name.
>> EcoreUtil.resolveAll can be used to ensure that all proxies are resolved
>> so that no knowledge of the original resource URIs is retained within
>> the model itself. Within the UI, invoking Validate... will similarly
>> ensure that all references are visited and resolved.
>>
>>
>>
>
>
>

--------------090108040806060607070409
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">
Jonathan,<br>
<br>
Comments below.<br>
<br>
Jonathan Seng wrote:
<blockquote cite="mid:pan.2010.02.25.14.00.08.546897@valen.trick.gov"
type="cite">
<pre wrap="">Ed,

When writing to a file, I do the following:

....

resource.getContents().add(data);
EcoreUtil.resolveAll(resource);

try
{
resource.save(null);
} ...

The file continues to write hrefs.

Any other thoughts to force these references not to occur? Or, any other
issues to look for as I hunt through the documentation for similar issues?
</pre>
</blockquote>
The original generated resource implementation for your schema derived
model didn't do that though, right?<br>
<blockquote cite="mid:pan.2010.02.25.14.00.08.546897@valen.trick.gov"
type="cite">
<pre wrap="">
Thank you,

Jonathan


On Thu, 25 Feb 2010 08:27:00 -0500, Ed Merks wrote:

</pre>
<blockquote type="cite">
<pre wrap="">Jonathan,

If you spell out a set or reproducible steps so I can see the problem
locally, then I'll be able to help better.

One possible issue with saving to a different name is that the model may
have unresolved proxies references to the original name.
EcoreUtil.resolveAll can be used to ensure that all proxies are resolved
so that no knowledge of the original resource URIs is retained within
the model itself. Within the UI, invoking Validate... will similarly
ensure that all references are visited and resolved.


</pre>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
</body>
</html>

--------------090108040806060607070409--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Multiple Serializations [message #517039 is a reply to message #516925] Thu, 25 February 2010 20:45 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jseng.valen.trick.gov

Ed,

Copying before save (to file or stream) fixes all hrefs except those
caused by opening a file then saving it. This defers the problem, but
does not solve it.

I realized that the saving to stream of an EObject that was not the root
node was serializing with the tagname of the child feature type when I was
expecting to see the child feature name. This makes sense since the
EObject is being saved without reference to a containing feature.
However, load() from stream does not recognized the tag. What can I do to
get load() to recognize an arbitrary element from within the schema?

Thank you,

Jonathan


On Thu, 25 Feb 2010 09:13:02 -0500, Ed Merks wrote:

> Jonathan,
>
> Comments below.
>
> Jonathan Seng wrote:
>> Ed,
>>
>> I will try the resolveAll() next; however, I just found an issue that may
>> render this moot.
>>
>> In order to save an EObject (to file or stream), I must put it in a
>> Resopurce's contents and save the resource. However, this removes the
>> object from its parent. (That is, in the debugger,
>> resource.getContents().add(eobject) leaves eobject with eobject.eContainer
>> == null first observed by the application losing the parent/child).
>>
> Yes, but proxy resolving containments that's not the case.
> EcoreUtil.copy could be used to save a copy instead of the original. It
> copies the full tree, but you can specialize the EcoreUtil.Copier not to
> do that.
>> Is there a way to save just an object (without its children) without
>> putting it by itself in a resource?
>>
> No.
>> If not, then I have to change my implementation from keeping a full EMF
>> tree and saving each object individually, to only assmebling a full EMF
>> tree for saving the whole file and validating.
>>
> Copying an object without copying any contained children should be
> relatively simple and cheap.
>> Thank you,
>>
>> Jonathan
>>
Re: Multiple Serializations [message #517043 is a reply to message #517039] Thu, 25 February 2010 21:23 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------090106010500020406030903
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Jonathan,

This option might be useful:

/**
* Write only the subtree starting at the specified list of EObjects,
* which must be objects contained by the resource.
*/
String OPTION_ROOT_OBJECTS = "ROOT_OBJECTS";

If the child object is serialized using a tag that corresponds to a
global element declaration then you should be able to deserialize it as
well. If not, your serialization doesn't conform to a schema anyway, so
you might as well use an XMI serialization.


Jonathan Seng wrote:
> Ed,
>
> Copying before save (to file or stream) fixes all hrefs except those
> caused by opening a file then saving it. This defers the problem, but
> does not solve it.
>
> I realized that the saving to stream of an EObject that was not the root
> node was serializing with the tagname of the child feature type when I was
> expecting to see the child feature name. This makes sense since the
> EObject is being saved without reference to a containing feature.
> However, load() from stream does not recognized the tag. What can I do to
> get load() to recognize an arbitrary element from within the schema?
>
> Thank you,
>
> Jonathan
>
>
> On Thu, 25 Feb 2010 09:13:02 -0500, Ed Merks wrote:
>
>
>> Jonathan,
>>
>> Comments below.
>>
>> Jonathan Seng wrote:
>>
>>> Ed,
>>>
>>> I will try the resolveAll() next; however, I just found an issue that may
>>> render this moot.
>>>
>>> In order to save an EObject (to file or stream), I must put it in a
>>> Resopurce's contents and save the resource. However, this removes the
>>> object from its parent. (That is, in the debugger,
>>> resource.getContents().add(eobject) leaves eobject with eobject.eContainer
>>> == null first observed by the application losing the parent/child).
>>>
>>>
>> Yes, but proxy resolving containments that's not the case.
>> EcoreUtil.copy could be used to save a copy instead of the original. It
>> copies the full tree, but you can specialize the EcoreUtil.Copier not to
>> do that.
>>
>>> Is there a way to save just an object (without its children) without
>>> putting it by itself in a resource?
>>>
>>>
>> No.
>>
>>> If not, then I have to change my implementation from keeping a full EMF
>>> tree and saving each object individually, to only assmebling a full EMF
>>> tree for saving the whole file and validating.
>>>
>>>
>> Copying an object without copying any contained children should be
>> relatively simple and cheap.
>>
>>> Thank you,
>>>
>>> Jonathan
>>>
>>>

--------------090106010500020406030903
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">
Jonathan,<br>
<br>
This option might be useful:<br>
<blockquote>&nbsp; /**<br>
&nbsp;&nbsp; * Write only the subtree starting at the specified list of EObjects,
<br>
&nbsp;&nbsp; * which must be objects contained by the resource.<br>
&nbsp;&nbsp; */<br>
&nbsp; String OPTION_ROOT_OBJECTS = "ROOT_OBJECTS";<br>
</blockquote>
If the child object is serialized using a tag that corresponds to a
global element declaration then you should be able to deserialize it as
well. If not, your serialization doesn't conform to a schema anyway, so
you might as well use an XMI serialization.<br>
<br>
<br>
Jonathan Seng wrote:
<blockquote cite="mid:pan.2010.02.25.20.45.02.906254@valen.trick.gov"
type="cite">
<pre wrap="">Ed,

Copying before save (to file or stream) fixes all hrefs except those
caused by opening a file then saving it. This defers the problem, but
does not solve it.

I realized that the saving to stream of an EObject that was not the root
node was serializing with the tagname of the child feature type when I was
expecting to see the child feature name. This makes sense since the
EObject is being saved without reference to a containing feature.
However, load() from stream does not recognized the tag. What can I do to
get load() to recognize an arbitrary element from within the schema?

Thank you,

Jonathan


On Thu, 25 Feb 2010 09:13:02 -0500, Ed Merks wrote:

</pre>
<blockquote type="cite">
<pre wrap="">Jonathan,

Comments below.

Jonathan Seng wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Ed,

I will try the resolveAll() next; however, I just found an issue that may
render this moot.

In order to save an EObject (to file or stream), I must put it in a
Resopurce's contents and save the resource. However, this removes the
object from its parent. (That is, in the debugger,
resource.getContents().add(eobject) leaves eobject with eobject.eContainer
== null first observed by the application losing the parent/child).

</pre>
</blockquote>
<pre wrap="">Yes, but proxy resolving containments that's not the case.
EcoreUtil.copy could be used to save a copy instead of the original. It
copies the full tree, but you can specialize the EcoreUtil.Copier not to
do that.
</pre>
<blockquote type="cite">
<pre wrap="">Is there a way to save just an object (without its children) without
putting it by itself in a resource?

</pre>
</blockquote>
<pre wrap="">No.
</pre>
<blockquote type="cite">
<pre wrap="">If not, then I have to change my implementation from keeping a full EMF
tree and saving each object individually, to only assmebling a full EMF
tree for saving the whole file and validating.

</pre>
</blockquote>
<pre wrap="">Copying an object without copying any contained children should be
relatively simple and cheap.
</pre>
<blockquote type="cite">
<pre wrap="">Thank you,

Jonathan

</pre>
</blockquote>
</blockquote>
</blockquote>
</body>
</html>

--------------090106010500020406030903--


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[EMF + Teneo + EAV]: How to customize table names used in EAV schema?
Next Topic:Accessing editor preference page preferences from Edit plugin
Goto Forum:
  


Current Time: Fri Sep 20 08:24:21 GMT 2024

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

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

Back to the top