Search in sources :

Example 1 with ServerTypeResourceFactoryImpl

use of org.eclipse.jst.server.generic.internal.servertype.definition.util.ServerTypeResourceFactoryImpl in project webtools.servertools by eclipse.

the class XMLUtils method readFile.

private ServerRuntime readFile(java.net.URI file) {
    // Create a resource set.
    ResourceSet resourceSet = new ResourceSetImpl();
    // Register the default resource factory -- only needed for
    // stand-alone!
    resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new ServerTypeResourceFactoryImpl());
    ServerTypePackage gstPack = ServerTypePackage.eINSTANCE;
    // Get the URI of the model file.
    URI fileURI = URI.createURI(file.toString());
    // Demand load the resource for this file.
    Resource resource = null;
    try {
        resource = resourceSet.getResource(fileURI, true);
    } catch (WrappedException e) {
        // sth wrong with this .server file.
        CorePlugin.getDefault().getLog().log(new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, 1, "Error loading the server type definition", // $NON-NLS-1$
        e));
    }
    if (resource != null) {
        ServerRuntime def = (ServerRuntime) resource.getContents().get(0);
        if (def != null) {
            def.setFilename(file.toString());
            return def;
        }
    }
    return null;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) WrappedException(org.eclipse.emf.common.util.WrappedException) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) ServerRuntime(org.eclipse.jst.server.generic.servertype.definition.ServerRuntime) Resource(org.eclipse.emf.ecore.resource.Resource) ServerTypeResourceFactoryImpl(org.eclipse.jst.server.generic.internal.servertype.definition.util.ServerTypeResourceFactoryImpl) ServerTypePackage(org.eclipse.jst.server.generic.internal.servertype.definition.ServerTypePackage) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI)

Aggregations

IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 URI (org.eclipse.emf.common.util.URI)1 WrappedException (org.eclipse.emf.common.util.WrappedException)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)1 ServerTypePackage (org.eclipse.jst.server.generic.internal.servertype.definition.ServerTypePackage)1 ServerTypeResourceFactoryImpl (org.eclipse.jst.server.generic.internal.servertype.definition.util.ServerTypeResourceFactoryImpl)1 ServerRuntime (org.eclipse.jst.server.generic.servertype.definition.ServerRuntime)1