Search in sources :

Example 71 with IStructuredModel

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

the class ModelManagerImpl method getExistingModelForRead.

public IStructuredModel getExistingModelForRead(IFile iFile) {
    // $NON-NLS-1$
    Assert.isNotNull(iFile, "IFile parameter can not be null");
    Object id = calculateId(iFile);
    IStructuredModel result = getExistingModelForRead(id);
    return result;
}
Also used : IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 72 with IStructuredModel

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

the class ModelManagerImpl method createUnManagedStructuredModelFor.

/**
 * Conveience method. It depends on the loaders newModel method to return
 * an appropriate StrucuturedModel appropriately initialized.
 */
public IStructuredModel createUnManagedStructuredModelFor(IFile iFile) throws IOException, CoreException {
    IStructuredModel result = null;
    result = createUnManagedEmptyModelFor(iFile);
    IDocumentLoader loader = result.getModelHandler().getDocumentLoader();
    IEncodedDocument document = loader.createNewStructuredDocument(iFile);
    result.getStructuredDocument().setText(this, document.get());
    return result;
}
Also used : IDocumentLoader(org.eclipse.wst.sse.core.internal.document.IDocumentLoader) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IEncodedDocument(org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument)

Example 73 with IStructuredModel

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

the class ModelManagerImpl method getExistingModelForRead.

/**
 * Note: users of this 'model' must still release it when finished.
 * Returns null if there's not a model corresponding to document.
 */
public IStructuredModel getExistingModelForRead(IDocument document) {
    IStructuredModel result = null;
    SYNC.acquire();
    // create a snapshot
    Set ids = new HashSet(fManagedObjects.keySet());
    SYNC.release();
    for (Iterator iterator = ids.iterator(); iterator.hasNext(); ) {
        Object potentialId = iterator.next();
        SYNC.acquire();
        if (fManagedObjects.containsKey(potentialId)) {
            // check to see if still valid
            SYNC.release();
            IStructuredModel tempResult = getExistingModel(potentialId);
            if (tempResult != null && document == tempResult.getStructuredDocument()) {
                result = getExistingModelForRead(potentialId);
                break;
            }
        } else {
            SYNC.release();
        }
    }
    return result;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Iterator(java.util.Iterator) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) HashSet(java.util.HashSet)

Example 74 with IStructuredModel

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

the class ModelManagerImpl method copyModelForEdit.

/**
 */
public IStructuredModel copyModelForEdit(String oldId, String newId) throws ResourceInUse {
    IStructuredModel newModel = null;
    // get the existing model associated with this id
    IStructuredModel model = getExistingModel(oldId);
    // be a programming error.
    if (model == null)
        return null;
    SharedObject sharedObject = null;
    try {
        SYNC.acquire();
        // now be sure newModel does not exist
        sharedObject = (SharedObject) fManagedObjects.get(newId);
        if (sharedObject != null) {
            throw new ResourceInUse();
        }
        sharedObject = new SharedObject(newId);
        fManagedObjects.put(newId, sharedObject);
    } finally {
        SYNC.release();
    }
    // ask the loader to copy
    synchronized (sharedObject) {
        sharedObject.doWait = false;
        newModel = copy(model, newId);
        sharedObject.doWait = true;
    }
    if (newModel != null) {
        // add to our cache
        synchronized (sharedObject) {
            sharedObject.theSharedModel = newModel;
            sharedObject.referenceCountForEdit = 1;
            // $NON-NLS-1$
            trace("copied model", newId, sharedObject.referenceCountForEdit);
        }
    } else {
        SYNC.acquire();
        fManagedObjects.remove(newId);
        SYNC.release();
    }
    sharedObject.setLoaded();
    return newModel;
}
Also used : IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) ResourceInUse(org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse)

Example 75 with IStructuredModel

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

Aggregations

IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)482 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)110 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)102 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)81 IFile (org.eclipse.core.resources.IFile)75 IOException (java.io.IOException)69 CoreException (org.eclipse.core.runtime.CoreException)49 IDocument (org.eclipse.jface.text.IDocument)46 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)42 InputStream (java.io.InputStream)40 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)36 Path (org.eclipse.core.runtime.Path)35 BadLocationException (org.eclipse.jface.text.BadLocationException)34 IJsTranslation (org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation)32 JsTranslationAdapter (org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)32 IProject (org.eclipse.core.resources.IProject)31 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)31 IPath (org.eclipse.core.runtime.IPath)27 ByteArrayInputStream (java.io.ByteArrayInputStream)22 Document (org.w3c.dom.Document)19