Search in sources :

Example 1 with IModelLoader

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;
}
Also used : IModelLoader(org.eclipse.wst.sse.core.internal.provisional.IModelLoader) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)

Example 2 with IModelLoader

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();
    }
}
Also used : IModelLoader(org.eclipse.wst.sse.core.internal.provisional.IModelLoader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException) ResourceInUse(org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse)

Example 3 with IModelLoader

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();
    }
}
Also used : IModelLoader(org.eclipse.wst.sse.core.internal.provisional.IModelLoader) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) DocumentReader(org.eclipse.wst.sse.core.internal.document.DocumentReader) IContentDescription(org.eclipse.core.runtime.content.IContentDescription) ResourceInUse(org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse)

Example 4 with IModelLoader

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;
}
Also used : IModelLoader(org.eclipse.wst.sse.core.internal.provisional.IModelLoader) URIResolver(org.eclipse.wst.sse.core.internal.util.URIResolver) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler) URIResolverExtension(org.eclipse.wst.sse.core.internal.util.URIResolverExtension) ResourceInUse(org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse)

Example 5 with IModelLoader

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;
}
Also used : IModelLoader(org.eclipse.wst.sse.core.internal.provisional.IModelLoader) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)

Aggregations

IModelLoader (org.eclipse.wst.sse.core.internal.provisional.IModelLoader)8 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)7 IModelHandler (org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)5 ResourceInUse (org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse)4 IOException (java.io.IOException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 CoreException (org.eclipse.core.runtime.CoreException)1 IContentDescription (org.eclipse.core.runtime.content.IContentDescription)1 DocumentReader (org.eclipse.wst.sse.core.internal.document.DocumentReader)1 AbstractStructuredModel (org.eclipse.wst.sse.core.internal.model.AbstractStructuredModel)1 URIResolver (org.eclipse.wst.sse.core.internal.util.URIResolver)1 URIResolverExtension (org.eclipse.wst.sse.core.internal.util.URIResolverExtension)1