use of org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceAlreadyExists in project webtools.sourceediting by eclipse.
the class ModelManagerImpl method createNewStructuredDocumentFor.
/**
* Factory method, since a proper IStructuredDocument must have a proper
* parser assigned. Note: its assume that IFile does not actually exist as
* a resource yet. If it does, ResourceAlreadyExists exception is thrown.
* If the resource does already exist, then createStructuredDocumentFor is
* the right API to use.
*
* @throws ResourceInUse
*/
public IStructuredDocument createNewStructuredDocumentFor(IFile iFile) throws ResourceAlreadyExists, IOException, CoreException {
if (iFile.exists()) {
throw new ResourceAlreadyExists(iFile.getFullPath().toOSString());
}
// Will reconsider in future version
// String id = calculateId(iFile);
// if (isResourceInUse(id)) {
// throw new ResourceInUse(iFile.getFullPath().toOSString());
// }
IDocumentLoader loader = null;
IModelHandler handler = calculateType(iFile);
loader = handler.getDocumentLoader();
// for this API, "createNew" we assume the IFile does not exist yet
// as checked above, so just create empty document.
IStructuredDocument result = (IStructuredDocument) loader.createNewStructuredDocument();
return result;
}
use of org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceAlreadyExists in project webtools.sourceediting by eclipse.
the class TestModelManager method testCreateNewStructuredDocumentFor.
public void testCreateNewStructuredDocumentFor() throws IOException, CoreException {
IStructuredModel model = null;
try {
IFile file = getFile();
// ensure model already exists
model = getStructuredModelForEdit();
boolean resourceExists = false;
try {
getMM().createNewStructuredDocumentFor(file);
} catch (ResourceAlreadyExists ex) {
resourceExists = true;
}
assertTrue("should have gotten ResourceAlreadyExits exception", resourceExists);
} finally {
if (model != null)
model.releaseFromEdit();
}
}
use of org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceAlreadyExists in project webtools.sourceediting by eclipse.
the class URLModelProviderCSS method getNewModelForRead.
public IStructuredModel getNewModelForRead(IFile iFile) {
if (iFile == null)
return null;
IModelManager manager = getModelManager();
if (manager == null)
return null;
IStructuredModel model = null;
try {
model = manager.getNewModelForEdit(iFile, false);
} catch (IOException ex) {
} catch (ResourceInUse riu) {
} catch (ResourceAlreadyExists rae) {
} catch (CoreException ce) {
}
return model;
}
use of org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceAlreadyExists in project webtools.sourceediting by eclipse.
the class URLModelProviderCSS method getNewModelForEdit.
public IStructuredModel getNewModelForEdit(IFile iFile) {
if (iFile == null)
return null;
IModelManager manager = getModelManager();
if (manager == null)
return null;
IStructuredModel model = null;
try {
model = manager.getNewModelForEdit(iFile, false);
} catch (IOException ex) {
} catch (ResourceInUse riu) {
} catch (ResourceAlreadyExists rae) {
} catch (CoreException ce) {
}
return model;
}
use of org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceAlreadyExists in project webtools.sourceediting by eclipse.
the class ModelManagerImpl method _commonNewModel.
private SharedObject _commonNewModel(IFile iFile, boolean force) throws ResourceAlreadyExists, ResourceInUse, IOException, CoreException {
IStructuredModel aSharedModel = null;
if (iFile.exists() && !force) {
throw new ResourceAlreadyExists();
}
SharedObject sharedObject = null;
String id = calculateId(iFile);
try {
SYNC.acquire();
sharedObject = (SharedObject) fManagedObjects.get(id);
if (sharedObject != null && !force) {
// in call
throw new ResourceInUse();
}
sharedObject = new SharedObject(id);
fManagedObjects.put(id, sharedObject);
} finally {
SYNC.release();
}
// if we get to here 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.theSharedModel = 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;
}
Aggregations