Search in sources :

Example 6 with ResourceInUse

use of org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse in project webtools.sourceediting by eclipse.

the class TestModelManager method testCopyJSPModelForEdit.

public void testCopyJSPModelForEdit() throws IOException {
    IStructuredModel model = null;
    try {
        IModelManager modelManager = StructuredModelManager.getModelManager();
        model = modelManager.getModelForEdit("test.jsp", new NullInputStream(), null);
        IStructuredModel modelCopy = modelManager.copyModelForEdit(model.getId(), getName() + ".newId");
        assertNotNull("copied JSP model was null", modelCopy);
        assertEquals("ModelHandlers differ", model.getModelHandler(), modelCopy.getModelHandler());
        assertEquals("StructuredDocument RegionParsers differ", model.getStructuredDocument().getParser().getClass(), modelCopy.getStructuredDocument().getParser().getClass());
        assertEquals("Text document contents differ", model.getStructuredDocument().get(), modelCopy.getStructuredDocument().get());
    } catch (ResourceInUse e) {
        fail("Resource in use reported for " + model.getId());
    } finally {
        if (model != null)
            model.releaseFromEdit();
    }
}
Also used : IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) ResourceInUse(org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse)

Example 7 with ResourceInUse

use of org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse in project webtools.sourceediting by eclipse.

the class URLModelProviderCSS method getNewModelForRead.

public IStructuredModel getNewModelForRead(IFile iFile) {
    if (iFile == null)
        return null;
    IModelManager manager = getModelManager();
    if (manager == null)
        return null;
    IStructuredModel model = null;
    try {
        model = manager.getNewModelForEdit(iFile, false);
    } catch (IOException ex) {
    } catch (ResourceInUse riu) {
    } catch (ResourceAlreadyExists rae) {
    } catch (CoreException ce) {
    }
    return model;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException) ResourceAlreadyExists(org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceAlreadyExists) ResourceInUse(org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse)

Example 8 with ResourceInUse

use of org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse in project webtools.sourceediting by eclipse.

the class URLModelProviderCSS method getNewModelForEdit.

public IStructuredModel getNewModelForEdit(IFile iFile) {
    if (iFile == null)
        return null;
    IModelManager manager = getModelManager();
    if (manager == null)
        return null;
    IStructuredModel model = null;
    try {
        model = manager.getNewModelForEdit(iFile, false);
    } catch (IOException ex) {
    } catch (ResourceInUse riu) {
    } catch (ResourceAlreadyExists rae) {
    } catch (CoreException ce) {
    }
    return model;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException) ResourceAlreadyExists(org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceAlreadyExists) ResourceInUse(org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse)

Example 9 with ResourceInUse

use of org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse in project webtools.sourceediting by eclipse.

the class ModelManagerImpl method createUnManagedEmptyModelFor.

/**
 * @param iFile
 * @param result
 * @return
 * @throws CoreException
 */
private IStructuredModel createUnManagedEmptyModelFor(IFile iFile) throws CoreException {
    IStructuredModel result = null;
    IModelHandler handler = calculateType(iFile);
    String id = calculateId(iFile);
    URIResolver resolver = calculateURIResolver(iFile);
    try {
        result = _commonCreateModel(id, 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;
}
Also used : 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) ResourceInUse(org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse)

Example 10 with ResourceInUse

use of org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse 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)

Aggregations

IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)15 ResourceInUse (org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse)15 IOException (java.io.IOException)6 CoreException (org.eclipse.core.runtime.CoreException)5 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)5 ResourceAlreadyExists (org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceAlreadyExists)5 IModelHandler (org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)4 IModelLoader (org.eclipse.wst.sse.core.internal.provisional.IModelLoader)4 URIResolver (org.eclipse.wst.sse.core.internal.util.URIResolver)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)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 ModelHandlerRegistry (org.eclipse.wst.sse.core.internal.modelhandler.ModelHandlerRegistry)1 URIResolverExtension (org.eclipse.wst.sse.core.internal.util.URIResolverExtension)1