Java 类org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl 实例源码

项目:xtext-core    文件:ResourceStorageLoadable.java   
protected void readContents(final StorageAwareResource resource, final InputStream inputStream) throws IOException {
  Map<Object, Object> _emptyMap = CollectionLiterals.<Object, Object>emptyMap();
  final BinaryResourceImpl.EObjectInputStream in = new BinaryResourceImpl.EObjectInputStream(inputStream, _emptyMap) {
    @Override
    public int readCompressedInt() throws IOException {
      int _xblockexpression = (int) 0;
      {
        this.resourceSet = null;
        _xblockexpression = super.readCompressedInt();
      }
      return _xblockexpression;
    }

    @Override
    public InternalEObject loadEObject() throws IOException {
      final InternalEObject result = super.loadEObject();
      ResourceStorageLoadable.this.handleLoadEObject(result, this);
      return result;
    }
  };
  in.loadResource(resource);
}
项目:xtext-core    文件:QualifiedNameTest.java   
@Test public void testDeserializeAsLowerCase() throws IOException {
    QualifiedName upperCase = QualifiedName.create("A", "B");
    QualifiedName lowerCase = upperCase.toLowerCase();

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    EObjectOutputStream out = new BinaryResourceImpl.EObjectOutputStream(bos, Collections.emptyMap());
    upperCase.writeToStream(out);
    lowerCase.writeToStream(out);
    out.flush();

    EObjectInputStream in = new BinaryResourceImpl.EObjectInputStream(new ByteArrayInputStream(bos.toByteArray()), Collections.emptyMap());
    QualifiedName readUpperCase = QualifiedName.createFromStream(in);
    QualifiedName readLowerCase = QualifiedName.createFromStream(in);
    assertEquals(QualifiedName.class.getName(), readUpperCase.getClass().getName());
    assertEquals(QualifiedName.class.getName() + "$QualifiedNameLowerCase", readLowerCase.getClass().getName());
    assertEquals(upperCase, readUpperCase);
    assertEquals(lowerCase, readLowerCase);
}
项目:xtext-extras    文件:BatchLinkableResourceStorageWritable.java   
@Override
protected Object beforeSaveEObject(final InternalEObject object, final BinaryResourceImpl.EObjectOutputStream writable) throws IOException {
  JvmType _xblockexpression = null;
  {
    super.beforeSaveEObject(object, writable);
    JvmType _xifexpression = null;
    if ((object instanceof XComputedTypeReference)) {
      _xifexpression = ((XComputedTypeReference)object).getType();
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
项目:xtext-extras    文件:BatchLinkableResourceStorageWritable.java   
@Override
protected void handleSaveEObject(final InternalEObject object, final BinaryResourceImpl.EObjectOutputStream out) throws IOException {
  super.handleSaveEObject(object, out);
  DocumentationAdapter documentationAdapter = null;
  JvmIdentifiableMetaData metaDataAdapter = null;
  EList<Adapter> _eAdapters = object.eAdapters();
  for (final Adapter adapter : _eAdapters) {
    {
      if ((adapter instanceof DocumentationAdapter)) {
        documentationAdapter = ((DocumentationAdapter)adapter);
      }
      if ((adapter instanceof JvmIdentifiableMetaData)) {
        metaDataAdapter = ((JvmIdentifiableMetaData)adapter);
      }
    }
  }
  if ((documentationAdapter != null)) {
    out.writeBoolean(true);
    out.writeString(documentationAdapter.getDocumentation());
  } else {
    out.writeBoolean(false);
  }
  if ((metaDataAdapter != null)) {
    out.writeBoolean(true);
    out.writeBoolean(metaDataAdapter.isSynthetic());
  } else {
    out.writeBoolean(false);
  }
}
项目:xtext-extras    文件:GrammarAccessFragment.java   
@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);
    }
}
项目:xtext-core    文件:ResourceStorageWritable.java   
protected void writeContents(final StorageAwareResource storageAwareResource, final OutputStream outputStream) throws IOException {
  Map<Object, Object> _emptyMap = CollectionLiterals.<Object, Object>emptyMap();
  final BinaryResourceImpl.EObjectOutputStream out = new BinaryResourceImpl.EObjectOutputStream(outputStream, _emptyMap) {
    @Override
    public void writeURI(final URI uri, final String fragment) throws IOException {
      final URI fullURI = uri.appendFragment(fragment);
      URI _elvis = null;
      URI _portableURI = storageAwareResource.getPortableURIs().toPortableURI(storageAwareResource, fullURI);
      if (_portableURI != null) {
        _elvis = _portableURI;
      } else {
        _elvis = fullURI;
      }
      final URI uriToWrite = _elvis;
      super.writeURI(uriToWrite.trimFragment(), uriToWrite.fragment());
    }

    @Override
    public void saveEObject(final InternalEObject internalEObject, final BinaryResourceImpl.EObjectOutputStream.Check check) throws IOException {
      ResourceStorageWritable.this.beforeSaveEObject(internalEObject, this);
      super.saveEObject(internalEObject, check);
      ResourceStorageWritable.this.handleSaveEObject(internalEObject, this);
    }
  };
  try {
    out.saveResource(storageAwareResource);
  } finally {
    out.flush();
  }
}
项目:emf-fragments    文件:EmfSaveLargeChainTest.java   
@Test
public void theTest() throws Exception {
    EPackage.Registry.INSTANCE.put(EcorePackage.eINSTANCE.getNsURI(), EcorePackage.eINSTANCE);
    Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new ResourceFactoryImpl() {
        @Override
        public Resource createResource(URI uri) {           
            return new BinaryResourceImpl(uri);
        }           
    });
    Resource resource = new ResourceSetImpl().createResource(URI.createURI("test.ecore"));
    EPackage thePkg = EcoreFactory.eINSTANCE.createEPackage();
    resource.getContents().add(thePkg);
    thePkg.setName("ThePkg");
    EClass lastClass = null;
    for (int i = 0; i < 10000; i++) {
        EClass newClass = EcoreFactory.eINSTANCE.createEClass();
        newClass.setName("Class" + i);
        thePkg.getEClassifiers().add(newClass);
        if (lastClass != null) {
            EReference ref = EcoreFactory.eINSTANCE.createEReference();
            ref.setName("ref");
            ref.setEType(newClass);
            lastClass.getEStructuralFeatures().add(ref);
        }
        lastClass = newClass;
    }

    resource.save(null);
}
项目:xtext-core    文件:ResourceStorageLoadable.java   
protected Object handleLoadEObject(final InternalEObject loaded, final BinaryResourceImpl.EObjectInputStream input) throws IOException {
  return null;
}
项目:xtext-core    文件:ResourceStorageWritable.java   
protected Object beforeSaveEObject(final InternalEObject object, final BinaryResourceImpl.EObjectOutputStream writable) throws IOException {
  return null;
}
项目:xtext-core    文件:ResourceStorageWritable.java   
protected void handleSaveEObject(final InternalEObject object, final BinaryResourceImpl.EObjectOutputStream out) throws IOException {
}
项目:xtext-core    文件:GrammarAccessFragment2.java   
protected void writeGrammar() {
  final Wrapper<Boolean> isSaving = Wrapper.<Boolean>wrap(Boolean.valueOf(false));
  final ResourceSet cloneInto = new ResourceSetImpl();
  Map<String, Object> _extensionToFactoryMap = cloneInto.getResourceFactoryRegistry().getExtensionToFactoryMap();
  FragmentFakingEcoreResource.FactoryImpl _factoryImpl = new FragmentFakingEcoreResource.FactoryImpl(isSaving);
  _extensionToFactoryMap.put(
    FragmentFakingEcoreResource.FactoryImpl.ECORE_SUFFIX, _factoryImpl);
  final ResourceSet resourceSet = EcoreUtil2.<ResourceSet>clone(cloneInto, this.getLanguage().getGrammar().eResource().getResourceSet());
  EObject _head = IterableExtensions.<EObject>head(resourceSet.getResource(this.getLanguage().getGrammar().eResource().getURI(), true).getContents());
  final Grammar copy = ((Grammar) _head);
  String _xifexpression = null;
  if ((this.xmlVersion == null)) {
    _xifexpression = GrammarUtil.getClasspathRelativePathToBinGrammar(copy);
  } else {
    String _xblockexpression = null;
    {
      String _simpleName = GrammarAccessFragment2.class.getSimpleName();
      String _plus = ("The property \'xmlVersion\' has been specified for this " + _simpleName);
      String _plus_1 = (_plus + ". Therefore, the grammar is persisted as XMI and not as binary. This can be a performance drawback.");
      GrammarAccessFragment2.LOG.warn(_plus_1);
      _xblockexpression = GrammarUtil.getClasspathRelativePathToXmi(copy);
    }
    _xifexpression = _xblockexpression;
  }
  final String path = _xifexpression;
  final URI uri = this.getProjectConfig().getRuntime().getSrcGen().getURI(path);
  final Resource resource = resourceSet.createResource(uri, ContentHandler.UNSPECIFIED_CONTENT_TYPE);
  HashSet<Grammar> _hashSet = new HashSet<Grammar>();
  this.addAllGrammarsToResource(resource, copy, _hashSet);
  isSaving.set(Boolean.valueOf(true));
  final Map<String, Object> saveOptions = CollectionLiterals.<String, Object>newHashMap();
  if ((resource instanceof XMLResource)) {
    String _elvis = null;
    if (this.xmlVersion != null) {
      _elvis = this.xmlVersion;
    } else {
      _elvis = "1.0";
    }
    ((XMLResource)resource).setXMLVersion(_elvis);
  } else {
    if ((resource instanceof BinaryResourceImpl)) {
      saveOptions.put(BinaryResourceImpl.OPTION_VERSION, BinaryResourceImpl.BinaryIO.Version.VERSION_1_1);
      saveOptions.put(BinaryResourceImpl.OPTION_STYLE_DATA_CONVERTER, Boolean.valueOf(true));
    }
  }
  try {
    resource.save(saveOptions);
  } catch (final Throwable _t) {
    if (_t instanceof IOException) {
      final IOException e = (IOException)_t;
      GrammarAccessFragment2.LOG.error(e.getMessage(), e);
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  } finally {
    isSaving.set(Boolean.valueOf(false));
  }
}
项目:model-repository-benchmark    文件:BenchmarkUtils.java   
@Override
public Resource createResource(URI uri) {
    return new BinaryResourceImpl(uri);
}
项目:eclipse-avro    文件:EFactoryImpl.java   
/**
 * @since 2.9
 */
public BinaryResourceImpl.DataConverter<?> create(EDataType eDataType)
{
  return null;
}
项目:dynemf    文件:ResourceSetWrapper.java   
/**
 * Creates a prepared {@link ResourceSet} with some registered factories.
 * Produced resources by extensions are:
 * <ul>
 * <li>.xmi uses {@link XMIResourceImpl}</li>
 * <li>.bin uses {@link BinaryResourceImpl}</li>
 * <li>.ecore uses {@link XMIResourceImpl}</li>
 * <li>.* uses {@link XMIResourceImpl}</li>
 * </ul>
 * This method can be override in order to change the basic ResourceSet used
 * by this wrapper.
 * 
 * @return a configured ResourceSet
 */
protected static ResourceSet createResourceSet() {
    ResourceSet result = new ResourceSetImpl();
    result.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
    result.getResourceFactoryRegistry().getExtensionToFactoryMap().put("bin", new ResourceFactoryImpl() {
        @Override
        public Resource createResource(URI uri) {
            return new BinaryResourceImpl(uri);
        }
    });
    result.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
    result.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
    return result;
}
项目:dynemf    文件:ResourceSetWrapper.java   
/**
 * Creates a prepared {@link ResourceSet} with some registered factories.
 * Produced resources by extensions are:
 * <ul>
 * <li>.xmi uses {@link XMIResourceImpl}</li>
 * <li>.bin uses {@link BinaryResourceImpl}</li>
 * <li>.ecore uses {@link XMIResourceImpl}</li>
 * <li>.* uses {@link XMIResourceImpl}</li>
 * </ul>
 * This method can be override in order to change the basic ResourceSet used
 * by this wrapper.
 * 
 * @return a configured ResourceSet
 */
protected static ResourceSet createResourceSet() {
    ResourceSet result = new ResourceSetImpl();
    result.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
    result.getResourceFactoryRegistry().getExtensionToFactoryMap().put("bin", new ResourceFactoryImpl() {
        @Override
        public Resource createResource(URI uri) {
            return new BinaryResourceImpl(uri);
        }
    });
    result.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
    result.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
    return result;
}