Home » Modeling » EMF » EMF XML Serialization
EMF XML Serialization [message #431578] |
Fri, 17 July 2009 10:37 |
Eclipse User |
|
|
|
Originally posted by: sebastien.bordes.gmail.com
Hi all,
I have a root object that I want to serialize into a single XML file,
this root object have a list of object which are not contained
(containment=false).
I don't want to add them directly into the resource because I have a lot
of object deeper into my object graph.
Is it possible or must I have to add them into the resource or create a
special engine that will parse my graph to retrieve not contained reference.
Thanks
|
|
| |
Re: EMF XML Serialization [message #431581 is a reply to message #431579] |
Fri, 17 July 2009 12:16 |
Eclipse User |
|
|
|
Originally posted by: sebastien.bordes.gmail.com
Thanks for your reply Robert,
But my problem is not resolved by the addition of the OPTION_SCHEMA_LOCATION
My problem is tah Iwant ot serialize OBject A which have a list of
Object B (the reference is not contained, so my objects B didn't have
container)
The xml generated only contain an element for object A.
If I add objects B into the resource contents, with XMLResource they are
not processed, whereas with the XMIResource they are...
I search a way not to have to add Object (which don't have container)
into the root contents of my Resource.
I've got a lot of Objects which are stored deeper in my graph and it
will be painful to do it by hand ....
Here my resource factory used with default options
public class SpecialXMLResourceFactoryImpl extends ResourceFactoryImpl {
private List lookupTable = new ArrayList();
private XMLParserPool parserPool = new XMLParserPoolImpl();
private Map nameToFeatureMap = new HashMap();
/**
* {@inheritDoc}
*/
@Override
public Resource createResource(URI uri) {
XMLResource resource = new XMLResourceImpl(uri);
Map saveOptions = resource.getDefaultSaveOptions();
saveOptions.put(XMLResource.OPTION_PROCESS_DANGLING_HREF,
XMLResource.OPTION_PROCESS_DANGLING_HREF_RECORD);
saveOptions.put(XMLResource.OPTION_CONFIGURATION_CACHE,
Boolean.TRUE);
saveOptions.put(XMLResource.OPTION_USE_CACHED_LOOKUP_TABLE,
lookupTable);
Map loadOptions = resource.getDefaultLoadOptions();
loadOptions.put(XMLResource.OPTION_PROCESS_DANGLING_HREF,
XMLResource.OPTION_PROCESS_DANGLING_HREF_RECORD);
loadOptions.put(XMLResource.OPTION_DEFER_ATTACHMENT, Boolean.TRUE);
loadOptions.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION,
Boolean.TRUE);
loadOptions.put(XMLResource.OPTION_USE_DEPRECATED_METHODS,
Boolean.TRUE);
loadOptions.put(XMLResource.OPTION_USE_PARSER_POOL, parserPool);
loadOptions.put(XMLResource.OPTION_USE_XML_NAME_TO_FEATURE_M AP,
nameToFeatureMap);
return resource;
}
}
and how I use it
public ResourceSet getResourceSet() {
if (resourceSet == null) {
resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "xml",
new SpecialXMLResourceFactoryImpl());
}
return resourceSet;
}
Resource resource = getResourceSet().createResource(getURI());
resource.getContents().add(getMyRootObject());
resource.save(Collections.EMPTY_MAP);
Thanks for your support.
Robert Walter a écrit :
> Hi Sébastian
>
> this is how I have done it once:
>
> <<<<<<<<<<<<<<<CODE>>>>>>>>>>>>>>>>>>>>
> ResourceSet resourceSet = new ResourceSetImpl();
>
> // Register XML resource factory
> resourceSet.getResourceFactoryRegistry().
> getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
>
> Map<String, Boolean> options = new HashMap<String, Boolean>();
> options.put(XMIResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
> Resource resource = resourceSet.createResource(
> URI.createFileURI("XMIModels/Component.xmi"));
>
> // add the root object to the resource
> resource.getContents().add(modelRoot);
> // write the XMI file
> resource.save(options);
> <<<<<<<<<<<<<<<CODE>>>>>>>>>>>>>>>>>>>>
>
> This was with eclipse 3.2 (or 3.3) I think...
> Hope that helps anyway!
>
> -> Robert
>
> Bordes Sébastien wrote:
>
>> Hi all,
>
>> I have a root object that I want to serialize into a single XML file,
>> this root object have a list of object which are not contained
>> (containment=false).
>
>> I don't want to add them directly into the resource because I have a
>> lot of object deeper into my object graph.
>
>> Is it possible or must I have to add them into the resource or create
>> a special engine that will parse my graph to retrieve not contained
>> reference.
>
>> Thanks
>
>
|
|
|
Re: EMF XML Serialization [message #431586 is a reply to message #431581] |
Fri, 17 July 2009 15:28 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Sébastien,
Comments below.
Bordes Sébastien wrote:
> Thanks for your reply Robert,
>
> But my problem is not resolved by the addition of the
> OPTION_SCHEMA_LOCATION
>
> My problem is tah Iwant ot serialize OBject A which have a list of
> Object B (the reference is not contained, so my objects B didn't have
> container)
To serialize a reference to an object, that object must be contained by
a resource. It can be contained by a different resource though...
>
> The xml generated only contain an element for object A.
And will complain about dangling references if the referenced object
isn't contained by a resource.
>
> If I add objects B into the resource contents, with XMLResource they
> are not processed, whereas with the XMIResource they are...
Yes, XML can only have one root, and only XMIResource introduces a
"fake" XMI root element...
>
> I search a way not to have to add Object (which don't have container)
> into the root contents of my Resource.
The question is, what do you expect the serialization to look like? Do
you want it to serialize as if the reference were containment? Why not
make it a containment?
>
> I've got a lot of Objects which are stored deeper in my graph and it
> will be painful to do it by hand ....
>
>
> Here my resource factory used with default options
>
> public class SpecialXMLResourceFactoryImpl extends ResourceFactoryImpl {
>
> private List lookupTable = new ArrayList();
>
> private XMLParserPool parserPool = new XMLParserPoolImpl();
>
> private Map nameToFeatureMap = new HashMap();
>
> /**
> * {@inheritDoc}
> */
> @Override
> public Resource createResource(URI uri) {
>
> XMLResource resource = new XMLResourceImpl(uri);
>
> Map saveOptions = resource.getDefaultSaveOptions();
> saveOptions.put(XMLResource.OPTION_PROCESS_DANGLING_HREF,
> XMLResource.OPTION_PROCESS_DANGLING_HREF_RECORD);
>
> saveOptions.put(XMLResource.OPTION_CONFIGURATION_CACHE,
> Boolean.TRUE);
> saveOptions.put(XMLResource.OPTION_USE_CACHED_LOOKUP_TABLE,
> lookupTable);
>
> Map loadOptions = resource.getDefaultLoadOptions();
> loadOptions.put(XMLResource.OPTION_PROCESS_DANGLING_HREF,
> XMLResource.OPTION_PROCESS_DANGLING_HREF_RECORD);
>
> loadOptions.put(XMLResource.OPTION_DEFER_ATTACHMENT,
> Boolean.TRUE);
> loadOptions.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION,
> Boolean.TRUE);
> loadOptions.put(XMLResource.OPTION_USE_DEPRECATED_METHODS,
> Boolean.TRUE);
> loadOptions.put(XMLResource.OPTION_USE_PARSER_POOL, parserPool);
>
> loadOptions.put(XMLResource.OPTION_USE_XML_NAME_TO_FEATURE_M AP,
> nameToFeatureMap);
>
> return resource;
> }
>
> }
>
>
>
> and how I use it
>
>
>
> public ResourceSet getResourceSet() {
> if (resourceSet == null) {
> resourceSet = new ResourceSetImpl();
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "xml",
> new SpecialXMLResourceFactoryImpl());
> }
> return resourceSet;
> }
>
>
> Resource resource = getResourceSet().createResource(getURI());
> resource.getContents().add(getMyRootObject());
> resource.save(Collections.EMPTY_MAP);
>
> Thanks for your support.
>
> Robert Walter a écrit :
>> Hi Sébastian
>>
>> this is how I have done it once:
>>
>> <<<<<<<<<<<<<<<CODE>>>>>>>>>>>>>>>>>>>>
>> ResourceSet resourceSet = new ResourceSetImpl();
>>
>> // Register XML resource factory
>> resourceSet.getResourceFactoryRegistry().
>> getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
>>
>> Map<String, Boolean> options = new HashMap<String, Boolean>();
>> options.put(XMIResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
>> Resource resource = resourceSet.createResource(
>> URI.createFileURI("XMIModels/Component.xmi"));
>> // add the root object to the resource
>> resource.getContents().add(modelRoot);
>> // write the XMI file
>> resource.save(options);
>> <<<<<<<<<<<<<<<CODE>>>>>>>>>>>>>>>>>>>>
>>
>> This was with eclipse 3.2 (or 3.3) I think...
>> Hope that helps anyway!
>>
>> -> Robert
>>
>> Bordes Sébastien wrote:
>>
>>> Hi all,
>>
>>> I have a root object that I want to serialize into a single XML
>>> file, this root object have a list of object which are not contained
>>> (containment=false).
>>
>>> I don't want to add them directly into the resource because I have a
>>> lot of object deeper into my object graph.
>>
>>> Is it possible or must I have to add them into the resource or
>>> create a special engine that will parse my graph to retrieve not
>>> contained reference.
>>
>>> Thanks
>>
>>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: EMF XML Serialization [message #431587 is a reply to message #431586] |
Fri, 17 July 2009 16:10 |
Eclipse User |
|
|
|
Originally posted by: sebastien.bordes.gmail.com
Thanks Ed,
You confirm my thoughts, I read and re-read the EMF book to find an
alternative ...
I'm working on a graphical editor which can have a lot of "nomenclature
objects" and shared object.
For example : I've got 10 000 Tasks and only 20 TaskType object
I don't want to serialize the TaskType 10 000 times but only 20. I
understand that like EMF persistence is coded I should use as many
resource as I have Container (and its related contained objects), my my
requisite is to have only one file (like the most time when we want an
xml file to exchange with other applications)
Now I explain my notion of shared objects and why I can't use
containment=true, the root object (Planning) I want to serialize is
loaded into one editor, and it's contained into the root application
object (Data).
So the Data object will contain a list of Planning. Each planning have a
dedicated graphical editor, and planning have a list of 'Person' which
can be shared by many Planning.
If I activate the containement=true, My Person couldn't be into 2 or
more planning.
This afternoon I coded a workaround that I Will automate soon , I
iterate over my graph to find object without container (ie: Person) and
I add them to the resource. The save and load works well.
But for largest model it could be a waste of time to parse the model
twice, one time to add object with have an eContainer==null and another
time to serialize the graph to XML.
Is it possible to add an XMI option why will allow to add object into
the resource if they are not contained instead of throw A DanglingException.
Could I override easily a XMISaveImpl class to do this ?
Thanks for your expertise :D
Ed Merks a écrit :
> Sébastien,
>
> Comments below.
>
> Bordes Sébastien wrote:
>> Thanks for your reply Robert,
>>
>> But my problem is not resolved by the addition of the
>> OPTION_SCHEMA_LOCATION
>>
>> My problem is tah Iwant ot serialize OBject A which have a list of
>> Object B (the reference is not contained, so my objects B didn't have
>> container)
> To serialize a reference to an object, that object must be contained by
> a resource. It can be contained by a different resource though...
>>
>> The xml generated only contain an element for object A.
> And will complain about dangling references if the referenced object
> isn't contained by a resource.
>>
>> If I add objects B into the resource contents, with XMLResource they
>> are not processed, whereas with the XMIResource they are...
> Yes, XML can only have one root, and only XMIResource introduces a
> "fake" XMI root element...
>>
>> I search a way not to have to add Object (which don't have container)
>> into the root contents of my Resource.
> The question is, what do you expect the serialization to look like? Do
> you want it to serialize as if the reference were containment? Why not
> make it a containment?
>>
>> I've got a lot of Objects which are stored deeper in my graph and it
>> will be painful to do it by hand ....
>>
>>
>> Here my resource factory used with default options
>>
>> public class SpecialXMLResourceFactoryImpl extends ResourceFactoryImpl {
>>
>> private List lookupTable = new ArrayList();
>>
>> private XMLParserPool parserPool = new XMLParserPoolImpl();
>>
>> private Map nameToFeatureMap = new HashMap();
>>
>> /**
>> * {@inheritDoc}
>> */
>> @Override
>> public Resource createResource(URI uri) {
>>
>> XMLResource resource = new XMLResourceImpl(uri);
>>
>> Map saveOptions = resource.getDefaultSaveOptions();
>> saveOptions.put(XMLResource.OPTION_PROCESS_DANGLING_HREF,
>> XMLResource.OPTION_PROCESS_DANGLING_HREF_RECORD);
>>
>> saveOptions.put(XMLResource.OPTION_CONFIGURATION_CACHE,
>> Boolean.TRUE);
>> saveOptions.put(XMLResource.OPTION_USE_CACHED_LOOKUP_TABLE,
>> lookupTable);
>>
>> Map loadOptions = resource.getDefaultLoadOptions();
>> loadOptions.put(XMLResource.OPTION_PROCESS_DANGLING_HREF,
>> XMLResource.OPTION_PROCESS_DANGLING_HREF_RECORD);
>>
>> loadOptions.put(XMLResource.OPTION_DEFER_ATTACHMENT,
>> Boolean.TRUE);
>> loadOptions.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION,
>> Boolean.TRUE);
>> loadOptions.put(XMLResource.OPTION_USE_DEPRECATED_METHODS,
>> Boolean.TRUE);
>> loadOptions.put(XMLResource.OPTION_USE_PARSER_POOL, parserPool);
>>
>> loadOptions.put(XMLResource.OPTION_USE_XML_NAME_TO_FEATURE_M AP,
>> nameToFeatureMap);
>>
>> return resource;
>> }
>>
>> }
>>
>>
>>
>> and how I use it
>>
>>
>>
>> public ResourceSet getResourceSet() {
>> if (resourceSet == null) {
>> resourceSet = new ResourceSetImpl();
>>
>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "xml",
>> new SpecialXMLResourceFactoryImpl());
>> }
>> return resourceSet;
>> }
>>
>>
>> Resource resource = getResourceSet().createResource(getURI());
>> resource.getContents().add(getMyRootObject());
>> resource.save(Collections.EMPTY_MAP);
>>
>> Thanks for your support.
>>
>> Robert Walter a écrit :
>>> Hi Sébastian
>>>
>>> this is how I have done it once:
>>>
>>> <<<<<<<<<<<<<<<CODE>>>>>>>>>>>>>>>>>>>>
>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>
>>> // Register XML resource factory
>>> resourceSet.getResourceFactoryRegistry().
>>> getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
>>>
>>> Map<String, Boolean> options = new HashMap<String, Boolean>();
>>> options.put(XMIResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
>>> Resource resource = resourceSet.createResource(
>>> URI.createFileURI("XMIModels/Component.xmi"));
>>> // add the root object to the resource
>>> resource.getContents().add(modelRoot);
>>> // write the XMI file
>>> resource.save(options);
>>> <<<<<<<<<<<<<<<CODE>>>>>>>>>>>>>>>>>>>>
>>>
>>> This was with eclipse 3.2 (or 3.3) I think...
>>> Hope that helps anyway!
>>>
>>> -> Robert
>>>
>>> Bordes Sébastien wrote:
>>>
>>>> Hi all,
>>>
>>>> I have a root object that I want to serialize into a single XML
>>>> file, this root object have a list of object which are not contained
>>>> (containment=false).
>>>
>>>> I don't want to add them directly into the resource because I have a
>>>> lot of object deeper into my object graph.
>>>
>>>> Is it possible or must I have to add them into the resource or
>>>> create a special engine that will parse my graph to retrieve not
>>>> contained reference.
>>>
>>>> Thanks
>>>
>>>
|
|
|
Re: EMF XML Serialization [message #431650 is a reply to message #431587] |
Mon, 20 July 2009 18:47 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Sébastien,
Comments below.
Bordes Sébastien wrote:
> Thanks Ed,
>
> You confirm my thoughts, I read and re-read the EMF book to find an
> alternative ...
>
> I'm working on a graphical editor which can have a lot of
> "nomenclature objects" and shared object.
>
> For example : I've got 10 000 Tasks and only 20 TaskType object
>
> I don't want to serialize the TaskType 10 000 times but only 20. I
> understand that like EMF persistence is coded I should use as many
> resource as I have Container (and its related contained objects), my
> my requisite is to have only one file (like the most time when we want
> an xml file to exchange with other applications)
>
>
> Now I explain my notion of shared objects and why I can't use
> containment=true, the root object (Planning) I want to serialize is
> loaded into one editor, and it's contained into the root application
> object (Data).
> So the Data object will contain a list of Planning. Each planning have
> a dedicated graphical editor, and planning have a list of 'Person'
> which can be shared by many Planning.
> If I activate the containement=true, My Person couldn't be into 2 or
> more planning.
>
>
> This afternoon I coded a workaround that I Will automate soon , I
> iterate over my graph to find object without container (ie: Person)
> and I add them to the resource. The save and load works well.
Who's creating the instance? An editor or some program?
>
> But for largest model it could be a waste of time to parse the model
> twice, one time to add object with have an eContainer==null and
> another time to serialize the graph to XML.
Generally I'd worry about performance only after you've measured it.
>
> Is it possible to add an XMI option why will allow to add object into
> the resource if they are not contained instead of throw A
> DanglingException.
I suppose, but modifying the thing while saving it seems problematic...
>
> Could I override easily a XMISaveImpl class to do this ?
XMLHelperImpl.handleDanglingHREF would be the place to look.
>
> Thanks for your expertise :D
>
> Ed Merks a écrit :
>> Sébastien,
>>
>> Comments below.
>>
>> Bordes Sébastien wrote:
>>> Thanks for your reply Robert,
>>>
>>> But my problem is not resolved by the addition of the
>>> OPTION_SCHEMA_LOCATION
>>>
>>> My problem is tah Iwant ot serialize OBject A which have a list of
>>> Object B (the reference is not contained, so my objects B didn't
>>> have container)
>> To serialize a reference to an object, that object must be contained
>> by a resource. It can be contained by a different resource though...
>>>
>>> The xml generated only contain an element for object A.
>> And will complain about dangling references if the referenced object
>> isn't contained by a resource.
>>>
>>> If I add objects B into the resource contents, with XMLResource they
>>> are not processed, whereas with the XMIResource they are...
>> Yes, XML can only have one root, and only XMIResource introduces a
>> "fake" XMI root element...
>>>
>>> I search a way not to have to add Object (which don't have
>>> container) into the root contents of my Resource.
>> The question is, what do you expect the serialization to look like?
>> Do you want it to serialize as if the reference were containment?
>> Why not make it a containment?
>>>
>>> I've got a lot of Objects which are stored deeper in my graph and it
>>> will be painful to do it by hand ....
>>>
>>>
>>> Here my resource factory used with default options
>>>
>>> public class SpecialXMLResourceFactoryImpl extends
>>> ResourceFactoryImpl {
>>>
>>> private List lookupTable = new ArrayList();
>>>
>>> private XMLParserPool parserPool = new XMLParserPoolImpl();
>>>
>>> private Map nameToFeatureMap = new HashMap();
>>>
>>> /**
>>> * {@inheritDoc}
>>> */
>>> @Override
>>> public Resource createResource(URI uri) {
>>>
>>> XMLResource resource = new XMLResourceImpl(uri);
>>>
>>> Map saveOptions = resource.getDefaultSaveOptions();
>>> saveOptions.put(XMLResource.OPTION_PROCESS_DANGLING_HREF,
>>> XMLResource.OPTION_PROCESS_DANGLING_HREF_RECORD);
>>>
>>> saveOptions.put(XMLResource.OPTION_CONFIGURATION_CACHE,
>>> Boolean.TRUE);
>>> saveOptions.put(XMLResource.OPTION_USE_CACHED_LOOKUP_TABLE,
>>> lookupTable);
>>>
>>> Map loadOptions = resource.getDefaultLoadOptions();
>>> loadOptions.put(XMLResource.OPTION_PROCESS_DANGLING_HREF,
>>> XMLResource.OPTION_PROCESS_DANGLING_HREF_RECORD);
>>>
>>> loadOptions.put(XMLResource.OPTION_DEFER_ATTACHMENT,
>>> Boolean.TRUE);
>>> loadOptions.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION,
>>> Boolean.TRUE);
>>> loadOptions.put(XMLResource.OPTION_USE_DEPRECATED_METHODS,
>>> Boolean.TRUE);
>>> loadOptions.put(XMLResource.OPTION_USE_PARSER_POOL,
>>> parserPool);
>>>
>>> loadOptions.put(XMLResource.OPTION_USE_XML_NAME_TO_FEATURE_M AP,
>>> nameToFeatureMap);
>>>
>>> return resource;
>>> }
>>>
>>> }
>>>
>>>
>>>
>>> and how I use it
>>>
>>>
>>>
>>> public ResourceSet getResourceSet() {
>>> if (resourceSet == null) {
>>> resourceSet = new ResourceSetImpl();
>>>
>>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "xml",
>>> new SpecialXMLResourceFactoryImpl());
>>> }
>>> return resourceSet;
>>> }
>>>
>>>
>>> Resource resource = getResourceSet().createResource(getURI());
>>> resource.getContents().add(getMyRootObject());
>>> resource.save(Collections.EMPTY_MAP);
>>>
>>> Thanks for your support.
>>>
>>> Robert Walter a écrit :
>>>> Hi Sébastian
>>>>
>>>> this is how I have done it once:
>>>>
>>>> <<<<<<<<<<<<<<<CODE>>>>>>>>>>>>>>>>>>>>
>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>>
>>>> // Register XML resource factory
>>>> resourceSet.getResourceFactoryRegistry().
>>>> getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
>>>>
>>>> Map<String, Boolean> options = new HashMap<String, Boolean>();
>>>> options.put(XMIResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
>>>> Resource resource = resourceSet.createResource(
>>>> URI.createFileURI("XMIModels/Component.xmi"));
>>>> // add the root object to the resource
>>>> resource.getContents().add(modelRoot);
>>>> // write the XMI file
>>>> resource.save(options);
>>>> <<<<<<<<<<<<<<<CODE>>>>>>>>>>>>>>>>>>>>
>>>>
>>>> This was with eclipse 3.2 (or 3.3) I think...
>>>> Hope that helps anyway!
>>>>
>>>> -> Robert
>>>>
>>>> Bordes Sébastien wrote:
>>>>
>>>>> Hi all,
>>>>
>>>>> I have a root object that I want to serialize into a single XML
>>>>> file, this root object have a list of object which are not
>>>>> contained (containment=false).
>>>>
>>>>> I don't want to add them directly into the resource because I have
>>>>> a lot of object deeper into my object graph.
>>>>
>>>>> Is it possible or must I have to add them into the resource or
>>>>> create a special engine that will parse my graph to retrieve not
>>>>> contained reference.
>>>>
>>>>> Thanks
>>>>
>>>>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: EMF XML Serialization [message #431676 is a reply to message #431650] |
Tue, 21 July 2009 14:08 |
Eclipse User |
|
|
|
Originally posted by: sebastien.bordes.gmail.com
I tried to override the XMIHelperImpl in order to redefine the
handleDanglingHREF but I had been compelled to override the
XMISaveImpl.traverse method.
And I hurt myself with the processObjects and processObject and the
famous XMI root tag
I succeed in saving the xml file with everything I want but the loading
failed because objects are not in the same order. (I do an iteration in
larger (parcours en profondeur) instead of an iteration in deep (parcour
en profondeur)...:( I don't know how you say in English)
So this process is realizable but quite difficult and I haven't got
enought time to do it now...
Ed Merks a écrit :
> Sébastien,
>
> Comments below.
>
> Bordes Sébastien wrote:
>> Thanks Ed,
>>
>> You confirm my thoughts, I read and re-read the EMF book to find an
>> alternative ...
>>
>> I'm working on a graphical editor which can have a lot of
>> "nomenclature objects" and shared object.
>>
>> For example : I've got 10 000 Tasks and only 20 TaskType object
>>
>> I don't want to serialize the TaskType 10 000 times but only 20. I
>> understand that like EMF persistence is coded I should use as many
>> resource as I have Container (and its related contained objects), my
>> my requisite is to have only one file (like the most time when we want
>> an xml file to exchange with other applications)
>>
>>
>> Now I explain my notion of shared objects and why I can't use
>> containment=true, the root object (Planning) I want to serialize is
>> loaded into one editor, and it's contained into the root application
>> object (Data).
>> So the Data object will contain a list of Planning. Each planning have
>> a dedicated graphical editor, and planning have a list of 'Person'
>> which can be shared by many Planning.
>> If I activate the containement=true, My Person couldn't be into 2 or
>> more planning.
>>
>>
>> This afternoon I coded a workaround that I Will automate soon , I
>> iterate over my graph to find object without container (ie: Person)
>> and I add them to the resource. The save and load works well.
> Who's creating the instance? An editor or some program?
>>
>> But for largest model it could be a waste of time to parse the model
>> twice, one time to add object with have an eContainer==null and
>> another time to serialize the graph to XML.
> Generally I'd worry about performance only after you've measured it.
>>
>> Is it possible to add an XMI option why will allow to add object into
>> the resource if they are not contained instead of throw A
>> DanglingException.
> I suppose, but modifying the thing while saving it seems problematic...
>>
>> Could I override easily a XMISaveImpl class to do this ?
> XMLHelperImpl.handleDanglingHREF would be the place to look.
>>
>> Thanks for your expertise :D
>>
>> Ed Merks a écrit :
>>> Sébastien,
>>>
>>> Comments below.
>>>
>>> Bordes Sébastien wrote:
>>>> Thanks for your reply Robert,
>>>>
>>>> But my problem is not resolved by the addition of the
>>>> OPTION_SCHEMA_LOCATION
>>>>
>>>> My problem is tah Iwant ot serialize OBject A which have a list of
>>>> Object B (the reference is not contained, so my objects B didn't
>>>> have container)
>>> To serialize a reference to an object, that object must be contained
>>> by a resource. It can be contained by a different resource though...
>>>>
>>>> The xml generated only contain an element for object A.
>>> And will complain about dangling references if the referenced object
>>> isn't contained by a resource.
>>>>
>>>> If I add objects B into the resource contents, with XMLResource they
>>>> are not processed, whereas with the XMIResource they are...
>>> Yes, XML can only have one root, and only XMIResource introduces a
>>> "fake" XMI root element...
>>>>
>>>> I search a way not to have to add Object (which don't have
>>>> container) into the root contents of my Resource.
>>> The question is, what do you expect the serialization to look like?
>>> Do you want it to serialize as if the reference were containment?
>>> Why not make it a containment?
>>>>
>>>> I've got a lot of Objects which are stored deeper in my graph and it
>>>> will be painful to do it by hand ....
>>>>
>>>>
>>>> Here my resource factory used with default options
>>>>
>>>> public class SpecialXMLResourceFactoryImpl extends
>>>> ResourceFactoryImpl {
>>>>
>>>> private List lookupTable = new ArrayList();
>>>>
>>>> private XMLParserPool parserPool = new XMLParserPoolImpl();
>>>>
>>>> private Map nameToFeatureMap = new HashMap();
>>>>
>>>> /**
>>>> * {@inheritDoc}
>>>> */
>>>> @Override
>>>> public Resource createResource(URI uri) {
>>>>
>>>> XMLResource resource = new XMLResourceImpl(uri);
>>>>
>>>> Map saveOptions = resource.getDefaultSaveOptions();
>>>> saveOptions.put(XMLResource.OPTION_PROCESS_DANGLING_HREF,
>>>> XMLResource.OPTION_PROCESS_DANGLING_HREF_RECORD);
>>>>
>>>> saveOptions.put(XMLResource.OPTION_CONFIGURATION_CACHE,
>>>> Boolean.TRUE);
>>>> saveOptions.put(XMLResource.OPTION_USE_CACHED_LOOKUP_TABLE,
>>>> lookupTable);
>>>>
>>>> Map loadOptions = resource.getDefaultLoadOptions();
>>>> loadOptions.put(XMLResource.OPTION_PROCESS_DANGLING_HREF,
>>>> XMLResource.OPTION_PROCESS_DANGLING_HREF_RECORD);
>>>>
>>>> loadOptions.put(XMLResource.OPTION_DEFER_ATTACHMENT,
>>>> Boolean.TRUE);
>>>> loadOptions.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION,
>>>> Boolean.TRUE);
>>>> loadOptions.put(XMLResource.OPTION_USE_DEPRECATED_METHODS,
>>>> Boolean.TRUE);
>>>> loadOptions.put(XMLResource.OPTION_USE_PARSER_POOL,
>>>> parserPool);
>>>>
>>>> loadOptions.put(XMLResource.OPTION_USE_XML_NAME_TO_FEATURE_M AP,
>>>> nameToFeatureMap);
>>>>
>>>> return resource;
>>>> }
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> and how I use it
>>>>
>>>>
>>>>
>>>> public ResourceSet getResourceSet() {
>>>> if (resourceSet == null) {
>>>> resourceSet = new ResourceSetImpl();
>>>>
>>>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "xml",
>>>> new SpecialXMLResourceFactoryImpl());
>>>> }
>>>> return resourceSet;
>>>> }
>>>>
>>>>
>>>> Resource resource = getResourceSet().createResource(getURI());
>>>> resource.getContents().add(getMyRootObject());
>>>> resource.save(Collections.EMPTY_MAP);
>>>>
>>>> Thanks for your support.
>>>>
>>>> Robert Walter a écrit :
>>>>> Hi Sébastian
>>>>>
>>>>> this is how I have done it once:
>>>>>
>>>>> <<<<<<<<<<<<<<<CODE>>>>>>>>>>>>>>>>>>>>
>>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>>>
>>>>> // Register XML resource factory
>>>>> resourceSet.getResourceFactoryRegistry().
>>>>> getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
>>>>>
>>>>> Map<String, Boolean> options = new HashMap<String, Boolean>();
>>>>> options.put(XMIResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
>>>>> Resource resource = resourceSet.createResource(
>>>>> URI.createFileURI("XMIModels/Component.xmi"));
>>>>> // add the root object to the resource
>>>>> resource.getContents().add(modelRoot);
>>>>> // write the XMI file
>>>>> resource.save(options);
>>>>> <<<<<<<<<<<<<<<CODE>>>>>>>>>>>>>>>>>>>>
>>>>>
>>>>> This was with eclipse 3.2 (or 3.3) I think...
>>>>> Hope that helps anyway!
>>>>>
>>>>> -> Robert
>>>>>
>>>>> Bordes Sébastien wrote:
>>>>>
>>>>>> Hi all,
>>>>>
>>>>>> I have a root object that I want to serialize into a single XML
>>>>>> file, this root object have a list of object which are not
>>>>>> contained (containment=false).
>>>>>
>>>>>> I don't want to add them directly into the resource because I have
>>>>>> a lot of object deeper into my object graph.
>>>>>
>>>>>> Is it possible or must I have to add them into the resource or
>>>>>> create a special engine that will parse my graph to retrieve not
>>>>>> contained reference.
>>>>>
>>>>>> Thanks
>>>>>
>>>>>
|
|
|
Goto Forum:
Current Time: Tue Apr 23 13:31:40 GMT 2024
Powered by FUDForum. Page generated in 0.03060 seconds
|