Search in sources :

Example 6 with IModelLoader

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

the class ModelManagerImpl method copy.

/**
 * this used to be in loader, but has been moved here
 */
private IStructuredModel copy(IStructuredModel model, String newId) throws ResourceInUse {
    IStructuredModel newModel = null;
    IStructuredModel oldModel = model;
    IModelHandler modelHandler = oldModel.getModelHandler();
    IModelLoader loader = modelHandler.getModelLoader();
    // newModel = loader.newModel();
    newModel = loader.createModel(oldModel);
    // newId, oldModel.getResolver(), oldModel.getModelManager());
    newModel.setModelHandler(modelHandler);
    // IStructuredDocument oldStructuredDocument =
    // oldModel.getStructuredDocument();
    // IStructuredDocument newStructuredDocument =
    // oldStructuredDocument.newInstance();
    // newModel.setStructuredDocument(newStructuredDocument);
    newModel.setResolver(oldModel.getResolver());
    newModel.setModelManager(oldModel.getModelManager());
    // duplicateFactoryRegistry(newModel, oldModel);
    newModel.setId(newId);
    // set text of new one after all initialization is done
    String contents = oldModel.getStructuredDocument().getText();
    newModel.getStructuredDocument().setText(this, contents);
    return newModel;
}
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)

Example 7 with IModelLoader

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

the class ModelManagerImpl method _commonCreateModel.

private IStructuredModel _commonCreateModel(String id, IModelHandler handler, URIResolver resolver) throws ResourceInUse {
    IModelLoader loader = handler.getModelLoader();
    IStructuredModel result = loader.createModel();
    // try and set it
    if (id != null) {
        result.setId(id);
    }
    result.setModelHandler(handler);
    result.setResolver(resolver);
    // some obvious redunancy here that maybe could be improved
    // in future, but is necessary for now
    result.setBaseLocation(id);
    if (resolver != null) {
        resolver.setFileBaseLocation(id);
    }
    addFactories(result, handler);
    return result;
}
Also used : IModelLoader(org.eclipse.wst.sse.core.internal.provisional.IModelLoader) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 8 with IModelLoader

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

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