<commit_before>/**
 * Copyright (c) 2010 Bolton University, UK.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the License
 * which accompanies this distribution in the file LICENSE.txt
 */
package uk.ac.bolton.archimate.model.util;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EModelElement;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceFactoryImpl;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.BasicExtendedMetaData;
import org.eclipse.emf.ecore.util.ExtendedMetaData;
import org.eclipse.emf.ecore.xmi.XMLResource;

import uk.ac.bolton.archimate.model.IArchimatePackage;

/**
 * <!-- begin-user-doc -->
 * The <b>Resource Factory</b> associated with the package.
 * <!-- end-user-doc -->
 * @see uk.ac.bolton.archimate.model.util.ArchimateResource
 * @generated
 */
public class ArchimateResourceFactory extends ResourceFactoryImpl {
    
    private Map<Object, Object> options;
    
    /**
     * Creates an instance of the resource factory.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public ArchimateResourceFactory() {
        super();
    }
    
    /**
     * @return a Resource that allows saving and loading files with any type of file extension
     *          as registered in plugin.xml
     */
    public static Resource createResource(File file) {
        ResourceSet resourceSet = createResourceSet();
        
        // This will return an ArchimateResource as registered in plugin.xml
        Resource resource = resourceSet.createResource(URI.createFileURI(file.getAbsolutePath()));
        return resource;
    }

    /**
     * @return a ResourceSet that allows saving and loading files with any type of extension
     */
    public static ResourceSet createResourceSet() {
        ResourceSet resourceSet = new ResourceSetImpl();
        // Register the * extension on the ResourceSet to over-ride the ECore global one
        resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new ArchimateResourceFactory());
        return resourceSet;
    }

    /**
     * Creates an instance of the resource.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated NOT
     */
    @Override
    public Resource createResource(URI uri) {
        ArchimateResource result = new ArchimateResource(uri);
        result.getDefaultLoadOptions().putAll(getOptions());
        result.getDefaultSaveOptions().putAll(getOptions());
        return result;
    }
    
    /**
     * Add customisation to serialsiation
     * See Chapter 15.3.5 of the EMF book, 2nd edition
     * @return
     */
    private Map<Object, Object> getOptions() {
        if(options == null) {
            options = new HashMap<Object, Object>();
            
            // UTF-8
            options.put(XMLResource.OPTION_ENCODING, "UTF-8");
            
            // A Map to map Ecore features and classes to elememt names and types
            ExtendedMetaData ext = new BasicExtendedMetaData(ExtendedMetaData.ANNOTATION_URI, 
                    EPackage.Registry.INSTANCE, new HashMap<EModelElement, EAnnotation>()) {
                
                @Override
                public EClassifier getType(EPackage ePackage, String name) {
                    /*
                     * Backwards compatibility for the old "DiagramModel" type<commit_msg>Use simple constructor of BasicExtendedMetaData<commit_after>/**
 * Copyright (c) 2010 Bolton University, UK.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the License
 * which accompanies this distribution in the file LICENSE.txt
 */
package uk.ac.bolton.archimate.model.util;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceFactoryImpl;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.BasicExtendedMetaData;
import org.eclipse.emf.ecore.util.ExtendedMetaData;
import org.eclipse.emf.ecore.xmi.XMLResource;

import uk.ac.bolton.archimate.model.IArchimatePackage;

/**
 * <!-- begin-user-doc -->
 * The <b>Resource Factory</b> associated with the package.
 * <!-- end-user-doc -->
 * @see uk.ac.bolton.archimate.model.util.ArchimateResource
 * @generated
 */
public class ArchimateResourceFactory extends ResourceFactoryImpl {
    
    private Map<Object, Object> options;
    
    /**
     * Creates an instance of the resource factory.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public ArchimateResourceFactory() {
        super();
    }
    
    /**
     * @return a Resource that allows saving and loading files with any type of file extension
     *          as registered in plugin.xml
     */
    public static Resource createResource(File file) {
        ResourceSet resourceSet = createResourceSet();
        
        // This will return an ArchimateResource as registered in plugin.xml
        Resource resource = resourceSet.createResource(URI.createFileURI(file.getAbsolutePath()));
        return resource;
    }

    /**
     * @return a ResourceSet that allows saving and loading files with any type of extension
     */
    public static ResourceSet createResourceSet() {
        ResourceSet resourceSet = new ResourceSetImpl();
        // Register the * extension on the ResourceSet to over-ride the ECore global one
        resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new ArchimateResourceFactory());
        return resourceSet;
    }

    /**
     * Creates an instance of the resource.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated NOT
     */
    @Override
    public Resource createResource(URI uri) {
        ArchimateResource result = new ArchimateResource(uri);
        result.getDefaultLoadOptions().putAll(getOptions());
        result.getDefaultSaveOptions().putAll(getOptions());
        return result;
    }
    
    /**
     * Add customisation to serialsiation
     * See Chapter 15.3.5 of the EMF book, 2nd edition
     * @return
     */
    private Map<Object, Object> getOptions() {
        if(options == null) {
            options = new HashMap<Object, Object>();
            
            // UTF-8
            options.put(XMLResource.OPTION_ENCODING, "UTF-8");
            
            // A Map to map Ecore features and classes to elememt names and types
            ExtendedMetaData ext = new BasicExtendedMetaData() {
                @Override
                public EClassifier getType(EPackage ePackage, String name) {
                    /*
                     * Backwards compatibility for the old "DiagramModel" type
{'fraction_non_alphanumeric': 0.10209637898175879, 'fraction_numerical': 0.0029948271167982575, 'mean_word_length': 2.6552238805970148, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2376133', 'n_tokens_mistral': 1987, 'n_tokens_neox': 1957, 'n_words': 527}