use of org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse 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;
}
use of org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse in project webtools.sourceediting by eclipse.
the class TestModelManager method testCopyModel.
public void testCopyModel() {
IStructuredModel model = null;
try {
model = getStructuredModelForEdit();
try {
IStructuredModel modelCopy = getMM().copyModelForEdit(model.getId(), "newId");
assertNotNull("copied model was null", modelCopy);
} catch (ResourceInUse e) {
e.printStackTrace();
}
} finally {
if (model != null)
model.releaseFromEdit();
}
}
use of org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse in project webtools.sourceediting by eclipse.
the class FileBufferModelManager method getModel.
public IStructuredModel getModel(IStructuredDocument document) {
if (document == null) {
// $NON-NLS-1$
Exception iae = new IllegalArgumentException("can not get/create a model without a document reference");
Logger.logException(iae);
return null;
}
DocumentInfo info = (DocumentInfo) fDocumentMap.get(document);
if (info != null && info.model == null) {
if (Logger.DEBUG_FILEBUFFERMODELMANAGEMENT) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Logger.log(Logger.INFO, "FileBufferModelManager creating model for " + locationString(info.buffer) + " " + info.buffer.getDocument());
}
info.modelReferenceCount++;
IStructuredModel model = null;
IModelHandler handler = ModelHandlerRegistry.getInstance().getHandlerForContentTypeId(info.contentTypeID);
IModelLoader loader = handler.getModelLoader();
String id = (info.buffer.getLocation() != null ? info.buffer.getLocation().toString() : String.valueOf(document.hashCode()));
model = loader.createModel(document, id, handler);
try {
info.model = model;
model.setId(id);
// model.setModelHandler(handler);
if (model instanceof AbstractStructuredModel) {
((AbstractStructuredModel) model).setContentTypeIdentifier(info.contentTypeID);
}
model.setResolver(createURIResolver(info.buffer));
if (info.buffer.isDirty()) {
model.setDirtyState(true);
}
} catch (ResourceInUse e) {
// $NON-NLS-1$
Logger.logException("attempted to create new model with existing ID", e);
model = null;
}
}
if (info != null) {
return info.model;
}
return null;
}
use of org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse in project webtools.sourceediting by eclipse.
the class URLModelProvider 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.ResourceInUse in project webtools.sourceediting by eclipse.
the class URLModelProvider 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;
}
Aggregations