/* Object.c generated by valac 0.56.19, the Vala compiler
 * generated from Object.vala, do not modify */

/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
/*
 *
 * Copyright (C) 2016-2019  Daniel Espinosa <esodan@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *      Daniel Espinosa <esodan@gmail.com>
 */

#include "gxml/gxml.h"
#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.h>
#include <glib/gi18n-lib.h>
#include <gee.h>
#include "gxml.h"

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#define _g_param_spec_unref0(var) ((var == NULL) ? NULL : (var = (g_param_spec_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

static GList* gxml_object_real_get_properties_list (GXmlObject* self);
static GParamSpec* gxml_object_real_find_property_name (GXmlObject* self,
                                                 const gchar* nick);
static GParamSpec* gxml_object_real_find_object_property_name (GXmlObject* self,
                                                        const gchar* pname);
static GList* gxml_object_real_get_property_element_list (GXmlObject* self);
static gchar* gxml_object_real_get_property_string (GXmlObject* self,
                                             GParamSpec* prop);
static gchar* gxml_object_real_get_attribute (GXmlObject* self,
                                       const gchar* name);
static GXmlProperty* gxml_object_real_find_property (GXmlObject* self,
                                              const gchar* name);
static gboolean gxml_object_real_set_attribute (GXmlObject* self,
                                         const gchar* name,
                                         const gchar* val);
static GXmlDomElement* gxml_object_real_get_child (GXmlObject* self,
                                            const gchar* name);
static GXmlDomElementList* gxml_object_real_find_elements (GXmlObject* self,
                                                    const gchar* name);
static gboolean gxml_object_real_remove_attribute (GXmlObject* self,
                                            const gchar* name);
static gboolean gxml_object_real_set_instance_property (GXmlObject* self,
                                                 const gchar* name);
static void gxml_object_real_clean_property_elements (GXmlObject* self,
                                               const gchar* name,
                                               GError** error);
static GType gxml_object_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

/**
   * Returns a list with all properties' nick with "::" prefix. Nick name,
   * with "::" prefix will be used on serialization to an attribute's name.
   */
static gpointer
_g_param_spec_ref0 (gpointer self)
{
	return self ? g_param_spec_ref (self) : NULL;
}

static gboolean
string_contains (const gchar* self,
                 const gchar* needle)
{
	gchar* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (needle != NULL, FALSE);
	_tmp0_ = strstr ((gchar*) self, (gchar*) needle);
	result = _tmp0_ != NULL;
	return result;
}

static GList*
gxml_object_real_get_properties_list (GXmlObject* self)
{
	GList* l = NULL;
	GObjectClass* _tmp0_;
	guint _tmp1_ = 0;
	GParamSpec** _tmp2_;
	GList* result;
	l = NULL;
	_tmp0_ = G_OBJECT_GET_CLASS ((GObject*) self);
	_tmp2_ = g_object_class_list_properties (_tmp0_, &_tmp1_);
	{
		GParamSpec** spec_collection = NULL;
		gint spec_collection_length1 = 0;
		gint _spec_collection_size_ = 0;
		gint spec_it = 0;
		spec_collection = _tmp2_;
		spec_collection_length1 = _tmp1_;
		for (spec_it = 0; spec_it < spec_collection_length1; spec_it = spec_it + 1) {
			GParamSpec* _tmp3_;
			GParamSpec* spec = NULL;
			_tmp3_ = _g_param_spec_ref0 (spec_collection[spec_it]);
			spec = _tmp3_;
			{
				GParamSpec* _tmp4_;
				const gchar* _tmp5_;
				_tmp4_ = spec;
				_tmp5_ = g_param_spec_get_nick (_tmp4_);
				if (string_contains (_tmp5_, "::")) {
					GParamSpec* _tmp6_;
					GParamSpec* _tmp7_;
					_tmp6_ = spec;
					_tmp7_ = _g_param_spec_ref0 (_tmp6_);
					l = g_list_append (l, _tmp7_);
				}
				_g_param_spec_unref0 (spec);
			}
		}
		spec_collection = (g_free (spec_collection), NULL);
	}
	result = l;
	return result;
}

GList*
gxml_object_get_properties_list (GXmlObject* self)
{
	GXmlObjectIface* _iface_;
	g_return_val_if_fail (self != NULL, NULL);
	_iface_ = GXML_OBJECT_GET_INTERFACE (self);
	if (_iface_->get_properties_list) {
		return _iface_->get_properties_list (self);
	}
	return NULL;
}

/**
   * Returns property's {@link GLib.ParamSpec} based on given nick, without '::'
   * This function is case insensitive.
   *
   * By default any property to be serialized, should set its nick with a prefix
   * '::', while this method requires to avoid '::' for property's name to find.
   * '::' will not be present on serialization output, so you can use any convention
   * for your attribute's name, like using camel case.
   */
static gchar*
string_replace (const gchar* self,
                const gchar* old,
                const gchar* replacement)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (old != NULL, NULL);
	g_return_val_if_fail (replacement != NULL, NULL);
	if ((*((gchar*) self)) == '\0') {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = (*((gchar*) old)) == '\0';
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = g_strcmp0 (old, replacement) == 0;
	}
	if (_tmp0_) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (self);
		result = _tmp2_;
		return result;
	}
	{
		GRegex* regex = NULL;
		gchar* _tmp3_;
		gchar* _tmp4_;
		GRegex* _tmp5_;
		GRegex* _tmp6_;
		gchar* _tmp7_ = NULL;
		GRegex* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		_tmp3_ = g_regex_escape_string (old, -1);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_regex_new (_tmp4_, 0, 0, &_inner_error0_);
		_tmp6_ = _tmp5_;
		_g_free0 (_tmp4_);
		regex = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp8_ = regex;
		_tmp9_ = g_regex_replace_literal (_tmp8_, self, (gssize) -1, 0, replacement, 0, &_inner_error0_);
		_tmp7_ = _tmp9_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp10_ = _tmp7_;
		_tmp7_ = NULL;
		result = _tmp10_;
		_g_free0 (_tmp7_);
		_g_regex_unref0 (regex);
		return result;
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		g_clear_error (&_inner_error0_);
		g_assert_not_reached ();
	}
	__finally0:
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
	g_clear_error (&_inner_error0_);
	return NULL;
}

static GParamSpec*
gxml_object_real_find_property_name (GXmlObject* self,
                                     const gchar* nick)
{
	GObjectClass* _tmp0_;
	guint _tmp1_ = 0;
	GParamSpec** _tmp2_;
	GParamSpec* result;
	g_return_val_if_fail (nick != NULL, NULL);
	_tmp0_ = G_OBJECT_GET_CLASS ((GObject*) self);
	_tmp2_ = g_object_class_list_properties (_tmp0_, &_tmp1_);
	{
		GParamSpec** spec_collection = NULL;
		gint spec_collection_length1 = 0;
		gint _spec_collection_size_ = 0;
		gint spec_it = 0;
		spec_collection = _tmp2_;
		spec_collection_length1 = _tmp1_;
		for (spec_it = 0; spec_it < spec_collection_length1; spec_it = spec_it + 1) {
			GParamSpec* _tmp3_;
			GParamSpec* spec = NULL;
			_tmp3_ = _g_param_spec_ref0 (spec_collection[spec_it]);
			spec = _tmp3_;
			{
				gchar* name = NULL;
				GParamSpec* _tmp4_;
				const gchar* _tmp5_;
				gchar* _tmp6_;
				const gchar* _tmp7_;
				_tmp4_ = spec;
				_tmp5_ = g_param_spec_get_nick (_tmp4_);
				_tmp6_ = g_strdup (_tmp5_);
				name = _tmp6_;
				_tmp7_ = name;
				if (string_contains (_tmp7_, "::")) {
					const gchar* _tmp8_;
					gchar* _tmp9_;
					const gchar* _tmp10_;
					gchar* _tmp11_;
					gchar* _tmp12_;
					gchar* _tmp13_;
					gchar* _tmp14_;
					gboolean _tmp15_;
					_tmp8_ = name;
					_tmp9_ = string_replace (_tmp8_, "::", "");
					_g_free0 (name);
					name = _tmp9_;
					_tmp10_ = name;
					_tmp11_ = g_utf8_strdown (_tmp10_, (gssize) -1);
					_tmp12_ = _tmp11_;
					_tmp13_ = g_utf8_strdown (nick, (gssize) -1);
					_tmp14_ = _tmp13_;
					_tmp15_ = g_strcmp0 (_tmp12_, _tmp14_) == 0;
					_g_free0 (_tmp14_);
					_g_free0 (_tmp12_);
					if (_tmp15_) {
						result = spec;
						_g_free0 (name);
						spec_collection = (g_free (spec_collection), NULL);
						return result;
					}
				}
				_g_free0 (name);
				_g_param_spec_unref0 (spec);
			}
		}
		spec_collection = (g_free (spec_collection), NULL);
	}
	result = NULL;
	return result;
}

GParamSpec*
gxml_object_find_property_name (GXmlObject* self,
                                const gchar* nick)
{
	GXmlObjectIface* _iface_;
	g_return_val_if_fail (self != NULL, NULL);
	_iface_ = GXML_OBJECT_GET_INTERFACE (self);
	if (_iface_->find_property_name) {
		return _iface_->find_property_name (self, nick);
	}
	return NULL;
}

/**
   * Returns a {@link GXml.Object} or a {@link Collection} property's
   * {@link GLib.ParamSpec} based on given name. This method is
   * case insensitive.
   *
   * This method will check if nick's name is equal than given name
   * in order to avoid use canonical names like "your-name" if your
   * property is your_name; so you can use nick to "YourName" to find
   * and instantiate it.
   */
static GParamSpec*
gxml_object_real_find_object_property_name (GXmlObject* self,
                                            const gchar* pname)
{
	GObjectClass* _tmp0_;
	guint _tmp1_ = 0;
	GParamSpec** _tmp2_;
	GParamSpec* result;
	g_return_val_if_fail (pname != NULL, NULL);
	_tmp0_ = G_OBJECT_GET_CLASS ((GObject*) self);
	_tmp2_ = g_object_class_list_properties (_tmp0_, &_tmp1_);
	{
		GParamSpec** spec_collection = NULL;
		gint spec_collection_length1 = 0;
		gint _spec_collection_size_ = 0;
		gint spec_it = 0;
		spec_collection = _tmp2_;
		spec_collection_length1 = _tmp1_;
		for (spec_it = 0; spec_it < spec_collection_length1; spec_it = spec_it + 1) {
			GParamSpec* _tmp3_;
			GParamSpec* spec = NULL;
			_tmp3_ = _g_param_spec_ref0 (spec_collection[spec_it]);
			spec = _tmp3_;
			{
				gchar* name = NULL;
				gchar* _tmp4_;
				const gchar* _tmp5_;
				gchar* nick = NULL;
				GParamSpec* _tmp8_;
				const gchar* _tmp9_;
				gchar* _tmp10_;
				const gchar* _tmp11_;
				gchar* sname = NULL;
				GParamSpec* _tmp14_;
				const gchar* _tmp15_;
				gchar* _tmp16_;
				gboolean _tmp17_ = FALSE;
				const gchar* _tmp18_;
				const gchar* _tmp19_;
				_tmp4_ = g_utf8_strdown (pname, (gssize) -1);
				name = _tmp4_;
				_tmp5_ = name;
				if (string_contains (_tmp5_, "::")) {
					const gchar* _tmp6_;
					gchar* _tmp7_;
					_tmp6_ = name;
					_tmp7_ = string_replace (_tmp6_, "::", "");
					_g_free0 (name);
					name = _tmp7_;
				}
				_tmp8_ = spec;
				_tmp9_ = g_param_spec_get_nick (_tmp8_);
				_tmp10_ = g_utf8_strdown (_tmp9_, (gssize) -1);
				nick = _tmp10_;
				_tmp11_ = nick;
				if (string_contains (_tmp11_, "::")) {
					const gchar* _tmp12_;
					gchar* _tmp13_;
					_tmp12_ = nick;
					_tmp13_ = string_replace (_tmp12_, "::", "");
					_g_free0 (nick);
					nick = _tmp13_;
				}
				_tmp14_ = spec;
				_tmp15_ = _tmp14_->name;
				_tmp16_ = g_utf8_strdown (_tmp15_, (gssize) -1);
				sname = _tmp16_;
				_tmp18_ = sname;
				_tmp19_ = name;
				if (g_strcmp0 (_tmp18_, _tmp19_) == 0) {
					_tmp17_ = TRUE;
				} else {
					const gchar* _tmp20_;
					const gchar* _tmp21_;
					_tmp20_ = nick;
					_tmp21_ = name;
					_tmp17_ = g_strcmp0 (_tmp20_, _tmp21_) == 0;
				}
				if (_tmp17_) {
					gboolean _tmp22_ = FALSE;
					GParamSpec* _tmp23_;
					_tmp23_ = spec;
					if (g_type_is_a (_tmp23_->value_type, GXML_TYPE_OBJECT)) {
						_tmp22_ = TRUE;
					} else {
						GParamSpec* _tmp24_;
						_tmp24_ = spec;
						_tmp22_ = g_type_is_a (_tmp24_->value_type, GXML_TYPE_COLLECTION);
					}
					if (_tmp22_) {
						result = spec;
						_g_free0 (sname);
						_g_free0 (nick);
						_g_free0 (name);
						spec_collection = (g_free (spec_collection), NULL);
						return result;
					}
				}
				_g_free0 (sname);
				_g_free0 (nick);
				_g_free0 (name);
				_g_param_spec_unref0 (spec);
			}
		}
		spec_collection = (g_free (spec_collection), NULL);
	}
	result = NULL;
	return result;
}

GParamSpec*
gxml_object_find_object_property_name (GXmlObject* self,
                                       const gchar* pname)
{
	GXmlObjectIface* _iface_;
	g_return_val_if_fail (self != NULL, NULL);
	_iface_ = GXML_OBJECT_GET_INTERFACE (self);
	if (_iface_->find_object_property_name) {
		return _iface_->find_object_property_name (self, pname);
	}
	return NULL;
}

/**
   * Returns a list of names for all {@link DomElement}
   * present as object's properties.
   */
static GList*
gxml_object_real_get_property_element_list (GXmlObject* self)
{
	GList* l = NULL;
	GObjectClass* _tmp0_;
	guint _tmp1_ = 0;
	GParamSpec** _tmp2_;
	GList* result;
	l = NULL;
	_tmp0_ = G_OBJECT_GET_CLASS ((GObject*) self);
	_tmp2_ = g_object_class_list_properties (_tmp0_, &_tmp1_);
	{
		GParamSpec** spec_collection = NULL;
		gint spec_collection_length1 = 0;
		gint _spec_collection_size_ = 0;
		gint spec_it = 0;
		spec_collection = _tmp2_;
		spec_collection_length1 = _tmp1_;
		for (spec_it = 0; spec_it < spec_collection_length1; spec_it = spec_it + 1) {
			GParamSpec* _tmp3_;
			GParamSpec* spec = NULL;
			_tmp3_ = _g_param_spec_ref0 (spec_collection[spec_it]);
			spec = _tmp3_;
			{
				gboolean _tmp4_ = FALSE;
				gboolean _tmp5_ = FALSE;
				GParamSpec* _tmp6_;
				_tmp6_ = spec;
				if (g_type_is_a (_tmp6_->value_type, GXML_TYPE_OBJECT)) {
					_tmp5_ = TRUE;
				} else {
					GParamSpec* _tmp7_;
					_tmp7_ = spec;
					_tmp5_ = g_type_is_a (_tmp7_->value_type, GXML_TYPE_COLLECTION);
				}
				if (_tmp5_) {
					GParamSpec* _tmp8_;
					_tmp8_ = spec;
					_tmp4_ = G_TYPE_IS_INSTANTIATABLE (_tmp8_->value_type);
				} else {
					_tmp4_ = FALSE;
				}
				if (_tmp4_) {
					GParamSpec* _tmp9_;
					GParamSpec* _tmp10_;
					_tmp9_ = spec;
					_tmp10_ = _g_param_spec_ref0 (_tmp9_);
					l = g_list_append (l, _tmp10_);
				}
				_g_param_spec_unref0 (spec);
			}
		}
		spec_collection = (g_free (spec_collection), NULL);
	}
	result = l;
	return result;
}

GList*
gxml_object_get_property_element_list (GXmlObject* self)
{
	GXmlObjectIface* _iface_;
	g_return_val_if_fail (self != NULL, NULL);
	_iface_ = GXML_OBJECT_GET_INTERFACE (self);
	if (_iface_->get_property_element_list) {
		return _iface_->get_property_element_list (self);
	}
	return NULL;
}

/**
   * Returns an string representation of an Object's property.
   */
static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static gchar*
double_to_string (gdouble self)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gint _tmp1__length1;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* result;
	_tmp0_ = g_new0 (gchar, G_ASCII_DTOSTR_BUF_SIZE);
	_tmp1_ = _tmp0_;
	_tmp1__length1 = G_ASCII_DTOSTR_BUF_SIZE;
	_tmp2_ = g_ascii_dtostr (_tmp1_, (gint) G_ASCII_DTOSTR_BUF_SIZE, self);
	_tmp3_ = g_strdup (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp1_ = (g_free (_tmp1_), NULL);
	result = _tmp4_;
	return result;
}

static gchar*
bool_to_string (gboolean self)
{
	gchar* result;
	if (self) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup ("true");
		result = _tmp0_;
		return result;
	} else {
		gchar* _tmp1_;
		_tmp1_ = g_strdup ("false");
		result = _tmp1_;
		return result;
	}
}

static gchar*
gxml_object_real_get_property_string (GXmlObject* self,
                                      GParamSpec* prop)
{
	GValue v = {0};
	GValue _tmp0_ = {0};
	const gchar* _tmp1_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (prop != NULL, NULL);
	g_value_init (&_tmp0_, prop->value_type);
	v = _tmp0_;
	_tmp1_ = prop->name;
	g_object_get_property ((GObject*) self, _tmp1_, &v);
	if (g_type_is_a (prop->value_type, GXML_TYPE_PROPERTY)) {
		GObject* so = NULL;
		GObject* _tmp2_;
		GObject* _tmp3_;
		GObject* _tmp4_;
		GObject* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		_tmp2_ = g_value_get_object (&v);
		_tmp3_ = _g_object_ref0 (_tmp2_);
		so = _tmp3_;
		_tmp4_ = so;
		if (_tmp4_ == NULL) {
			result = NULL;
			_g_object_unref0 (so);
			G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
			return result;
		}
		_tmp5_ = so;
		_tmp6_ = gxml_property_get_value (G_TYPE_CHECK_INSTANCE_CAST (_tmp5_, GXML_TYPE_PROPERTY, GXmlProperty));
		_tmp7_ = _tmp6_;
		result = _tmp7_;
		_g_object_unref0 (so);
		G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
		return result;
	}
	if (g_type_is_a (prop->value_type, G_TYPE_STRING)) {
		GValue _tmp8_;
		gchar* _tmp9_;
		_tmp8_ = v;
		_tmp9_ = g_strdup (g_value_get_string (&_tmp8_));
		result = _tmp9_;
		G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
		return result;
	}
	if (g_type_is_a (prop->value_type, G_TYPE_INT)) {
		GValue _tmp10_;
		gchar* _tmp11_;
		_tmp10_ = v;
		_tmp11_ = g_strdup_printf ("%i", g_value_get_int (&_tmp10_));
		result = _tmp11_;
		G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
		return result;
	}
	if (g_type_is_a (prop->value_type, G_TYPE_UINT)) {
		GValue _tmp12_;
		gchar* _tmp13_;
		_tmp12_ = v;
		_tmp13_ = g_strdup_printf ("%u", g_value_get_uint (&_tmp12_));
		result = _tmp13_;
		G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
		return result;
	}
	if (g_type_is_a (prop->value_type, G_TYPE_FLOAT)) {
		GValue _tmp14_;
		gchar* _tmp15_;
		_tmp14_ = v;
		_tmp15_ = g_strdup_printf ("%g", g_value_get_float (&_tmp14_));
		result = _tmp15_;
		G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
		return result;
	}
	if (g_type_is_a (prop->value_type, G_TYPE_DOUBLE)) {
		GValue _tmp16_;
		gchar* _tmp17_;
		_tmp16_ = v;
		_tmp17_ = double_to_string (g_value_get_double (&_tmp16_));
		result = _tmp17_;
		G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
		return result;
	}
	if (g_type_is_a (prop->value_type, G_TYPE_BOOLEAN)) {
		GValue _tmp18_;
		gchar* _tmp19_;
		_tmp18_ = v;
		_tmp19_ = bool_to_string (g_value_get_boolean (&_tmp18_));
		result = _tmp19_;
		G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
		return result;
	}
	if (g_type_is_a (prop->value_type, G_TYPE_ENUM)) {
		gint n = 0;
		n = g_value_get_enum (&v);
		{
			gchar* _tmp20_ = NULL;
			gchar* _tmp21_;
			gchar* _tmp22_;
			_tmp21_ = gxml_enumeration_get_string (prop->value_type, n, TRUE, TRUE, &_inner_error0_);
			_tmp20_ = _tmp21_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			_tmp22_ = _tmp20_;
			_tmp20_ = NULL;
			result = _tmp22_;
			_g_free0 (_tmp20_);
			G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
			return result;
		}
		goto __finally0;
		__catch0_g_error:
		{
			g_clear_error (&_inner_error0_);
			g_warning ("Object.vala:170: %s", _ ("Enumeration is out of range"));
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
	}
	result = NULL;
	G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
	return result;
}

gchar*
gxml_object_get_property_string (GXmlObject* self,
                                 GParamSpec* prop)
{
	GXmlObjectIface* _iface_;
	g_return_val_if_fail (self != NULL, NULL);
	_iface_ = GXML_OBJECT_GET_INTERFACE (self);
	if (_iface_->get_property_string) {
		return _iface_->get_property_string (self, prop);
	}
	return NULL;
}

/**
   * Search for properties in objects, it should be
   * an {@link GLib.Object}'s property. If found a
   * property with given name its value is returned
   * as string representation.
   *
   * If property is a {@link GXml.Property}
   * returned value is a string representation according
   * with object implementation.
   *
   * If given property name is not found, then {@link DomElement.get_attribute}
   * is called.
   *
   * By default all {@link GLib.Object} are children of
   * this object, see {@link get_child}
   */
static gchar*
gxml_object_real_get_attribute (GXmlObject* self,
                                const gchar* name)
{
	GParamSpec* prop = NULL;
	GParamSpec* _tmp0_;
	GParamSpec* _tmp1_;
	GParamSpec* _tmp2_;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = gxml_object_find_property_name (self, name);
	prop = _tmp0_;
	_tmp1_ = prop;
	if (_tmp1_ == NULL) {
		result = NULL;
		_g_param_spec_unref0 (prop);
		return result;
	}
	_tmp2_ = prop;
	_tmp3_ = gxml_object_get_property_string (self, _tmp2_);
	result = _tmp3_;
	_g_param_spec_unref0 (prop);
	return result;
}

gchar*
gxml_object_get_attribute (GXmlObject* self,
                           const gchar* name)
{
	GXmlObjectIface* _iface_;
	g_return_val_if_fail (self != NULL, NULL);
	_iface_ = GXML_OBJECT_GET_INTERFACE (self);
	if (_iface_->get_attribute) {
		return _iface_->get_attribute (self, name);
	}
	return NULL;
}

/**
   * Search for a property of type {@link GXml.Property}
   * and returns it as object
   */
static GXmlProperty*
gxml_object_real_find_property (GXmlObject* self,
                                const gchar* name)
{
	GParamSpec* prop = NULL;
	GParamSpec* _tmp0_;
	GParamSpec* _tmp1_;
	GXmlProperty* result;
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = gxml_object_find_property_name (self, name);
	prop = _tmp0_;
	_tmp1_ = prop;
	if (_tmp1_ != NULL) {
		GValue v = {0};
		GParamSpec* _tmp2_;
		GValue _tmp3_ = {0};
		gboolean _tmp4_ = FALSE;
		GParamSpec* _tmp5_;
		_tmp2_ = prop;
		g_value_init (&_tmp3_, _tmp2_->value_type);
		v = _tmp3_;
		_tmp5_ = prop;
		if (g_type_is_a (_tmp5_->value_type, GXML_TYPE_PROPERTY)) {
			GParamSpec* _tmp6_;
			_tmp6_ = prop;
			_tmp4_ = G_TYPE_IS_INSTANTIATABLE (_tmp6_->value_type);
		} else {
			_tmp4_ = FALSE;
		}
		if (_tmp4_) {
			GParamSpec* _tmp7_;
			const gchar* _tmp8_;
			GXmlProperty* so = NULL;
			GValue _tmp9_;
			GXmlObject* _tmp10_;
			GXmlProperty* _tmp11_;
			GXmlProperty* _tmp12_;
			_tmp7_ = prop;
			_tmp8_ = _tmp7_->name;
			g_object_get_property ((GObject*) self, _tmp8_, &v);
			_tmp9_ = v;
			_tmp10_ = g_value_get_object (&_tmp9_);
			_tmp11_ = _g_object_ref0 (GXML_IS_PROPERTY (_tmp10_) ? ((GXmlProperty*) _tmp10_) : NULL);
			so = _tmp11_;
			_tmp12_ = so;
			if (_tmp12_ == NULL) {
				GObject* obj = NULL;
				GParamSpec* _tmp13_;
				GObject* _tmp14_;
				GObject* _tmp15_;
				GObject* _tmp16_;
				GParamSpec* _tmp17_;
				const gchar* _tmp18_;
				GValue _tmp19_;
				GObject* _tmp20_;
				GXmlProperty* _tmp21_;
				_tmp13_ = prop;
				_tmp14_ = g_object_new (_tmp13_->value_type, NULL);
				_tmp15_ = G_IS_INITIALLY_UNOWNED (_tmp14_) ? g_object_ref_sink (_tmp14_) : _tmp14_;
				obj = _tmp15_;
				_tmp16_ = obj;
				g_value_set_object (&v, _tmp16_);
				_tmp17_ = prop;
				_tmp18_ = _tmp17_->name;
				_tmp19_ = v;
				g_object_set_property ((GObject*) self, _tmp18_, &_tmp19_);
				_tmp20_ = obj;
				_tmp21_ = _g_object_ref0 (GXML_IS_PROPERTY (_tmp20_) ? ((GXmlProperty*) _tmp20_) : NULL);
				_g_object_unref0 (so);
				so = _tmp21_;
				_g_object_unref0 (obj);
			}
			result = so;
			G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
			_g_param_spec_unref0 (prop);
			return result;
		}
		G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
	}
	result = NULL;
	_g_param_spec_unref0 (prop);
	return result;
}

GXmlProperty*
gxml_object_find_property (GXmlObject* self,
                           const gchar* name)
{
	GXmlObjectIface* _iface_;
	g_return_val_if_fail (self != NULL, NULL);
	_iface_ = GXML_OBJECT_GET_INTERFACE (self);
	if (_iface_->find_property) {
		return _iface_->find_property (self, name);
	}
	return NULL;
}

/**
   * Search for a {@link GLib.Object} property with
   * given name, if found, given string representation
   * is used as value to property, using any required
   * transformation from string.
   *
   * By default all {@link GLib.Object} are children of
   * this object.
   */
static gdouble
double_parse (const gchar* str)
{
	gdouble result;
	g_return_val_if_fail (str != NULL, -1.0);
	result = g_ascii_strtod (str, NULL);
	return result;
}

static gboolean
bool_parse (const gchar* str)
{
	gboolean result;
	g_return_val_if_fail (str != NULL, FALSE);
	if (g_strcmp0 (str, "true") == 0) {
		result = TRUE;
		return result;
	} else {
		result = FALSE;
		return result;
	}
}

static gboolean
gxml_object_real_set_attribute (GXmlObject* self,
                                const gchar* name,
                                const gchar* val)
{
	GParamSpec* prop = NULL;
	GParamSpec* _tmp0_;
	GParamSpec* _tmp1_;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (name != NULL, FALSE);
	g_return_val_if_fail (val != NULL, FALSE);
	_tmp0_ = gxml_object_find_property_name (self, name);
	prop = _tmp0_;
	_tmp1_ = prop;
	if (_tmp1_ != NULL) {
		GValue v = {0};
		GParamSpec* _tmp2_;
		GValue _tmp3_ = {0};
		gboolean _tmp4_ = FALSE;
		GParamSpec* _tmp5_;
		GParamSpec* _tmp23_;
		GParamSpec* _tmp27_;
		GParamSpec* _tmp31_;
		GParamSpec* _tmp35_;
		GParamSpec* _tmp39_;
		GParamSpec* _tmp43_;
		GParamSpec* _tmp47_;
		_tmp2_ = prop;
		g_value_init (&_tmp3_, _tmp2_->value_type);
		v = _tmp3_;
		_tmp5_ = prop;
		if (g_type_is_a (_tmp5_->value_type, GXML_TYPE_PROPERTY)) {
			GParamSpec* _tmp6_;
			_tmp6_ = prop;
			_tmp4_ = G_TYPE_IS_INSTANTIATABLE (_tmp6_->value_type);
		} else {
			_tmp4_ = FALSE;
		}
		if (_tmp4_) {
			GParamSpec* _tmp7_;
			const gchar* _tmp8_;
			GXmlProperty* so = NULL;
			GValue _tmp9_;
			GXmlObject* _tmp10_;
			GXmlProperty* _tmp11_;
			GXmlProperty* _tmp12_;
			GXmlProperty* _tmp22_;
			_tmp7_ = prop;
			_tmp8_ = _tmp7_->name;
			g_object_get_property ((GObject*) self, _tmp8_, &v);
			_tmp9_ = v;
			_tmp10_ = g_value_get_object (&_tmp9_);
			_tmp11_ = _g_object_ref0 (GXML_IS_PROPERTY (_tmp10_) ? ((GXmlProperty*) _tmp10_) : NULL);
			so = _tmp11_;
			_tmp12_ = so;
			if (_tmp12_ == NULL) {
				GObject* obj = NULL;
				GParamSpec* _tmp13_;
				GObject* _tmp14_;
				GObject* _tmp15_;
				GObject* _tmp16_;
				GParamSpec* _tmp17_;
				const gchar* _tmp18_;
				GValue _tmp19_;
				GObject* _tmp20_;
				GXmlProperty* _tmp21_;
				_tmp13_ = prop;
				_tmp14_ = g_object_new (_tmp13_->value_type, NULL);
				_tmp15_ = G_IS_INITIALLY_UNOWNED (_tmp14_) ? g_object_ref_sink (_tmp14_) : _tmp14_;
				obj = _tmp15_;
				_tmp16_ = obj;
				g_value_set_object (&v, _tmp16_);
				_tmp17_ = prop;
				_tmp18_ = _tmp17_->name;
				_tmp19_ = v;
				g_object_set_property ((GObject*) self, _tmp18_, &_tmp19_);
				_tmp20_ = obj;
				_tmp21_ = _g_object_ref0 (GXML_IS_PROPERTY (_tmp20_) ? ((GXmlProperty*) _tmp20_) : NULL);
				_g_object_unref0 (so);
				so = _tmp21_;
				_g_object_unref0 (obj);
			}
			_tmp22_ = so;
			gxml_property_set_value (_tmp22_, val);
			result = TRUE;
			_g_object_unref0 (so);
			G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
			_g_param_spec_unref0 (prop);
			return result;
		}
		_tmp23_ = prop;
		if (g_type_is_a (_tmp23_->value_type, G_TYPE_STRING)) {
			GParamSpec* _tmp24_;
			const gchar* _tmp25_;
			GValue _tmp26_;
			g_value_set_string (&v, val);
			_tmp24_ = prop;
			_tmp25_ = _tmp24_->name;
			_tmp26_ = v;
			g_object_set_property ((GObject*) self, _tmp25_, &_tmp26_);
			result = TRUE;
			G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
			_g_param_spec_unref0 (prop);
			return result;
		}
		_tmp27_ = prop;
		if (g_type_is_a (_tmp27_->value_type, G_TYPE_INT)) {
			gint iv = 0;
			GParamSpec* _tmp28_;
			const gchar* _tmp29_;
			GValue _tmp30_;
			iv = (gint) double_parse (val);
			g_value_set_int (&v, iv);
			_tmp28_ = prop;
			_tmp29_ = _tmp28_->name;
			_tmp30_ = v;
			g_object_set_property ((GObject*) self, _tmp29_, &_tmp30_);
			result = TRUE;
			G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
			_g_param_spec_unref0 (prop);
			return result;
		}
		_tmp31_ = prop;
		if (g_type_is_a (_tmp31_->value_type, G_TYPE_UINT)) {
			guint iv = 0U;
			GParamSpec* _tmp32_;
			const gchar* _tmp33_;
			GValue _tmp34_;
			iv = (guint) double_parse (val);
			g_value_set_uint (&v, (guint) ((gint) iv));
			_tmp32_ = prop;
			_tmp33_ = _tmp32_->name;
			_tmp34_ = v;
			g_object_set_property ((GObject*) self, _tmp33_, &_tmp34_);
			result = TRUE;
			G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
			_g_param_spec_unref0 (prop);
			return result;
		}
		_tmp35_ = prop;
		if (g_type_is_a (_tmp35_->value_type, G_TYPE_FLOAT)) {
			gdouble dv = 0.0;
			GParamSpec* _tmp36_;
			const gchar* _tmp37_;
			GValue _tmp38_;
			dv = double_parse (val);
			g_value_set_float (&v, (gfloat) dv);
			_tmp36_ = prop;
			_tmp37_ = _tmp36_->name;
			_tmp38_ = v;
			g_object_set_property ((GObject*) self, _tmp37_, &_tmp38_);
			result = TRUE;
			G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
			_g_param_spec_unref0 (prop);
			return result;
		}
		_tmp39_ = prop;
		if (g_type_is_a (_tmp39_->value_type, G_TYPE_DOUBLE)) {
			gdouble dv = 0.0;
			GParamSpec* _tmp40_;
			const gchar* _tmp41_;
			GValue _tmp42_;
			dv = double_parse (val);
			g_value_set_double (&v, dv);
			_tmp40_ = prop;
			_tmp41_ = _tmp40_->name;
			_tmp42_ = v;
			g_object_set_property ((GObject*) self, _tmp41_, &_tmp42_);
			result = TRUE;
			G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
			_g_param_spec_unref0 (prop);
			return result;
		}
		_tmp43_ = prop;
		if (g_type_is_a (_tmp43_->value_type, G_TYPE_BOOLEAN)) {
			gboolean bv = FALSE;
			GParamSpec* _tmp44_;
			const gchar* _tmp45_;
			GValue _tmp46_;
			bv = bool_parse (val);
			g_value_set_boolean (&v, bv);
			_tmp44_ = prop;
			_tmp45_ = _tmp44_->name;
			_tmp46_ = v;
			g_object_set_property ((GObject*) self, _tmp45_, &_tmp46_);
			result = TRUE;
			G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
			_g_param_spec_unref0 (prop);
			return result;
		}
		_tmp47_ = prop;
		if (g_type_is_a (_tmp47_->value_type, G_TYPE_ENUM)) {
			{
				GEnumValue* _tmp48_ = NULL;
				GParamSpec* _tmp49_;
				GEnumValue* _tmp50_;
				gint n = 0;
				_tmp49_ = prop;
				_tmp50_ = gxml_enumeration_parse (_tmp49_->value_type, val, &_inner_error0_);
				_tmp48_ = _tmp50_;
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					goto __catch0_g_error;
				}
				n = (gint) (*_tmp48_).value;
				g_value_set_enum (&v, n);
				_g_free0 (_tmp48_);
			}
			goto __finally0;
			__catch0_g_error:
			{
				g_clear_error (&_inner_error0_);
				g_warning ("Object.vala:285: %s", _ ("Enumeration can't be parsed from string"));
				result = FALSE;
				G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
				_g_param_spec_unref0 (prop);
				return result;
			}
			__finally0:
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				gboolean _tmp51_ = FALSE;
				G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
				_g_param_spec_unref0 (prop);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
				g_clear_error (&_inner_error0_);
				return _tmp51_;
			}
			result = TRUE;
			G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
			_g_param_spec_unref0 (prop);
			return result;
		}
		G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
	}
	result = FALSE;
	_g_param_spec_unref0 (prop);
	return result;
}

gboolean
gxml_object_set_attribute (GXmlObject* self,
                           const gchar* name,
                           const gchar* val)
{
	GXmlObjectIface* _iface_;
	g_return_val_if_fail (self != NULL, FALSE);
	_iface_ = GXML_OBJECT_GET_INTERFACE (self);
	if (_iface_->set_attribute) {
		return _iface_->set_attribute (self, name, val);
	}
	return FALSE;
}

/**
   * Search a {@link GLib.Object} property with given name
   * and returns it, if it is a {@link DomElement}. If not found,
   * {@link DomElement.get_elements_by_tag_name} is called, returning
   * first node found. Tag name to use, is the given name parameter.
   *
   * @param name a name of this object's property of type {@link DomElement} or
   * first {@link DomNode} with that name in child nodes.
   *
   */
static GXmlDomElement*
gxml_object_real_get_child (GXmlObject* self,
                            const gchar* name)
{
	GParamSpec* prop = NULL;
	GObjectClass* _tmp0_;
	GParamSpec* _tmp1_;
	GParamSpec* _tmp2_;
	GParamSpec* _tmp3_;
	GXmlDomElement* result;
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = G_OBJECT_GET_CLASS ((GObject*) self);
	_tmp1_ = g_object_class_find_property (_tmp0_, name);
	_tmp2_ = _g_param_spec_ref0 (_tmp1_);
	prop = _tmp2_;
	_tmp3_ = prop;
	if (_tmp3_ != NULL) {
		GParamSpec* _tmp4_;
		_tmp4_ = prop;
		if (g_type_is_a (_tmp4_->value_type, GXML_TYPE_DOM_ELEMENT)) {
			GValue vo = {0};
			GParamSpec* _tmp5_;
			GValue _tmp6_ = {0};
			GParamSpec* _tmp7_;
			const gchar* _tmp8_;
			GValue _tmp9_;
			GXmlDomElement* _tmp10_;
			_tmp5_ = prop;
			g_value_init (&_tmp6_, _tmp5_->value_type);
			vo = _tmp6_;
			_tmp7_ = prop;
			_tmp8_ = _tmp7_->name;
			g_object_get_property ((GObject*) self, _tmp8_, &vo);
			_tmp9_ = vo;
			_tmp10_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (g_value_get_object (&_tmp9_), GXML_TYPE_DOM_ELEMENT, GXmlDomElement));
			result = _tmp10_;
			G_IS_VALUE (&vo) ? (g_value_unset (&vo), NULL) : NULL;
			_g_param_spec_unref0 (prop);
			return result;
		}
	}
	if (gxml_dom_node_has_child_nodes (G_TYPE_CHECK_INSTANCE_CAST (self, GXML_TYPE_DOM_NODE, GXmlDomNode))) {
		GXmlDomHTMLCollection* els = NULL;
		GXmlDomHTMLCollection* _tmp11_;
		GXmlDomHTMLCollection* _tmp12_;
		gint _tmp13_;
		gint _tmp14_;
		_tmp11_ = gxml_dom_element_get_elements_by_tag_name (G_TYPE_CHECK_INSTANCE_CAST (self, GXML_TYPE_DOM_ELEMENT, GXmlDomElement), name);
		els = _tmp11_;
		_tmp12_ = els;
		_tmp13_ = gee_collection_get_size ((GeeCollection*) _tmp12_);
		_tmp14_ = _tmp13_;
		if (_tmp14_ != 0) {
			GXmlDomHTMLCollection* _tmp15_;
			GXmlDomElement* _tmp16_;
			_tmp15_ = els;
			_tmp16_ = gxml_dom_html_collection_item (_tmp15_, 0);
			result = _tmp16_;
			_g_object_unref0 (els);
			_g_param_spec_unref0 (prop);
			return result;
		}
		_g_object_unref0 (els);
	}
	result = NULL;
	_g_param_spec_unref0 (prop);
	return result;
}

GXmlDomElement*
gxml_object_get_child (GXmlObject* self,
                       const gchar* name)
{
	GXmlObjectIface* _iface_;
	g_return_val_if_fail (self != NULL, NULL);
	_iface_ = GXML_OBJECT_GET_INTERFACE (self);
	if (_iface_->get_child) {
		return _iface_->get_child (self, name);
	}
	return NULL;
}

/**
   * From a given property name of type {@link GXml.Element}, search all
   * child nodes with node's local name equal to property.
   */
static GXmlDomElementList*
gxml_object_real_find_elements (GXmlObject* self,
                                const gchar* name)
{
	GXmlDomElementList* l = NULL;
	GXmlDomElementList* _tmp0_;
	GParamSpec* prop = NULL;
	GObjectClass* _tmp1_;
	GParamSpec* _tmp2_;
	GParamSpec* _tmp3_;
	GParamSpec* _tmp4_;
	GXmlDomElementList* result;
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = gxml_dom_element_list_new ();
	l = _tmp0_;
	_tmp1_ = G_OBJECT_GET_CLASS ((GObject*) self);
	_tmp2_ = g_object_class_find_property (_tmp1_, name);
	_tmp3_ = _g_param_spec_ref0 (_tmp2_);
	prop = _tmp3_;
	_tmp4_ = prop;
	if (_tmp4_ != NULL) {
		GParamSpec* _tmp5_;
		_tmp5_ = prop;
		if (g_type_is_a (_tmp5_->value_type, GXML_TYPE_DOM_ELEMENT)) {
			GXmlDomElement* o = NULL;
			GParamSpec* _tmp6_;
			GObject* _tmp7_;
			GObject* _tmp8_;
			GXmlDomElement* _tmp9_;
			_tmp6_ = prop;
			_tmp7_ = g_object_new (_tmp6_->value_type, NULL);
			_tmp8_ = G_IS_INITIALLY_UNOWNED (_tmp7_) ? g_object_ref_sink (_tmp7_) : _tmp7_;
			_tmp9_ = GXML_IS_DOM_ELEMENT (_tmp8_) ? ((GXmlDomElement*) _tmp8_) : NULL;
			if (_tmp9_ == NULL) {
				_g_object_unref0 (_tmp8_);
			}
			o = _tmp9_;
			{
				GXmlDomNodeList* _n_list = NULL;
				GXmlDomNodeList* _tmp10_;
				GXmlDomNodeList* _tmp11_;
				gint _n_size = 0;
				GXmlDomNodeList* _tmp12_;
				gint _tmp13_;
				gint _tmp14_;
				gint _n_index = 0;
				_tmp10_ = gxml_dom_node_get_child_nodes ((GXmlDomNode*) self);
				_tmp11_ = _tmp10_;
				_n_list = _tmp11_;
				_tmp12_ = _n_list;
				_tmp13_ = gee_collection_get_size ((GeeCollection*) _tmp12_);
				_tmp14_ = _tmp13_;
				_n_size = _tmp14_;
				_n_index = -1;
				while (TRUE) {
					gint _tmp15_;
					gint _tmp16_;
					GXmlDomNode* n = NULL;
					GXmlDomNodeList* _tmp17_;
					gpointer _tmp18_;
					GXmlDomNode* _tmp19_;
					GXmlDomNode* _tmp20_;
					gchar* _tmp21_;
					gchar* _tmp22_;
					gchar* _tmp23_;
					gchar* _tmp24_;
					gchar* _tmp25_;
					GXmlDomElement* _tmp26_;
					gchar* _tmp27_;
					gchar* _tmp28_;
					gchar* _tmp29_;
					gchar* _tmp30_;
					gchar* _tmp31_;
					gboolean _tmp32_;
					_n_index = _n_index + 1;
					_tmp15_ = _n_index;
					_tmp16_ = _n_size;
					if (!(_tmp15_ < _tmp16_)) {
						break;
					}
					_tmp17_ = _n_list;
					_tmp18_ = gee_list_get ((GeeList*) _tmp17_, _n_index);
					n = (GXmlDomNode*) _tmp18_;
					_tmp19_ = n;
					if (!GXML_IS_DOM_ELEMENT (_tmp19_)) {
						_g_object_unref0 (n);
						continue;
					}
					_tmp20_ = n;
					_tmp21_ = gxml_dom_element_get_local_name (G_TYPE_CHECK_INSTANCE_CAST (_tmp20_, GXML_TYPE_DOM_ELEMENT, GXmlDomElement));
					_tmp22_ = _tmp21_;
					_tmp23_ = _tmp22_;
					_tmp24_ = g_utf8_strdown (_tmp23_, (gssize) -1);
					_tmp25_ = _tmp24_;
					_tmp26_ = o;
					_tmp27_ = gxml_dom_element_get_local_name (_tmp26_);
					_tmp28_ = _tmp27_;
					_tmp29_ = _tmp28_;
					_tmp30_ = g_utf8_strdown (_tmp29_, (gssize) -1);
					_tmp31_ = _tmp30_;
					_tmp32_ = g_strcmp0 (_tmp25_, _tmp31_) == 0;
					_g_free0 (_tmp31_);
					_g_free0 (_tmp29_);
					_g_free0 (_tmp25_);
					_g_free0 (_tmp23_);
					if (_tmp32_) {
						GXmlDomElementList* _tmp33_;
						GXmlDomNode* _tmp34_;
						_tmp33_ = l;
						_tmp34_ = n;
						gee_abstract_collection_add ((GeeAbstractCollection*) _tmp33_, G_TYPE_CHECK_INSTANCE_CAST (_tmp34_, GXML_TYPE_DOM_ELEMENT, GXmlDomElement));
					}
					_g_object_unref0 (n);
				}
				_g_object_unref0 (_n_list);
			}
			_g_object_unref0 (o);
		}
	}
	result = l;
	_g_param_spec_unref0 (prop);
	return result;
}

GXmlDomElementList*
gxml_object_find_elements (GXmlObject* self,
                           const gchar* name)
{
	GXmlObjectIface* _iface_;
	g_return_val_if_fail (self != NULL, NULL);
	_iface_ = GXML_OBJECT_GET_INTERFACE (self);
	if (_iface_->find_elements) {
		return _iface_->find_elements (self, name);
	}
	return NULL;
}

/**
   * Search for a property and set it to null if possible returning true,
   * if value can't be removed or located, returns false without change.
   */
static gboolean
gxml_object_real_remove_attribute (GXmlObject* self,
                                   const gchar* name)
{
	GParamSpec* prop = NULL;
	GObjectClass* _tmp0_;
	GParamSpec* _tmp1_;
	GParamSpec* _tmp2_;
	GParamSpec* _tmp3_;
	gboolean result;
	g_return_val_if_fail (name != NULL, FALSE);
	_tmp0_ = G_OBJECT_GET_CLASS ((GObject*) self);
	_tmp1_ = g_object_class_find_property (_tmp0_, name);
	_tmp2_ = _g_param_spec_ref0 (_tmp1_);
	prop = _tmp2_;
	_tmp3_ = prop;
	if (_tmp3_ != NULL) {
		GParamSpec* _tmp4_;
		GParamSpec* _tmp7_;
		_tmp4_ = prop;
		if (g_type_is_a (_tmp4_->value_type, GXML_TYPE_OBJECT)) {
			GValue v = {0};
			GValue _tmp5_ = {0};
			GValue _tmp6_;
			g_value_init (&_tmp5_, GXML_TYPE_OBJECT);
			v = _tmp5_;
			_tmp6_ = v;
			g_object_set_property ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, GXML_TYPE_OBJECT, GXmlObject), name, &_tmp6_);
			result = TRUE;
			G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
			_g_param_spec_unref0 (prop);
			return result;
		}
		_tmp7_ = prop;
		if (g_type_is_a (_tmp7_->value_type, G_TYPE_STRING)) {
			GValue v = {0};
			GValue _tmp8_ = {0};
			GParamSpec* _tmp9_;
			const gchar* _tmp10_;
			GValue _tmp11_;
			g_value_init (&_tmp8_, G_TYPE_STRING);
			v = _tmp8_;
			g_value_set_string (&v, NULL);
			_tmp9_ = prop;
			_tmp10_ = _tmp9_->name;
			_tmp11_ = v;
			g_object_set_property ((GObject*) self, _tmp10_, &_tmp11_);
			result = TRUE;
			G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
			_g_param_spec_unref0 (prop);
			return result;
		}
	}
	result = FALSE;
	_g_param_spec_unref0 (prop);
	return result;
}

gboolean
gxml_object_remove_attribute (GXmlObject* self,
                              const gchar* name)
{
	GXmlObjectIface* _iface_;
	g_return_val_if_fail (self != NULL, FALSE);
	_iface_ = GXML_OBJECT_GET_INTERFACE (self);
	if (_iface_->remove_attribute) {
		return _iface_->remove_attribute (self, name);
	}
	return FALSE;
}

/**
   * Convenient method to set an instance of given property's
   * name and initialize according to have same {@link DomNode.owner_document}
   * and set its {@link DomNode.parent_node} to this appending it as a child.
   * If property is a {@link Collection} it is initialize to use
   * this as its {@link Collection.element}.
   *
   * Instance is set to object's property.
   *
   * Property should be a {@link GXml.Element} or {@link Collection}
   *
   * While an object could be created and set to a Object's property, it
   * is not correctly initialized by default. This method helps in the process.
   *
   * If Object's property has been set, this method overwrite it.
   *
   * {{{
   * class NodeA : GXml.Object {
   *   construct { try { initialize ("NodeA"); } catch { warning ("Can't initialize); }
   * }
   * class NodeB : GXml.Object {
   *   public NodeA node { get; set; }
   * }
   *
   * var nb = new NodeB ();
   * nb.create_instance_property ("node");
   * assert (nb.node != null);
   * }}}
   *
   * Property's name can be canonical or its nick name, see {@link find_object_property_name}
   *
   * Returns: true if property has been set and initialized, false otherwise.
   */
static gboolean
gxml_object_real_set_instance_property (GXmlObject* self,
                                        const gchar* name)
{
	GParamSpec* prop = NULL;
	GParamSpec* _tmp0_;
	GParamSpec* _tmp1_;
	GValue v = {0};
	GParamSpec* _tmp2_;
	GValue _tmp3_ = {0};
	GObject* obj = NULL;
	GParamSpec* _tmp4_;
	GParamSpec* _tmp12_;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (name != NULL, FALSE);
	_tmp0_ = gxml_object_find_object_property_name (self, name);
	prop = _tmp0_;
	_tmp1_ = prop;
	if (_tmp1_ == NULL) {
		result = FALSE;
		_g_param_spec_unref0 (prop);
		return result;
	}
	_tmp2_ = prop;
	g_value_init (&_tmp3_, _tmp2_->value_type);
	v = _tmp3_;
	_tmp4_ = prop;
	if (g_type_is_a (_tmp4_->value_type, GXML_TYPE_COLLECTION)) {
		GParamSpec* _tmp5_;
		GObject* _tmp6_;
		GObject* _tmp7_;
		GObject* _tmp8_;
		GParamSpec* _tmp9_;
		const gchar* _tmp10_;
		GValue _tmp11_;
		_tmp5_ = prop;
		_tmp6_ = g_object_new (_tmp5_->value_type, "element", self, NULL);
		_tmp7_ = G_IS_INITIALLY_UNOWNED (_tmp6_) ? g_object_ref_sink (_tmp6_) : _tmp6_;
		_g_object_unref0 (obj);
		obj = _tmp7_;
		_tmp8_ = obj;
		g_value_set_object (&v, _tmp8_);
		_tmp9_ = prop;
		_tmp10_ = _tmp9_->name;
		_tmp11_ = v;
		g_object_set_property ((GObject*) self, _tmp10_, &_tmp11_);
		result = TRUE;
		_g_object_unref0 (obj);
		G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
		_g_param_spec_unref0 (prop);
		return result;
	}
	_tmp12_ = prop;
	if (g_type_is_a (_tmp12_->value_type, GXML_TYPE_ELEMENT)) {
		GParamSpec* _tmp13_;
		GXmlDomDocument* _tmp14_;
		GXmlDomDocument* _tmp15_;
		GObject* _tmp16_;
		GObject* _tmp17_;
		GObject* _tmp26_;
		GParamSpec* _tmp27_;
		const gchar* _tmp28_;
		GValue _tmp29_;
		_tmp13_ = prop;
		_tmp14_ = gxml_dom_node_get_owner_document ((GXmlDomNode*) self);
		_tmp15_ = _tmp14_;
		_tmp16_ = g_object_new (_tmp13_->value_type, "owner-document", _tmp15_, NULL);
		_tmp17_ = G_IS_INITIALLY_UNOWNED (_tmp16_) ? g_object_ref_sink (_tmp16_) : _tmp16_;
		_g_object_unref0 (obj);
		obj = _tmp17_;
		{
			GObject* _tmp18_;
			GXmlDomNode* _tmp19_;
			GXmlDomNode* _tmp20_;
			_tmp18_ = obj;
			_tmp19_ = gxml_dom_node_append_child ((GXmlDomNode*) self, (GXmlDomNode*) (GXML_IS_ELEMENT (_tmp18_) ? ((GXmlElement*) _tmp18_) : NULL), &_inner_error0_);
			_tmp20_ = _tmp19_;
			_g_object_unref0 (_tmp20_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* e = NULL;
			GError* _tmp21_;
			const gchar* _tmp22_;
			gchar* _tmp23_;
			gchar* _tmp24_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp21_ = e;
			_tmp22_ = _tmp21_->message;
			_tmp23_ = g_strdup_printf (_ ("Error while attempting to instantiate property object: %s"), _tmp22_);
			_tmp24_ = _tmp23_;
			g_warning ("Object.vala:407: %s", _tmp24_);
			_g_free0 (_tmp24_);
			result = FALSE;
			_g_error_free0 (e);
			_g_object_unref0 (obj);
			G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
			_g_param_spec_unref0 (prop);
			return result;
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp25_ = FALSE;
			_g_object_unref0 (obj);
			G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
			_g_param_spec_unref0 (prop);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return _tmp25_;
		}
		_tmp26_ = obj;
		g_value_set_object (&v, _tmp26_);
		_tmp27_ = prop;
		_tmp28_ = _tmp27_->name;
		_tmp29_ = v;
		g_object_set_property ((GObject*) self, _tmp28_, &_tmp29_);
		result = TRUE;
		_g_object_unref0 (obj);
		G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
		_g_param_spec_unref0 (prop);
		return result;
	}
	result = FALSE;
	_g_object_unref0 (obj);
	G_IS_VALUE (&v) ? (g_value_unset (&v), NULL) : NULL;
	_g_param_spec_unref0 (prop);
	return result;
}

gboolean
gxml_object_set_instance_property (GXmlObject* self,
                                   const gchar* name)
{
	GXmlObjectIface* _iface_;
	g_return_val_if_fail (self != NULL, FALSE);
	_iface_ = GXML_OBJECT_GET_INTERFACE (self);
	if (_iface_->set_instance_property) {
		return _iface_->set_instance_property (self, name);
	}
	return FALSE;
}

/**
   * Utility method to remove all instances of a property being child elements
   * of object. Is useful if you have a {@link GXml.Element} property, it should be
   * just one child of this type and you want to overwrite it.
   *
   * In this example you have defined an element MyClass to be child of
   * MyParentClass, but it should have just one element, once you set child_elements
   * it calls {@link clean_property_elements} using property's canonicals name.
   *
   * {{{
   *  public class MyClass : GXml.Element {
   *    public string name { get; set; }
   *  }
   *  public class MyParentClass : GXml.Element {
   *    private Myclass _child_elements = null;
   *    public MyClass child_elements {
   *      get { return _child_elements; }
   *      set {
   *        try {
   *          clean_property_elements ("child-elements");
   *          _child_elements = value;
   *          append_child (_child_elements);
   *        } catch (GLib.Error e) {
   *          warning (e.message);
   *        }
   *      }
   *    }
   *  }
   * }}}
   *
   * @param name property name to search value type, use canonical names.
   *
   * @throws DomError if property is not a {@link GXml.Element}.
   */
static void
gxml_object_real_clean_property_elements (GXmlObject* self,
                                          const gchar* name,
                                          GError** error)
{
	GParamSpec* prop = NULL;
	GObjectClass* _tmp0_;
	GParamSpec* _tmp1_;
	GParamSpec* _tmp2_;
	GParamSpec* _tmp3_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (name != NULL);
	_tmp0_ = G_OBJECT_GET_CLASS ((GObject*) self);
	_tmp1_ = g_object_class_find_property (_tmp0_, name);
	_tmp2_ = _g_param_spec_ref0 (_tmp1_);
	prop = _tmp2_;
	_tmp3_ = prop;
	if (_tmp3_ != NULL) {
		GParamSpec* _tmp4_;
		GXmlDomElementList* l = NULL;
		GXmlDomElementList* _tmp6_;
		GXmlDomElementList* _tmp7_;
		gint _tmp8_;
		gint _tmp9_;
		_tmp4_ = prop;
		if (!g_type_is_a (_tmp4_->value_type, GXML_TYPE_ELEMENT)) {
			GError* _tmp5_;
			_tmp5_ = g_error_new_literal (GXML_DOM_ERROR, GXML_DOM_ERROR_TYPE_MISMATCH_ERROR, _ ("Can't set value. It is not a GXmlGXml.Element type"));
			_inner_error0_ = _tmp5_;
			g_propagate_error (error, _inner_error0_);
			_g_param_spec_unref0 (prop);
			return;
		}
		_tmp6_ = gxml_object_find_elements (self, name);
		l = _tmp6_;
		_tmp7_ = l;
		_tmp8_ = gxml_dom_html_collection_get_length ((GXmlDomHTMLCollection*) _tmp7_);
		_tmp9_ = _tmp8_;
		if (_tmp9_ != 0) {
			{
				GXmlDomElementList* _e_list = NULL;
				GXmlDomElementList* _tmp10_;
				gint _e_size = 0;
				GXmlDomElementList* _tmp11_;
				gint _tmp12_;
				gint _tmp13_;
				gint _e_index = 0;
				_tmp10_ = l;
				_e_list = _tmp10_;
				_tmp11_ = _e_list;
				_tmp12_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp11_);
				_tmp13_ = _tmp12_;
				_e_size = _tmp13_;
				_e_index = -1;
				while (TRUE) {
					gint _tmp14_;
					gint _tmp15_;
					GXmlDomElement* e = NULL;
					GXmlDomElementList* _tmp16_;
					gpointer _tmp17_;
					GXmlDomElement* _tmp18_;
					_e_index = _e_index + 1;
					_tmp14_ = _e_index;
					_tmp15_ = _e_size;
					if (!(_tmp14_ < _tmp15_)) {
						break;
					}
					_tmp16_ = _e_list;
					_tmp17_ = gee_abstract_list_get ((GeeAbstractList*) _tmp16_, _e_index);
					e = (GXmlDomElement*) _tmp17_;
					_tmp18_ = e;
					gxml_dom_child_node_remove ((GXmlDomChildNode*) _tmp18_);
					_g_object_unref0 (e);
				}
			}
		}
		_g_object_unref0 (l);
	}
	_g_param_spec_unref0 (prop);
}

void
gxml_object_clean_property_elements (GXmlObject* self,
                                     const gchar* name,
                                     GError** error)
{
	GXmlObjectIface* _iface_;
	g_return_if_fail (self != NULL);
	_iface_ = GXML_OBJECT_GET_INTERFACE (self);
	if (_iface_->clean_property_elements) {
		_iface_->clean_property_elements (self, name, error);
	}
}

static void
gxml_object_default_init (GXmlObjectIface * iface,
                          gpointer iface_data)
{
	iface->get_properties_list = gxml_object_real_get_properties_list;
	iface->find_property_name = gxml_object_real_find_property_name;
	iface->find_object_property_name = gxml_object_real_find_object_property_name;
	iface->get_property_element_list = gxml_object_real_get_property_element_list;
	iface->get_property_string = gxml_object_real_get_property_string;
	iface->get_attribute = gxml_object_real_get_attribute;
	iface->find_property = gxml_object_real_find_property;
	iface->set_attribute = gxml_object_real_set_attribute;
	iface->get_child = gxml_object_real_get_child;
	iface->find_elements = gxml_object_real_find_elements;
	iface->remove_attribute = gxml_object_real_remove_attribute;
	iface->set_instance_property = gxml_object_real_set_instance_property;
	iface->clean_property_elements = gxml_object_real_clean_property_elements;
}

/**
 * A GXml Object Model represents a {@link DomElement}. It has attributes
 * and children. All object's properties are handled as attributes if they are
 * basic types like integers, strings, enums and others; {@link Property}
 * objects are handled as attributes too. If object's attribute is a {@link GLib.Object}
 * it is handled as node's child, but only if it is a {@link GXml.Element} object,
 * other wise it is ignored when this object is used as {@link DomNode} in XML
 * documents.
 */
static GType
gxml_object_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GXmlObjectIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gxml_object_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
	GType gxml_object_type_id;
	gxml_object_type_id = g_type_register_static (G_TYPE_INTERFACE, "GXmlObject", &g_define_type_info, 0);
	g_type_interface_add_prerequisite (gxml_object_type_id, G_TYPE_OBJECT);
	g_type_interface_add_prerequisite (gxml_object_type_id, GXML_TYPE_DOM_NODE);
	g_type_interface_add_prerequisite (gxml_object_type_id, GXML_TYPE_DOM_ELEMENT);
	return gxml_object_type_id;
}

GType
gxml_object_get_type (void)
{
	static volatile gsize gxml_object_type_id__once = 0;
	if (g_once_init_enter (&gxml_object_type_id__once)) {
		GType gxml_object_type_id;
		gxml_object_type_id = gxml_object_get_type_once ();
		g_once_init_leave (&gxml_object_type_id__once, gxml_object_type_id);
	}
	return gxml_object_type_id__once;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

