Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_object_meta.c
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Adaptive Framework interface helpers for afw_object*
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
14 #include "afw_internal.h"
15 
16 
17 #define impl_afw_object_get_meta \
18  afw_object_impl_internal_get_meta
19 
20 #define impl_afw_object_get_property_meta \
21  afw_object_impl_internal_get_property_meta
22 
23 #define impl_afw_object_get_next_property_meta \
24  afw_object_impl_internal_get_next_property_meta
25 
26 
27 /* Declares and rti/inf defines for interface afw_object */
28 #define AFW_IMPLEMENTATION_ID "object_meta"
31 
32 
33 #define IMPL_ASSERT_META_MUTABLE(instance, xctx) \
34 if (!(instance)->p) {\
35  AFW_THROW_ERROR_Z(general, \
36  "Can not set meta in a const object", xctx); \
37 }
38 
39 
40 static const afw_object_t *
41 impl_set_meta_object(
42  afw_object_t *self,
43  const afw_object_t *delta,
44  afw_xctx_t *xctx)
45 {
46  afw_object_meta_object_t *meta_self;
47 
48  meta_self = afw_pool_calloc_type(self->p,
50  meta_self->pub.p = self->p;
51  meta_self->pub.inf = &impl_afw_object_inf;
52  meta_self->pub.meta.embedding_object = self;
53  meta_self->pub.meta.id = &afw_s_a_meta_key;
54  meta_self->pub.meta.object_type_uri = &afw_s__AdaptiveMeta_;
55  meta_self->setter.inf = &impl_afw_object_setter_inf;
56  meta_self->setter.object = (const afw_object_t *)meta_self;
57  meta_self->delta = delta;
58  self->meta.meta_object = (const afw_object_t *)meta_self;
59 
60  return delta;
61 }
62 
63 
64 
65 /* Add a needed object type object. */
66 AFW_DEFINE(void)
68  const afw_object_t *instance,
69  const afw_object_t *object_type,
70  afw_xctx_t *xctx)
71 {
72  const afw_object_t *entity;
73  const afw_object_t *meta;
74  const afw_object_t *objectTypes;
75 
76  entity = afw_object_get_entity(instance, xctx);
77  meta = afw_object_meta_get_nonempty_delta(entity, xctx);
78  objectTypes = afw_object_old_get_property_as_object(meta,
79  &afw_s_objectTypes, xctx);
80  if (!objectTypes) {
81  objectTypes = afw_object_create_embedded(meta,
82  &afw_s_objectTypes, xctx);
83  }
85  object_type->meta.id, object_type, xctx);
86 }
87 
88 
89 
90 /* Set object's meta using a clone of the meta of another object. */
91 AFW_DEFINE(void)
93  const afw_object_t *instance,
94  const afw_object_t *from,
95  afw_xctx_t *xctx)
96 {
97  afw_object_t *self = (afw_object_t *)instance;
98 
99  if (!from->meta.meta_object) {
100  return;
101  }
102 
103  if (self->meta.meta_object) {
104  AFW_THROW_ERROR_Z(general, "Instance already has meta", xctx);
105  }
106 
107  impl_set_meta_object(
108  (afw_object_t *)instance,
111  instance->p, xctx),
112  xctx);
113 }
114 
115 
116 
117 /* Get entity object's object id value. */
120  const afw_object_t *instance,
121  afw_xctx_t *xctx)
122 {
123  const afw_utf8_t *object_id;
124  const afw_value_t *value;
125 
127  object_id = afw_object_meta_get_object_id(instance, xctx);
128  if (!object_id) {
129  return NULL;
130  }
131  value = afw_value_create_string(object_id, instance->p, xctx);
132  return (const afw_value_string_t *)value;
133 }
134 
135 
136 
137 /* Add parent path. */
138 AFW_DEFINE(void)
140  const afw_object_t *instance,
141  const afw_utf8_t *parent_path,
142  afw_xctx_t *xctx)
143 {
144  const afw_value_list_t *existing_parent_paths;
145  afw_value_list_t *parent_paths;
146  const afw_object_t *meta;
147 
148  existing_parent_paths = afw_object_meta_get_parent_paths_value(instance, xctx);
149  parent_paths = afw_value_allocate_list(instance->p, xctx);
150 
151  if (existing_parent_paths) {
152  parent_paths->internal = afw_list_create_or_clone(
153  existing_parent_paths->internal, afw_data_type_anyURI, false,
154  instance->p, xctx);
155  }
156  else {
157  parent_paths->internal = afw_list_of_create(
158  afw_data_type_anyURI, instance->p, xctx);
159  }
160 
161  afw_list_of_anyURI_add(parent_paths->internal, parent_path, xctx);
162  meta = afw_object_meta_get_nonempty_delta(instance, xctx);
163  afw_object_set_property(meta, &afw_s_parentPaths,
164  (const afw_value_t *)parent_paths, xctx);
165 }
166 
167 
168 
169 /* Get meta parentPaths property. */
172  const afw_object_t *instance,
173  afw_xctx_t *xctx)
174 {
175  const afw_value_t *value;
176  const afw_object_t *meta;
177 
178  value = NULL;
179  meta = afw_object_meta_object(instance);
180  if (meta) {
181  value = afw_object_get_property(
182  afw_object_meta_object(instance),
183  &afw_s_parentPaths, xctx);
184  if (value && !afw_value_is_list_of_anyURI(value))
185  {
186  AFW_THROW_ERROR_Z(general,
187  "Expecting parentPaths to be a list of anyURI",
188  xctx);
189  }
190  }
191 
192  return (const afw_value_list_t *)value;
193 }
194 
195 
196 
197 /* Get entity object's object id. */
198 AFW_DEFINE(const afw_utf8_t *)
200  const afw_object_t *instance,
201  afw_xctx_t *xctx)
202 {
203  if (instance->meta.embedding_object) {
204  AFW_THROW_ERROR_Z(general,
205  "afw_object_meta_get_object_id() called for embedded object",
206  xctx);
207  }
208  return instance->meta.id;
209 }
210 
211 
212 
213 /* Get Get object's property name in embedding object.. */
214 AFW_DEFINE(const afw_utf8_t *)
216  const afw_object_t *instance,
217  afw_xctx_t *xctx)
218 {
219  if (!instance->meta.embedding_object) {
220  AFW_THROW_ERROR_Z(general,
221  "afw_object_meta_get_property_name() called for entity object",
222  xctx);
223  }
224  return instance->meta.id;
225 }
226 
227 
228 
229 /* Get an object's path. */
230 AFW_DEFINE(const afw_utf8_t *)
232  const afw_object_t *instance,
233  afw_xctx_t *xctx)
234 {
235  afw_object_t *self = (afw_object_t *)instance;
236  const afw_utf8_t *path;
237 
239  /* Get path from meta. */
240  path = instance->meta.object_uri;
241 
242  /*
243  * If there is not already a path and this is an embedded object, attempt
244  * to make one and save it if it does not contain an asterisk.
245  */
246  if (!path && instance->p && instance->meta.embedding_object) {
247  path = afw_object_path_make_for_embedded(instance,
248  instance->p, xctx);
249  self->meta.object_uri = path;
250  }
251 
252  return path;
253 }
254 
255 
256 
257 /*
258  * Get the property type object for an object's property from the meta
259  * of an object, creating it if needed
260  */
261 AFW_DEFINE(const afw_object_t *)
263  const afw_object_t *instance,
264  const afw_utf8_t *property_name,
265  afw_xctx_t *xctx)
266 {
267  const afw_object_t *meta;
268  const afw_object_t *property_types;
269  const afw_object_t *property_type;
270 
271  /* This is here for const objects for now. */
272  if (!instance->meta.meta_object && !instance->p) {
273  return NULL;
274  }
275 
276  meta = afw_object_meta_get_nonempty_delta(instance, xctx);
277 
278  property_types = afw_object_old_get_property_as_object(
279  instance->meta.meta_object,
280  &afw_s_propertyTypes, xctx);
281  if (!property_types) {
282  property_types = afw_object_create_embedded(
283  meta, &afw_s_propertyTypes, xctx);
284  ((afw_object_t *)property_types)->meta.object_type_uri =
285  &afw_s__AdaptiveMetaPropertyTypes_;
286  }
287 
288  property_type = afw_object_old_get_property_as_object(property_types,
289  property_name, xctx);
290  if (!property_type) {
292  instance->meta.meta_object,
293  &afw_s_otherProperties, xctx);
294  if (property_type) {
295  property_type = afw_object_create_clone(property_type,
296  instance->p, xctx);
297  afw_object_set_property_as_object(property_types,
298  property_name, property_type, xctx);
299  }
300  else {
301  property_type = afw_object_create_embedded(property_types,
302  property_name, xctx);
303  }
304  ((afw_object_t *)property_type)->meta.object_type_uri =
305  &afw_s__AdaptiveMetaPropertyType_;
306  }
307 
308  return property_type;
309 }
310 
311 
312 
313 /* Set object's meta object. */
314 AFW_DEFINE(void)
316  const afw_object_t *instance,
317  const afw_object_t *meta,
318  afw_xctx_t *xctx)
319 {
320  afw_object_t *self = (afw_object_t *)instance;
321  const afw_pool_t *p = instance->p;
322  const afw_object_setter_t *setter;
323  const afw_value_t *value;
324  const afw_utf8_t *path;
325  const afw_utf8_t *object_type_id;
326  const afw_object_t *property_types;
327  const afw_object_t *property_type;
328  const afw_object_path_parsed_t *parsed_path;
329  const afw_list_t *parent_paths;
330 
331  /* If no meta, just return. */
332  if (!meta) {
333  return;
334  }
335 
336  /* If there is already meta, fail. */
337  if (self->meta.meta_object) {
338  AFW_THROW_ERROR_Z(general, "Instance already has meta", xctx);
339  }
340 
341  /* Get setter for meta and fail if there is not one. */
342  setter = afw_object_get_setter(meta, xctx);
343  if (!setter) {
344  AFW_THROW_ERROR_Z(general, "Meta must be mutable", xctx);
345  }
346 
347  /* Make sure parentPaths is a list. */
348  value = afw_object_get_property(meta, &afw_s_parentPaths, xctx);
349  if (value) {
350  parent_paths = afw_list_of_create_from_value(
351  afw_data_type_anyURI, value, meta->p, xctx);
353  &afw_s_parentPaths, parent_paths, xctx);
354  }
355 
356  /* If path in meta, remove it from meta and if entity, use it to set path. */
357  path = afw_object_old_get_property_as_utf8(meta, &afw_s_path,
358  p, xctx);
359  if (path) {
360  parsed_path = afw_object_path_parse(path, NULL, NULL, p, xctx);
361  if (!parsed_path->first_property_name) {
362  afw_object_meta_set_ids_using_path(instance, path, xctx);
363  }
364  afw_object_set_property(meta, &afw_s_path, NULL, xctx);
365  }
366 
367  /* Try to determine object type if path didn't set it. */
368  if (!instance->meta.object_type_uri) {
369  object_type_id = afw_object_old_get_property_as_string(meta,
370  &afw_s_objectType, xctx);
371  if (!object_type_id &&
372  instance->meta.embedding_object &&
373  instance->meta.embedding_object->meta.meta_object)
374  {
375  property_types = afw_object_old_get_property_as_object(
376  meta, &afw_s_propertyTypes, xctx);
377  if (property_types) {
379  property_types, instance->meta.id, xctx);
380  if (property_type) {
381  object_type_id = afw_object_old_get_property_as_string(
382  property_type, &afw_s_dataTypeParameter, xctx);
383  }
384  }
385  }
386  if (object_type_id) {
387  afw_object_meta_set_object_type_id(instance, object_type_id, xctx);
388  }
389  }
390 
391  /* Set meta in instance. */
392  impl_set_meta_object(self, meta, xctx);
393 }
394 
395 
396 
397 AFW_DEFINE(const afw_object_t *)
399  const afw_object_t *instance,
400  afw_xctx_t *xctx)
401 {
402  const afw_object_t *result;
403 
404  if (instance->meta.meta_object) {
405  AFW_THROW_ERROR_Z(general, "Object already has meta", xctx);
406  }
407 
408  IMPL_ASSERT_META_MUTABLE(instance, xctx);
409 
410  /* Set meta in instance. */
411  result = impl_set_meta_object(
412  (afw_object_t *)instance,
413  afw_object_create(instance->p, xctx),
414  xctx);
415 
416  return result;
417 }
418 
419 
420 
423  const afw_object_t *instance,
424  afw_xctx_t *xctx)
425 {
426  if (!instance->meta.meta_object) {
427  afw_object_meta_set_empty(instance, xctx);
428  }
429 
430  if (instance->meta.meta_object->inf != &impl_afw_object_inf) {
431  AFW_THROW_ERROR_Z(general, "Object meta is not mutable", xctx);
432  }
433 
434  return (const afw_object_meta_object_t *)instance->meta.meta_object;
435 }
436 
437 
438 
439 AFW_DEFINE(const afw_object_t *)
441  const afw_object_t *instance,
442  afw_xctx_t *xctx)
443 {
444  if (!instance->meta.meta_object) {
445  afw_object_meta_set_empty(instance, xctx);
446  }
447 
448  if (instance->meta.meta_object->inf != &impl_afw_object_inf) {
449  AFW_THROW_ERROR_Z(general, "Object meta is not mutable", xctx);
450  }
451 
452  return ((const afw_object_meta_object_t *)instance->meta.meta_object)
453  ->delta;
454 }
455 
456 
457 
458 /* Set object's object type using afw object type id. */
459 AFW_DEFINE(void)
461  const afw_object_t *instance,
462  const afw_object_type_t *object_type,
463  afw_xctx_t *xctx)
464 {
465  afw_object_meta_object_t *meta_object;
466 
467  IMPL_ASSERT_META_MUTABLE(instance, xctx);
468 
469  meta_object = (afw_object_meta_object_t *)
471 
472  meta_object->object_type = object_type;
473 }
474 
475 
476 
477 /* Set object's object type id. */
478 AFW_DEFINE(void)
480  const afw_object_t *instance,
481  const afw_utf8_t *object_type_id,
482  afw_xctx_t *xctx)
483 {
484  IMPL_ASSERT_META_MUTABLE(instance, xctx);
485 
486  ((afw_object_t *)instance)->meta.object_type_uri = object_type_id;
487 }
488 
489 
490 
491 /* Set meta parentPaths property. */
492 AFW_DEFINE(void)
494  const afw_object_t *instance,
495  const afw_value_list_t *parent_paths,
496  afw_xctx_t *xctx)
497 {
498  const afw_object_t *meta;
499 
500  meta = afw_object_meta_get_nonempty_delta(instance, xctx);
501 
502  afw_object_set_property(meta, &afw_s_parentPaths,
503  (const afw_value_t *)parent_paths, xctx);
504 }
505 
506 
507 
508 /* Set object's ids. */
509 AFW_DEFINE(void)
511  const afw_object_t *instance,
512  const afw_utf8_t *adaptor_id,
513  const afw_utf8_t *object_type_id,
514  const afw_utf8_t *object_id,
515  afw_xctx_t *xctx)
516 {
517  afw_object_t *self = (afw_object_t *)instance;
518  const afw_utf8_t *path;
519 
520  IMPL_ASSERT_META_MUTABLE(instance, xctx);
521  AFW_OBJECT_ASSERT_ENTITY(instance, xctx);
522 
523  adaptor_id = afw_utf8_clone(adaptor_id, instance->p, xctx);
524  object_type_id = afw_utf8_clone(object_type_id, instance->p, xctx);
525  object_id = afw_utf8_clone(object_id, instance->p, xctx);
526 
527  self->meta.object_type_uri = object_type_id;
528  self->meta.id = object_id;
529  path = afw_object_path_make(
530  adaptor_id, object_type_id, object_id, instance->p, xctx);
531  self->meta.object_uri = path;
532 }
533 
534 
535 
536 /* Set object's ids using path. */
537 AFW_DEFINE(void)
539  const afw_object_t *instance,
540  const afw_utf8_t *path,
541  afw_xctx_t *xctx)
542 {
543  afw_object_t *self = (afw_object_t *)instance;
544  const afw_utf8_t *adaptor_id;
545  const afw_utf8_t *object_type_id;
546  const afw_utf8_t *object_id;
547 
548  IMPL_ASSERT_META_MUTABLE(instance, xctx);
549 
550  path = afw_utf8_clone(path, instance->p, xctx);
552  &adaptor_id, &object_type_id, &object_id,
553  instance->p, xctx);
554  self->meta.object_type_uri = object_type_id;
555  self->meta.id = object_id;
556  self->meta.object_uri = path;
557  if (afw_utf8_equal(adaptor_id, &afw_s_a_asterisk) ||
558  afw_utf8_equal(object_type_id, &afw_s_a_asterisk) ||
559  afw_utf8_equal(object_id, &afw_s_a_asterisk))
560  {
561  AFW_THROW_ERROR_Z(general, "Unexpected asterisk", xctx);
562  }
563 }
564 
565 
566 
567 /* Set object's meta to indicate object is read-only. */
568 AFW_DEFINE(void)
570  const afw_object_t *instance,
571  afw_xctx_t *xctx)
572 {
574  &afw_s_allowChange, afw_value_false, xctx);
576  &afw_s_allowDelete, afw_value_false, xctx);
577 }
578 
579 
580 
581 AFW_DEFINE(void)
583  const afw_object_t *instance,
584  const afw_utf8_t *message,
585  afw_xctx_t *xctx)
586 {
587  const afw_value_t *value;
588  const afw_object_t *meta;
589  const afw_list_t *errors;
590 
591  meta = afw_object_meta_get_nonempty_delta(instance, xctx);
592  errors = afw_object_old_get_property_as_list(meta, &afw_s_errors, xctx);
593  if (!errors) {
594  errors = afw_list_of_create(
595  afw_data_type_string, instance->p, xctx);
597  &afw_s_errors, errors, xctx);
598  afw_object_set_property(meta, &afw_s_hasErrors, afw_value_true, xctx);
600  &afw_s_hasErrors, afw_value_true, xctx);
601  }
602 
603  value = afw_value_create_string(message, instance->p, xctx);
604  afw_list_add_value(errors, value, xctx);
605 }
606 
607 
608 /* Check if object flagged for errors. */
611  const afw_object_t *instance,
612  afw_xctx_t *xctx)
613 {
614  afw_boolean_t result;
615 
616  result = false;
617  if (instance->meta.meta_object) {
619  afw_object_meta_object(instance),
620  &afw_s_hasErrors, xctx);
621  }
622 
623  return result;
624 }
625 
626 
627 
628 static void
629 impl_log_errors(
630  const afw_list_t *errors,
631  const afw_utf8_t *source_location,
632  afw_xctx_t *xctx)
633 {
634  const afw_iterator_t *iterator;
635  const afw_utf8_t *error;
636 
637  iterator = NULL;
638  while ((error = afw_list_of_string_get_next(errors,
639  &iterator, xctx)))
640  {
641  AFW_LOG_FZ(info, xctx,
643  "%" AFW_UTF8_FMT,
644  AFW_UTF8_FMT_ARG(source_location),
645  AFW_UTF8_FMT_ARG(error));
646  }
647 }
648 
649 
650 
651 /* Log meta errors. */
652 AFW_DEFINE(void)
654  const afw_object_t *instance,
655  const afw_utf8_t *source_location,
656  afw_xctx_t *xctx)
657 {
658  const afw_pool_t *p;
659  const afw_list_t *errors;
660  const afw_object_t *meta;
661  const afw_object_t *property_types;
662  const afw_object_t *property_type;
663  const afw_iterator_t *iterator;
664  const afw_utf8_t *property_name;
665  const afw_utf8_t *property_source_location;
666  const afw_object_t *embedded;
667  const afw_value_t *value;
668 
669  /* If no errors, return. */
670  if (!afw_object_meta_has_errors(instance, xctx)) {
671  return;
672  }
673  meta = afw_object_meta_object(instance);
674 
675  /* Use instance's p. */
676  p = instance->p;
677 
678  /* Log object level errors. */
679  errors = afw_object_old_get_property_as_list(meta, &afw_s_errors, xctx);
680  if (errors) {
681  impl_log_errors(errors, source_location, xctx);
682  }
683 
684  /* Log property level errors. */
685  property_types = afw_object_old_get_property_as_object(meta,
686  &afw_s_propertyTypes, xctx);
687  if (property_types) {
688  iterator = NULL;
689  while ((property_type = afw_object_old_get_next_property_as_object(
690  property_types, &iterator, &property_name, xctx)))
691  {
692  errors = afw_object_old_get_property_as_list(property_type,
693  &afw_s_errors, xctx);
694  if (errors) {
695  property_source_location = afw_utf8_printf(p, xctx,
696  "%" AFW_UTF8_FMT
697  ".%" AFW_UTF8_FMT,
698  AFW_UTF8_FMT_ARG(source_location),
699  AFW_UTF8_FMT_ARG(property_name));
700  impl_log_errors(errors, property_source_location, xctx);
701  }
702  }
703  }
704 
705  /* Log errors for embedded objects. */
706  iterator = NULL;
707  while ((value = afw_object_get_next_property(instance,
708  &iterator, &property_name, xctx)))
709  {
710  if (!afw_value_is_object(value)) {
711  continue;
712  }
713  embedded = ((afw_value_object_t *)value)->internal;
714  if (afw_object_meta_has_errors(embedded, xctx)) {
715  property_source_location = afw_utf8_printf(p, xctx,
716  "%" AFW_UTF8_FMT
717  ".%" AFW_UTF8_FMT,
718  AFW_UTF8_FMT_ARG(source_location),
719  AFW_UTF8_FMT_ARG(property_name));
721  property_source_location, xctx);
722  }
723  }
724 }
725 
726 
727 
728 AFW_DEFINE(void)
730  const afw_object_t *instance,
731  const afw_error_t *error,
732  afw_xctx_t *xctx)
733 {
734  const afw_utf8_t *message;
735 
736  if (afw_flag_is_active(
737  xctx->env->flag_index_response_error_hasAdditionalDetail, xctx))
738  {
739  message = afw_error_to_utf8(error, instance->p, xctx);
740  }
741 
742  else {
743  message = afw_utf8_create_copy(error->message_z, AFW_UTF8_Z_LEN,
744  instance->p, xctx);
745  }
746 
747  afw_object_meta_add_error(instance, message, xctx);
748 }
749 
750 
751 AFW_DEFINE(void)
753  const afw_object_t *instance,
754  const afw_utf8_t *property_name,
755  const afw_utf8_t *message,
756  afw_xctx_t *xctx)
757 {
758  const afw_object_t *property_type;
759  const afw_value_t *value;
760  const afw_list_t *errors;
761 
762  property_type = afw_object_meta_get_property_type(instance,
763  property_name, xctx);
764  errors = afw_object_old_get_property_as_list(property_type,
765  &afw_s_errors, xctx);
766  if (!errors) {
767  errors = afw_list_of_create(
768  afw_data_type_string, instance->p, xctx);
769  afw_object_set_property_as_list(property_type,
770  &afw_s_errors, errors, xctx);
772  &afw_s_hasErrors, afw_value_true, xctx);
774  &afw_s_hasErrors, afw_value_true, xctx);
775  }
776 
777  value = afw_value_create_string(message, instance->p, xctx);
778  afw_list_add_value(errors, value, xctx);
779 }
780 
781 AFW_DEFINE(void)
783  const afw_object_t *instance,
784  const afw_utf8_t *property_name,
785  afw_integer_t index,
786  const afw_error_t *error,
787  afw_xctx_t *xctx)
788 {
789  const afw_utf8_t *message;
790 
791  /* If property name is NULL, just add error to object. */
792  if (!property_name) {
793  afw_object_meta_add_thrown_error(instance, error, xctx);
794  return;
795  }
796 
801  if (afw_flag_is_active(
802  xctx->env->flag_index_response_error_hasAdditionalDetail, xctx))
803  { message = afw_error_to_utf8(error, instance->p, xctx);
804  if (index >= 0) {
805  message = afw_utf8_printf(instance->p, xctx,
806  "[%" AFW_INTEGER_FMT "] %" AFW_UTF8_FMT,
807  index,
808  AFW_UTF8_FMT_ARG(message));
809  }
810  }
811 
812  else if (index >= 0) {
813  message = afw_utf8_printf(instance->p, xctx,
814  "[%" AFW_INTEGER_FMT "] %s",
815  index,
816  error->message_z);
817  }
818 
819  else {
820  message = afw_utf8_create_copy(error->message_z, AFW_UTF8_Z_LEN,
821  instance->p, xctx);
822  }
823 
824  /* Add error to property's meta. */
825  afw_object_meta_add_property_error(instance, property_name,
826  message, xctx);
827 }
828 
829 
830 
831 /*
832  * Implementation of method release for interface afw_object.
833  */
834 void
836  const afw_object_t *instance,
837  afw_xctx_t *xctx)
838 {
840  (afw_object_meta_object_t *)instance;
841 
842  afw_object_release(self->pub.meta.embedding_object, xctx);
843 }
844 
845 /*
846  * Implementation of method add_reference for interface afw_object.
847  */
848 void
849 impl_afw_object_add_reference(
850  const afw_object_t *instance,
851  afw_xctx_t *xctx)
852 {
854  (afw_object_meta_object_t *)instance;
855 
856  afw_object_add_reference(self->pub.meta.embedding_object, xctx);
857 }
858 
859 /*
860  * Implementation of method get_count for interface afw_object.
861  */
864  const afw_object_t * instance,
865  afw_xctx_t * xctx)
866 {
867 // <afwdev {prefixed_interface_name}>_self_t *self =
868 // (<afwdev {prefixed_interface_name}>_self_t *)instance;
869 
871  AFW_THROW_ERROR_Z(general, "Method not implemented.", xctx);
872 
873 }
874 
875 /*
876  * Implementation of method get_property for interface afw_object.
877  */
878 const afw_value_t *
880  const afw_object_t *instance,
881  const afw_utf8_t *property_name,
882  afw_xctx_t *xctx)
883 {
885  (afw_object_meta_object_t *)instance;
886  const afw_value_t *result;
887 
888  result = afw_object_get_property(self->delta, property_name, xctx);
889 
890  if (!result && afw_utf8_equal(property_name, &afw_s_properties)) {
891 
892  }
893 
894  if (!result && self->object_type && self->object_type->object_type_object) {
895  result = afw_object_get_property(self->object_type->object_type_object,
896  property_name, xctx);
897  }
898 
899  return result;
900 }
901 
902 
903 typedef struct {
904  const afw_iterator_t *iterator;
905  afw_boolean_t on_delta;
907 
908 /*
909  * Implementation of method get_next_property for interface afw_object.
910  */
911 const afw_value_t *
912 impl_afw_object_get_next_property(
913  const afw_object_t *instance,
914  const afw_iterator_t **iterator,
915  const afw_utf8_t **property_name,
916  afw_xctx_t *xctx)
917 {
919  (afw_object_meta_object_t *)instance;
920  const afw_value_t *result;
921  const afw_utf8_t *next_property_name;
923 
924  if (!*iterator) {
925  *iterator = (afw_iterator_t *)afw_xctx_calloc_type(
927  if (!self->object_type || !self->object_type->object_type_object)
928  {
929  if (!self->delta) {
930  if (property_name) {
931  *property_name = NULL;
932  }
933  return NULL;
934  }
935  ((impl_get_next_property_iterator_t *)*iterator)->on_delta = true;
936  }
937  }
938  i = (impl_get_next_property_iterator_t *)* iterator;
939 
940  result = NULL;
941  if (!i->on_delta) {
942  for (;;) {
944  self->object_type->object_type_object,
945  &i->iterator, &next_property_name, xctx);
946  if (!result) {
947  if (!self->delta) {
948  if (property_name) {
949  *property_name = NULL;
950  }
951  return NULL;
952  }
953  i->on_delta = true;
954  i->iterator = NULL;
955  break;
956  }
957  if (self->delta &&
958  !afw_object_has_property(self->delta, next_property_name,
959  xctx))
960  {
961  if (property_name) {
962  *property_name = next_property_name;
963  }
964  return result;
965  }
966  }
967  }
968 
970  self->delta, &i->iterator, property_name, xctx);
971  return result;
972 }
973 
974 /*
975  * Implementation of method has_property for interface afw_object.
976  */
978 impl_afw_object_has_property(
979  const afw_object_t *instance,
980  const afw_utf8_t *property_name,
981  afw_xctx_t *xctx)
982 {
984  (afw_object_meta_object_t *)instance;
985  afw_boolean_t result;
986 
987  result = afw_object_has_property(self->delta, property_name, xctx);
988 
989  return result;
990 }
991 
992 /*
993  * Implementation of method get_setter for interface afw_object.
994  */
995 const afw_object_setter_t *
996 impl_afw_object_get_setter(
997  const afw_object_t *instance,
998  afw_xctx_t *xctx)
999 {
1000  afw_object_meta_object_t *self =
1001  (afw_object_meta_object_t *)instance;
1002 
1003  return &self->setter;
1004 }
1005 
1006 
1007 /*
1008  * Implementation of method set_immutable for interface afw_object_setter.
1009  */
1010 void
1012  const afw_object_setter_t * instance,
1013  afw_xctx_t *xctx)
1014 {
1016  AFW_THROW_ERROR_Z(general, "Method not implemented.", xctx);
1017 
1018 }
1019 
1020 /*
1021  * Implementation of method set_property for interface afw_object_setter.
1022  */
1023 void
1025  const afw_object_setter_t * instance,
1026  const afw_utf8_t * property_name,
1027  const afw_value_t * value,
1028  afw_xctx_t *xctx)
1029 {
1030  afw_object_meta_object_t *self =
1031  (afw_object_meta_object_t *)instance->object;
1032 
1033  if (afw_utf8_equal(property_name, &afw_s_path)) {
1036  self->pub.meta.embedding_object,
1037  &((const afw_value_anyURI_t *)value)->internal,
1038  xctx);
1039  }
1040 
1041  else {
1042  if (!self->delta) {
1043  self->delta = afw_object_create(self->pub.p, xctx);
1044  }
1045  afw_object_set_property(self->delta, property_name, value, xctx);
1046  }
1047 }
AFW_DEFINE(const afw_object_t *)
Adaptive Framework Core Internal.
Interface afw_interface implementation declares.
Interface afw_interface implementation declares.
afw_data_type_anyURI
Data type struct for anyURI.
#define afw_value_is_list_of_anyURI(A_VALUE)
Macro to determine if value is evaluated list of anyURI.
afw_list_of_anyURI_add(const afw_list_t *instance, const afw_utf8_t *value, afw_xctx_t *xctx)
Add value from list of anyURI.
afw_value_allocate_list(const afw_pool_t *p, afw_xctx_t *xctx)
Allocate function for unmanaged data type list value.
#define afw_object_old_get_property_as_list(object, property_name, xctx)
Get property function for data type list value.
afw_object_set_property_as_list(const afw_object_t *object, const afw_utf8_t *property_name, const afw_list_t *internal, afw_xctx_t *xctx)
Set property function for data type list values.
#define afw_value_is_object(A_VALUE)
Macro to determine if value is evaluated object.
afw_object_set_property_as_object(const afw_object_t *object, const afw_utf8_t *property_name, const afw_object_t *internal, afw_xctx_t *xctx)
Set property function for data type object values.
#define afw_object_old_get_property_as_object(object, property_name, xctx)
Get property function for data type object value.
#define afw_object_old_get_next_property_as_object(object, iterator, property_name, xctx)
Get next property function for data type object value.
afw_value_create_string(const afw_utf8_t *internal, const afw_pool_t *p, afw_xctx_t *xctx)
Create function for unmanaged data type string value.
#define afw_object_old_get_property_as_string(object, property_name, xctx)
Get property function for data type string value.
afw_data_type_string
Data type struct for string.
#define afw_list_of_string_get_next(list, iterator, xctx)
Get next value from list of string.
#define AFW_UTF8_FMT_ARG(A_STRING)
Convenience Macro for use with AFW_UTF8_FMT to specify arg.
Definition: afw_common.h:605
#define AFW_UTF8_Z_LEN
String is NUL (0) terminate.
Definition: afw_common.h:266
#define AFW_UTF8_CONTEXTUAL_LABEL_FMT
Format string used for source location.
Definition: afw_common.h:595
struct afw_iterator_s afw_iterator_t
#define AFW_INTEGER_FMT
Format string specifier used for afw_integer_t.
Definition: afw_common.h:326
_Bool afw_boolean_t
Definition: afw_common.h:373
#define AFW_UTF8_FMT
Format string specifier used for afw_utf8_t.
Definition: afw_common.h:588
apr_size_t afw_size_t
size_t.
Definition: afw_common.h:151
apr_int64_t afw_integer_t
typedef for big signed int.
Definition: afw_common.h:321
afw_error_to_utf8(const afw_error_t *error, const afw_pool_t *p, afw_xctx_t *xctx)
Convert error to utf8.
Definition: afw_error.c:547
#define AFW_THROW_ERROR_Z(code, message_z, xctx)
Macro used to set error and 0 rv in xctx and throw it.
Definition: afw_error.h:283
#define afw_flag_is_active(flag_index, xctx)
Determine if flag for flag index is set in xctx.
Definition: afw_flag.h:84
const afw_list_t * afw_list_create_or_clone(const afw_list_t *list, const afw_data_type_t *data_type, afw_boolean_t clone_values, const afw_pool_t *p, afw_xctx_t *xctx)
Create a clone of a list in memory.
const afw_list_t * afw_list_of_create_from_value(const afw_data_type_t *data_type, const afw_value_t *value, const afw_pool_t *p, afw_xctx_t *xctx)
Create a typed list from a value.
afw_list_add_value(const afw_list_t *instance, const afw_value_t *value, afw_xctx_t *xctx)
Call method add_value of interface afw_list_setter.
Definition: afw_list.c:104
#define afw_list_of_create(data_type, p, xctx)
Create an list of a specific data type in memory.
Definition: afw_list.h:64
#define AFW_LOG_FZ(priority, xctx, format_z,...)
Log an message to environment's log using a printf style format and parameters.
Definition: afw_log.h:192
void impl_afw_object_release(const afw_object_t *instance, afw_xctx_t *xctx)
const afw_value_t * impl_afw_object_get_property(const afw_object_t *instance, const afw_utf8_t *property_name, afw_xctx_t *xctx)
afw_size_t impl_afw_object_get_count(const afw_object_t *instance, afw_xctx_t *xctx)
#define afw_object_get_property(instance, property_name, xctx)
Call method get_property of interface afw_object.
#define afw_object_add_reference(instance, xctx)
Call method add_reference of interface afw_object.
#define afw_object_get_next_property(instance, iterator, property_name, xctx)
Call method get_next_property of interface afw_object.
#define afw_object_has_property(instance, property_name, xctx)
Call method has_property of interface afw_object.
#define afw_object_release(instance, xctx)
Call method release of interface afw_object.
#define afw_object_get_setter(instance, xctx)
Call method get_setter of interface afw_object.
afw_object_meta_get_object_id_value(const afw_object_t *instance, afw_xctx_t *xctx)
Get entity object's object id value.
afw_object_meta_set_object_type(const afw_object_t *instance, const afw_object_type_t *object_type, afw_xctx_t *xctx)
Set object's object type id.
afw_object_meta_add_thrown_error(const afw_object_t *instance, const afw_error_t *error, afw_xctx_t *xctx)
Add a thrown error to instance's meta.
afw_object_meta_get_property_type(const afw_object_t *instance, const afw_utf8_t *property_name, afw_xctx_t *xctx)
Get the property type object for an object's property from the meta of an object, creating it if need...
afw_object_meta_set_ids_using_path(const afw_object_t *instance, const afw_utf8_t *path, afw_xctx_t *xctx)
Set object's ids using path.
afw_object_meta_add_parent_path(const afw_object_t *instance, const afw_utf8_t *parent_path, afw_xctx_t *xctx)
Add a parent path to instance's meta.
afw_object_meta_set_parent_paths(const afw_object_t *instance, const afw_value_list_t *parent_paths, afw_xctx_t *xctx)
Set meta parentPaths property.
afw_object_meta_get_property_name(const afw_object_t *instance, afw_xctx_t *xctx)
Get object's property name in embedding object.
afw_object_meta_get_path(const afw_object_t *instance, afw_xctx_t *xctx)
Get an object's path.
afw_object_meta_get_nonempty_meta_object(const afw_object_t *instance, afw_xctx_t *xctx)
Return meta object for an object creating an empty one if needed.
afw_object_meta_set_object_type_id(const afw_object_t *instance, const afw_utf8_t *object_type_id, afw_xctx_t *xctx)
Set object's object type id.
afw_object_meta_get_nonempty_delta(const afw_object_t *instance, afw_xctx_t *xctx)
Return meta delta object for an object creating an empty one if needed.
afw_object_meta_set_read_only(const afw_object_t *instance, afw_xctx_t *xctx)
Set object's meta to indicate object is read-only.
afw_object_meta_add_error(const afw_object_t *instance, const afw_utf8_t *message, afw_xctx_t *xctx)
Add an error message to instance's meta.
#define afw_object_meta_object(instance)
Return meta object for an object or NULL if there is not one.
afw_object_meta_clone_and_set(const afw_object_t *instance, const afw_object_t *from, afw_xctx_t *xctx)
Set object's meta using a clone of the meta of another object.
afw_object_meta_get_parent_paths_value(const afw_object_t *instance, afw_xctx_t *xctx)
Get meta parentPaths property value.
afw_object_meta_add_property_error(const afw_object_t *instance, const afw_utf8_t *property_name, const afw_utf8_t *message, afw_xctx_t *xctx)
Add an error message for a property to instance's meta.
afw_object_meta_add_needed_object_type(const afw_object_t *instance, const afw_object_t *object_type, afw_xctx_t *xctx)
Add a needed object type object.
afw_object_meta_set_meta_object(const afw_object_t *instance, const afw_object_t *meta, afw_xctx_t *xctx)
Set an object's meta from a meta object.
afw_object_meta_set_empty(const afw_object_t *instance, afw_xctx_t *xctx)
Create and set object's meta to an empty object and return delta.
afw_object_meta_has_errors(const afw_object_t *instance, afw_xctx_t *xctx)
Check if object flagged for errors.
afw_object_meta_log_errors(const afw_object_t *instance, const afw_utf8_t *source_location, afw_xctx_t *xctx)
Log meta errors.
afw_object_meta_add_thrown_property_error(const afw_object_t *instance, const afw_utf8_t *property_name, afw_integer_t index, const afw_error_t *error, afw_xctx_t *xctx)
Add a thrown error for a property to instance's meta.
#define afw_object_meta_set_property(instance, property_name, value, xctx)
Set a property in the meta of an object.
afw_object_meta_set_ids(const afw_object_t *instance, const afw_utf8_t *adaptor_id, const afw_utf8_t *object_type_id, const afw_utf8_t *object_id, afw_xctx_t *xctx)
Set object's ids.
afw_object_meta_get_object_id(const afw_object_t *instance, afw_xctx_t *xctx)
Get entity object's object id.
afw_object_path_parse(const afw_utf8_t *path, const afw_utf8_t *current_path, const afw_object_options_t *default_options, const afw_pool_t *p, afw_xctx_t *xctx)
Parse an object value path in specific pool.
afw_object_path_make_for_embedded(const afw_object_t *embedded_object, const afw_pool_t *p, afw_xctx_t *xctx)
Construct the path for an embedded object.
afw_object_path_make(const afw_utf8_t *adaptor_id, const afw_utf8_t *object_type_id, const afw_utf8_t *object_id, const afw_pool_t *p, afw_xctx_t *xctx)
Construct an object path in a specified pool.
afw_object_path_parse_simple(const afw_utf8_t *path, const afw_utf8_t **adaptor_id, const afw_utf8_t **object_type_id, const afw_utf8_t **object_id, const afw_pool_t *p, afw_xctx_t *xctx)
Parse simple path into ids.
void impl_afw_object_setter_set_immutable(const afw_object_setter_t *instance, afw_xctx_t *xctx)
void impl_afw_object_setter_set_property(const afw_object_setter_t *instance, const afw_utf8_t *property_name, const afw_value_t *value, afw_xctx_t *xctx)
#define AFW_OBJECT_ASSERT_ENTITY(instance, xctx)
Asserts that an object is an entity.
Definition: afw_object.h:172
afw_object_create_clone(const afw_object_t *object, const afw_pool_t *p, afw_xctx_t *xctx)
Clone an object to a specified pool.
Definition: afw_memory.c:138
afw_object_old_get_property_as_utf8(const afw_object_t *instance, const afw_utf8_t *property_name, const afw_pool_t *p, afw_xctx_t *xctx)
Get an object's property value as a string in specified pool.
Definition: afw_object.c:531
#define afw_object_create(p, xctx)
Create an empty unmanaged object in memory.
Definition: afw_object.h:948
const afw_object_t * afw_object_get_entity(const afw_object_t *object, afw_xctx_t *xctx)
Get entity for object.
Definition: afw_object.h:443
afw_object_old_get_property_as_boolean_deprecated(const afw_object_t *instance, const afw_utf8_t *property_name, afw_xctx_t *xctx)
Get an object's property value as a boolean.
Definition: afw_object.c:436
afw_object_set_property(const afw_object_t *instance, const afw_utf8_t *property_name, const afw_value_t *value, afw_xctx_t *xctx)
Set the value of an object's property.
Definition: afw_object.c:46
const afw_object_t * afw_object_create_embedded(const afw_object_t *embedding_object, const afw_utf8_t *property_name, afw_xctx_t *xctx)
Create an empty embedded object in a memory object.
#define afw_pool_calloc_type(instance, type, xctx)
Macro to allocate cleared memory to hold type in pool.
Definition: afw_pool.h:167
#define afw_utf8_create_copy(s, len, p, xctx)
Make a utf-8 sting from chars in pool specified.
Definition: afw_utf8.h:369
afw_boolean_t afw_utf8_equal(const afw_utf8_t *s1, const afw_utf8_t *s2)
Check to see if a string equals another string.
const afw_utf8_t * afw_utf8_clone(const afw_utf8_t *string, const afw_pool_t *p, afw_xctx_t *xctx)
Clone a utf-8 string into a specific pool.
Definition: afw_utf8.h:347
afw_utf8_printf(const afw_pool_t *p, afw_xctx_t *xctx, const afw_utf8_z_t *format,...)
Create a utf-8 string using a c format string in specified pool.
Definition: afw_utf8.c:459
#define AFW_VALUE_ASSERT_IS_ANYURI_OR_STRING(A_VALUE, A_SCOPE)
Throw and error if A_VALUE is not anyURI or string.
Definition: afw_value.h:777
afw_value_false
Adaptive value false.
Definition: afw_value.h:354
afw_value_true
Adaptive value true.
Definition: afw_value.h:348
#define afw_xctx_calloc_type(type, xctx)
Macro to allocate cleared memory to hold type in xctx's pool.
Definition: afw_xctx.h:199
Adaptive Framework Error.
Definition: afw_error.h:65
Interface afw_list public struct.
const afw_utf8_t * id
Object id or property name.
Definition: afw_common.h:782
const afw_object_t * embedding_object
Embedding object.
Definition: afw_common.h:768
const afw_utf8_t * object_type_uri
Object type object URI or NULL.
Definition: afw_common.h:796
const afw_object_t * meta_object
Meta object.
Definition: afw_common.h:761
Typedef for parsed object path.
Interface afw_object public struct.
Interface afw_object_setter public struct.
Struct for afw_object_type_t.
Interface afw_pool public struct.
NFC normalized UTF-8 string.
Definition: afw_common.h:545
struct for data type anyURI values.
struct for data type list values.
struct for data type object values.
Interface afw_value public struct.
struct for data type string values.
Interface afw_xctx public struct.