// This file is part of the Coral project.
// Please read the copyright notice in the LICENSE file.

#include <coral/core/DCE_UUID.h>

#include <coral/coral.h>
#include "XMI.h"
#include <coral/core/ElementDefinition.h>
#include <coral/core/PrimitiveProperties.h>

NAMESPACE_BEGIN(coral);
NAMESPACE_BEGIN(XMI);

static bool has_loaded = false;

coral::Language* language;

coral::ElementDefinition* Extension;

/*
 * All our enumerations
 */
static const coral::util::mmcreator::Enumeration* enums[] = {
	NULL
};

static const coral::util::mmcreator::Datatype dtypes[] = {
	{ NULL, NULL }
};
	
/*
 * All our metamodel elements
 */
static const coral::util::mmcreator::Element elems[] = {
	{ &Extension, "Extension" },
	{ NULL, NULL }
};

/*
 * All our subclass <-> superclass relations
 * They have to be given as names due to c++ restrictions.
 */
static const coral::util::mmcreator::SubAndSuper bases[] = {
	{ NULL, NULL }
};

/*
 * All our slots
 */
static const coral::util::mmcreator::Feature slots[] = {
	{ "Extension", "extender", "CORE::String", NULL, 1, 1, coral::kind_t::KIND_COMPOSITION },
	{ "Extension", "extenderID", "CORE::String", NULL, 0, 1, coral::kind_t::KIND_COMPOSITION },
	{ "Extension", "xmi_contents", "CORE::AnyElement", NULL, 0, -1, coral::kind_t::KIND_COMPOSITION | coral::kind_t::KIND_ORDERED },
	{ NULL, NULL, NULL, NULL, 0, 0, 0 }
};

/*
 * The initialization routines
 * - Create all metamodel elements 
 * - create metamodel slots and insert them into respective metamodel
 *   elements
 */
bool init_language() throw () {

	if (has_loaded) return true;

	try {
		if (!language) language = new coral::Language(std::string("XMI"), 1, 2);

		coral::util::mmcreator::create_elems(language, enums, dtypes, elems, bases, slots);
		language->setRoot(Extension);
		language->setXMLNS("http://schema.omg.org/spec/XMI/1.2");

	} catch (...) {

		return false;
	}

	has_loaded = true;
	return true;
}
NAMESPACE_END();
NAMESPACE_END();
