Search in sources :

Example 1 with ResourceAlreadyExists

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

the class ModelManagerImpl method createNewStructuredDocumentFor.

/**
 * Factory method, since a proper IStructuredDocument must have a proper
 * parser assigned. Note: its assume that IFile does not actually exist as
 * a resource yet. If it does, ResourceAlreadyExists exception is thrown.
 * If the resource does already exist, then createStructuredDocumentFor is
 * the right API to use.
 *
 * @throws ResourceInUse
 */
public IStructuredDocument createNewStructuredDocumentFor(IFile iFile) throws ResourceAlreadyExists, IOException, CoreException {
    if (iFile.exists()) {
        throw new ResourceAlreadyExists(iFile.getFullPath().toOSString());
    }
    // Will reconsider in future version
    // String id = calculateId(iFile);
    // if (isResourceInUse(id)) {
    // throw new ResourceInUse(iFile.getFullPath().toOSString());
    // }
    IDocumentLoader loader = null;
    IModelHandler handler = calculateType(iFile);
    loader = handler.getDocumentLoader();
    // for this API, "createNew" we assume the IFile does not exist yet
    // as checked above, so just create empty document.
    IStructuredDocument result = (IStructuredDocument) loader.createNewStructuredDocument();
    return result;
}
Also used : IDocumentLoader(org.eclipse.wst.sse.core.internal.document.IDocumentLoader) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) ResourceAlreadyExists(org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceAlreadyExists) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)

Example 2 with ResourceAlreadyExists

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

the class TestModelManager method testCreateNewStructuredDocumentFor.

public void testCreateNewStructuredDocumentFor() throws IOException, CoreException {
    IStructuredModel model = null;
    try {
        IFile file = getFile();
        // ensure model already exists
        model = getStructuredModelForEdit();
        boolean resourceExists = false;
        try {
            getMM().createNewStructuredDocumentFor(file);
        } catch (ResourceAlreadyExists ex) {
            resourceExists = true;
        }
        assertTrue("should have gotten ResourceAlreadyExits exception", resourceExists);
    } finally {
        if (model != null)
            model.releaseFromEdit();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) ResourceAlreadyExists(org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceAlreadyExists)

Example 3 with ResourceAlreadyExists

use of org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceAlreadyExists 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 4 with ResourceAlreadyExists

use of org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceAlreadyExists 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 5 with ResourceAlreadyExists

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

Aggregations

ResourceAlreadyExists (org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceAlreadyExists)7 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)6 ResourceInUse (org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse)5 IOException (java.io.IOException)4 CoreException (org.eclipse.core.runtime.CoreException)4 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)4 IFile (org.eclipse.core.resources.IFile)1 IDocumentLoader (org.eclipse.wst.sse.core.internal.document.IDocumentLoader)1 IModelHandler (org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)1 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)1