making class handling more generic
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 2 Aug 2005 20:36:46 +0000 (20:36 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 2 Aug 2005 20:36:46 +0000 (20:36 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@1587 dcc99617-32d9-48b4-a31d-7c20da2025e4

OpenSRF/src/gateway/fieldmapper-c-xml-out.pl

index 7f7ef3e..eccc63a 100755 (executable)
@@ -85,61 +85,108 @@ void _rest_xml_output(growing_buffer* buf, object* obj, char * fm_class, int fm_
        }
         
         /* add class hints if we have a class name */
-        if(obj->classname)
-                buffer_fadd(buf,"<Fieldmapper hint=\\\"%s\\\">", obj->classname);
+        if(obj->classname) {
+               if(obj->is_null) {
+                       buffer_fadd(buf,"<Object class_hint=\\\"%s\\\"/>", obj->classname);
+                       return;
+               } else {
+                       buffer_fadd(buf,"<Object class_hint=\\\"%s\\\">", obj->classname);
+               }
+       }
 
        /* now add the data */
-        if(obj->is_null)
+       if(obj->is_null)
                buffer_fadd(buf, "<%s/>",tag);
                 
-        else if(obj->is_bool && obj->bool_value)
-               buffer_fadd(buf, "<%s>true</%s>",tag,tag);
+       else if(obj->is_bool && obj->bool_value) {
+               if (obj->classname)
+                       buffer_add(buf, "true");
+               else
+                       buffer_fadd(buf, "<%s>true</%s>",tag,tag);
                 
-        else if(obj->is_bool && ! obj->bool_value)
-               buffer_fadd(buf, "<%s>false</%s>",tag,tag);
+       } else if(obj->is_bool && ! obj->bool_value) {
+               if (obj->classname)
+                       buffer_add(buf, "false");
+               else
+                       buffer_fadd(buf, "<%s>false</%s>",tag,tag);
 
-       else if (obj->is_string)
-                buffer_fadd(buf,"<%s>%s</%s>",tag,obj->string_data,tag);
+       } else if (obj->is_string) {
+               if (obj->classname)
+                       buffer_add(buf,"%s",obj->string_data);
+               else
+                       buffer_fadd(buf,"<%s>%s</%s>",tag,obj->string_data,tag);
 
-        else if(obj->is_number)
-                buffer_fadd(buf,"<%s>%ld</%s>",tag,obj->num_value,tag);
+       } else if(obj->is_number) {
+               if (obj->classname)
+                       buffer_add(buf,"%ld",obj->num_value);
+               else
+                       buffer_fadd(buf,"<%s>%ld</%s>",tag,obj->num_value,tag);
 
-        else if(obj->is_double)
-                buffer_fadd(buf,"<%s>%lf</%s>",tag,obj->double_value,tag);
+       } else if(obj->is_double) {
+               if (obj->classname)
+                       buffer_fadd(buf,"%lf",tag,obj->double_value,tag);
+               else
+                       buffer_fadd(buf,"<%s>%lf</%s>",tag,obj->double_value,tag);
 
 
-       else if (obj->is_array) {
-               if(!fm_class)
-                               buffer_add(buf,"<array>");
-               else
-                               buffer_fadd(buf,"<%s>",tag);
+       } else if (obj->is_array) {
+               if(!obj->classname) {
+                       if(!fm_class)
+                               buffer_add(buf,"<array>");
+                       else
+                                       buffer_fadd(buf,"<%s>",tag);
+               }
 
                for( i = 0; i!= obj->size; i++ ) {
                        _rest_xml_output(buf, obj->get_index(obj,i), obj->classname, i);
                }
 
-               if(!fm_class)
-                               buffer_add(buf,"</array>");
-               else
-                               buffer_fadd(buf,"</%s>",tag);
+               if(!obj->classname) {
+                       if(!fm_class)
+                               buffer_add(buf,"</array>");
+                       else
+                                       buffer_fadd(buf,"</%s>",tag);
+               }
 
         } else if (obj->is_hash) {
-                       buffer_add(buf,"<hash>");
+
+                       if(!obj->classname) {
+                       if(!fm_class)
+                               buffer_add(buf,"<hash>");
+                       else
+                                       buffer_fadd(buf,"<%s>",tag);
+               }
+
                 object_iterator* itr = new_iterator(obj);
                 object_node* tmp;
                 while( (tmp = itr->next(itr)) ) {
-                               buffer_add(buf,"<pair>");
-                        buffer_fadd(buf,"<key>%s</key>",tmp->key);
+                       if (obj->classname) {
+                               buffer_fadd(buf,"<%s>",tmp->key);
+                       } else {
+                               buffer_add(buf,"<pair>");
+                               buffer_fadd(buf,"<key>%s</key><value>",tmp->key);
+                       }
+
                         _rest_xml_output(buf, tmp->item, NULL,0);
-                               buffer_add(buf,"</pair>");
+
+                       if (obj->classname) {
+                               buffer_fadd(buf,"</%s>",tmp->key);
+                       } else {
+                               buffer_add(buf,"</value></pair>");
+                       }
                 }
                 free_iterator(itr);
-                       buffer_add(buf,"</hash>");
-        }
+               if(!obj->classname) {
+                       if(!fm_class)
+                               buffer_add(buf,"</hash>");
+                       else
+                                       buffer_fadd(buf,"</%s>",tag);
+               }
 
+       }
 
         if(obj->classname)
-                buffer_add(buf,"</Fieldmapper>");
+                buffer_add(buf,"</Object>");
 }
 
 char * _lookup_fm_field(char * class, int pos) {