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


Java Resource.getContents方法代码示例

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


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

示例1: loadManifest

import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
ProjectDescription loadManifest(URI manifest) {
	try {
		ProjectDescription result = null;
		ResourceSet resourceSet = resourceSetProvider.get(null /* we don't care about the project right now */);
		String platformPath = manifest.toPlatformString(true);
		if (manifest.isArchive() || platformPath != null) {
			if (manifest.isArchive() || workspace.getFile(new Path(platformPath)).exists()) {
				Resource resource = resourceSet.getResource(manifest, true);
				if (resource != null) {
					List<EObject> contents = resource.getContents();
					if (contents.isEmpty() || !(contents.get(0) instanceof ProjectDescription)) {
						return null;
					}
					result = (ProjectDescription) contents.get(0);
					contents.clear();
				}
			}
		}
		return result;
	} catch (WrappedException e) {
		throw new IllegalStateException("Unexpected manifest URI: " + manifest, e);
	}
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:24,代码来源:EclipseBasedN4JSWorkspace.java

示例2: read

import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public List<T> read(final URI uri) throws IOException {
  final Resource res = this.getResourceSet().createResource(uri);

  if (res == null) {
    return new ArrayList<T>();
  }
  res.load(null);
  final EList<EObject> contents = res.getContents();

  final List<T> list = new ArrayList<T>();
  for (final EObject content : contents) {

    try {
      list.add((T) content);
    } catch (final Exception e) {
      throw new RuntimeException("Unexpected resource type.");
    }
  }

  return list;
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:23,代码来源:ModelIO.java

示例3: apiSuperCrossReferencer

import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
@Test
public void apiSuperCrossReferencer() {
    final File apiFile = new File("/Users/mkoester/Development/commercetools-api-reference/api.raml");
    assumeTrue(apiFile.exists());

    final URI fileURI = URI.createURI(apiFile.toURI().toString());
    final Resource resource = fromUri(fileURI);
    assertThat(resource).isNotNull();
    assertThat(resource.getErrors()).isEmpty();

    final EList<EObject> contents = resource.getContents();
    final Api api = (Api) contents.get(0);
    final Optional<AnyType> optionalDestinationType = api.getTypes().stream()
            .filter(anyType -> "Destination".equals(anyType.getName()))
            .findFirst();

    assertThat(optionalDestinationType.isPresent());
    final AnyType destinationType = optionalDestinationType.get();
    final List<AnyType> subTypes = destinationType.subTypes();
    assertThat(subTypes).hasSize(3);
}
 
开发者ID:vrapio,项目名称:rest-modeling-framework,代码行数:22,代码来源:RamlResourceTest.java

示例4: findReferences

import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
@Override
public void findReferences(Predicate<URI> targetURIs, Resource resource, Acceptor acceptor,
		IProgressMonitor monitor) {
	// make sure data is present
	keys.getData((TargetURIs) targetURIs, new SimpleResourceAccess(resource.getResourceSet()));
	EList<EObject> astContents;
	if (resource instanceof N4JSResource) {
		// In case of N4JSResource, we search only in the AST but NOT in TModule tree!
		Script script = (Script) ((N4JSResource) resource).getContents().get(0);
		astContents = new BasicEList<>();
		astContents.add(script);
	} else {
		astContents = resource.getContents();
	}
	for (EObject content : astContents) {
		findReferences(targetURIs, content, acceptor, monitor);
	}
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:19,代码来源:ConcreteSyntaxAwareReferenceFinder.java

示例5: loadManifest

import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
protected ProjectDescription loadManifest(URI manifest) {
	ResourceSet resourceSet = resourceSetProvider.get();
	Resource resource = resourceSet.getResource(manifest, true);
	List<EObject> contents = resource.getContents();
	if (contents.isEmpty() || !(contents.get(0) instanceof ProjectDescription)) {
		return null;
	}
	// do some error handling:
	if (!resource.getErrors().isEmpty()) {
		throw new N4JSBrokenProjectException("Reading project description from "
				+ manifest
				+ " raised the following errors: "
				+ Joiner.on('\n').join(
						resource.getErrors().stream().map(
								error -> error.getMessage() + "  at line " + error.getLine())
								.iterator()));
	}
	ProjectDescription result = (ProjectDescription) contents.get(0);
	contents.clear();
	return result;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:22,代码来源:LazyProjectDescriptionHandle.java

示例6: loadManifest

import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
@Override
public ProjectDescription loadManifest(URI manifest) {
	ResourceSet resourceSet = resourceSetProvider.get();
	Resource resource = resourceSet.getResource(manifest, true);
	List<EObject> contents = resource.getContents();
	if (contents.isEmpty() || !(contents.get(0) instanceof ProjectDescription)) {
		return null;
	}
	// do some error handling:
	if (!resource.getErrors().isEmpty()) {
		throw new N4JSBrokenProjectException("Reading project description from "
				+ manifest
				+ " raised the following errors: "
				+ Joiner.on('\n').join(
						resource.getErrors().stream().map(
								error -> error.getMessage() + " at line " + error.getLine())
								.iterator()));
	}
	ProjectDescription result = (ProjectDescription) contents.get(0);
	contents.clear();
	return result;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:23,代码来源:FileBasedExternalPackageManager.java

示例7: loadConfiguraton

import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
public static Chart loadConfiguraton ( final String configurationUri )
{
    if ( configurationUri == null || configurationUri.isEmpty () )
    {
        return null;
    }

    // load
    ChartPackage.eINSTANCE.eClass ();

    final ResourceSet resourceSet = new ResourceSetImpl ();

    resourceSet.getResourceFactoryRegistry ().getExtensionToFactoryMap ().put ( "*", new XMIResourceFactoryImpl () ); //$NON-NLS-1$

    final Resource resource = resourceSet.getResource ( URI.createURI ( configurationUri ), true );

    for ( final EObject o : resource.getContents () )
    {
        if ( o instanceof Chart )
        {
            return (Chart)o;
        }
    }
    return null;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:26,代码来源:ChartHelper.java

示例8: load

import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
private void load ()
{
    logger.info ( "Loading: {}", this.uri ); //$NON-NLS-1$

    final ResourceSet resourceSet = new ResourceSetImpl ();

    resourceSet.getResourceFactoryRegistry ().getExtensionToFactoryMap ().put ( "*", new XMIResourceFactoryImpl () ); //$NON-NLS-1$

    final URI file = URI.createURI ( this.uri );
    final Resource resource = resourceSet.getResource ( file, true );

    for ( final EObject o : resource.getContents () )
    {
        if ( o instanceof View )
        {
            createView ( (View)o );
        }
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:20,代码来源:DetailViewImpl.java

示例9: load

import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
public T load ( final URI uri, final String contentTypeId ) throws IOException
{
    final ResourceSet rs = new ResourceSetImpl ();
    final Resource r = rs.createResource ( uri, contentTypeId );
    r.load ( null );

    for ( final Object o : r.getContents () )
    {
        if ( this.clazz.isAssignableFrom ( o.getClass () ) )
        {
            return this.clazz.cast ( o );
        }
    }

    throw new IllegalStateException ( String.format ( "Model %s does not contain an object of type %s", uri, this.clazz ) );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:17,代码来源:ModelLoader.java

示例10: generatorLibrary

import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
@Test
public void generatorLibrary() throws IOException {
    final Resource resource = fromClasspath("/generator.raml");
    assertThat(resource.getErrors()).hasSize(0);

    final EList<EObject> contents = resource.getContents();

    assertThat(contents).hasSize(1);
    final EObject rootObject = contents.get(0);
    assertThat(rootObject).isInstanceOf(Library.class);

    final Library library = (Library) rootObject;
    final EList<AnyAnnotationType> annotationTypes = library.getAnnotationTypes();
    assertThat(annotationTypes).hasSize(1);

    assertThat(annotationTypes.get(0)).isInstanceOf(StringAnnotationType.class);
    final StringAnnotationType annotationStringType = (StringAnnotationType) annotationTypes.get(0);
    assertThat(annotationStringType.getAllowedTargets()).containsExactly(AnnotationTarget.LIBRARY);
}
 
开发者ID:vrapio,项目名称:rest-modeling-framework,代码行数:20,代码来源:RamlResourceTest.java

示例11: addTypeModel

import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
@Override
public void addTypeModel(TypeModel typeModel) throws PortException {
    int timer = Timer.start("TM to Ecore");
    this.m_currentTypeModel = typeModel;
    visitTypeModel(typeModel);
    Timer.stop(timer);

    timer = Timer.start("Ecore save");
    Resource typeResource = this.m_ecoreResource.getTypeResource(typeModel.getQualName());
    EList<EObject> contents = typeResource.getContents();

    for (EPackage pkg : this.m_rootPackages) {
        //pkg.setNsPrefix(pkg.getName().toLowerCase());
        //pkg.setNsURI("file://./" + typeModel.getName() + ".ecore#" + pkg.getName().toLowerCase());
        contents.add(pkg);
    }
    Timer.stop(timer);
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:19,代码来源:TypeToEcore.java

示例12: findScript

import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
/** Searches the script node in the given input. */
private Script findScript(Object input) {
	if (input instanceof ResourceSet) {
		ResourceSet rs = (ResourceSet) input;
		if (!rs.getResources().isEmpty()) {
			Resource res = rs.getResources().get(0);
			EList<EObject> contents = res.getContents();
			if (!contents.isEmpty()) {
				Script script = EcoreUtil2.getContainerOfType(contents.get(0), Script.class);
				return script;
			}
		}
	}
	return null;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:16,代码来源:CFGraphProvider.java

示例13: setTarget

import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
@Override
protected void setTarget(Resource target) {
	if (target instanceof N4JSResource) {
		// copied from super method:
		basicSetTarget(target);
		InternalEList<EObject> contents = (InternalEList<EObject>) target.getContents();
		for (int i = 0, size = contents.size(); i < size; ++i) {
			Notifier notifier = contents.basicGet(i); // changed from contents.get(i) to contents.basicGet(i)
			// to avoid resolving the object (i.e. avoid call to
			// ModuleAwareContentsList#resolve() in N4JSResource)
			addAdapter(notifier);
		}
	} else
		super.setTarget(target);
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:16,代码来源:N4JSCache.java

示例14: getRootObject

import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
default <T> T getRootObject(final Resource resource) {
       final EList<EObject> contents = resource.getContents();

       assertThat(contents).hasSize(1);

       return (T) contents.get(0);
   }
 
开发者ID:vrapio,项目名称:rest-modeling-framework,代码行数:9,代码来源:ResourceFixtures.java

示例15: getGroup

import org.eclipse.emf.ecore.resource.Resource; //导入方法依赖的package包/类
private Group getGroup() {
	final Group res;
	final IEditorPart editor = PlatformUI.getWorkbench()
			.getActiveWorkbenchWindow().getActivePage()
			.getActiveEditor();

	if (editor instanceof IEditingDomainProvider) {
		final EditingDomain editingDomain = ((IEditingDomainProvider) editor)
				.getEditingDomain();
		final ResourceSet resourceSet = editingDomain.getResourceSet();
		Group group = null;

		for (Resource resource : resourceSet.getResources()) {
			for (EObject eObj : resource.getContents()) {
				if (eObj instanceof Group) {
					group = (Group) eObj;
					break;
				}
			}
		}
		res = group;
	} else {
		res = null;
	}

	return res;
}
 
开发者ID:eclipse,项目名称:gemoc-studio-modeldebugging,代码行数:28,代码来源:NewGemocDebugRepresentationWizard.java


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