1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; -*- */
6 * Copyright (C) 2005 Novell, Inc.
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 * DEALINGS IN THE SOFTWARE.
32 #include "beagle-private.h"
33 #include "beagle-query-part.h"
36 BeagleQueryPartLogic logic
;
37 } BeagleQueryPartPrivate
;
39 #define BEAGLE_QUERY_PART_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BEAGLE_TYPE_QUERY_PART, BeagleQueryPartPrivate))
41 static GObjectClass
*parent_class
= NULL
;
43 G_DEFINE_TYPE (BeagleQueryPart
, beagle_query_part
, G_TYPE_OBJECT
)
46 beagle_query_part_finalize (GObject
*obj
)
48 BeagleQueryPartPrivate
*priv
= BEAGLE_QUERY_PART_GET_PRIVATE (obj
);
50 if (G_OBJECT_CLASS (parent_class
)->finalize
)
51 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
55 beagle_query_part_class_init (BeagleQueryPartClass
*klass
)
57 GObjectClass
*obj_class
= G_OBJECT_CLASS (klass
);
59 parent_class
= g_type_class_peek_parent (klass
);
61 obj_class
->finalize
= beagle_query_part_finalize
;
63 g_type_class_add_private (klass
, sizeof (BeagleQueryPartPrivate
));
67 beagle_query_part_init (BeagleQueryPart
*part
)
73 * beagle_query_part_set_logic:
74 * @part: a #BeagleQueryPart
75 * @logic: a value in enum #BeagleQueryLogic
77 * Set the #BeagleQueryLogic for a #BeagleQueryPart. This is used to determine whether
78 * this part should be required or prohibited.
81 beagle_query_part_set_logic (BeagleQueryPart
*part
,
82 BeagleQueryPartLogic logic
)
84 BeagleQueryPartPrivate
*priv
;
86 g_return_if_fail (BEAGLE_IS_QUERY_PART (part
));
88 priv
= BEAGLE_QUERY_PART_GET_PRIVATE (part
);
94 _beagle_query_part_to_xml (BeagleQueryPart
*part
)
96 g_return_val_if_fail (BEAGLE_IS_QUERY_PART (part
), NULL
);
98 return BEAGLE_QUERY_PART_GET_CLASS (part
)->to_xml (part
);
102 _beagle_query_part_append_standard_header (GString
*data
,
103 BeagleQueryPart
*part
,
104 const char *xsi_type
)
106 BeagleQueryPartPrivate
*priv
= BEAGLE_QUERY_PART_GET_PRIVATE (part
);
108 g_string_append_printf (data
, "<Part xsi:type=\"QueryPart_%s\">", xsi_type
);
110 switch (priv
->logic
) {
111 case BEAGLE_QUERY_PART_LOGIC_REQUIRED
:
112 g_string_append (data
, "<Logic>Required</Logic>");
114 case BEAGLE_QUERY_PART_LOGIC_PROHIBITED
:
115 g_string_append (data
, "<Logic>Prohibited</Logic>");
121 _beagle_query_part_append_standard_footer (GString
*data
)
123 g_string_append (data
, "</Part>");