use of org.eclipse.wst.sse.core.internal.provisional.IModelLoader in project webtools.sourceediting by eclipse.
the class ModelManagerImpl method reinitialize.
/*
* @see IModelManager#reinitialize(IStructuredModel)
*/
public IStructuredModel reinitialize(IStructuredModel model) {
// getHandler (assume its the "new one")
IModelHandler handler = model.getModelHandler();
// getLoader for that new one
IModelLoader loader = handler.getModelLoader();
// ask it to reinitialize
model = loader.reinitialize(model);
// its embedded content checking and initialization
return model;
}
use of org.eclipse.wst.sse.core.internal.provisional.IModelLoader 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();
}
}
use of org.eclipse.wst.sse.core.internal.provisional.IModelLoader 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.IModelLoader in project webtools.sourceediting by eclipse.
the class ModelManagerImpl method createNewInstance.
/**
* Similar to clone, except the new instance has no content. Note: this
* produces an unmanaged model, for temporary use. If a true shared model
* is desired, use "copy".
*/
public IStructuredModel createNewInstance(IStructuredModel oldModel) throws IOException {
IModelHandler handler = oldModel.getModelHandler();
IModelLoader loader = handler.getModelLoader();
IStructuredModel newModel = loader.createModel(oldModel);
newModel.setModelHandler(handler);
if (newModel instanceof AbstractStructuredModel) {
((AbstractStructuredModel) newModel).setContentTypeIdentifier(oldModel.getContentTypeIdentifier());
}
URIResolver oldResolver = oldModel.getResolver();
if (oldResolver instanceof URIResolverExtension) {
oldResolver = ((URIResolverExtension) oldResolver).newInstance();
}
newModel.setResolver(oldResolver);
try {
newModel.setId(DUPLICATED_MODEL);
} catch (ResourceInUse e) {
// impossible, since this is an unmanaged model
}
// base location should be null, but we'll set to
// null to be sure.
newModel.setBaseLocation(null);
return newModel;
}
use of org.eclipse.wst.sse.core.internal.provisional.IModelLoader in project webtools.sourceediting by eclipse.
the class ModelManagerImpl method reloadModel.
/**
* This is similar to the getModel method, except this method does not use
* the cached version, but forces the cached version to be replaced with a
* fresh, unchanged version. Note: this method does not change any
* reference counts. Also, if there is not already a cached version of the
* model, then this call is essentially ignored (that is, it does not put
* a model in the cache) and returns null.
*
* @deprecated - will become protected, use reload directly on model
*/
public IStructuredModel reloadModel(Object id, java.io.InputStream inputStream) throws java.io.UnsupportedEncodingException {
// $NON-NLS-1$
Assert.isNotNull(id, "id parameter can not be null");
// get the existing model associated with this id
IStructuredModel structuredModel = getExistingModel(id);
// that model.
if (structuredModel != null) {
// get loader based on existing type
// dmwTODO evaluate when reload should occur
// with potentially new type (e.g. html 'save as' jsp).
IModelHandler handler = structuredModel.getModelHandler();
IModelLoader loader = handler.getModelLoader();
// ask the loader to re-load
loader.reload(Utilities.getMarkSupportedStream(inputStream), structuredModel);
// $NON-NLS-1$
trace("re-loading model", id);
}
return structuredModel;
}
Aggregations