/** * Create a resource from the given URI and append a new Network instance to its contents. The * resourceSet used must be authorized to write on the disk. This means that the default * EditingDomain's resourceSet must be used in a write transaction (for example). If it is not * possible, do not provide a resourceSet, the default one will be used. * * @param resourceSet * @param uri * @return The created network * @throws IOException */ public static Network createNetworkResource(final ResourceSet resourceSet, final URI uri) throws IOException { final String fileName; if (uri.isPlatform()) { fileName = uri.toPlatformString(true); } else { fileName = uri.toString(); } // Create the network final Network network = DfFactory.eINSTANCE.createNetwork(fileName); // Compute the new network name final Path networkPath = new Path(uri.trimFileExtension().path()); // 3 first segments are resource/<PROJECT>/src network.setName(networkPath.removeFirstSegments(3).toString().replace('/', '.')); // Create the resource Resource res = resourceSet.createResource(uri); res.getContents().add(network); res.save(Collections.EMPTY_MAP); return network; }