当前位置: 首页>>代码示例>>Java>>正文


Java URIConverter.exists方法代码示例

本文整理汇总了Java中org.eclipse.emf.ecore.resource.URIConverter.exists方法的典型用法代码示例。如果您正苦于以下问题:Java URIConverter.exists方法的具体用法?Java URIConverter.exists怎么用?Java URIConverter.exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.emf.ecore.resource.URIConverter的用法示例。


在下文中一共展示了URIConverter.exists方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isValidUri

import org.eclipse.emf.ecore.resource.URIConverter; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:26,代码来源:EcoreUtil2.java

示例2: registerUsedGenModel

import org.eclipse.emf.ecore.resource.URIConverter; //导入方法依赖的package包/类
private void registerUsedGenModel(final URIConverter converter, final Grammar grammar) {
  final URI genModelUri = this.getGenModelUri(grammar);
  boolean _exists = converter.exists(genModelUri, null);
  if (_exists) {
    try {
      GenModelHelper _genModelHelper = new GenModelHelper();
      XtextResourceSet _xtextResourceSet = new XtextResourceSet();
      _genModelHelper.registerGenModel(_xtextResourceSet, genModelUri);
    } catch (final Throwable _t) {
      if (_t instanceof Exception) {
        final Exception e = (Exception)_t;
        EMFGeneratorFragment2.LOG.error("Failed to register GenModel", e);
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
  }
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:19,代码来源:EMFGeneratorFragment2.java

示例3: findExtensionURI

import org.eclipse.emf.ecore.resource.URIConverter; //导入方法依赖的package包/类
/**
 * Find URI of extended FormatConfiguration.
 * The following heuristic is used to find the URI: extract grammar name from the extensionName (path name) and then replace the file name segment of the
 * context's URI with the extracted grammar name.
 *
 * @param context
 *          the context
 * @param extensionName
 *          the extension name
 * @return the URI if found, otherwise null
 */
private URI findExtensionURI(final Resource context, final String extensionName) {
  URI uri = context.getURI().trimFileExtension();
  String name = convertPathNameToShortName(extensionName);
  final URI extensionURI = uri.trimSegments(1).appendSegment(name).appendFileExtension(FormatConstants.FILE_EXTENSION);
  final ResourceSet resourceSet = context.getResourceSet();
  final URIConverter uriConverter = resourceSet.getURIConverter();
  try {
    if (resourceSet.getResource(extensionURI, false) != null || uriConverter.exists(extensionURI, null)) {
      return extensionURI;
    }
    // CHECKSTYLE:OFF
  } catch (Exception e) {// NOPMD
    // no resource found - return null
    // CHECKSTYLE:ON
  }
  return null;
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:29,代码来源:FormatScopeUtil.java

示例4: registerUsedGenModel

import org.eclipse.emf.ecore.resource.URIConverter; //导入方法依赖的package包/类
private void registerUsedGenModel(URIConverter converter) {
	if (genModel == null)
		return;
	URI genModelUri = URI.createURI(genModel);
	genModelUri = toPlatformResourceURI(genModelUri);
	if (converter.exists(genModelUri, null)) {
		try {
			new GenModelHelper().registerGenModel(new XtextResourceSet(), genModelUri);
		} catch (ConfigurationException ce) {
			throw ce;
		} catch (Exception e) {
			log.error(e, e);
		}
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:16,代码来源:EMFGeneratorFragment.java

示例5: UserContentManager

import org.eclipse.emf.ecore.resource.URIConverter; //导入方法依赖的package包/类
/**
 * Constructor.
 * 
 * @param uriConverter
 *            the {@link URIConverter uri converter} to use.
 * @param documentTemplate
 *            the input {@link DocumentTemplate}
 * @param destination
 *            the destination {@link URI}
 * @throws IOException
 *             IOException if the destination can't be copied to a temporary file
 */
public UserContentManager(URIConverter uriConverter, DocumentTemplate documentTemplate, URI destination)
        throws IOException {
    this.uriConverter = uriConverter;
    this.documentTemplate = documentTemplate;
    this.destination = destination;
    if (uriConverter.exists(destination, Collections.EMPTY_MAP)) {
        // Copy file
        generatedFileCopy = tempCopyFile(destination);
        // Launch parsing
        launchParsing();
    } else {
        generatedFileCopy = null;
    }
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:27,代码来源:UserContentManager.java

示例6: loadXtendFile

import org.eclipse.emf.ecore.resource.URIConverter; //导入方法依赖的package包/类
/**
 * Expects an Xtend file named <code>MyDsl</code>PostProcessor.ext with an extension with signature
 * process(xtext::GeneratedMetamodel) in the same folder as the grammar file.
 * 
 * @param metamodel
 *            the metamodel to augment
 * @return the xtendFile to execute
 */
protected Resource loadXtendFile(GeneratedMetamodel metamodel) {
	if (xtendFile == null) {
		final String extension = getExtensionName(metamodel);
		try {
			URI uri = getXtendFileLocation(metamodel);
			if (uri != null) {
				URIConverter uriConverter = metamodel.eResource().getResourceSet().getURIConverter();
				if (uriConverter.exists(uri, null)) {
					InputStream in = uriConverter.createInputStream(uri);
					try {
						XtendResourceParser parser = new XtendResourceParser();
						xtendFile = parser.parse(new InputStreamReader(in), extension + '.'
								+ XtendFile.FILE_EXTENSION);
						fireXtendFileLoaded();
					} finally {
						if (in != null)
							in.close();
					}
				}
			}
		} catch (ClasspathUriResolutionException ignored) {
			// no xtend file found
		} catch (Exception e) {
			logger.error("Could not parse " + extension, e);
		}
	}
	return xtendFile;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:37,代码来源:XtendXtext2EcorePostProcessor.java

示例7: visit

import org.eclipse.emf.ecore.resource.URIConverter; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unused")
public boolean visit(IResourceDelta delta) throws CoreException {
	IResource changedResource = delta.getResource();
	if (changedResource.getType() == IResource.FILE) {
		try {
			ResourceSet resourceSet = editingDomain.getResourceSet();
			URI uri = EMFUtils.getURI(changedResource);
			URIConverter uriConverter = resourceSet.getURIConverter();
			if (uriConverter.exists(uri, null)) {
				Resource res = resourceSet.getResource(uri, false);
				if (res != null) {
					if (res.isLoaded()) {
						res.unload();
					}
					res.load(resourceSet.getLoadOptions());
					final TreeViewer viewer = (TreeViewer) _viewer;
					WidgetUtils.runInDisplayThread(viewer.getControl(), new Runnable() {
						@Override
						public void run() {
							TreePath[] treePaths = viewer.getExpandedTreePaths();
							viewer.refresh();
							viewer.setExpandedTreePaths(treePaths);
						}
					});
				}
			}
		} catch (Exception e) {
			LogUtil.error("Error reloading resource", e);
		}	
		return false;
	}
	return true;
}
 
开发者ID:nasa,项目名称:OpenSPIFe,代码行数:35,代码来源:ProfileNavigatorContentProvider.java


注:本文中的org.eclipse.emf.ecore.resource.URIConverter.exists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。