Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Sapphire » reinitialization of the model
reinitialization of the model [message #714159] Tue, 09 August 2011 23:35 Go to next message
Alex Smirnoff is currently offline Alex SmirnoffFriend
Messages: 28
Registered: July 2009
Junior Member
Is there a way to reinitialize the model? I.e. forget the previous state and load the new state in one generic operation. For example, I have empty model initialized and some time later I want to reinitialize it from other model or xml string. Can I do that?
Re: reinitialization of the model [message #714165 is a reply to message #714159] Wed, 10 August 2011 00:15 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
Just go back to how you created the initial model and create a new instance. Then call dispose on the initial model and let it go out of scope.

- Konstantin
Re: reinitialization of the model [message #714212 is a reply to message #714165] Wed, 10 August 2011 04:18 Go to previous messageGo to next message
Alex Smirnoff is currently offline Alex SmirnoffFriend
Messages: 28
Registered: July 2009
Junior Member
The question is related to launch configuration life cycle. Launch configuration tab has createControl and to initialize sapphire control I need to pass the model to it. However initialization of the model will happen in initializeFrom method in with the model state will be set from launch configuration using condig.getAttribute calls.

My take on this would be, rather than storing each property in LC separately, store the whole model in launch configuration as single XML string.

However it is not clear how to reinitialize the same model object from different persisted stores.
Re: reinitialization of the model [message #714218 is a reply to message #714212] Wed, 10 August 2011 04:51 Go to previous messageGo to next message
Alex Smirnoff is currently offline Alex SmirnoffFriend
Messages: 28
Registered: July 2009
Junior Member
The problem with this example is that createControl happens earlier than initializeFrom. This means that I need to keep the model handle between two calls and initialize the model state during second call. To be generic it would be nice to reinitialize the whole model from XML string. But it also possible to create some temporary model instance from xml string and set the state using get/set methods. Any advice?

-alex
Re: reinitialization of the model [message #714232 is a reply to message #714218] Wed, 10 August 2011 06:05 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
So a Sapphire model is layered like so in common XML scenarios...

ModelElement -> XmlResource -> XmlResourceStore -> FileResourceStore or ByteArrayResourceStore

If you've instantiated the model, you are also in control of the resource store. I'd be inclined to take a look at sub-classing XmlResourceStore so that you can control the DOM tree that it is responsible for maintaining. Let's say you replace DOM in XmlResourceStore, you can then invoke refresh( true, true ) on the model root to force the model to re-read everything from the resource.

An alternative for solving the launch configuration initialization problem is to create an empty composite in createControl method. Then in initializeFrom, create the model and SapphireControl as a child of the composite created in createControl.

- Konstantin
Re: reinitialization of the model [message #714566 is a reply to message #714232] Wed, 10 August 2011 21:28 Go to previous messageGo to next message
Alex Smirnoff is currently offline Alex SmirnoffFriend
Messages: 28
Registered: July 2009
Junior Member
If I do initialization like this:

store = new ByteArrayResourceStore();
model = Model.TYPE.instantiate(new RootXmlResource(new XMLResourceStore(store)));


Then in initializeFrom method I do something like this:

String setup = configuration.getAttribute(SETUP, (String)null);
if (setup != null){
    store.setContents(setup.getBytes());
    model.refresh(true, true);
}


It is not working: the model does not change.

If I parse the content using separate model instance and then setting new DOM document to XMLResourceStore, this also does nothing. In this case I also have to extend XMLResourceStore b/c setDomDocument is protected.

So it looks like your last proposition is the only alternative.

-alex.
Re: reinitialization of the model [message #714568 is a reply to message #714566] Wed, 10 August 2011 21:54 Go to previous message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
XmlResourceStore does not listen on ByteArrayResourceStore, so it make sense that setContents() is not noticed. We can fix that if that's an interesting usecase.

It also looks like RootXmlResource caches DOM document during resource construction, so yeah, swapping out DOM isn't going to work now either.

If you are interested in pursuing this usecase, please go ahead and open a bug. I think RootXmlResource/XmlResourceStore/ByteArrayResourceStore should be connected by listeners. It should be sufficient to call setContents on ByteArrayResourceStore and have the model update. Even refresh call should not be necessary as RootXmlResource can take care of that once it is notified that the DOM tree has been replaced.

- Konstantin
Previous Topic:Overriding Sapphire Actions
Next Topic:Unit Testing
Goto Forum:
  


Current Time: Tue Mar 19 04:57:02 GMT 2024

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

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

Back to the top