Java 类org.eclipse.xtext.resource.persistence.ResourceStorageLoadable 实例源码

项目:xtext-core    文件:StorageAwareResource.java   
@Override
public void load(final Map<?, ?> options) throws IOException {
  if (((((!this.isLoaded) && (!this.isLoading)) && (this.resourceStorageFacade != null)) && this.resourceStorageFacade.shouldLoadFromStorage(this))) {
    boolean _isDebugEnabled = StorageAwareResource.LOG.isDebugEnabled();
    if (_isDebugEnabled) {
      URI _uRI = this.getURI();
      String _plus = ("Loading " + _uRI);
      String _plus_1 = (_plus + " from storage.");
      StorageAwareResource.LOG.debug(_plus_1);
    }
    try {
      final ResourceStorageLoadable in = this.resourceStorageFacade.getOrCreateResourceStorageLoadable(this);
      this.loadFromStorage(in);
      return;
    } catch (final Throwable _t) {
      if (_t instanceof IOException) {
        this.contents.clear();
        this.eAdapters.clear();
        this.unload();
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
  }
  super.load(options);
}
项目:xtext-core    文件:StorageAwareResource.java   
public void loadFromStorage(final ResourceStorageLoadable storageInputStream) throws IOException {
  if ((storageInputStream == null)) {
    throw new NullPointerException("storageInputStream");
  }
  final Stopwatches.StoppedTask task = Stopwatches.forTask("Loading from storage");
  task.start();
  this.isLoading = true;
  this.isLoadedFromStorage = true;
  try {
    storageInputStream.loadIntoResource(this);
    this.isLoaded = true;
  } finally {
    this.isLoading = false;
    task.stop();
  }
}
项目:xtext-core    文件:ResourceStorageFacade.java   
/**
 * Finds or creates a ResourceStorageLoadable for the given resource.
 * Clients should first call shouldLoadFromStorage to check whether there exists a storage version
 * of the given resource.
 * 
 * @return an IResourceStorageLoadable
 */
@Override
public ResourceStorageLoadable getOrCreateResourceStorageLoadable(final StorageAwareResource resource) {
  try {
    final ResourceStorageProviderAdapter stateProvider = IterableExtensions.<ResourceStorageProviderAdapter>head(Iterables.<ResourceStorageProviderAdapter>filter(resource.getResourceSet().eAdapters(), ResourceStorageProviderAdapter.class));
    if ((stateProvider != null)) {
      final ResourceStorageLoadable inputStream = stateProvider.getResourceStorageLoadable(resource);
      if ((inputStream != null)) {
        return inputStream;
      }
    }
    InputStream _xifexpression = null;
    boolean _exists = resource.getResourceSet().getURIConverter().exists(this.getBinaryStorageURI(resource.getURI()), CollectionLiterals.<Object, Object>emptyMap());
    if (_exists) {
      _xifexpression = resource.getResourceSet().getURIConverter().createInputStream(this.getBinaryStorageURI(resource.getURI()));
    } else {
      InputStream _xblockexpression = null;
      {
        final AbstractFileSystemAccess2 fsa = this.getFileSystemAccess(resource);
        final String outputRelativePath = this.computeOutputPath(resource);
        _xblockexpression = fsa.readBinaryFile(outputRelativePath);
      }
      _xifexpression = _xblockexpression;
    }
    final InputStream inputStream_1 = _xifexpression;
    return this.createResourceStorageLoadable(inputStream_1);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:xtext-core    文件:PortableURIsTest.java   
@Test
public void testPortableReferenceDescriptions() {
  try {
    final XtextResourceSet resourceSet = this.<XtextResourceSet>get(XtextResourceSet.class);
    Resource _createResource = resourceSet.createResource(URI.createURI("hubba:/bubba.langatestlanguage"));
    final StorageAwareResource resourceA = ((StorageAwareResource) _createResource);
    Resource _createResource_1 = resourceSet.createResource(URI.createURI("hubba:/bubba2.langatestlanguage"));
    final StorageAwareResource resourceB = ((StorageAwareResource) _createResource_1);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("type B");
    _builder.newLine();
    resourceB.load(this.getAsStream(_builder.toString()), null);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("import \'hubba:/bubba2.langatestlanguage\'");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("type A extends B");
    _builder_1.newLine();
    resourceA.load(this.getAsStream(_builder_1.toString()), null);
    final ByteArrayOutputStream bout = new ByteArrayOutputStream();
    final ResourceStorageWritable writable = resourceA.getResourceStorageFacade().createResourceStorageWritable(bout);
    writable.writeResource(resourceA);
    byte[] _byteArray = bout.toByteArray();
    ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_byteArray);
    final ResourceStorageLoadable loadable = resourceA.getResourceStorageFacade().createResourceStorageLoadable(_byteArrayInputStream);
    Resource _createResource_2 = resourceSet.createResource(URI.createURI("hubba:/bubba3.langatestlanguage"));
    final StorageAwareResource resourceC = ((StorageAwareResource) _createResource_2);
    resourceC.loadFromStorage(loadable);
    final IReferenceDescription refDesc = IterableExtensions.<IReferenceDescription>head(resourceC.getResourceDescription().getReferenceDescriptions());
    EObject _head = IterableExtensions.<EObject>head(resourceB.getContents());
    Assert.assertSame(IterableExtensions.<Type>head(((Main) _head).getTypes()), resourceSet.getEObject(refDesc.getTargetEObjectUri(), false));
    EObject _head_1 = IterableExtensions.<EObject>head(resourceC.getContents());
    Assert.assertSame(IterableExtensions.<Type>head(((Main) _head_1).getTypes()), resourceSet.getEObject(refDesc.getSourceEObjectUri(), false));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:xtext-extras    文件:BatchLinkableResourceStorageFacade.java   
@Override
public ResourceStorageLoadable createResourceStorageLoadable(final InputStream in) {
  boolean _isStoreNodeModel = this.isStoreNodeModel();
  return new BatchLinkableResourceStorageLoadable(in, _isStoreNodeModel);
}
项目:xtext-core    文件:ResourceStorageProviderAdapter.java   
public ResourceStorageLoadable getResourceStorageLoadable(final StorageAwareResource resource) {
  return null;
}
项目:xtext-core    文件:ResourceStorageFacade.java   
@Override
public ResourceStorageLoadable createResourceStorageLoadable(final InputStream in) {
  boolean _isStoreNodeModel = this.isStoreNodeModel();
  return new ResourceStorageLoadable(in, _isStoreNodeModel);
}
项目:dsl-devkit    文件:DirectLinkingResourceStorageFacade.java   
@Override
public ResourceStorageLoadable createResourceStorageLoadable(final InputStream in) {
  return new DirectLinkingResourceStorageLoadable(in, isStoreNodeModel(), traceSet);
}
项目:xtext-core    文件:IResourceStorageFacade.java   
/**
 * Finds or creates a ResourceStorageLoadable for the given resource.
 * Clients should first call shouldLoadFromStorage to check whether there exists a storage version
 * of the given resource.
 * 
 * @return an IResourceStorageLoadable
 */
public abstract ResourceStorageLoadable getOrCreateResourceStorageLoadable(final StorageAwareResource resource);
项目:xtext-core    文件:IResourceStorageFacade.java   
/**
 * Creates a fresh ResourceStorageLoadable wrapping the given InputStream
 */
public abstract ResourceStorageLoadable createResourceStorageLoadable(final InputStream inputStream);