Search in sources :

Example 11 with ResourceInUse

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

the class ModelManagerImpl method _commonNewModel.

private SharedObject _commonNewModel(IFile iFile, boolean force) throws ResourceAlreadyExists, ResourceInUse, IOException, CoreException {
    IStructuredModel aSharedModel = null;
    if (iFile.exists() && !force) {
        throw new ResourceAlreadyExists();
    }
    SharedObject sharedObject = null;
    String id = calculateId(iFile);
    try {
        SYNC.acquire();
        sharedObject = (SharedObject) fManagedObjects.get(id);
        if (sharedObject != null && !force) {
            // in call
            throw new ResourceInUse();
        }
        sharedObject = new SharedObject(id);
        fManagedObjects.put(id, sharedObject);
    } finally {
        SYNC.release();
    }
    // if we get to here without above exceptions, then all is ok
    // to get model like normal, but set 'new' attribute (where the
    // 'new' attribute means this is a model without a corresponding
    // underlying resource.
    aSharedModel = FileBufferModelManager.getInstance().getModel(iFile);
    aSharedModel.setNewState(true);
    sharedObject.theSharedModel = aSharedModel;
    // when resource is provided, we can set
    // synchronization stamp ... otherwise client should
    // Note: one client which does this is FileModelProvider.
    aSharedModel.resetSynchronizationStamp(iFile);
    return sharedObject;
}
Also used : IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) ResourceAlreadyExists(org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceAlreadyExists) ResourceInUse(org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse)

Example 12 with ResourceInUse

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

the class TestModelManager method testCopyModel.

public void testCopyModel() {
    IStructuredModel model = null;
    try {
        model = getStructuredModelForEdit();
        try {
            IStructuredModel modelCopy = getMM().copyModelForEdit(model.getId(), "newId");
            assertNotNull("copied model was null", modelCopy);
        } catch (ResourceInUse e) {
            e.printStackTrace();
        }
    } finally {
        if (model != null)
            model.releaseFromEdit();
    }
}
Also used : IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) ResourceInUse(org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse)

Example 13 with ResourceInUse

use of org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse 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;
}
Also used : IModelLoader(org.eclipse.wst.sse.core.internal.provisional.IModelLoader) AbstractStructuredModel(org.eclipse.wst.sse.core.internal.model.AbstractStructuredModel) 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) CoreException(org.eclipse.core.runtime.CoreException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 14 with ResourceInUse

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

the class URLModelProvider 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 15 with ResourceInUse

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

the class URLModelProvider 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)

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