Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [ChangeRecoder] Unexpected behavior
[ChangeRecoder] Unexpected behavior [message #1254558] Sun, 23 February 2014 14:38 Go to next message
Bertrand Quenin is currently offline Bertrand QueninFriend
Messages: 70
Registered: July 2009
Member
Hi (again),

I'm trying to evaluate the Change Recorder. I adapted the sample provided in the EMF reference book like this:

    @Test
    def void testChangeRecorder() {

        // Initialize the model
        ParticipantPackage.eINSTANCE.eClass()

        // Retrieve the default factory singleton
        val factory = ParticipantFactory.eINSTANCE

        // create the content of the model via this program
        val org = factory.createOrganization

        // Register the XMI resource factory for the .website extension
        val reg = Resource.Factory.Registry.INSTANCE

        val m = reg.getExtensionToFactoryMap()
        m.put("xmi", new XMIResourceFactoryImpl())

        // Obtain a new resource set
        val resSet = new ResourceSetImpl()

        // create a resource
        val resource = resSet.createResource(URI.createURI("resource.xmi"))

        // add the instance to the resource
        resource.contents += org

        // start recording
        val recorder = new ChangeRecorder(resource)

        org.name = "Axway"
        org.url = "axway://participant"

        // now save the content.
        try {
            resource.save(Collections.EMPTY_MAP);
        } catch (IOException e) {

            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        // stop recording
        val description = recorder.endRecording()

        log.info("description = " + ReflectionToStringBuilder.toString(description, ToStringStyle.MULTI_LINE_STYLE))
    }


I was expecting to see the changes to the "org" instance in the change description. However, here is the output of the program:

[main] INFO com.axway.mda.runtime.PrototypeTest - description = org.eclipse.emf.ecore.change.impl.ChangeDescriptionImpl@687191d6[
  objectChanges=[org.eclipse.emf.ecore.change.impl.EObjectToChangesMapEntryImpl@2525732f]
  objectsToDetach=<null>
  objectsToAttach=[]
  resourceChanges=[]
  oldContainmentInformation=<null>
  eFlags=1
  eAdapters=<null>
  eContainer=<null>
  eContainerFeatureID=0
  eProperties=<null>
]


It seems that the change set is empty whereas I expected to see 2 entries (1 for the name change and 1 for the url change).

Note that I'm running as a standalone application (not inside Eclipse).

Can anyone explain what I miss?

Regards,
BQ.
Re: [ChangeRecoder] Unexpected behavior [message #1254588 is a reply to message #1254558] Sun, 23 February 2014 15:22 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Bertrand,

Comments below.

On 23/02/2014 3:38 PM, Bertrand Quenin wrote:
> Hi (again),
>
> I'm trying to evaluate the Change Recorder. I adapted the sample
> provided in the EMF reference book like this:
>
>
> @Test
> def void testChangeRecorder() {
>
> // Initialize the model
> ParticipantPackage.eINSTANCE.eClass()
>
> // Retrieve the default factory singleton
> val factory = ParticipantFactory.eINSTANCE
>
> // create the content of the model via this program
> val org = factory.createOrganization
>
> // Register the XMI resource factory for the .website extension
> val reg = Resource.Factory.Registry.INSTANCE
>
> val m = reg.getExtensionToFactoryMap()
> m.put("xmi", new XMIResourceFactoryImpl())
>
> // Obtain a new resource set
> val resSet = new ResourceSetImpl()
>
> // create a resource
> val resource =
> resSet.createResource(URI.createURI("resource.xmi"))
>
> // add the instance to the resource
> resource.contents += org
>
> // start recording
> val recorder = new ChangeRecorder(resource)
>
> org.name = "Axway"
> org.url = "axway://participant"
>
> // now save the content.
> try {
> resource.save(Collections.EMPTY_MAP);
> } catch (IOException e) {
>
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
> // stop recording
> val description = recorder.endRecording()
>
> log.info("description = " +
> ReflectionToStringBuilder.toString(description,
> ToStringStyle.MULTI_LINE_STYLE))
> }
>
>
> I was expecting to see the changes to the "org" instance in the change
> description. However, here is the output of the program:
>
>
> [main] INFO com.axway.mda.runtime.PrototypeTest - description =
> org.eclipse.emf.ecore.change.impl.ChangeDescriptionImpl@687191d6[
> objectChanges=[org.eclipse.emf.ecore.change.impl.EObjectToChangesMapEntryImpl@2525732f]
>
> objectsToDetach=<null>
> objectsToAttach=[]
> resourceChanges=[]
> oldContainmentInformation=<null>
> eFlags=1
> eAdapters=<null>
> eContainer=<null>
> eContainerFeatureID=0
> eProperties=<null>
> ]
>
>
> It seems that the change set is empty whereas I expected to see 2
> entries (1 for the name change and 1 for the url change).
There appears to be one entry in the object changes map.
>
> Note that I'm running as a standalone application (not inside Eclipse).
>
> Can anyone explain what I miss?
My might try putting the change description itself into a resource and
saving that to see the full contents. Don't expect toString of an
implementation to show you the full tree of contained objects.
>
> Regards,
> BQ.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [ChangeRecoder] Unexpected behavior [message #1254608 is a reply to message #1254588] Sun, 23 February 2014 15:51 Go to previous messageGo to next message
Bertrand Quenin is currently offline Bertrand QueninFriend
Messages: 70
Registered: July 2009
Member
Hi Ed,

Quote:

My might try putting the change description itself into a resource and
saving that to see the full contents. Don't expect toString of an
implementation to show you the full tree of contained objects.


Thanks! Here is the result:

<?xml version="1.0" encoding="ASCII"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:change="http://www.eclipse.org/emf/2003/Change" xmlns:participant="participant">
  <participant:Organization name="Axway" url="axway://participant"/>
  <change:ChangeDescription>
    <objectChanges key="/0">
      <value featureName="name" set="false"/>
      <value featureName="url" set="false"/>
    </objectChanges>
  </change:ChangeDescription>
</xmi:XMI>


I can see the changes but I can't see the values though.

Regards,
BQ.
Re: [ChangeRecoder] Unexpected behavior [message #1255149 is a reply to message #1254608] Mon, 24 February 2014 06:12 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Bertrand,

Comments below.

On 23/02/2014 4:51 PM, Bertrand Quenin wrote:
> Hi Ed,
>
> Quote:
>> My might try putting the change description itself into a resource
>> and saving that to see the full contents. Don't expect toString of an
>> implementation to show you the full tree of contained objects.
>
>
> Thanks! Here is the result:
>
>
> <?xml version="1.0" encoding="ASCII"?>
> <xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:change="http://www.eclipse.org/emf/2003/Change"
> xmlns:participant="participant">
> <participant:Organization name="Axway" url="axway://participant"/>
> <change:ChangeDescription>
> <objectChanges key="/0">
> <value featureName="name" set="false"/>
> <value featureName="url" set="false"/>
> </objectChanges>
> </change:ChangeDescription>
> </xmi:XMI>
>
>
> I can see the changes but I can't see the values though.
The change description describes the changes needed to get from the
current state of the model to the original state of the model at the
point when you started recording, i.e., its a reverse delta. Have a
look at
http://git.eclipse.org/c/emf/org.eclipse.emf.git/tree/tests/org.eclipse.emf.test.core/src/org/eclipse/emf/test/core/change/ChangeDescriptionReverseTest.java
to see how to get it to produce a forward delta.
>
> Regards,
> BQ.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [ChangeRecoder] Unexpected behavior [message #1255306 is a reply to message #1255149] Mon, 24 February 2014 09:56 Go to previous message
Bertrand Quenin is currently offline Bertrand QueninFriend
Messages: 70
Registered: July 2009
Member
Thanks for the pointer, will check.
Previous Topic:[Dynamic EMF] adding features to generated EClass at runtime
Next Topic:EMF Model, Resource loading issue
Goto Forum:
  


Current Time: Fri Apr 19 17:06:49 GMT 2024

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

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

Back to the top