Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 106324

Summary: ModelManager#getNewModelForRead/Edit always throws ResourceAlreadyExists exception
Product: [WebTools] WTP Source Editing Reporter: Hirotaka Matsumoto <jljlmatu>
Component: wst.sseAssignee: David Williams <david_williams>
Status: CLOSED FIXED QA Contact:
Severity: critical    
Priority: P1 CC: sisikawa
Version: 0.7.1   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Hirotaka Matsumoto CLA 2005-08-08 05:54:10 EDT
In our editor, we create a model of which file doesn't exist yet. To
do this, we call IModelManager#getNewModelForRead/Edit with IFile
which doesn't exist. But ModelManagerImpl always throw
ResourceAlreadyExists exception so that we can't create a model.
This is critical for our editor's frame support
.
Comment 1 David Williams CLA 2005-08-31 22:43:56 EDT
This was a conceptual error on my part in implementation. 
We'll investigate fixing in 071 stream. 
Comment 2 David Williams CLA 2005-09-04 00:44:49 EDT
I could not reproduce. 
I tried our testNonExistentJSP JUnit test and it seemed to work as 
exected. So ... eihter there is more to the scenerio we'll need to know
... or .. this porblem is related to something else not seen in this simple
tests? If you can provide a JUnit test similar to testNonExisentJSP, but which 
show's the problem, that would be very helpful for us. 
Comment 3 Hirotaka Matsumoto CLA 2005-09-04 23:18:22 EDT
I've a JUnit test case for this, but it depends on our
proprietary code, I can't put this as is, but the net code is that
given that you have a project named "Project" but you don't have
a file of "/Project/WebContent/a.jsp", if you call model manager api
like :

IModelManager modelManager = StructuredModelManager.getModelManager();
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IFile input = root.getFile(new Path("Project/WebContent/a.jsp"));
IStructuredModel model = modelManager.getNewModelForEdit(input,false);

it throws ResourceAlreadyExists exception.



Comment 4 David Williams CLA 2005-09-05 04:00:45 EDT
Thanks, It was the 'false' part of getNewModelForEdit(input,false); that I
didn't have. 

I can reproduce the problem now. 

I will investigate after I get some sleep :) 
Comment 5 David Williams CLA 2005-09-06 03:11:27 EDT
Thanks, I've fixed the etNewModelForEdit(input,false) method so I think it works
as expected now. I will commit to HEAD now, if it would do you some good being
in 0.7.1 stream, I believe we safely could. 

As I fixed this method, though, I realized we do not do much in there, that you
could not do yourself -- indicating this maybe should not be an API method at
all? We do, however, set the 'new' state of the model, meaning it is a model
without an underlying resource. Can you investigate some how tightly that is
required from your current code. Feel free to explain to me in an email (or we
can set up phone call if easier). 
Comment 6 David Williams CLA 2005-09-06 03:13:27 EDT
*** Bug 107316 has been marked as a duplicate of this bug. ***
Comment 7 David Williams CLA 2005-09-06 03:15:33 EDT
*** Bug 107420 has been marked as a duplicate of this bug. ***
Comment 8 Hirotaka Matsumoto CLA 2005-09-07 00:48:49 EDT
(In reply to comment #5)
> without an underlying resource. Can you investigate some how tightly that is
> required from your current code. Feel free to explain to me in an email (or we
> can set up phone call if easier). 

I think the following is a key and not a confidential one, and
we should share this kind of information, so I'll put it here :)

We are mainly three usages for new model.

a) File > New

In eclipse, File > New asks us to create an actual file. I would
think it's ok for the development language ( i.e. C++, java, ...)
But it may not good for non development language ( i.e. html. jsp, 
...) Actually, other tool such as .NET, word, power point, ...don't
ask us to create an actual html/jspfile when we start File > New. In
our editor, we use this new model for creating a freme document
from the existing file ( we call it 'split frame' ) and when saving 
such documents, we ask a filename and save it with that filename. So
our first usage is for frame.

I see this is out-of Eclipse-Way and probably it could be told that
this isn't better Eclipse-Editor-Behaviour. We may change our current
Frame behaviour, but again, this is huge design chagne for our
editor.


b) Save As

Our editors have the functionality for link fixups when the document
is going to be saved so that the saved files can be safely deployed.
( No broken links are there. ) To do this, what we are doing for
SaveAs is :

  - Create a new model
  - Copy the content(text) from the old model to new model
  - Process link fixup for the new model so that the linked 
    resources are copied and the links are fixed up.
  - Save that new model
  - Note: During this process, we can cancel SaveAs so that the
    content of the original model isn't modified. ( because we 
    are using new model for fixup. )

This is our second usage. 


c) Thumbnail

    Our editor(actually some wizards) has a functionality for
    the preview of the file and we are using new model for this
    thumbnail view.

This is our third usage.




Comment 9 Hirotaka Matsumoto CLA 2005-09-22 08:05:02 EDT
I've confirmed that this was fixed.

.