public void writeToEcore(File file) { ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl()); Resource resource = resourceSet.createResource(URI.createFileURI(file.getAbsolutePath())); for (EPackage ePackage : packages.values()) { resource.getContents().add(ePackage); } try { resource.save(null); } catch (IOException e) { LOGGER.error("", e); } }
public void writeEMF(String fileName) { ResourceSet metaResourceSet = new ResourceSetImpl(); metaResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new XMLResourceFactoryImpl()); URI resUri = URI.createURI(fileName); Resource metaResource = metaResourceSet.createResource(resUri); metaResource.getContents().add(schemaPack); try { metaResource.save(null); } catch (Exception e) { LOGGER.error("", e); } } }
Resource resource = resources.get(virtualFile); OutputStream openOutputStream = virtualFile.openOutputStream(); resource.save(openOutputStream, null); openOutputStream.close(); } catch (IOException e) {
URI schemaURI = URI.createFileURI("foo.xsd"); Collection<Resource> ecoreResources = XSDEcoreBuilder.generateResources(schemaURI); for (Resource ecoreResource : ecoreResources) { ecoreResource.save(null); }
/** * @see com.ibm.etools.archive.SaveStrategy */ protected void saveMofResource(org.eclipse.emf.ecore.resource.Resource aResource, OutputStream os) throws IOException { aResource.save(os, Collections.EMPTY_MAP); }
@Override public void save() throws IOException { if (saveAndRestore) resource.save(null); }
/** * Save resource * * @param res * resource to save */ public static void save(final Resource res) throws IOException { res.save(Collections.EMPTY_MAP); }
public void save(OutputStream outputStream, Resource resource, Map<?, ?> options) throws IOException { if (options != null) { Map<Object, Object> mergedOptions = new HashMap<Object, Object>(saveOptions); mergedOptions.putAll(options); resource.save(outputStream, mergedOptions); } else { resource.save(outputStream, saveOptions); } }
public void save(OutputStream outputStream, Resource resource, Map<?, ?> options) throws IOException { if (options != null) { Map<Object, Object> mergedOptions = new HashMap<Object, Object>(saveOptions); mergedOptions.putAll(options); resource.save(outputStream, mergedOptions); } else { resource.save(outputStream, saveOptions); } }
private static void saveResource(Resource resource) { try { resource.save(Collections.emptyMap()); } catch (IOException e) { logger.error(e); } }
@Override public String toString() { ByteArrayOutputStream out = new ByteArrayOutputStream(); try { resource.save(out, Collections.emptyMap()); } catch (IOException e) { return Throwables.getStackTraceAsString(e); } return out.toString(); }
/** * Save * * @aResource. */ protected void primSaveResource(Resource aResource) throws Exception { if (aResource.isModified()) aResource.save(Collections.EMPTY_MAP); }
protected String saveResource(Resource resource) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(content.length()); try { Map<Object, Object> options = Maps.newHashMap(); options.put(XtextResource.OPTION_ENCODING, INTERNAL_ENCODING); SaveOptions.defaultOptions().addTo(options); resource.save(out, options); String result = new String(out.toByteArray(), INTERNAL_ENCODING); return result; } finally { out.close(); } }
public void convertEDIMap(EPackage pkg, OutputStream out) throws IOException { ResourceSet rs = createResourceSet(); Resource resource = addSchemaResource(rs, pkg); resource.save(out, null); resource = null; System.gc(); }
System system = ...; //Creating the AST programmatically ResourceSet set = new ResourceSetImpl(); Resource resource = set.createResource(URI.create...URI("filename")); //Initializing an EMF resource that represents a file resource.getContents.add(system); //adding your AST to the file resource resource.save();
public void store ( final URI uri ) throws IOException { logger.debug ( "Storing model to: {}", uri ); final ResourceSet rs = new ResourceSetImpl (); final Resource r = rs.createResource ( uri ); r.getContents ().add ( this.content ); r.save ( null ); } }
private void processProfile ( final File output ) throws IOException { final Profile profile = makeProfile ( this.app ); final File profileFile = new File ( output, this.app.getName () + ".profile.xml" ); //$NON-NLS-1$ final ResourceSet rs = new ResourceSetImpl (); final Resource r = rs.createResource ( URI.createFileURI ( profileFile.toString () ) ); r.getContents ().add ( EcoreUtil.copy ( profile ) ); final Map<Object, Object> options = new HashMap<> (); options.put ( XMLResource.OPTION_ENCODING, "UTF-8" ); //$NON-NLS-1$ r.save ( options ); }
private void processProfile ( final File output ) throws IOException { final Profile profile = makeProfile ( this.app ); final File profileFile = new File ( output, this.app.getName () + ".profile.xml" ); //$NON-NLS-1$ final ResourceSet rs = new ResourceSetImpl (); final Resource r = rs.createResource ( URI.createFileURI ( profileFile.toString () ) ); r.getContents ().add ( EcoreUtil.copy ( profile ) ); final Map<Object, Object> options = new HashMap<> (); options.put ( XMLResource.OPTION_ENCODING, "UTF-8" ); //$NON-NLS-1$ r.save ( options ); }
public void save(Iterable<IResourceDescription> descriptions) { Resource res = createResource(); if (res != null) { saveToResource(res, descriptions); try { res.save(null); } catch (IOException e) { throw new WrappedException(e); } } }
public void addSaveAsUpdate(Resource resource, IRefactoringUpdateAcceptor updateAcceptor) throws IOException { IRefactoringDocument document = updateAcceptor.getDocument(resource.getURI()); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); resource.save(outputStream, null); String newContent = new String(outputStream.toByteArray(), encodingProvider.getEncoding(resource.getURI())); updateAcceptor.accept(resource.getURI(), new ReplaceEdit(0, document.getOriginalContents().length(), newContent)); }