use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class ModelManagerImpl method getExistingModelForRead.
public IStructuredModel getExistingModelForRead(IFile iFile) {
// $NON-NLS-1$
Assert.isNotNull(iFile, "IFile parameter can not be null");
Object id = calculateId(iFile);
IStructuredModel result = getExistingModelForRead(id);
return result;
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class ModelManagerImpl method createUnManagedStructuredModelFor.
/**
* Conveience method. It depends on the loaders newModel method to return
* an appropriate StrucuturedModel appropriately initialized.
*/
public IStructuredModel createUnManagedStructuredModelFor(IFile iFile) throws IOException, CoreException {
IStructuredModel result = null;
result = createUnManagedEmptyModelFor(iFile);
IDocumentLoader loader = result.getModelHandler().getDocumentLoader();
IEncodedDocument document = loader.createNewStructuredDocument(iFile);
result.getStructuredDocument().setText(this, document.get());
return result;
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class ModelManagerImpl method getExistingModelForRead.
/**
* Note: users of this 'model' must still release it when finished.
* Returns null if there's not a model corresponding to document.
*/
public IStructuredModel getExistingModelForRead(IDocument document) {
IStructuredModel result = null;
SYNC.acquire();
// create a snapshot
Set ids = new HashSet(fManagedObjects.keySet());
SYNC.release();
for (Iterator iterator = ids.iterator(); iterator.hasNext(); ) {
Object potentialId = iterator.next();
SYNC.acquire();
if (fManagedObjects.containsKey(potentialId)) {
// check to see if still valid
SYNC.release();
IStructuredModel tempResult = getExistingModel(potentialId);
if (tempResult != null && document == tempResult.getStructuredDocument()) {
result = getExistingModelForRead(potentialId);
break;
}
} else {
SYNC.release();
}
}
return result;
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class ModelManagerImpl method copyModelForEdit.
/**
*/
public IStructuredModel copyModelForEdit(String oldId, String newId) throws ResourceInUse {
IStructuredModel newModel = null;
// get the existing model associated with this id
IStructuredModel model = getExistingModel(oldId);
// be a programming error.
if (model == null)
return null;
SharedObject sharedObject = null;
try {
SYNC.acquire();
// now be sure newModel does not exist
sharedObject = (SharedObject) fManagedObjects.get(newId);
if (sharedObject != null) {
throw new ResourceInUse();
}
sharedObject = new SharedObject(newId);
fManagedObjects.put(newId, sharedObject);
} finally {
SYNC.release();
}
// ask the loader to copy
synchronized (sharedObject) {
sharedObject.doWait = false;
newModel = copy(model, newId);
sharedObject.doWait = true;
}
if (newModel != null) {
// add to our cache
synchronized (sharedObject) {
sharedObject.theSharedModel = newModel;
sharedObject.referenceCountForEdit = 1;
// $NON-NLS-1$
trace("copied model", newId, sharedObject.referenceCountForEdit);
}
} else {
SYNC.acquire();
fManagedObjects.remove(newId);
SYNC.release();
}
sharedObject.setLoaded();
return newModel;
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class ModelManagerImpl method _doCommonCreateModel.
private void _doCommonCreateModel(IFile file, String id, IModelHandler handler, URIResolver resolver, ReadEditType rwType, EncodingRule encodingRule, SharedObject sharedObject) throws CoreException, IOException {
// XXX: Does not integrate with FileBuffers
boolean doRemove = true;
try {
synchronized (sharedObject) {
InputStream inputStream = null;
IStructuredModel model = null;
try {
model = _commonCreateModel(id, handler, resolver);
IModelLoader loader = handler.getModelLoader();
inputStream = Utilities.getMarkSupportedStream(file.getContents(true));
loader.load(Utilities.getMarkSupportedStream(inputStream), model, encodingRule);
} catch (ResourceInUse e) {
// impossible, since we've already found
handleProgramError(e);
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
}
}
}
if (model != null) {
// add to our cache
sharedObject.theSharedModel = model;
_initCount(sharedObject, rwType);
doRemove = false;
}
}
} finally {
if (doRemove) {
SYNC.acquire();
fManagedObjects.remove(id);
SYNC.release();
}
sharedObject.setLoaded();
}
}
Aggregations