00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "midgard/midgard_object_property.h"
00021 #include "schema.h"
00022
00023 #define _MGD_GET_PRIVATE_CLASS_DATA \
00024 g_assert(classname != NULL); \
00025 g_assert(property != NULL); \
00026 MidgardObjectClass *oc = \
00027 (MidgardObjectClass*) g_type_class_peek(g_type_from_name(classname)); \
00028 MgdSchemaTypeAttr *type_attr = oc->data ;\
00029
00030
00031 static void _midgard_object_property_class_init(
00032 gpointer g_class, gpointer g_class_data)
00033 {
00034 GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
00035 MidgardObjectPropertyClass *klass = MIDGARD_OBJECT_PROPERTY_CLASS (g_class);
00036
00037 gobject_class->set_property = NULL;
00038 gobject_class->get_property = NULL;
00039 gobject_class->finalize = NULL;
00040
00041 klass->is_multilang = midgard_object_property_is_multilang;
00042 }
00043
00044
00045 GType
00046 midgard_object_property_get_type (void)
00047 {
00048 static GType type = 0;
00049 if (type == 0) {
00050 static const GTypeInfo info = {
00051 sizeof (MidgardObjectPropertyClass),
00052 NULL,
00053 NULL,
00054 (GClassInitFunc) _midgard_object_property_class_init,
00055 NULL,
00056 NULL,
00057 sizeof (MidgardObjectProperty),
00058 0,
00059 NULL
00060 };
00061 type = g_type_register_static (G_TYPE_OBJECT,
00062 "MidgardObjectProperty",
00063 &info, 0);
00064 }
00065 return type;
00066 }
00067
00068
00069
00070 GType
00071 midgard_object_property_get_midgard_type(const gchar *classname, const gchar *property){
00072
00073 _MGD_GET_PRIVATE_CLASS_DATA;
00074
00075 MgdSchemaPropertyAttr *prop_attr;
00076 if((prop_attr = g_hash_table_lookup(type_attr->prophash, property)) == NULL)
00077 return MGD_TYPE_NONE;
00078
00079 return prop_attr->gtype;
00080 }
00081
00082
00083 gboolean
00084 midgard_object_property_is_link(const gchar *classname, const gchar *property){
00085
00086 _MGD_GET_PRIVATE_CLASS_DATA;
00087
00088 MgdSchemaPropertyAttr *prop_attr;
00089 if((prop_attr = g_hash_table_lookup(type_attr->prophash, property)) == NULL)
00090 return FALSE;
00091
00092 return prop_attr->is_link;
00093 }
00094
00095
00096 gboolean
00097 midgard_object_property_is_linked(const gchar *classname, const gchar *property){
00098
00099 _MGD_GET_PRIVATE_CLASS_DATA;
00100
00101 MgdSchemaPropertyAttr *prop_attr;
00102 if((prop_attr = g_hash_table_lookup(type_attr->prophash, property)) == NULL)
00103 return FALSE;
00104
00105 return prop_attr->is_linked;
00106
00107 }
00108
00109
00110 const gchar
00111 *midgard_object_property_get_link_name(const gchar *classname, const gchar *property){
00112
00113 _MGD_GET_PRIVATE_CLASS_DATA;
00114
00115 MgdSchemaPropertyAttr *prop_attr;
00116 if((prop_attr = g_hash_table_lookup(type_attr->prophash, property)) == NULL)
00117 return NULL;
00118
00119 return prop_attr->link;
00120 }
00121
00122
00123 const gchar
00124 *midgard_object_property_description(const gchar *classname, const gchar *property){
00125
00126 g_assert(classname != NULL);
00127 g_assert(property != NULL);
00128
00129 GObject *object = g_object_new(
00130 g_type_from_name(classname), NULL);
00131
00132 GParamSpec *prop = g_object_class_find_property(
00133 G_OBJECT_GET_CLASS(G_OBJECT(object)), property);
00134
00135 if(!prop)
00136 return NULL;
00137
00138 return g_param_spec_get_blurb(prop);
00139 }
00140
00141
00142 gboolean
00143 midgard_object_property_is_multilang(const gchar *classname, const gchar *property){
00144
00145 _MGD_GET_PRIVATE_CLASS_DATA;
00146
00147 MgdSchemaPropertyAttr *prop_attr;
00148 if((prop_attr = g_hash_table_lookup(type_attr->prophash, property)) == NULL)
00149 return FALSE;
00150
00151 return prop_attr->is_multilang;
00152 }
00153
00154
00155 extern MidgardObjectClass
00156 *midgard_object_property_get_link_class(MidgardObjectClass *klass, const gchar *property)
00157 {
00158 g_assert(klass != NULL);
00159 g_assert(property != NULL);
00160
00161 MgdSchemaPropertyAttr *prop_attr;
00162 if((prop_attr = g_hash_table_lookup(klass->data->prophash, property)) == NULL)
00163 return NULL;
00164
00165 if(prop_attr->is_link) {
00166
00167 MidgardObjectClass *link_klass =
00168 g_type_class_peek(g_type_from_name(prop_attr->link));
00169 return link_klass;
00170 }
00171 return NULL;
00172 }