use of org.eclipse.wst.sse.core.internal.model.AbstractStructuredModel 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;
}
Aggregations