ResourceSet resourceSet = ResourceSetFactory.createResourceSet(); Resource resource = resourceSet.getResource(xmlURI, true); resource.load(Collections.EMPTY_MAP); EObject root = resource.getContents().get(0);
ResourceSet set = new ResourceSetImpl(); set.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE); set.getResourceFactoryRegistry().getExtensionToFactoryMap() .put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE); Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap() .put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE); Resource res = set.getResource(URI.createFileURI("/path/to/my_model.uml"), true);
/** * @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); }
resourceSet.getResource( URI.createURI( resolvedSchemaLocationURI == null
protected void load () throws Exception { // register model VisualInterfacePackage.eINSTANCE.eClass (); this.symbol = null; final ResourceSet resourceSet = new ResourceSetImpl (); // set resource factory to XMI on extension map resourceSet.getResourceFactoryRegistry ().getExtensionToFactoryMap ().put ( "vi", FACTORY_INSTANCE ); //$NON-NLS-1$ final Resource resource = resourceSet.getResource ( this.uri, true ); this.symbol = (Symbol)EcoreUtil.getObjectByType ( resource.getContents (), VisualInterfacePackage.Literals.SYMBOL ); } }
protected URI computeUnusedUri(ResourceSet resourceSet) { String name = "__synthetic"; for (int i = 0; i < Integer.MAX_VALUE; i++) { URI syntheticUri = URI.createURI(name + i + "." + fileExtension); if (resourceSet.getResource(syntheticUri, false) == null) return syntheticUri; } throw new IllegalStateException(); }
protected URI computeUnusedUri(ResourceSet resourceSet) { for (int i = 0; i < Integer.MAX_VALUE; i++) { URI syntheticUri = URI.createURI(SYNTHETIC_URI_PREFIX + i + "." + fileExtension); if (resourceSet.getResource(syntheticUri, false) == null) return syntheticUri; } throw new IllegalStateException(); }
protected URI computeUnusedUri(ResourceSet resourceSet) { String name = "__synthetic"; for (int i = 0; i < Integer.MAX_VALUE; i++) { URI syntheticUri = URI.createURI(name+i+".uri"); if (resourceSet.getResource(syntheticUri, false)==null) return syntheticUri; } throw new IllegalStateException(); }
@Inject public void createResourceSet(Provider<XtextResourceSet> resourceSetProvider) { this.resourceSet = resourceSetProvider.get(); for (URI uri : libraryURIs) { resourceSet.getResource(uri, true); } }
XSDResourceImpl resource = (XSDResourceImpl) resourceSet.getResource( URI.createURI( EmfXsdLoadTest.class.getResource(filename).toString()),
/** * @see com.ibm.etools.archive.LoadStrategy#getExistingMofResource(String) */ public Resource getExistingMofResource(String uri) { return getResourceSet().getResource(URI.createURI(uri), false); }
public static Resource getResource(Resource context, String uri) { org.eclipse.emf.common.util.URI newURI = getResolvedImportUri(context, org.eclipse.emf.common.util.URI.createURI(uri)); try { return context.getResourceSet().getResource(newURI, true); } catch (RuntimeException e) { // thrown by org.eclipse.emf.ecore.resource.ResourceSet#getResource(URI, boolean) //log.trace("Cannot load resource: " + newURI, e); } return null; }
if (selection instanceof IStructuredSelection) { Object first = ((IStructuredSelection)selection).getFirstElement(); EObjectNode enode = (EObjectNode)first; ResourceSet resourceSet = new ResourceSetImpl(); Resource inResource = resourceSet.getResource(enode.getEObjectURI(),true); MyEcoreElement element = (MyEcoreElement)inResource.getEObject(enode.getEObjectURI().fragment()); //.... }
public LoadResult next() { URI uri = queue.poll(); try { Resource resource = parent.getResource(uri, true); return new LoadResult(resource, uri); } catch(WrappedException e) { throw new LoadOperationException(uri, (Exception) e.getCause() ); } }
protected ZenModel doLoad(URI modelLocation) { validateFile(modelLocation); ResourceSet resourceSet = new ResourceSetImpl(); org.eclipse.emf.ecore.resource.Resource resource = resourceSet.getResource(modelLocation, true); ZenModel model = (ZenModel) resource.getContents().get(0); return model; }
public void init(TestClass clazz, IInjectorProvider injector, URI uri) { this.clazz = clazz; this.injectorProvider = injector; this.resourceSet = injectorProvider.getInjector().getInstance(ResourceSet.class); this.resource = (XtextResource) resourceSet.getResource(uri, true); collectParameters(); setIndex(); }
public IResourceDescription getResourceDescription(URI uri) { Resource resource = resourceSet.getResource(uri, false); if (resource == null) return null; IResourceServiceProvider resourceServiceProvider = registry.getResourceServiceProvider(uri); if (resourceServiceProvider == null) return null; Manager manager = resourceServiceProvider.getResourceDescriptionManager(); if (manager==null) return null; return manager.getResourceDescription(resource); }
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); }
protected void handleChangedContents(Delta delta, IBuildContext context, IFileSystemAccess fileSystemAccess) { if (!resourceServiceProvider.canHandle(delta.getUri())) return; Resource resource = context.getResourceSet().getResource(delta.getUri(), true); if (shouldGenerate(resource, context)) { generator.doGenerate(resource, fileSystemAccess); context.needRebuild(); } }
private JvmType findTypeByClass(Class<?> clazz) throws UnknownNestedTypeException { IndexedJvmTypeAccess indexedJvmTypeAccess = getIndexedJvmTypeAccess(); URI resourceURI = uriHelper.createResourceURI(clazz); if (indexedJvmTypeAccess != null) { URI proxyURI = resourceURI.appendFragment(uriHelper.getFragment(clazz)); EObject candidate = indexedJvmTypeAccess.getIndexedJvmType(proxyURI, getResourceSet()); if (candidate instanceof JvmType) return (JvmType) candidate; } TypeResource result = (TypeResource) getResourceSet().getResource(resourceURI, true); return findTypeByClass(clazz, result); }