• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ContentHandler类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.eclipse.emf.ecore.resource.ContentHandler的典型用法代码示例。如果您正苦于以下问题:Java ContentHandler类的具体用法?Java ContentHandler怎么用?Java ContentHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ContentHandler类属于org.eclipse.emf.ecore.resource包,在下文中一共展示了ContentHandler类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: RamlResourceSet

import org.eclipse.emf.ecore.resource.ContentHandler; //导入依赖的package包/类
public RamlResourceSet() {
    final List<URIHandler> uriHandlers = Arrays.asList(
            new PlatformResourceURIHandlerImpl(),
            new FileURIHandlerImpl(),
            new EFSURIHandlerImpl(),
            new ArchiveURIHandlerImpl(),
            new ContentNegotiationURIHandler(ACCEPT_HEADER_VALUE));
    final ExtensibleURIConverterImpl uriConverter =
            new ExtensibleURIConverterImpl(uriHandlers, ContentHandler.Registry.INSTANCE.contentHandlers());
    setURIConverter(uriConverter);

    final Resource.Factory.Registry resourceFactoryRegistry = getResourceFactoryRegistry();
    final RamlResourceFactory resourceFactory = new RamlResourceFactory();
    resourceFactoryRegistry
            .getExtensionToFactoryMap().put("raml", resourceFactory);

    resourceFactoryRegistry.getProtocolToFactoryMap()
            .put("http", resourceFactory);

    final Map<String, Object> contentTypeToFactoryMap = resourceFactoryRegistry.getContentTypeToFactoryMap();
    for (final String contentType : ACCEPTED_MIME_TYPES) {
        contentTypeToFactoryMap
                .put(contentType, resourceFactory);
    }
    addBuiltinTypes();
}
 
开发者ID:vrapio,项目名称:rest-modeling-framework,代码行数:27,代码来源:RamlResourceSet.java


示例2: testSimple

import org.eclipse.emf.ecore.resource.ContentHandler; //导入依赖的package包/类
@Test public void testSimple() throws Exception {
	// this fails see bug #252181
	String model = "grammar foo with org.eclipse.xtext.common.Terminals Honolulu : name=ID;";

	// load grammar model
	XtextResourceSet rs = get(XtextResourceSet.class);
	Resource resource = rs.createResource(URI.createURI("foo.xtext"), ContentHandler.UNSPECIFIED_CONTENT_TYPE);
	resource.load(new StringInputStream(model), null);
	Grammar object = (Grammar) resource.getContents().get(0);

	// modify first rule
	object.getRules().get(0).setName("HONOLULU");

	// save
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	resource.save(out, SaveOptions.newBuilder().format().getOptions().toOptionsMap());
	String result = new String(out.toByteArray());

	// check
	assertFalse(model.equals(result));
	String expectedModel = LineDelimiters.toPlatform("grammar foo with org.eclipse.xtext.common.Terminals\n\nHONOLULU:\n	name=ID;");
	assertEquals(expectedModel, result);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:24,代码来源:XtextGrammarReconcilationTest.java


示例3: testBug_266807

import org.eclipse.emf.ecore.resource.ContentHandler; //导入依赖的package包/类
@Test
public void testBug_266807() throws Exception {
  final XtextResourceSet rs = this.<XtextResourceSet>get(XtextResourceSet.class);
  rs.setClasspathURIContext(this.getClass());
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("classpath:/");
  String _replace = this.getClass().getPackage().getName().replace(Character.valueOf('.').charValue(), Character.valueOf('/').charValue());
  _builder.append(_replace);
  _builder.append("/Test.xtext");
  Resource _createResource = rs.createResource(
    URI.createURI(_builder.toString()), 
    ContentHandler.UNSPECIFIED_CONTENT_TYPE);
  final XtextResource resource = ((XtextResource) _createResource);
  resource.load(null);
  EList<Resource.Diagnostic> _errors = resource.getErrors();
  for (final Resource.Diagnostic d : _errors) {
    Assert.fail(d.getMessage());
  }
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:20,代码来源:Xtext2EcoreTransformerTest.java


示例4: getDescriptionValue

import org.eclipse.emf.ecore.resource.ContentHandler; //导入依赖的package包/类
/**
 * Returns the given property's Eclipse value converted to EMF's corresponding basic value.
 * @param qualifiedName the name of the property for which this value applies.
 * @param value the value to convert.
 * @return the given property's Eclipse value converted to EMF's corresponding basic value.
 */
protected Object getDescriptionValue(QualifiedName qualifiedName, Object value)
{
  if (value == null)
  {
    return null;
  }
  else if (IContentDescription.BYTE_ORDER_MARK.equals(qualifiedName))
  {
    for (ByteOrderMark byteOrderMarker : ContentHandler.ByteOrderMark.values())
    {
      if (value == byteOrderMarker.bytes())
      {
        return byteOrderMarker;
      }
    }
    return null;
  }
  else
  {
    return value;
  }
}
 
开发者ID:LangleyStudios,项目名称:eclipse-avro,代码行数:29,代码来源:PlatformContentHandlerImpl.java


示例5: isRequestedProperty

import org.eclipse.emf.ecore.resource.ContentHandler; //导入依赖的package包/类
/**
 * Returns whether the named property is one requested in the options.
 * @param property the property in question.
 * @param options the options in which to look for the requested property.
 * @return whether the named property is one requested in the options.
 * @see #getRequestedProperties(Map)
 */
protected boolean isRequestedProperty(String property, Map<?, ?> options)
{
  if (ContentHandler.VALIDITY_PROPERTY.equals(property) || ContentHandler.CONTENT_TYPE_PROPERTY.equals(property))
  {
    return  true;
  }
  else
  {
    Set<String> requestedProperties = getRequestedProperties(options);
    if (requestedProperties == null)
    {
      return true;
    }
    else
    {
      return requestedProperties.contains(property);
    }
  }
}
 
开发者ID:LangleyStudios,项目名称:eclipse-avro,代码行数:27,代码来源:ContentHandlerImpl.java


示例6: getLineDelimiter

import org.eclipse.emf.ecore.resource.ContentHandler; //导入依赖的package包/类
/**
 * Returns the line delimiter of the input stream; it's computed from the bytes interpreted using the {@link #getCharset(URI, InputStream, Map, Map) appropriate character set}.
 * @param uri the URI of the input stream.
 * @param inputStream the input stream.
 * @param options any options that might influence the interpretation of the content.
 * @param context a cache for previously computed information.
 * @return the line delimiter of the input stream.
 * @throws IOException if there is a problem loading the content.
 * @since 2.9
 */
protected String getLineDelimiter(URI uri, InputStream inputStream, Map<?, ?> options, Map<Object, Object> context) throws IOException
{
  String result = (String)context.get(ContentHandler.LINE_DELIMITER_PROPERTY);
  if (result == null)
  {
    String charset = getCharset(uri, inputStream, options, context);
    if (charset != null)
    {
      result = getLineDelimiter(inputStream, charset);
      if (result != null)
      {
        context.put(ContentHandler.LINE_DELIMITER_PROPERTY, result);
      }
    }
  }
  return result;
}
 
开发者ID:LangleyStudios,项目名称:eclipse-avro,代码行数:28,代码来源:ContentHandlerImpl.java


示例7: getDescriptionValue

import org.eclipse.emf.ecore.resource.ContentHandler; //导入依赖的package包/类
/**
 * Returns the given property's basic EMF value converted to the corresponding Eclipse value.
 * @param qualifiedName the name of the property for which this value applies.
 * @param value the value to convert.
 * @return the given property's basic EMF value converted to the corresponding Eclipse value.
 */
protected Object getDescriptionValue(QualifiedName qualifiedName, Object value)
{
  if (value == null)
  {
    return null;
  }
  else if (IContentDescription.BYTE_ORDER_MARK.equals(qualifiedName))
  {
    return ((ContentHandler.ByteOrderMark)value).bytes();
  }
  else
  {
    return value;
  }
}
 
开发者ID:LangleyStudios,项目名称:eclipse-avro,代码行数:22,代码来源:ContentHandlerImpl.java


示例8: generate

import org.eclipse.emf.ecore.resource.ContentHandler; //导入依赖的package包/类
@Override
public void generate(Grammar grammar, XpandExecutionContext ctx) {
	RuleNames.ensureAdapterInstalled(grammar);
	super.generate(grammar, ctx);

	final ResourceSaveIndicator isSaving = new ResourceSaveIndicator();
	// create a defensive clone
	Grammar copy = deepCopy(grammar, isSaving);
	ResourceSet set = copy.eResource().getResourceSet();

	// save grammar model
	String path;
	if (xmlVersion == null) {
		path = GrammarUtil.getClasspathRelativePathToBinGrammar(copy);
	} else {
		log.warn("'xmlVersion' has been specified for this "
				+ GrammarAccessFragment.class.getSimpleName()
				+ ". Therefore, the grammar is persisted as XMI and not as binary. This can be a performance drawback.");
		path = GrammarUtil.getClasspathRelativePathToXmi(copy);
	}
	URI uri = URI.createURI(ctx.getOutput().getOutlet(Generator.SRC_GEN).getPath() + "/" + path);
	Resource resource = set.createResource(uri, ContentHandler.UNSPECIFIED_CONTENT_TYPE);
	addAllGrammarsToResource(resource, copy, new HashSet<Grammar>());
	isSaving.set(Boolean.TRUE);
	Map<String, Object> saveOptions = Maps.newHashMap();
	if (resource instanceof XMLResource) {
		((XMLResource) resource).setXMLVersion(getXmlVersion());
	} else if (resource instanceof BinaryResourceImpl){
		saveOptions.put(BinaryResourceImpl.OPTION_VERSION, BinaryResourceImpl.BinaryIO.Version.VERSION_1_1);
		saveOptions.put(BinaryResourceImpl.OPTION_STYLE_DATA_CONVERTER, Boolean.TRUE);
	}
	try {
		resource.save(saveOptions);
	} catch (IOException e) {
		log.error(e.getMessage(), e);
	} finally {
		isSaving.set(Boolean.FALSE);
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:40,代码来源:GrammarAccessFragment.java


示例9: movePackageToNewResource

import org.eclipse.emf.ecore.resource.ContentHandler; //导入依赖的package包/类
/**
 * @since 2.4
 */
protected void movePackageToNewResource(EPackage pack, ResourceSet set) {
	Resource resource = set.createResource(
			URI.createURI("___temp___." + FragmentFakingEcoreResourceFactoryImpl.ECORE_SUFFIX),
			ContentHandler.UNSPECIFIED_CONTENT_TYPE);
	resource.setURI(URI.createURI(pack.getNsURI()));
	resource.getContents().add(pack);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:11,代码来源:GrammarAccessFragment.java


示例10: createResourceForEPackages

import org.eclipse.emf.ecore.resource.ContentHandler; //导入依赖的package包/类
protected Resource createResourceForEPackages(Grammar grammar, XpandExecutionContext ctx, List<EPackage> packs,
		ResourceSet rs) {
	URI ecoreFileUri = getEcoreFileUri(grammar, ctx);
	ecoreFileUri = toPlatformResourceURI(ecoreFileUri);
	Resource existing = rs.getResource(ecoreFileUri, false);
	if (existing != null) {
		existing.unload();
		rs.getResources().remove(existing);
	}
	Resource ecoreFile = rs.createResource(ecoreFileUri, ContentHandler.UNSPECIFIED_CONTENT_TYPE);
	ecoreFile.getContents().addAll(packs);
	return ecoreFile;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:14,代码来源:EMFGeneratorFragment.java


示例11: getURIConverter

import org.eclipse.emf.ecore.resource.ContentHandler; //导入依赖的package包/类
@Override
protected synchronized URIConverter getURIConverter() {
	if (this.uriConverter == null) {
		List<ContentHandler> withoutPlatformDelegate = Lists.newArrayList();
		for (ContentHandler contentHandler : ContentHandler.Registry.INSTANCE.contentHandlers()) {
			if (!isTooEager(contentHandler))
				withoutPlatformDelegate.add(contentHandler);
		}
		this.uriConverter = new ExtensibleURIConverterImpl(URIHandler.DEFAULT_HANDLERS, withoutPlatformDelegate);
	}
	return this.uriConverter;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:13,代码来源:ResourceServiceProviderRegistryImpl.java


示例12: movePackageToNewResource

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


示例13: createResourceForEPackages

import org.eclipse.emf.ecore.resource.ContentHandler; //导入依赖的package包/类
protected Resource createResourceForEPackages(final Grammar grammar, final List<EPackage> packs, final ResourceSet rs) {
  final URI ecoreFileUri = this.getEcoreFileUri(grammar);
  final Resource existing = rs.getResource(ecoreFileUri, false);
  if ((existing != null)) {
    existing.unload();
    rs.getResources().remove(existing);
  }
  final Resource ecoreFile = rs.createResource(ecoreFileUri, ContentHandler.UNSPECIFIED_CONTENT_TYPE);
  ecoreFile.getContents().addAll(packs);
  return ecoreFile;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:12,代码来源:EMFGeneratorFragment2.java


示例14: testSimple

import org.eclipse.emf.ecore.resource.ContentHandler; //导入依赖的package包/类
@Test public void testSimple() throws Exception {
	ResourceSet rs = new ResourceSetImpl();
	Resource foo = rs.createResource(URI.createURI("foo.xmi"), ContentHandler.UNSPECIFIED_CONTENT_TYPE);
	EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
	foo.getContents().add(ePackage);
	Resource bar = rs.createResource(URI.createURI("bar.xmi"), ContentHandler.UNSPECIFIED_CONTENT_TYPE);
	bar.getContents().add(EcoreFactory.eINSTANCE.createEAttribute());
	
	assertEquals(true, EcoreUtil2.isValidUri(ePackage, URI.createURI("bar.xmi")));
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:11,代码来源:EcoreUtil2Test.java


示例15: testEPackageURI

import org.eclipse.emf.ecore.resource.ContentHandler; //导入依赖的package包/类
@Test public void testEPackageURI() throws Exception {
	ResourceSet rs = new ResourceSetImpl();
	Resource foo = rs.createResource(URI.createURI("foo.xmi"), ContentHandler.UNSPECIFIED_CONTENT_TYPE);
	EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
	foo.getContents().add(ePackage);
	
	assertEquals(true, EcoreUtil2.isValidUri(ePackage, URI.createURI(EcorePackage.eNS_URI)));
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:9,代码来源:EcoreUtil2Test.java


示例16: testClone

import org.eclipse.emf.ecore.resource.ContentHandler; //导入依赖的package包/类
@Test public void testClone() throws Exception {
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION,
			new XMIResourceFactoryImpl());
	EPackage.Registry.INSTANCE.put(EcorePackage.eINSTANCE.getNsURI(), EcorePackage.eINSTANCE);
	
	ResourceSetImpl rs = new ResourceSetImpl();
	Resource r1 = rs.createResource(URI.createURI("foo.xmi"), ContentHandler.UNSPECIFIED_CONTENT_TYPE);
	Resource r2 = rs.createResource(URI.createURI("bar.xmi"), ContentHandler.UNSPECIFIED_CONTENT_TYPE);
	EClass a = EcoreFactory.eINSTANCE.createEClass();
	a.setName("a");
	EClass b = EcoreFactory.eINSTANCE.createEClass();
	r1.getContents().add(a);
	b.setName("b");
	b.getESuperTypes().add(a);
	r2.getContents().add(b);
	
	ResourceSetImpl clone = EcoreUtil2.clone(new ResourceSetImpl(), rs);
	EList<Resource> list = clone.getResources();
	
	Resource resA = list.get(0);
	assertEquals(URI.createURI("foo.xmi"),resA.getURI());
	assertNotSame(resA, r1);
	
	Resource resB = list.get(1);
	assertEquals(URI.createURI("bar.xmi"),resB.getURI());
	assertNotSame(resB, r2);
	
	EClass a1 = (EClass)resA.getContents().get(0);
	EClass b1 = (EClass)resB.getContents().get(0);
	assertEquals("a", a1.getName());
	assertNotSame(a, a1);
	assertEquals("b", b1.getName());
	assertNotSame(b, b1);
	assertSame(b1.getESuperTypes().get(0),a1);
	assertSame(b.getESuperTypes().get(0),a);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:37,代码来源:EcoreUtil2Test.java


示例17: _testXtestSerializationSelfTest

import org.eclipse.emf.ecore.resource.ContentHandler; //导入依赖的package包/类
public void _testXtestSerializationSelfTest() throws Exception {
  Resource res = this.<XtextResourceSet>get(XtextResourceSet.class).createResource(URI.createURI("myfile.xtext"), 
    ContentHandler.UNSPECIFIED_CONTENT_TYPE);
  res.getContents().add(this.<XtextGrammarAccess>get(XtextGrammarAccess.class).getGrammar());
  OutputStream outputStream = new ByteArrayOutputStream();
  res.save(outputStream, Collections.<Object, Object>emptyMap());
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:8,代码来源:XtextGrammarSerializationTest.java


示例18: getResourceServiceProviderByExtension

import org.eclipse.emf.ecore.resource.ContentHandler; //导入依赖的package包/类
/**
 * Finds the {@link IResourceServiceProvider} for a language given its file extension.
 *
 * @param extension
 *          the language's file extension
 * @return the resource service provider for the {@code extension} or null if there is none
 */
public IResourceServiceProvider getResourceServiceProviderByExtension(final String extension) {
  Object object = IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().get(extension);
  if (object instanceof IResourceServiceProvider) {
    return (IResourceServiceProvider) object;
  } else {
    URI fake = URI.createURI("fake:/foo." + extension); //$NON-NLS-1$
    return IResourceServiceProvider.Registry.INSTANCE.getResourceServiceProvider(fake, ContentHandler.UNSPECIFIED_CONTENT_TYPE);
  }
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:17,代码来源:ResourceServiceProviderLocator.java


示例19: createResource

import org.eclipse.emf.ecore.resource.ContentHandler; //导入依赖的package包/类
protected XtextResource createResource(ResourceSet resourceSet, URI uri) {
	//TODO use the resource factory directly (injected), since the use might open any file with this editor.
	Resource aResource = resourceSet.createResource(uri, ContentHandler.UNSPECIFIED_CONTENT_TYPE);
	if (!(aResource instanceof XtextResource))
		throw new IllegalStateException("The resource factory registered for " + uri
				+ " does not yield an XtextResource. Make sure the file name extension is correct (case matters).");
	return (XtextResource) aResource;
}
 
开发者ID:cplutte,项目名称:bts,代码行数:9,代码来源:ResourceForIEditorInputFactory.java


示例20: getResource

import org.eclipse.emf.ecore.resource.ContentHandler; //导入依赖的package包/类
private XtextResource getResource(ResourceSet resourceSet, URI uri) {
	Resource aResource = resourceSet.createResource(uri, ContentHandler.UNSPECIFIED_CONTENT_TYPE);
	if (!(aResource instanceof XtextResource))
		throw new IllegalStateException("The resource factory registered for " + uri
				+ " does not yield an XtextResource. Make sure the right resource factory has been registered.");
	return (XtextResource) aResource;
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:8,代码来源:ResourceForFileEditorFactory.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SimpleAccountRealm类代码示例发布时间:2022-05-22
下一篇:
Java NullProgressListener类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap