當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。