[106324] ModelManager#getNewModelForRead/Edit always throws ResourceAlreadyExists exception
diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/model/ModelManagerImpl.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/model/ModelManagerImpl.java
index 4524d27..26da43e 100644
--- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/model/ModelManagerImpl.java
+++ b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/model/ModelManagerImpl.java
@@ -343,63 +343,35 @@
}
private SharedObject _commonNewModel(IFile iFile, boolean force) throws ResourceAlreadyExists, ResourceInUse, IOException, CoreException {
- // let's check to see if resource already exists, either in our cache,
- // or on the system
+ IStructuredModel aSharedModel = null;
+ // First, check if resource already exists on file system.
+ // if is does, then throw Resource in Use iff force==false
+
+ if (iFile.exists() && !force) {
+ throw new ResourceAlreadyExists();
+ }
+
String id = calculateId(iFile);
SharedObject sharedObject = (SharedObject) fManagedObjects.get(id);
- IStructuredModel aSharedModel = null;
- // if shared object is null, then we do not have it already, which is
- // as normally expected.
- if (sharedObject == null) {
- // if not in cache, see if we can retrieve it
- aSharedModel = FileBufferModelManager.getInstance().getModel(iFile);
+
+ if (sharedObject != null && !force) {
+ // if in cache already, and force is not true, then this is an
+ // error
+ // in call
+ throw new ResourceInUse();
}
- else {
- // if sharedObject is not null, then
- // someone has asked us to create a new model for a given id, but
- // it in fact
- // is already in our cache with that id. In this case we will
- // throw
- // an "in use" exception,
- // (unless force is set to true). Because, to do otherwise we will
- // basically be
- // over writing a model that another client is already using. Not
- // nice.
- if (!force) {
- throw new ResourceInUse();
- }
- }
- // if we get here, and result (and shared object) are still null,
- // then all is ok, and we can create it,
- if (aSharedModel == null) {
- aSharedModel = FileBufferModelManager.getInstance().getModel(iFile);
- // rembember, don't set 'true' in model init, since that's always
- // used,
- // even when not new. 'new' is intended to mean "there is not yet
- // a
- // file" for the model.
- aSharedModel.setNewState(true);
- sharedObject = addToCache(id, aSharedModel);
- // when resource is provided, we can set
- // synchronization stamp ... otherwise client should
- // Note: one client which does this is FileModelProvider.
- aSharedModel.resetSynchronizationStamp(iFile);
- }
- else {
- // if result is not null, then we have to check
- // if 'force' was false before deciding to
- // throw an already exists exception.
- if (force) {
- sharedObject = addToCache(id, aSharedModel);
- // when resource is provided, we can set
- // synchronization stamp ... otherwise client should
- // Note: one client which does this is FileModelProvider.
- aSharedModel.resetSynchronizationStamp(iFile);
- }
- else {
- throw new ResourceAlreadyExists();
- }
- }
+
+ // if we get to hear without above exceptions, then all is ok
+ // to get model like normal, but set 'new' attribute (where the
+ // 'new' attribute means this is a model without a corresponding
+ // underlying resource.
+ aSharedModel = FileBufferModelManager.getInstance().getModel(iFile);
+ aSharedModel.setNewState(true);
+ sharedObject = addToCache(id, aSharedModel);
+ // when resource is provided, we can set
+ // synchronization stamp ... otherwise client should
+ // Note: one client which does this is FileModelProvider.
+ aSharedModel.resetSynchronizationStamp(iFile);
return sharedObject;
}
@@ -483,19 +455,6 @@
return FileBufferModelManager.getInstance().calculateId(file);
}
- /**
- * CalculateId provides a common way to determine the id from the provided
- * filename.
- */
- public String calculateId(String filename) {
- // providing common method for consistency.
- // May eventually need to "clean up"
- // any initial "file://" protocols, etc., but currently don't
- // know of anyone doing that.
- String id = filename;
- return id;
- }
-
private IModelHandler calculateType(IFile iFile) throws CoreException {
// IModelManager mm = ((ModelManagerPlugin)
// Platform.getPlugin(ModelManagerPlugin.ID)).getModelManager();
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/NullModelProvider.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/NullModelProvider.java
deleted file mode 100644
index 792d7d8..0000000
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/NullModelProvider.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.sse.ui.internal;
-
-import java.util.HashMap;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.operation.IRunnableContext;
-import org.eclipse.jface.text.Document;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.source.AnnotationModel;
-import org.eclipse.jface.text.source.IAnnotationModel;
-import org.eclipse.ui.texteditor.AbstractDocumentProvider;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-
-
-/**
- * An IModelProvider that builds StructuredModels on top of IDocuments. A
- * prototype for "any IEditorInput" support
- *
- * *** VERY UNTESTED *** TODO: Currently BROKEN
- *
- * @deprecated
- */
-public class NullModelProvider extends AbstractDocumentProvider implements IModelProvider {
-
- private static NullModelProvider _instance = null;
-
- public static synchronized NullModelProvider getInstance() {
- if (_instance == null) {
- _instance = new NullModelProvider();
- }
- return _instance;
- }
-
- private HashMap fModelMap = new HashMap(1);
-
- public NullModelProvider() {
- super();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#createAnnotationModel(java.lang.Object)
- */
- protected IAnnotationModel createAnnotationModel(Object element) {
- return new AnnotationModel();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#createDocument(java.lang.Object)
- */
- protected IDocument createDocument(Object element) {
- // return getModel(element).getStructuredDocument();
- return new Document();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#createElementInfo(java.lang.Object)
- */
- // protected ElementInfo createElementInfo(Object element) throws
- // CoreException {
- // if (fModelMap.get(element) != null)
- // fModelMap.put(element,
- // getModelManager().createUnManagedStructuredModelFor(ContentTypeIdentifierForXML.ContentTypeID_XML));
- // return super.createElementInfo(element);
- // }
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#disposeElementInfo(java.lang.Object,
- * org.eclipse.ui.texteditor.AbstractDocumentProvider.ElementInfo)
- */
- protected void disposeElementInfo(Object element, ElementInfo info) {
- fModelMap.remove(element);
- super.disposeElementInfo(element, info);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#doSaveDocument(org.eclipse.core.runtime.IProgressMonitor,
- * java.lang.Object, org.eclipse.jface.text.IDocument, boolean)
- */
- protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) {
- return;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.ui.IModelProvider#getModel(java.lang.Object)
- */
- public IStructuredModel getModel(Object element) {
- return (IStructuredModel) fModelMap.get(element);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#getOperationRunner(org.eclipse.core.runtime.IProgressMonitor)
- */
- protected IRunnableContext getOperationRunner(IProgressMonitor monitor) {
- return null;
- }
-}