Refine search
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); } }
String prefix = Schemas.getTargetPrefix( schema ); String file = new File( schema.eResource().getURI().toFileString() ).getName();
/** * Laods the package and any sub-packages from their serialized form. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void loadPackage() { if (isLoaded) return; isLoaded = true; URL url = getClass().getResource(packageFilename); if (url == null) { throw new RuntimeException("Missing serialized package: " + packageFilename); } URI uri = URI.createURI(url.toString()); Resource resource = new EcoreResourceFactoryImpl().createResource(uri); try { resource.load(null); } catch (IOException exception) { throw new WrappedException(exception); } initializeFromLoadedEPackage(this, (EPackage)resource.getContents().get(0)); createResource(eNS_URI); }
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); } } }
@SuppressWarnings("rawtypes") public void loadEcore(String name, InputStream inputStream) { ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl()); Resource resource = resourceSet.createResource(URI.createURI(name)); try { resource.load(inputStream, new HashMap()); for (EObject eObject : resource.getContents()) { if (eObject instanceof EPackage) { EPackage ePackage = (EPackage)eObject; addEPackage(ePackage); } } } catch (IOException e) { LOGGER.error("", e); } }
@SuppressWarnings("unchecked") public T parse(InputStream in, URI uriToUse, Map<?, ?> options, ResourceSet resourceSet) { Resource resource = resourceFactory.createResource(uriToUse); resourceSet.getResources().add(resource); try { resource.load(in, options); final T root = (T) (resource.getContents().isEmpty() ? null : resource.getContents().get(0)); return root; } catch (IOException e) { throw new WrappedException(e); } }
if (resource == null) { final ResourceSet resourceSet = new ResourceSetImpl(); resource = (XSDResourceImpl) resourceSet.createResource(URI.createURI(".xsd")); resource.getContents().add(schema); schema.getContents().add(imprt); resource.getResourceSet().getAdapterFactories().add(adapterFactory); return imprt;
@Override protected void readTableOfContents(File tocFile) throws IOException { ResourceSet resourceSet = new ResourceSetImpl(); URI fileURI = URI.createFileURI(tocFile.getAbsolutePath()); Resource resource = resourceSet.createResource(fileURI); resource.load(null); ncxTOC = (Ncx) resource.getContents().get(0); }
private static SecurityModel read(final String modelString) throws IOException { final ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl()); final org.eclipse.emf.ecore.resource.Resource xmlResource = resourceSet.createResource(URI.createURI("dummy.deploy")); //$NON-NLS-1$ // Register the package -- only needed for stand-alone! resourceSet.getPackageRegistry().put(UamPackage.eNS_URI, UamPackage.eINSTANCE); resourceSet.getPackageRegistry().put(ExpressionPackage.eNS_URI, ExpressionPackage.eINSTANCE); resourceSet.getPackageRegistry().put(StdlibPackage.eNS_URI, StdlibPackage.eINSTANCE); final ByteArrayInputStream bais = new ByteArrayInputStream(modelString.getBytes()); xmlResource.load(bais, Collections.emptyMap()); return (SecurityModel) xmlResource.getContents().get(0); }
public static String toString(EObject entity, boolean resolveReferences) throws JsonProcessingException { EObject toSerialize = EmfUtils.clone(entity); //this should always be the case, just for debugging if (toSerialize.eResource() == null) { ResourceSet resourceSet = factory.createResourceSet(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("json", new JsonResourceFactory(customMapper)); Resource resource = resourceSet.createResource(URI.createURI(System.currentTimeMillis() + ".json")); resource.getContents().add(toSerialize); } if (resolveReferences) { EcoreUtil.resolveAll(toSerialize); } String result = selectMapper(resolveReferences).writeValueAsString(toSerialize.eResource()); return result; }
private static LightweightTypeReference findTopLevelType(LightweightTypeReference context, String typeName) { ITypeReferenceOwner owner = context.getOwner(); ResourceSet resourceSet = owner.getContextResourceSet(); Resource typeResource = resourceSet.getResource(URIHelperConstants.OBJECTS_URI.appendSegment(typeName), true); EList<EObject> contents = typeResource.getContents(); if (contents.isEmpty()) { return null; } JvmType type = (JvmType) contents.get(0); if (type == null) return null; return owner.newParameterizedTypeReference(type); }
public XtextResource createResource() { ResourceSet resourceSet = resourceSetProvider.get(null); Resource grammarResource = resourceSet.createResource( URI.createURI(SYNTHETIC_SCHEME + ":/" + grammarAccess.getGrammar().getName() + ".xtext")); grammarResource.getContents().add(EcoreUtil.copy(grammarAccess.getGrammar())); XtextResource result = (XtextResource) resourceSet.createResource( URI.createURI(SYNTHETIC_SCHEME + ":/" + grammarAccess.getGrammar().getName() + ".___singlecodetemplate")); resourceSet.getResources().add(result); return result; } }
/** * Returns the first element in the extent of the resource * * @throws EmptyResourceException - * thrown if the extent is empty */ public static EObject getRoot(Resource aResource) throws EmptyResourceException { EList extent = aResource.getContents(); if (extent.size() < 1) { throw new EmptyResourceException(aResource.getURI().toString()); } return (EObject) extent.get(0); }
protected void movePackageToNewResource(final EPackage pack, final ResourceSet set) { final Resource resource = set.createResource( URI.createURI(("___temp___." + FragmentFakingEcoreResource.FactoryImpl.ECORE_SUFFIX)), ContentHandler.UNSPECIFIED_CONTENT_TYPE); resource.setURI(URI.createURI(pack.getNsURI())); resource.getContents().add(pack); }
Resource resource = resourceSet.createResource(URI.createURI(ePackage.getName() + ".ecore")); resource.getContents().add(ePackage); VirtualFile ecoreFile = basedir.createFile(MODEL_PACKAGE.replace(".", "/") + ePackage.getName() + "/impl/" + ePackage.getName() + ".ecore"); resources.put(ecoreFile, resource); Resource resource = resources.get(virtualFile); OutputStream openOutputStream = virtualFile.openOutputStream(); resource.save(openOutputStream, null); openOutputStream.close(); } catch (IOException e) {
protected XtendFile getXtendFile(final EObject context) { Resource resource = context.eResource(); XtendFile result = (XtendFile) resource.getContents().get(0); return result; }
private <Type extends Object> void each(final ResourceSet resourceSet, final Class<Type> type, final Procedure1<? super Type> strategy) { for (int i = 0; (i < resourceSet.getResources().size()); i++) { { final Resource resource = resourceSet.getResources().get(i); final Consumer<Type> _function = (Type it) -> { strategy.apply(it); }; Iterables.<Type>filter(resource.getContents(), type).forEach(_function); } } }
/** * @see Archive */ public void addOrReplaceMofResource(Resource aResource) { Resource existingResource = getResourceSet().getResource(aResource.getURI(), false); if (existingResource != null) getResourceSet().getResources().remove(existingResource); getResourceSet().getResources().add(aResource); }
public Resource resource(InputStream in, URI uriToUse, Map<?, ?> options, ResourceSet resourceSet) { Resource resource = resourceFactory.createResource(uriToUse); resourceSet.getResources().add(resource); try { resource.load(in, options); return resource; } catch (IOException e) { throw new WrappedException(e); } }
/** * copies contents of a resource set into a new one */ public static <T extends ResourceSet> T clone(T target, ResourceSet source) { EList<Resource> resources = source.getResources(); EcoreUtil.Copier copier = new EcoreUtil.Copier(); for (Resource resource : resources) { Resource resource2 = target.createResource(resource.getURI()); resource2.getContents().addAll(copier.copyAll(resource.getContents())); } copier.copyReferences(); return target; }