Search in sources :

Example 1 with URIResolverExtension

use of org.eclipse.wst.sse.core.internal.util.URIResolverExtension 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

IModelHandler (org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)1 IModelLoader (org.eclipse.wst.sse.core.internal.provisional.IModelLoader)1 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)1 ResourceInUse (org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceInUse)1 URIResolver (org.eclipse.wst.sse.core.internal.util.URIResolver)1 URIResolverExtension (org.eclipse.wst.sse.core.internal.util.URIResolverExtension)1