use of org.eclipse.emf.ecore.resource.URIConverter in project xtext-core by eclipse.
the class AbstractResourceDescription method getNormalizedURI.
protected URI getNormalizedURI(Resource resource) {
URI uri = resource.getURI();
URIConverter uriConverter = resource.getResourceSet() != null ? resource.getResourceSet().getURIConverter() : null;
if (uri != null && uriConverter != null) {
if (!uri.isPlatform()) {
return uriConverter.normalize(uri);
}
// EMF's GenModelResourceDescriptionStrategy does so as it needs to call GenModel.reconcile() eagerly.
if (uri.isPlatformPlugin()) {
URI resourceURI = uri.replacePrefix(URI.createURI("platform:/plugin/"), URI.createURI("platform:/resource/"));
if (uriConverter.normalize(uri).equals(uriConverter.normalize(resourceURI)))
return resourceURI;
}
}
return uri;
}
use of org.eclipse.emf.ecore.resource.URIConverter in project xtext-core by eclipse.
the class EcoreUtil2 method isValidUri.
/**
* checks whether the given URI can be loaded given the context. I.e. there's a resource set with a corresponding
* resource factory and the physical resource exists.
*/
public static boolean isValidUri(Resource resource, URI uri) {
if (uri == null || uri.isEmpty()) {
return false;
}
URI newURI = getResolvedImportUri(resource, uri);
try {
ResourceSet resourceSet = resource.getResourceSet();
if (resourceSet.getResource(uri, false) != null)
return true;
URIConverter uriConverter = resourceSet.getURIConverter();
URI normalized = uriConverter.normalize(newURI);
if (normalized != null)
// fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=326760
if ("platform".equals(normalized.scheme()) && !normalized.isPlatform())
return false;
return uriConverter.exists(normalized, Collections.emptyMap());
} catch (RuntimeException e) {
// thrown by org.eclipse.emf.ecore.resource.ResourceSet#getResource(URI, boolean)
log.trace("Cannot load resource: " + newURI, e);
}
return false;
}
use of org.eclipse.emf.ecore.resource.URIConverter in project n4js by eclipse.
the class BuiltInSchemeAwareResource method createNewURIConverter.
private URIConverter createNewURIConverter() {
URIConverter result = new ExtensibleURIConverterImpl();
registrar.registerScheme(result);
return result;
}
use of org.eclipse.emf.ecore.resource.URIConverter in project tdq-studio-se by Talend.
the class TDQFileItemImpl method eResolveProxy.
// similar with FileItemImpl's same method, because this class can not extend that class.so copy the method from
// FileItemImpl.
@Override
public EObject eResolveProxy(InternalEObject proxy) {
URI proxyUri = proxy.eProxyURI();
URI resourceUri = proxyUri.trimFragment();
// bug 0020095
if (eResource() == null) {
return super.eResolveProxy(proxy);
}
ResourceSet resourceSet = eResource().getResourceSet();
ByteArrayResource byteArrayResource = null;
URIConverter theURIConverter = resourceSet.getURIConverter();
URI normalizedURI = theURIConverter.normalize(resourceUri);
// TUP-1814:because the routine proxyUri is File type,need handle with it.
if ((proxyUri.isPlatform() && proxyUri.segmentCount() > 1 && "resource".equals(proxyUri.segment(0))) || proxyUri.isFile()) {
List<Resource> resources = resourceSet.getResources();
synchronized (resources) {
for (Resource resource : resources) {
if (theURIConverter.normalize(resource.getURI()).equals(normalizedURI) && resource instanceof ByteArrayResource) {
byteArrayResource = (ByteArrayResource) resource;
break;
}
}
}
if (byteArrayResource == null) {
byteArrayResource = new ByteArrayResource(resourceUri);
resourceSet.getResources().add(byteArrayResource);
}
try {
byteArrayResource.load(null);
} catch (IOException e) {
}
} else {
List<Resource> resources = resourceSet.getResources();
synchronized (resources) {
for (Resource resource : resources) {
if (theURIConverter.normalize(resource.getURI()).equals(normalizedURI)) {
byteArrayResource = (ByteArrayResource) resource;
break;
}
}
}
}
if (byteArrayResource != null && byteArrayResource.isLoaded()) {
EObject object = byteArrayResource.getEObject(proxyUri.fragment().toString());
if (object != null) {
return object;
}
}
throw new UnsupportedOperationException();
}
use of org.eclipse.emf.ecore.resource.URIConverter in project dsl-devkit by dsldevkit.
the class CheckGenModelUtil method findGenModelInContainers.
/**
* Given an array of {@link IContainers}, searches through all *.genmodel files in all {@link IFolders}, ignoring nested folders, trying to find a
* {@link GenModel} for the given {@link EPackage}.
*
* @param containers
* To search, may be empty, but must not be {@code null}
* @param baseURI
* of these containers; must not be {@code null}
* @param ePackage
* to find a genmodel for; must not be {@code null}
* @param resourceSet
* to use for resource loading; must not be {@code null}
* @return the genmodel, if found, or {@code null} if not.
* @throws CoreException
* if enumerating folder contents does so
*/
private static GenModel findGenModelInContainers(final IContainer[] containers, final URI baseURI, final EPackage ePackage, final ResourceSet resourceSet) throws CoreException {
Preconditions.checkNotNull(containers);
Preconditions.checkNotNull(baseURI);
Preconditions.checkNotNull(ePackage);
Preconditions.checkNotNull(resourceSet);
final URIConverter uriConverter = resourceSet.getURIConverter();
for (IContainer container : containers) {
if (!(container instanceof IFolder)) {
continue;
}
IResource[] resources = container.members();
for (IResource r : resources) {
if (r.exists() && r instanceof IFile && GENMODEL_EXTENSION.equals(r.getFileExtension())) {
URI uriToTry = uriConverter.normalize(baseURI.appendSegment(URI.encodeSegment(r.getName(), false)));
GenModel result = loadGenModel(uriToTry, ePackage, resourceSet);
if (result != null) {
return result;
}
}
}
}
return null;
}
Aggregations