javaemfxtend

How to save an EMF Model


I am trying to save an EMF model with extension .xmi. But unable to do so, as I couldn't see any error neither in development nor in runtime.

If I save it at default location which is platform:/resource/CompanyToIT/instances/corr-2019_08_31-19_24_52.xmi it get's saved. But when I try to select a different location like C:\Users\PC\Desktop\XMI it doesn't save it, as I couldn't see the file at the location (I also tried adding platform: to the path, no luck).

Below is my function which I am using. This gets called from runtime environment UI. UI passes the path along with resource to this function.

private void saveModel(Resource r, String time, String newLocation) throws IOException {
        String newPath;
        URI newUri;

        newPath = FilenameUtils.getFullPath(newLocation);           
        newPath += FilenameUtils.getBaseName(newLocation) + "-";
        newPath += time + "." + FilenameUtils.getExtension(newLocation);            
        newUri = URI.createURI(newPath);

        r.setURI(newUri);
        r.save(null);
}

Any help would be appreciated. Thanks!


Solution

  • You want to use URI.createFileURI(String that is a filepath).