use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class ModelManagerImpl method _doCommonCreateModel.
private void _doCommonCreateModel(InputStream inputStream, String id, IModelHandler handler, URIResolver resolver, ReadEditType rwType, String encoding, String lineDelimiter, SharedObject sharedObject) throws IOException {
boolean doRemove = true;
try {
synchronized (sharedObject) {
IStructuredModel model = null;
try {
model = _commonCreateModel(id, handler, resolver);
IModelLoader loader = handler.getModelLoader();
if (inputStream == null) {
// $NON-NLS-1$ //$NON-NLS-2$
Logger.log(Logger.WARNING, "model was requested for id " + id + " without a content InputStream");
}
loader.load(id, Utilities.getMarkSupportedStream(inputStream), model, encoding, lineDelimiter);
} catch (ResourceInUse e) {
// impossible, since we've already found
handleProgramError(e);
}
if (model != null) {
/**
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=264228
*
* Ensure that the content type identifier field of the model
* is properly set. This is normally handled by the
* FileBufferModelManager when working with files as it knows
* the content type in advance; here is where we handle it for
* streams.
*/
if (model instanceof AbstractStructuredModel) {
DocumentReader reader = new DocumentReader(model.getStructuredDocument());
IContentDescription description = Platform.getContentTypeManager().getDescriptionFor(reader, id, new QualifiedName[0]);
reader.close();
if (description != null && description.getContentType() != null) {
((AbstractStructuredModel) model).setContentTypeIdentifier(description.getContentType().getId());
}
}
sharedObject.theSharedModel = model;
_initCount(sharedObject, rwType);
doRemove = false;
}
}
} finally {
if (doRemove) {
SYNC.acquire();
// remove it if we didn't get one back
fManagedObjects.remove(id);
SYNC.release();
}
sharedObject.setLoaded();
}
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class ModelManagerImpl method getModelForEdit.
public IStructuredModel getModelForEdit(String id, InputStream inputStream, URIResolver resolver) throws IOException {
if (id == null) {
// $NON-NLS-1$
throw new IllegalArgumentException("Program Error: id may not be null");
}
IStructuredModel result = null;
InputStream istream = Utilities.getMarkSupportedStream(inputStream);
IModelHandler handler = calculateType(id, istream);
if (handler != null) {
result = _commonCreateModel(istream, id, handler, resolver, EDIT, null, null);
} else {
// $NON-NLS-1$
Logger.log(Logger.INFO, "no model handler found for 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(String contentTypeId, URIResolver resolver) {
IStructuredModel result = null;
ModelHandlerRegistry cr = getModelHandlerRegistry();
IModelHandler handler = cr.getHandlerForContentTypeId(contentTypeId);
try {
// $NON-NLS-1$
result = _commonCreateModel(UNMANAGED_MODEL, handler, resolver);
} catch (ResourceInUse e) {
// this may need to be re-examined.
if (Logger.DEBUG_MODELMANAGER)
// $NON-NLS-1$ //$NON-NLS-2$
Logger.log(Logger.INFO, "ModelMangerImpl::createUnManagedStructuredModelFor. Model unexpectedly in use.");
}
return result;
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class AbstractStructuredModel method copy.
/**
* Provides a copy of the model, but a new ID must be provided. The
* principle of this copy is not to copy fields, etc., as is typically
* done in a clone method, but to return a model with the same content in
* the structuredDocument. Note: It is the callers responsibility to
* setBaseLocation, listners, etc., as appropriate. Type and Encoding are
* the only fields set by this method. If the newId provided already exist
* in the model manager, a ResourceInUse exception is thrown.
*/
public IStructuredModel copy(String newId) throws ResourceInUse {
IStructuredModel newModel = null;
// this first one should fail, if not, its treated as an error
// If the caller wants to use an existing one, they can call
// getExisting
// after this failure
newModel = getModelManager().getExistingModelForEdit(newId);
if (newModel != null) {
// be sure to release the reference we got "by accident" (and
// no
// longer need)
newModel.releaseFromEdit();
throw new ResourceInUse();
}
newModel = getModelManager().copyModelForEdit(getId(), newId);
return newModel;
}
use of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel in project webtools.sourceediting by eclipse.
the class AbstractStructuredModel method reload.
/**
* This function replenishes the model with the resource without saving
* any possible changes. It is used when one editor may be closing, and
* specifially says not to save the model, but another "display" of the
* model still needs to hang on to some model, so needs a fresh copy.
*/
public IStructuredModel reload(InputStream inputStream) throws IOException {
IStructuredModel result = null;
try {
aboutToChangeModel();
result = _getModelManager().reloadModel(getId(), inputStream);
} catch (UnsupportedEncodingException e) {
// log for now, unless we find reason not to
Logger.log(Logger.INFO, e.getMessage());
} finally {
changedModel();
}
return result;
}
Aggregations