00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "midgard/midgard_reflection_property.h"
00020 #include "schema.h"
00021
00022 struct _MidgardReflectionProperty{
00023 GObject parent;
00024
00025 MidgardObjectClass *klass;
00026 };
00027
00028 static void _midgard_reflection_property_finalize(GObject *object)
00029 {
00030 g_assert(object != NULL);
00031 return;
00032 }
00033
00034
00035 static void _midgard_reflection_property_class_init(
00036 gpointer g_class, gpointer g_class_data)
00037 {
00038 GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
00039 MidgardReflectionPropertyClass *klass = MIDGARD_REFLECTION_PROPERTY_CLASS (g_class);
00040
00041 gobject_class->set_property = NULL;
00042 gobject_class->get_property = NULL;
00043 gobject_class->finalize = _midgard_reflection_property_finalize;
00044
00045 klass->is_multilang = midgard_reflection_property_is_multilang;
00046 }
00047
00048
00049 GType midgard_reflection_property_get_type (void)
00050 {
00051 static GType type = 0;
00052 if (type == 0) {
00053 static const GTypeInfo info = {
00054 sizeof (MidgardReflectionPropertyClass),
00055 NULL,
00056 NULL,
00057 (GClassInitFunc) _midgard_reflection_property_class_init,
00058 NULL,
00059 NULL,
00060 sizeof (MidgardReflectionProperty),
00061 0,
00062 NULL
00063 };
00064 type = g_type_register_static (G_TYPE_OBJECT,
00065 "midgard_reflection_property",
00066 &info, 0);
00067 }
00068 return type;
00069 }
00070
00071
00072 MidgardReflectionProperty *midgard_reflection_property_new(
00073 MidgardObjectClass *klass)
00074 {
00075 g_assert(klass != NULL);
00076 MidgardReflectionProperty *self =
00077 g_object_new(MIDGARD_TYPE_REFLECTION_PROPERTY, NULL);
00078 self->klass = klass;
00079 return self;
00080 }
00081
00082
00083 GType midgard_reflection_property_get_midgard_type(
00084 MidgardReflectionProperty *object, const gchar *property)
00085 {
00086 g_assert(object != NULL);
00087 g_assert(property != NULL);
00088 MgdSchemaPropertyAttr *prop_attr;
00089 if((prop_attr = g_hash_table_lookup(object->klass->data->prophash,
00090 property)) == NULL)
00091 return MGD_TYPE_NONE;
00092
00093 return prop_attr->gtype;
00094 }
00095
00096
00097 gboolean midgard_reflection_property_is_link(
00098 MidgardReflectionProperty *object, const gchar *property)
00099 {
00100 g_assert(object != NULL);
00101 g_assert(property != NULL);
00102 MgdSchemaPropertyAttr *prop_attr;
00103 if((prop_attr = g_hash_table_lookup(object->klass->data->prophash,
00104 property)) == NULL)
00105 return FALSE;
00106
00107 return prop_attr->is_link;
00108 }
00109
00110
00111 gboolean midgard_reflection_property_is_linked(
00112 MidgardReflectionProperty *object, const gchar *property)
00113 {
00114 g_assert(object != NULL);
00115 g_assert(property != NULL);
00116 MgdSchemaPropertyAttr *prop_attr;
00117 if((prop_attr = g_hash_table_lookup(object->klass->data->prophash,
00118 property)) == NULL)
00119 return FALSE;
00120
00121 return prop_attr->is_linked;
00122 }
00123
00124
00125 const gchar *midgard_reflection_property_get_link_name(
00126 MidgardReflectionProperty *object, const gchar *property)
00127 {
00128 g_assert(object != NULL);
00129 g_assert(property != NULL);
00130 MgdSchemaPropertyAttr *prop_attr;
00131 if((prop_attr = g_hash_table_lookup(object->klass->data->prophash,
00132 property)) == NULL)
00133 return NULL;
00134
00135 return prop_attr->link;
00136 }
00137
00138
00139 const gchar *midgard_reflection_property_get_link_target(
00140 MidgardReflectionProperty *object, const gchar *property)
00141 {
00142 g_assert(object != NULL);
00143 g_assert(property != NULL);
00144 MgdSchemaPropertyAttr *prop_attr;
00145 if((prop_attr = g_hash_table_lookup(object->klass->data->prophash,
00146 property)) == NULL)
00147 return NULL;
00148
00149 return prop_attr->link_target;
00150 }
00151
00152
00153
00154 const gchar *midgard_reflection_property_description(
00155 MidgardReflectionProperty *object, const gchar *property)
00156 {
00157 g_assert(object != NULL);
00158 g_assert(property != NULL);
00159
00160 GParamSpec *prop = g_object_class_find_property(
00161 G_OBJECT_CLASS(object->klass), property);
00162
00163 if(!prop)
00164 return NULL;
00165
00166 return g_param_spec_get_blurb(prop);
00167 }
00168
00169
00170 gboolean midgard_reflection_property_is_multilang(
00171 MidgardReflectionProperty *object, const gchar *property)
00172 {
00173 g_assert(object != NULL);
00174 g_assert(property != NULL);
00175 MgdSchemaPropertyAttr *prop_attr;
00176 if((prop_attr = g_hash_table_lookup(object->klass->data->prophash,
00177 property)) == NULL)
00178 return FALSE;
00179
00180 return prop_attr->is_multilang;
00181 }
00182
00183
00184 extern MidgardObjectClass *midgard_reflection_property_get_link_class(
00185 MidgardReflectionProperty *object, const gchar *property)
00186 {
00187 g_assert(object != NULL);
00188 g_assert(property != NULL);
00189
00190 MgdSchemaPropertyAttr *prop_attr;
00191 if((prop_attr = g_hash_table_lookup(object->klass->data->prophash,
00192 property)) == NULL)
00193 return NULL;
00194
00195 if(prop_attr->is_link) {
00196 MidgardObjectClass *link_klass =
00197 g_type_class_peek(g_type_from_name(prop_attr->link));
00198 return link_klass;
00199 }
00200 return NULL;
00201 }