Search in sources :

Example 26 with XMLResource

use of org.eclipse.emf.ecore.xmi.XMLResource in project tbd-studio-se by Talend.

the class NosqlResourceFactoryImpl method createResource.

/**
 * Creates an instance of the resource.
 * <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
@Override
public Resource createResource(URI uri) {
    XMLResource result = new NosqlResourceImpl(uri);
    result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
    result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
    result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
    result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
    result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
    result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE);
    return result;
}
Also used : XMLResource(org.eclipse.emf.ecore.xmi.XMLResource)

Example 27 with XMLResource

use of org.eclipse.emf.ecore.xmi.XMLResource in project xtext-core by eclipse.

the class GrammarAccessFragment2 method writeGrammar.

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));
    }
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) BinaryResourceImpl(org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl) Resource(org.eclipse.emf.ecore.resource.Resource) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) FragmentFakingEcoreResource(org.eclipse.xtext.xtext.generator.grammarAccess.FragmentFakingEcoreResource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Grammar(org.eclipse.xtext.Grammar) IOException(java.io.IOException) URI(org.eclipse.emf.common.util.URI) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) EObject(org.eclipse.emf.ecore.EObject) EObject(org.eclipse.emf.ecore.EObject) FragmentFakingEcoreResource(org.eclipse.xtext.xtext.generator.grammarAccess.FragmentFakingEcoreResource) HashSet(java.util.HashSet)

Example 28 with XMLResource

use of org.eclipse.emf.ecore.xmi.XMLResource in project archi-modelrepository-plugin by archi-contribs.

the class GraficoModelExporter method createAndSaveResource.

/**
 * Save the model to Resource
 *
 * @param file
 * @param object
 * @throws IOException
 */
private void createAndSaveResource(File file, EObject object) throws IOException {
    // Update the URIConverter
    // Map the logical name (filename) to the physical name (path+filename)
    // Folders must be declared with absolute path or else the 'folder.xml' file is not created
    // The model object must be declared with relative path or else concepts reference profiles through absolute path (which are gonna be different for each users)
    URI key = (!(object instanceof IArchimateModel) && file.getName().equals(IGraficoConstants.FOLDER_XML)) ? URI.createFileURI(file.getAbsolutePath()) : URI.createFileURI(file.getName());
    URI value = URI.createFileURI(file.getAbsolutePath());
    fResourceSet.getURIConverter().getURIMap().put(key, value);
    // Create a new resource for selected file and add object to persist
    XMLResource resource = (XMLResource) fResourceSet.createResource(key);
    // Use UTF-8 and don't start with an XML declaration
    // $NON-NLS-1$
    resource.getDefaultSaveOptions().put(XMLResource.OPTION_ENCODING, "UTF-8");
    resource.getDefaultSaveOptions().put(XMLResource.OPTION_DECLARE_XML, Boolean.FALSE);
    // Make the produced XML easy to read
    resource.getDefaultSaveOptions().put(XMLResource.OPTION_FORMATTED, Boolean.TRUE);
    resource.getDefaultSaveOptions().put(XMLResource.OPTION_LINE_WIDTH, Integer.valueOf(5));
    // Don't use encoded attribute. Needed to have proper references inside Diagrams
    resource.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.FALSE);
    // Use cache
    resource.getDefaultSaveOptions().put(XMLResource.OPTION_CONFIGURATION_CACHE, Boolean.TRUE);
    // Use UNIX line endings to avoid EOL diffs
    // $NON-NLS-1$
    resource.getDefaultSaveOptions().put(Resource.OPTION_LINE_DELIMITER, "\n");
    // Add the object to the resource
    resource.getContents().add(object);
}
Also used : URI(org.eclipse.emf.common.util.URI) IArchimateModel(com.archimatetool.model.IArchimateModel) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource)

Example 29 with XMLResource

use of org.eclipse.emf.ecore.xmi.XMLResource in project mylyn.docs by eclipse.

the class NCXResourceFactoryImpl method createResource.

/**
 * Creates an instance of the resource.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public Resource createResource(URI uri) {
    XMLResource result = new NCXResourceImpl(uri);
    result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
    result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
    result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
    result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
    result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
    result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE);
    return result;
}
Also used : XMLResource(org.eclipse.emf.ecore.xmi.XMLResource)

Example 30 with XMLResource

use of org.eclipse.emf.ecore.xmi.XMLResource in project mylyn.docs by eclipse.

the class OPFResourceFactoryImpl method createResource.

/**
 * Creates an instance of the resource.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public Resource createResource(URI uri) {
    XMLResource result = new OPFResourceImpl(uri);
    result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
    result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
    result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
    result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
    result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
    result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE);
    return result;
}
Also used : XMLResource(org.eclipse.emf.ecore.xmi.XMLResource)

Aggregations

XMLResource (org.eclipse.emf.ecore.xmi.XMLResource)38 HashMap (java.util.HashMap)12 ByteArrayInputStream (java.io.ByteArrayInputStream)8 StringWriter (java.io.StringWriter)8 InputStream (java.io.InputStream)6 EObject (org.eclipse.emf.ecore.EObject)5 DocumentRoot (org.jboss.drools.DocumentRoot)5 DocumentRoot (org.eclipse.bpmn2.DocumentRoot)3 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)3 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)3 IOException (java.io.IOException)2 Bpmn2ResourceFactoryImpl (org.eclipse.bpmn2.util.Bpmn2ResourceFactoryImpl)2 URI (org.eclipse.emf.common.util.URI)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 DroolsResourceFactoryImpl (org.jboss.drools.util.DroolsResourceFactoryImpl)2 BPSimDataType (bpsim.BPSimDataType)1 DocumentRoot (bpsim.DocumentRoot)1 ElementParameters (bpsim.ElementParameters)1 Parameter (bpsim.Parameter)1 Scenario (bpsim.Scenario)1