<commit_before>package at.ac.tuwien.dsg.myx.monitor.aggregator.model;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import at.ac.tuwien.dsg.myx.util.DBLUtils;
import edu.uci.isr.xarch.IXArch;
import edu.uci.isr.xarch.IXArchImplementation;
import edu.uci.isr.xarch.XArchParseException;
import edu.uci.isr.xarch.XArchSerializeException;
import edu.uci.isr.xarch.XArchUtils;
import edu.uci.isr.xarch.hostproperty.IHostedArchStructure;
import edu.uci.isr.xarch.hostproperty.IHostpropertyContext;
import edu.uci.isr.xarch.types.IArchStructure;
import edu.uci.isr.xarch.types.ITypesContext;

public class ModelRootImpl implements ModelRoot {

    protected IXArchImplementation xArchImpl;
    protected IXArch xArchRoot;

    protected ITypesContext typesContext;
    protected IHostpropertyContext hostpropertyContext;

    public ModelRootImpl() {
        xArchImpl = XArchUtils.getDefaultXArchImplementation();
    }

    public ModelRootImpl(String xadlFile) {
        this();
        parse(xadlFile);
    }

    @Override
    public void parse(String xadlFile) {
        try {
            FileReader documentSource = new FileReader(new File(xadlFile));
            xArchRoot = xArchImpl.parse(documentSource);
            typesContext = (ITypesContext) xArchImpl.createContext(xArchRoot, "types");
            hostpropertyContext = (IHostpropertyContext) xArchImpl.createContext(xArchRoot, "hostproperty");
        } catch (XArchParseException | FileNotFoundException e) {
            throw new IllegalArgumentException("There was an error while parsing the given xadl file", e);
        }
    }

    @Override
    public void save(String xadlFile) {
        FileWriter fr = null;
        try {
            fr = new FileWriter(new File(xadlFile));
            fr.write(xArchImpl.serialize(xArchRoot, null));
            fr.close();
        } catch (IOException | XArchSerializeException e) {
            throw new IllegalArgumentException("There was an error while saving the architecture", e);
        } finally {
            if (fr != null) {
                try {
                    fr.close();
                } catch (IOException e) {
                }
            }
        }
    }

    @Override
    public ITypesContext getTypesContext() {
        return typesContext;
    }

    @Override
    public IHostpropertyContext getHostpropertyContext() {
        return hostpropertyContext;
    }

    @Override
    public IArchStructure getArchStructure(String id) {
        synchronized (xArchRoot) {
            IArchStructure archStructure = DBLUtils.getArchStructure(xArchRoot, id);
            if (archStructure == null) {
                archStructure = getTypesContext().createArchStructure();
                archStructure.setId(id);
            }
            return archStructure;
        }
    }

    @Override
    public IHostedArchStructure getHostedArchStructure(String id) {
        synchronized (xArchRoot) {
            IArchStructure archStructure = getArchStructure(id);
            if (archStructure instanceof IHostedArchStructure) {
                return (IHostedArchStructure) archStructure;
            }
            return getHostpropertyContext().promoteToHostedArchStructure(archStructure);
        }
    }

}<commit_msg>fixed a bug with arch structure creation<commit_after>package at.ac.tuwien.dsg.myx.monitor.aggregator.model;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import at.ac.tuwien.dsg.myx.util.DBLUtils;
import edu.uci.isr.xarch.IXArch;
import edu.uci.isr.xarch.IXArchImplementation;
import edu.uci.isr.xarch.XArchParseException;
import edu.uci.isr.xarch.XArchSerializeException;
import edu.uci.isr.xarch.XArchUtils;
import edu.uci.isr.xarch.hostproperty.IHostedArchStructure;
import edu.uci.isr.xarch.hostproperty.IHostpropertyContext;
import edu.uci.isr.xarch.types.IArchStructure;
import edu.uci.isr.xarch.types.ITypesContext;

public class ModelRootImpl implements ModelRoot {

    protected IXArchImplementation xArchImpl;
    protected IXArch xArchRoot;

    protected ITypesContext typesContext;
    protected IHostpropertyContext hostpropertyContext;

    public ModelRootImpl() {
        xArchImpl = XArchUtils.getDefaultXArchImplementation();
    }

    public ModelRootImpl(String xadlFile) {
        this();
        parse(xadlFile);
    }

    @Override
    public void parse(String xadlFile) {
        try {
            FileReader documentSource = new FileReader(new File(xadlFile));
            xArchRoot = xArchImpl.parse(documentSource);
            typesContext = (ITypesContext) xArchImpl.createContext(xArchRoot, "types");
            hostpropertyContext = (IHostpropertyContext) xArchImpl.createContext(xArchRoot, "hostproperty");
        } catch (XArchParseException | FileNotFoundException e) {
            throw new IllegalArgumentException("There was an error while parsing the given xadl file", e);
        }
    }

    @Override
    public void save(String xadlFile) {
        FileWriter fr = null;
        try {
            fr = new FileWriter(new File(xadlFile));
            fr.write(xArchImpl.serialize(xArchRoot, null));
            fr.close();
        } catch (IOException | XArchSerializeException e) {
            throw new IllegalArgumentException("There was an error while saving the architecture", e);
        } finally {
            if (fr != null) {
                try {
                    fr.close();
                } catch (IOException e) {
                }
            }
        }
    }

    @Override
    public ITypesContext getTypesContext() {
        return typesContext;
    }

    @Override
    public IHostpropertyContext getHostpropertyContext() {
        return hostpropertyContext;
    }

    @Override
    public IArchStructure getArchStructure(String id) {
        synchronized (xArchRoot) {
            IArchStructure archStructure = DBLUtils.getArchStructure(xArchRoot, id);
            if (archStructure == null) {
                archStructure = getTypesContext().createArchStructureElement();
                archStructure.setId(id);
                xArchRoot.addObject(archStructure);
            }
            return archStructure;
        }
    }

    @Override
    public IHostedArchStructure getHostedArchStructure(String id) {
        synchronized (xArchRoot) {
            IArchStructure archStructure = getArchStructure(id);
            if (archStructure instanceof IHostedArchStructure) {
                return (IHostedArchStructure) archStructure;
            }
            return getHostpropertyContext().promoteToHostedArchStructure(archStructure);
        }
    }

}
{'fraction_non_alphanumeric': 0.08404600412857564, 'fraction_numerical': 0.0, 'mean_word_length': 2.6605504587155964, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '5533194', 'n_tokens_mistral': 1919, 'n_tokens_neox': 1900, 'n_words': 379}