1 /*
2  * Portions of this file Copyright 1999-2005 University of Chicago
3  * Portions of this file Copyright 1999-2005 The University of Southern California.
4  *
5  * This file or a portion of this file is licensed under the
6  * terms of the Globus Toolkit Public License, found at
7  * http://www.globus.org/toolkit/download/license.html.
8  * If you redistribute this file, with or without
9  * modifications, you must include this notice in the file.
10  */
11
12
13 #include "globus_common.h"
14 #include "libxml/xmlschemas.h"
15 #include "libxml/schemasInternals.h"
16 #include "libxml/uri.h"
17
18 #include "wsdl.h"
19
20 #include "globus_wsdl_template.h"
21 #include "globus_i_wsdl_parser.h"
22 #include "globus_wsdl_config.h"
23
24 #include "js/jsstddef.h"
25 #include <errno.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include "js/jstypes.h"
30 #include "js/jsarena.h"
31 #include "js/jsutil.h"
32 #include "js/jsprf.h"
33 #include "js/jsapi.h"
34 #include "js/jsatom.h"
35 #include "js/jscntxt.h"
36 #include "js/jsdbgapi.h"
37 #include "js/jsemit.h"
38 #include "js/jsfun.h"
39 #include "js/jsgc.h"
40 #include "js/jslock.h"
41 #include "js/jsobj.h"
42 #include "js/jsparse.h"
43 #include "js/jsscope.h"
44 #include "js/jsscript.h"
45
46 #include <sys/types.h>
47 #include <sys/stat.h>
48 #include <errno.h>
49
50 #ifdef WIN32
51 #define FILE_SEPARATOR "\\"
52 #else
53 #define FILE_SEPARATOR "/"
54 #endif
55
56 #define GLOBUS_L_WSDL_JSCRIPT_UNBOUNDED (1 << 30)
57
58 size_t                                  gStackChunkSize = 8192;
59
60 typedef struct _StreamContext           StreamContext;
61 struct _StreamContext
62 {
63     FILE *                              error_stream;
64     FILE *                              out_stream;
65     StreamContext *                     next;
66 };
67
68 typedef struct _Template                Template;
69 struct _Template
70 {
71     char *                              filename;
72     char *                              buffer;
73     size_t                              length;
74 };
75
76 typedef struct _PrivateContext          PrivateContext;
77 struct _PrivateContext
78 {
79     StreamContext *                     streams;
80     globus_result_t                     result;
81     globus_hashtable_t                  nsmap;
82     int                                 free_nsmap;
83     globus_hashtable_t                  templates;
84     char *                              outdir;
85     globus_list_t *                     template_paths;
86 };
87
88 static
89 void TemplateFree(
90     void *                              template);
91
92 static JSBool
93 LoadTemplate(
94     JSContext *                         ctx,
95     JSObject *                          obj,
96     uintN                               argc,
97     jsval *                             argv,
98     jsval *                             rval);
99
100 static JSBool
101 FileExists(
102     JSContext *                         ctx,
103     JSObject *                          obj,
104     uintN                               argc,
105     jsval *                             argv,
106     jsval *                             rval);
107
108 static JSBool
109 CreateSubDir(
110     JSContext *                         ctx,
111     JSObject *                          obj,
112     uintN                               argc,
113     jsval *                             argv,
114     jsval *                             rval);
115
116 static JSBool
117 URIBasePath(
118     JSContext *                         ctx,
119     JSObject *                          obj,
120     uintN                               argc,
121     jsval *                             argv,
122     jsval *                             rval);
123          
124 static JSBool
125 NamespaceToPrefix(
126     JSContext *                         cx,
127     JSObject *                          obj,
128     uintN                               argc,
129     jsval *                             argv,
130     jsval *                             rval);
131
132 static JSBool
133 Debug(
134     JSContext *                         cx,
135     JSObject *                          obj,
136     uintN                               argc,
137     jsval *                             argv,
138     jsval *                             rval);
139
140 static JSBool
141 Abort(
142     JSContext *                         cx,
143     JSObject *                          obj,
144     uintN                               argc,
145     jsval *                             argv,
146     jsval *                             rval);
147
148 static JSBool
149 Print(
150     JSContext *                         cx,
151     JSObject *                          obj,
152     uintN                               argc,
153     jsval *                             argv,
154     jsval *                             rval);
155
156 static JSBool
157 Error(
158     JSContext *                         cx,
159     JSObject *                          obj,
160     uintN                               argc,
161     jsval *                             argv,
162     jsval *                             rval);
163
164 static JSBool
165 CanonicalizeString(
166     JSContext *                         cx,
167     JSObject *                          obj,
168     uintN                               argc,
169     jsval *                             argv,
170     jsval *                             rval);
171
172 #define DEF_GET_PROP(_PREFIX_)                                  \
173     static JSBool                                               \
174     _PREFIX_ ## Getter(                                         \
175         JSContext *                     cx,                     \
176         JSObject *                      obj,                    \
177         jsval                           id,                     \
178         jsval *                         vp)
179
180 #define DEF_ENUM_PROP(_PREFIX_)                         \
181     static JSBool                                       \
182     _PREFIX_ ## Enumerate(                              \
183         JSContext *                     cx,             \
184         JSObject *                      obj,            \
185         JSIterateOp                     enum_op,        \
186         jsval *                         statep,         \
187         jsid *                          idp)
188
189 #define DEF_CLASS(_PREFIX_)                                             \
190     static JSClass _PREFIX_ ## _class =                                 \
191     {                                                                   \
192         #_PREFIX_,             JSCLASS_HAS_PRIVATE|JSCLASS_NEW_RESOLVE, \
193         JS_PropertyStub,       JS_PropertyStub,                         \
194         _PREFIX_ ## Getter,    JS_PropertyStub,                         \
195         JS_EnumerateStub,      JS_ResolveStub,                          \
196         JS_ConvertStub,        JS_FinalizeStub                          \
197     };                                                                  \
198     static JSObject * _PREFIX_ ## Class
199
200 #define DEF_LISTCLASS(_PREFIX_)                                 \
201     static JSClass _PREFIX_ ## _class =                         \
202     {                                                           \
203         #_PREFIX_, JSCLASS_NEW_ENUMERATE|JSCLASS_HAS_PRIVATE,   \
204         JS_PropertyStub,       JS_PropertyStub,                 \
205         _PREFIX_ ## Getter,    JS_PropertyStub,                 \
206         (JSEnumerateOp) _PREFIX_ ## Enumerate,                  \
207         JS_ResolveStub,                                         \
208         JS_ConvertStub,        JS_FinalizeStub                  \
209     }
210
211 #define DEF_PROPS(_PREFIX_)                             \
212     extern JSPropertySpec _PREFIX_ ## _properties[]
213
214 #define DEF_LIST(_PREFIX_)                      \
215     DEF_ENUM_PROP(_PREFIX_);                    \
216     DEF_GET_PROP(_PREFIX_);                     \
217     DEF_LISTCLASS(_PREFIX_)
218
219 #define DEF_OBJECT(_PREFIX_)                    \
220     DEF_GET_PROP(_PREFIX_);                     \
221     DEF_PROPS(_PREFIX_);                        \
222     DEF_CLASS(_PREFIX_)
223
224 DEF_OBJECT(xsdType);
225 DEF_OBJECT(xsdAttr);
226 DEF_OBJECT(xsdElement);
227 DEF_OBJECT(xsdWildcard);
228 DEF_OBJECT(xsdFacet);
229
230 DEF_OBJECT(xsdQName);
231 DEF_OBJECT(part);
232 DEF_OBJECT(operation);
233 DEF_OBJECT(binding);
234 DEF_OBJECT(portType);
235 DEF_OBJECT(message);
236 DEF_OBJECT(param);
237 DEF_OBJECT(fault);
238 DEF_OBJECT(port);
239 DEF_OBJECT(service);
240 DEF_OBJECT(bindingOperation);
241 DEF_OBJECT(bindingOperationFault);
242
243 DEF_OBJECT(soapBinding);
244 DEF_OBJECT(soapOperation);
245 DEF_OBJECT(soapBindingParam);
246 DEF_OBJECT(soapBody);
247 DEF_OBJECT(soapFault);
248 DEF_OBJECT(soapHeader);
249 DEF_OBJECT(soapAddress);
250
251 DEF_GET_PROP(xsdEnum);
252 DEF_CLASS(xsdEnum);
253
254 DEF_PROPS(xsdTypeEnum);
255 DEF_PROPS(xsdContentTypeEnum);
256 DEF_PROPS(xsdAttrEnum);
257 DEF_PROPS(operationTypeEnum);
258 DEF_PROPS(bindingType);
259 DEF_PROPS(soapOperationStyleType);
260 DEF_PROPS(soapUseType);
261
262 DEF_LIST(xsdSubTypes);
263 DEF_LIST(xsdAttrs);
264 DEF_LIST(xsdQNames);
265 DEF_LIST(parts);
266 DEF_LIST(operations);
267 DEF_LIST(faults);
268 DEF_LIST(ports);
269 DEF_LIST(bindingOperations);
270 DEF_LIST(bindingOperationFaults);
271 DEF_LIST(xsdFacets);
272
273 static void
274 internal_ErrorReporter(
275     JSContext *                         cx,
276     const char *                        message,
277     JSErrorReport *                     report);
278
279 static JSFunctionSpec functions_defs[] = 
280 {
281     {"load",                 LoadTemplate,       0},
282     {"file_exists",          FileExists,         0},
283     {"uri_base_path",        URIBasePath,        0},
284     {"create_subdir",        CreateSubDir,       0},
285     {"debug",                Debug,              0},
286     {"abort",                Abort,              0},
287     {"error",                Error,              0},
288     {"print",                Print,              0},
289     {"canonical",            CanonicalizeString, 0},
290     {"NStoP",                NamespaceToPrefix,  0},
291     {0}
292 };
293
294 static JSClass global_class = 
295 {
296     "global", JSCLASS_NEW_RESOLVE,
297     JS_PropertyStub,  JS_PropertyStub,
298     JS_PropertyStub,  JS_PropertyStub,
299     JS_EnumerateStub, JS_ResolveStub,
300     JS_ConvertStub,   JS_FinalizeStub
301 };
302
303 static JSClass basic_class =
304 {
305     "basic", JSCLASS_NEW_RESOLVE,
306     JS_PropertyStub,  JS_PropertyStub,
307     JS_PropertyStub,  JS_PropertyStub,
308     JS_EnumerateStub, JS_ResolveStub,
309     JS_ConvertStub,   JS_FinalizeStub
310 };
311
312 typedef struct _ScannerData             ScannerData;
313 struct _ScannerData
314 {
315     wsdlSchemaPtr                       schema;
316     xmlSchemaPtr                        xsdSchema;
317     JSContext *                         context;
318     JSObject *                          global;
319     JSObject *                          types;
320     JSObject *                          elements;
321     JSObject *                          local_elements;
322     JSObject *                          attributes;
323     JSObject *                          local_attributes;
324     JSObject *                          messages;
325     JSObject *                          portTypes;
326     JSObject *                          bindings;
327     JSObject *                          services;
328     globus_result_t                     result;
329 };
330
331 static
332 void
333 globus_i_wsdl_parser_import_scanner(
334     void *                              payload,
335     void *                              data,
336     xmlChar *                           name);
337
338 static
339 void
340 globus_i_wsdl_parser_type_scanner(
341     void *                              payload,
342     void *                              data,
343     xmlChar *                           name);
344
345 static
346 void
347 globus_i_wsdl_parser_element_scanner(
348     void *                              payload,
349     void *                              data,
350     xmlChar *                           name);
351
352 static
353 void
354 globus_i_wsdl_parser_attribute_scanner(
355     void *                              payload,
356     void *                              data,
357     xmlChar *                           name);
358
359 static
360 void
361 globus_i_wsdl_parser_message_scanner(
362     void *                              payload,
363     void *                              data,
364     xmlChar *                           name);
365
366 static
367 void
368 globus_i_wsdl_parser_portType_scanner(
369     void *                              payload,
370     void *                              data,
371     xmlChar *                           name);
372
373 static
374 void
375 globus_i_wsdl_parser_binding_scanner(
376     void *                              payload,
377     void *                              data,
378     xmlChar *                           name);
379
380 static
381 void
382 globus_i_wsdl_parser_service_scanner(
383     void *                              payload,
384     void *                              data,
385     xmlChar *                           name);
386
387 static
388 void
389 globus_i_wsdl_parser_wsdl_imports_scanner(
390     void *                              payload,
391     void *                              data,
392     xmlChar *                           name);
393
394 static
395 globus_result_t
396 globus_i_wsdl_js_load_schema(
397     JSContext *                         cx,
398     wsdlSchemaPtr                       schema);
399
400 static 
401 globus_result_t
402 globus_i_wsdl_execute_script(
403     JSContext *                         ctx,
404     JSObject *                          glob,
405     const char *                        tmpl_filename,
406     const char *                        out_filename,
407     const char *                        out_dir,
408     globus_hashtable_t                  nsmap,
409     globus_list_t *                     template_paths);
410
411 static
412 JSString *
413 globus_l_wsdl_jscript_qname_string(
414     JSContext *                         ctx,
415     const char *                        href,
416     const char *                        local);
417
418 static
419 void
420 globus_i_wsdl_parser_classes_init(
421     JSContext *                         cx,
422     JSObject *                          glob)
423 17 {
424 17     xsdTypeClass = JS_InitClass(cx, glob, NULL, &xsdType_class, NULL, 0,
425                                 xsdType_properties, NULL, NULL, NULL);
426
427 17     xsdElementClass = JS_InitClass(cx, glob, NULL, &xsdElement_class, NULL, 0,
428                                    xsdElement_properties, NULL, NULL, NULL);
429
430 17     xsdAttrClass = JS_InitClass(cx, glob, NULL, &xsdAttr_class, NULL, 0,
431                                 xsdAttr_properties, NULL, NULL, NULL);
432
433 17     xsdWildcardClass = JS_InitClass(cx, glob, NULL, &xsdWildcard_class, NULL, 0,
434                                     xsdWildcard_properties, NULL, NULL, NULL);
435
436 17     xsdFacetClass = JS_InitClass(cx, glob, NULL, &xsdFacet_class, NULL, 0,
437                                  xsdFacet_properties, NULL, NULL, NULL);
438
439 17     messageClass = JS_InitClass(cx, glob, NULL, &message_class, NULL, 0,
440                                 message_properties, NULL, NULL, NULL);
441
442 17     portTypeClass = JS_InitClass(cx, glob, NULL, &portType_class, NULL, 0,
443                                 portType_properties, NULL, NULL, NULL);
444
445 17     operationClass = JS_InitClass(cx, glob, NULL, &operation_class, NULL, 0,
446                                   operation_properties, NULL, NULL, NULL);
447
448 17     bindingClass = JS_InitClass(cx, glob, NULL, &binding_class, NULL, 0,
449                                 binding_properties, NULL, NULL, NULL);
450
451 17     serviceClass = JS_InitClass(cx, glob, NULL, &service_class, NULL, 0,
452                                 service_properties, NULL, NULL, NULL);
453
454 17     bindingOperationClass = JS_InitClass(cx, glob, NULL, 
455                                          &bindingOperation_class, NULL, 0,
456                                          bindingOperation_properties, 
457                                          NULL, NULL, NULL);
458
459 17     soapBindingClass = JS_InitClass(cx, glob, NULL, &soapBinding_class, NULL, 0,
460                                     soapBinding_properties, NULL, NULL, NULL);
461
462 17     soapOperationClass = JS_InitClass(cx, glob, NULL, &soapOperation_class, 
463                                       NULL, 0, soapOperation_properties, 
464                                       NULL, NULL, NULL);
465
466 }
467
468 static JSBool
469 URIBasePath(
470     JSContext *                         cx, 
471     JSObject *                          obj, 
472     uintN                               argc,
473     jsval *                             argv,
474     jsval *                             rval)
475 7 {
476 7     char *                              uri_base_path;
477 7     JSString *                          str;
478 7     char *                              uri_string;
479 7     xmlURIPtr                           uri_handle;
480 7     JSBool                              res = JS_TRUE;
481 7     GlobusFuncName(URIBasePath);
482 7     GlobusWSDLDebugEnter();
483
484 7     if(argc < 1)
485     {
486 0         JS_ReportError(cx, 
487                        "Wrong number of arguments "
488                        "passed to function: %s",
489                        argc, 2, "load(template, outfile)");
490 0         res = JS_FALSE;
491 0         goto exit;
492     }
493
494 7     str = JS_ValueToString(cx, argv[0]);
495 7     if(!str)
496     {
497 0         JS_ReportError(cx,
498                        "Failed to load template");
499 0         res = JS_FALSE;
500 0         goto exit;
501     }
502     
503 7     uri_string = globus_common_create_string("%*s", 
504                                              JS_GetStringLength(str),
505                                              JS_GetStringBytes(str));
506     
507 7     uri_handle = xmlParseURI(uri_string);
508 7     if(!uri_handle)
509     {
510 0         JS_ReportError(cx, "Failed to parse uri: %s", uri_string);
511 0         res = JS_FALSE;
512 0         goto exit;
513     }
514
515 7     uri_base_path = uri_handle->path;
516 14     while((*uri_base_path) == '/')
517     {
518 7         ++uri_base_path;
519     }
520
521 7     str = JS_InternString(cx, uri_base_path);
522 7     *rval = STRING_TO_JSVAL(str);
523
524  exit:
525 7     GlobusWSDLDebugExit();
526 7     return res;
527 }
528
529 static JSBool
530 CreateSubDir(
531     JSContext *                         cx, 
532     JSObject *                          obj, 
533     uintN                               argc,
534     jsval *                             argv,
535     jsval *                             rval)
536 5 {
537 5     JSString *                          str;
538 5     char *                              dir_string;
539 5     JSBool                              res = JS_TRUE;
540 5     PrivateContext *                    private = NULL;
541 5     GlobusFuncName(CreateSubDir);
542 5     GlobusWSDLDebugEnter();
543
544 5     if(argc < 1)
545     {
546 0         JS_ReportError(cx, 
547                        "Wrong number of arguments "
548                        "passed to function: %s",
549                        argc, 2, "load(template, outfile)");
550 0         res = JS_FALSE;
551 0         goto exit;
552     }
553
554 5     private = (PrivateContext *) JS_GetContextPrivate(cx);
555
556 5     str = JS_ValueToString(cx, argv[0]);
557 5     if(!str)
558     {
559 0         JS_ReportError(cx,
560                        "Failed to load template");
561 0         res = JS_FALSE;
562 0         goto exit;
563     }
564     
565 5     dir_string = globus_common_create_string(
566         "%s%s%*s", 
567         (private->outdir ? private->outdir : ""),
568         (private->outdir ? FILE_SEPARATOR : ""),
569         (int) JS_GetStringLength(str),
570         JS_GetStringBytes(str));
571     
572 5     if(mkdir(dir_string, 00770) < 0)
573     {
574 4         if(errno != EEXIST)
575         {
576 0             globus_object_t *           errobj;
577 0             char *                      errstr;
578
579 0             errobj = globus_error_wrap_errno_error(
580                     GLOBUS_WSDL_PARSER_MODULE,
581                     errno,
582                     GLOBUS_WSDL_ERROR_JSRUNTIME,
583                     __FILE__,
584                     _globus_func_name,
585                     __LINE__,
586                     "Failed to create directory: %s",
587                     dir_string); 
588 0             errstr = globus_error_print_friendly(errobj);
589 0             globus_object_free(errobj);
590 0             JS_ReportError(cx, "subdir %s creation failed:%d:%s", 
591                            dir_string, errno, errstr);
592 0             globus_free(errstr);
593 0             free(dir_string);
594 0             res = JS_FALSE;
595 0             goto exit;
596         }
597     }
598
599 5     free(dir_string);
600
601 5     *rval = JSVAL_NULL;
602
603  exit:
604 5     GlobusWSDLDebugExit();
605 5     return res;
606 }
607
608 static JSBool
609 LoadTemplate(
610     JSContext *                         cx, 
611     JSObject *                          obj, 
612     uintN                               argc,
613     jsval *                             argv,
614     jsval *                             rval)
615 1248 {
616 1248     char *                              script_buffer = NULL;
617 1248     size_t                              script_length = 0;
618 1248     jsval                               result;
619 1248     JSBool                              res = JS_TRUE;
620 1248     char *                              error = NULL;
621 1248     char *                              path = NULL;
622 1248     JSString *                          str;
623 1248     char                                filename[500];
624 1248     char                                out_filename[500];
625 1248     FILE *                              out_stream = NULL;
626 1248     PrivateContext *                    private = NULL;
627 1248     Template *                          template = NULL;
628 1248     StreamContext *                     new_streams = NULL;
629 1248     StreamContext *                     tmp_streams = NULL;
630 1248     globus_list_t *                     paths = NULL;
631 1248     struct stat                         statbuf;
632 1248     int                                 filename_found = 0;
633 1248     GlobusFuncName(LoadTemplate);
634 1248     GlobusWSDLDebugEnter();
635
636 1248     if(argc < 1)
637     {
638 0         JS_ReportError(cx, 
639                        "Wrong number of arguments "
640                        "passed to function: %s",
641                        argc, 2, "load(template, outfile)");
642 0         res = JS_FALSE;
643 0         goto exit;
644     }
645
646 1248     str = JS_ValueToString(cx, argv[0]);
647 1248     if(!str)
648     {
649 0         JS_ReportError(cx,
650                        "Failed to load template");
651 0         res = JS_FALSE;
652 0         goto exit;
653     }
654     
655 1248     private = (PrivateContext *) JS_GetContextPrivate(cx);
656 1248     paths = private->template_paths;
657
658 2513     while(paths)
659     {
660 2496         path = globus_list_first(paths);
661 2496         sprintf(filename, "%s/%*s", 
662                 path, (int) JS_GetStringLength(str), 
663                 JS_GetStringBytes(str));
664         
665 2496         if(private->templates)
666         {
667 2462             template = globus_hashtable_lookup(&private->templates, filename);
668 2462             if(template)
669             {
670 1003                 filename_found = 1;
671 1003                 break;
672             }
673         }
674
675 1493         if(stat(filename, &statbuf))
676         {
677 1265             if(errno != ENOENT)
678             {
679 0                 char *                      errstr;
680 0                 result = GlobusWSDLErrorAccessingTemplateFile(errno, filename);
681 0                 errstr = globus_error_print_chain(globus_error_get(result));
682                 
683 0                 JS_ReportError(cx, errstr);
684 0                 res = JS_FALSE;
685 0                 goto exit;
686             }
687         }
688         else
689         {
690 228             filename_found = 1;
691 228             break;
692         }
693                 
694 1265         paths = globus_list_rest(paths);
695     }
696
697 1248     if(!filename_found)
698     {
699 17         sprintf(filename, "%*s", (int) JS_GetStringLength(str), JS_GetStringBytes(str));
700 17         if(private->templates)
701         {
702 0             template = globus_hashtable_lookup(&private->templates, filename);
703         }
704     }
705
706 1248     if(!template)
707     {
708 245         if(stat(filename, &statbuf))
709         {
710 0             char *                      errstr;
711 0             result = GlobusWSDLErrorAccessingTemplateFile(errno, filename);
712 0             errstr = globus_error_print_chain(globus_error_get(result));
713
714 0             JS_ReportError(cx, errstr);
715 0             res = JS_FALSE;
716 0             goto exit;
717         }
718
719 245         res = globus_wsdl_template_get_jsbuf(
720             (const char *) filename, &script_buffer, &script_length, &error,
721             '@', '$');
722 245         if(res != 0)
723         {
724 0             if(error)
725             {
726 0                 JS_ReportError(cx, "%s", error);
727 0                 free(error);
728             }
729 0             res = JS_FALSE;
730 0             goto exit;
731         }
732         
733 245         GlobusWSDLDebugPrintf(GLOBUS_WSDL_DEBUG_TEMPLATE,
734                               ("TEMPLATE BUFFER:"
735                                "\n----------------------\n"));
736 245         GlobusWSDLDebugWrite(GLOBUS_WSDL_DEBUG_TEMPLATE,
737                              script_length, script_buffer);
738 245         GlobusWSDLDebugPrintf(GLOBUS_WSDL_DEBUG_TEMPLATE,
739                               ("\n----------------------\n"));
740         
741 245         template = globus_malloc(sizeof(Template));
742 245         if(!template)
743         {
744 0             JS_ReportError(cx,
745                            "Memory allocation failed.");
746 0             res = JS_FALSE;
747 0             goto exit;
748         }
749 245         template->filename = globus_libc_strdup(filename);
750 245         template->buffer = script_buffer;
751 245         template->length = script_length;
752         
753 245         if(!private->templates)
754         {
755 17             globus_hashtable_init(&private->templates, 10, 
756                                   globus_hashtable_string_hash, 
757                                   globus_hashtable_string_keyeq);
758         }
759         
760 245         globus_hashtable_insert(&private->templates, template->filename, template);
761     }
762     else
763     {
764 1003         script_buffer = template->buffer;
765 1003         script_length = template->length;
766     }
767     
768 1248     if(argc > 1 && (argv[1] != JSVAL_NULL))
769     {
770 1112         str = JS_ValueToString(cx, argv[1]);
771 1112         if(!str)
772         {
773 0             JS_ReportError(cx, 
774                            "Failed to load template %s.  "
775                            "Second argument to load function should "
776                            "be output filename but is not of type string.",
777                            filename);
778 0             res = JS_FALSE;
779 0             goto exit;
780         }
781         
782 1112         sprintf(out_filename, "%s%s%*s", 
783                 (private->outdir ? private->outdir : ""),
784                 (private->outdir ? FILE_SEPARATOR : ""),
785                 (int) JS_GetStringLength(str), 
786                 JS_GetStringBytes(str));
787         
788 1112         out_stream = fopen(out_filename, "w+");
789 1112         if(!out_stream)
790         {
791 0             JS_ReportError(cx, "Failed to open output file %s for writing", 
792                            out_filename);
793 0             res = JS_FALSE;
794 0             goto exit;
795         }
796     }
797
798 1248     globus_assert(private && private->streams);
799
800 1248     new_streams = (StreamContext *) malloc(sizeof(StreamContext));
801 1248     if(!new_streams)
802     {
803 0         JS_ReportOutOfMemory(cx);
804 0         res = JS_FALSE;
805 0         goto exit;
806     }
807
808 1248     memset(new_streams, 0, sizeof(StreamContext));
809     
810 1248     new_streams->next = private->streams;
811 1248     new_streams->error_stream = private->streams->error_stream;
812 1248     new_streams->out_stream = out_stream;
813 1248     private->streams = new_streams;
814
815 1248     JS_SetContextPrivate(cx, (void *) private);
816
817 1248     res = JS_EvaluateScript(cx, obj, script_buffer, 
818                             script_length, filename, 0, &result);
819 1248     if(!res)
820     {
821 0         JS_ReportError(cx, "Failed to evaluate script: %s", filename);
822 0         goto exit;
823     }
824     
825 /*     res = JS_ExecuteScript(cx, obj, script, &result); */
826 /*     JS_DestroyScript(cx, script); */
827
828 1248     private = JS_GetContextPrivate(cx);
829 1248     globus_assert(private);
830
831 1248     if(private->streams->out_stream)
832     {
833 1112         fclose(private->streams->out_stream);
834     }
835     
836 1248     tmp_streams = private->streams;
837 1248     if(tmp_streams)
838     {
839 1248         private->streams = private->streams->next;
840 1248         free(tmp_streams);
841     }
842
843 1248     JS_SetContextPrivate(cx, (void *) private);
844
845   exit:
846 1248     GlobusWSDLDebugExit();
847 1248     return res;
848 }    
849
850 static JSBool
851 FileExists(
852     JSContext *                         cx, 
853     JSObject *                          obj, 
854     uintN                               argc,
855     jsval *                             argv,
856     jsval *                             rval)
857 2725 {
858 2725     JSBool                              res = JS_TRUE;
859 2725     JSString *                          str;
860 2725     char                                filename[500];
861 2725     PrivateContext *                    private = NULL;
862 2725     struct stat                         statbuf;
863 2725     GlobusFuncName(FileExists);
864 2725     GlobusWSDLDebugEnter();
865
866 2725     if(argc < 1)
867     {
868 0         JS_ReportError(cx, 
869                        "Wrong number of arguments "
870                        "passed to function: %s",
871                        argc, 2, "file_exists(filename)");
872 0         res = JS_FALSE;
873 0         goto exit;
874     }
875
876 2725     str = JS_ValueToString(cx, argv[0]);
877 2725     if(!str)
878     {
879 0         JS_ReportError(cx,
880                        "Failed to load filename");
881 0         res = JS_FALSE;
882 0         goto exit;
883     }
884
885 2725     private = (PrivateContext *) JS_GetContextPrivate(cx);
886     
887 2725     sprintf(filename, "%s%s%*s", 
888             (private->outdir ? private->outdir : ""),
889             (private->outdir ? FILE_SEPARATOR : ""),
890             (int) JS_GetStringLength(str), 
891             JS_GetStringBytes(str));
892
893 2725     if(!stat(filename, &statbuf))
894     {
895 1613         *rval = BOOLEAN_TO_JSVAL(JS_TRUE);
896     }
897     else
898     {
899 1112         *rval = BOOLEAN_TO_JSVAL(JS_FALSE);
900     }
901
902
903   exit:
904 2725     GlobusWSDLDebugExit();
905 2725     return res;
906 }    
907
908 static JSBool
909 CanonicalizeString(
910     JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
911 19613 {
912 19613     uintN i, n;
913 19613     JSString *str;
914 19613     char *s, *news;
915
916 19613     if(argc < 1)
917     {
918 0         JS_ReportError(cx, "function canonical called with no parameters");
919 0         return JS_FALSE;
920     }
921
922 19613     if(JSVAL_IS_NULL(argv[0]) || JSVAL_IS_VOID(argv[0]))
923     {
924 0         str = JS_InternString(cx, "NULL");
925 0         *rval = STRING_TO_JSVAL(str);
926 0         return JS_TRUE;
927     }
928
929 19613     if(!JSVAL_IS_STRING(argv[0]))
930     {
931 0         JS_ReportError(cx, "parameter passed to canonical is not a string");
932 0         return JS_FALSE;
933     }
934
935 19613     str = JSVAL_TO_STRING(argv[0]);
936 19613     n = JSSTRING_LENGTH(str);
937 19613     news = (char *) JS_malloc(cx, (n + 1) * sizeof(char));
938 19613     if(!news)
939     {
940 0         JS_ReportOutOfMemory(cx);
941 0         return JS_FALSE;
942     }
943
944 19613     s = JS_GetStringBytes(str);
945 295362     for(i = 0; i < n; ++i)
946     {
947 275749         switch(s[i])
948         {
949         case '-':
950 0             news[i] = '_';
951 0             break;
952         case ' ':
953 100             news[i] = '_';
954 100             break;
955         default:
956 275649             news[i] = s[i];
957 275749             break;
958         }
959     }
960     
961 19613     news[n] = 0;
962 19613     str = JS_InternString(cx, news);
963 19613     JS_free(cx, news);
964 19613     if(!str)
965     {
966 0         JS_ReportError(cx, "Failed to internalize string in canonical function");
967 0         return JS_FALSE;
968     }
969
970 19613     *rval = STRING_TO_JSVAL(str);
971 19613     return JS_TRUE;
972 }
973
974 static JSBool
975 NamespaceToPrefix(JSContext *cx, JSObject *obj, 
976                   uintN argc, jsval *argv, jsval *rval)
977 15226 {
978 15226     globus_hashtable_t                  nsmap;
979 15226     PrivateContext *                    ctx;
980 15226     JSString *                          str;
981 15226     char *                              prefix;
982
983 15226     ctx = (PrivateContext *) JS_GetContextPrivate(cx);
984
985 15226     nsmap = (globus_hashtable_t) ctx->nsmap;
986 15226     if(!nsmap)
987     {
988 0         str = JS_InternString(cx, "");
989 0         if(!str)
990         {
991 0             JS_ReportError(cx, 
992                            "Failed to access namespace mapping table in NStoP");
993 0             return JS_FALSE;
994         }
995
996 0         *rval = STRING_TO_JSVAL(str);
997 0         return JS_TRUE;
998     }
999
1000 15226     str = JS_ValueToString(cx, argv[0]);
1001 15226     if (!str)
1002     {
1003 0         JS_ReportError(cx, "Parameter passed to NStoP is not a string");
1004 0         return JS_FALSE;
1005     }
1006     
1007 15226     prefix = globus_wsdl_config_get_property(nsmap, 
1008                                              (const char *)JS_GetStringBytes(str));
1009 15226     if(!prefix)
1010     {
1011 214         str = JS_InternString(cx, "");
1012 214         if(!str)
1013         {
1014 0             JS_ReportError(cx, "NStoP failed: could not internalize string");
1015 0             return JS_FALSE;
1016         }
1017
1018 214         *rval = STRING_TO_JSVAL(str);
1019 214         return JS_TRUE;
1020     }
1021
1022 15012     str = JS_InternString(cx, prefix);
1023 15012     *rval = STRING_TO_JSVAL(str);
1024 15012     return JS_TRUE;
1025 }
1026     
1027         
1028 static JSBool
1029 Debug(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
1030 2177 {
1031 2177     uintN i, n;
1032 2177     JSString *str;
1033
1034 4354     for (i = n = 0; i < argc; i++) {
1035 2177         str = JS_ValueToString(cx, argv[i]);
1036 2177         if (!str)
1037         {
1038 0             JS_ReportError(
1039                 cx, 
1040                 "Argument %d to debug function is not a string", i);
1041 0             return JS_FALSE;
1042         }
1043
1044 2177         fprintf(stdout, "%s%s", i ? " " : "", JS_GetStringBytes(str));
1045     }
1046
1047 2177     n++;
1048 2177     return JS_TRUE;
1049 }
1050
1051 static JSBool
1052 Error(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
1053 0 {
1054 0     uintN i, n;
1055 0     JSString *str;
1056 0     char error_string[5000];
1057 0     int len = 0;
1058 0     PrivateContext * ctx_handle;
1059     
1060 0     ctx_handle = (PrivateContext *) JS_GetContextPrivate(cx);
1061
1062 0     for (i = n = 0; i < argc; i++) {
1063 0         str = JS_ValueToString(cx, argv[i]);
1064 0         if (!str)
1065         {
1066 0             JS_ReportError(
1067                 cx, 
1068                 "Argument %d to debug function is not a string", i);
1069 0             return JS_FALSE;
1070         }
1071
1072 0         len += sprintf(error_string + len, 
1073                        "%s%s", i ? " " : "", JS_GetStringBytes(str));
1074     }
1075
1076 0     JS_ReportError(
1077         cx, "ERROR: %s", error_string);
1078 0     return JS_FALSE;
1079 }
1080
1081 static JSBool
1082 Abort(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
1083 0 {
1084 0     abort();
1085 }
1086
1087 static JSBool
1088 Print(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
1089 320313 {
1090 320313     uintN i, n;
1091 320313     JSString *str;
1092 320313     PrivateContext * ctx_handle;
1093 320313     FILE * ostream;
1094     
1095 320313     ctx_handle = (PrivateContext *) JS_GetContextPrivate(cx);
1096 320313     if(!ctx_handle || !ctx_handle->streams || !ctx_handle->streams->out_stream)
1097     {
1098 272         ostream = stdout;
1099     }
1100     else
1101     {
1102 320041         ostream = ctx_handle->streams->out_stream;
1103     }
1104
1105 640626     for (i = n = 0; i < argc; i++) {
1106 320313         str = JS_ValueToString(cx, argv[i]);
1107 320313         if (!str)
1108         {
1109 0             JS_ReportError(cx, "Argument %d to print function is not a string", i);
1110 0             return JS_FALSE;
1111         }
1112
1113 320313         fprintf(ostream, "%s%s", i ? " " : "", JS_GetStringBytes(str));
1114     }
1115
1116 320313     n++;
1117 320313     return JS_TRUE;
1118 }
1119
1120
1121 static void
1122 internal_ErrorReporter(
1123     JSContext *                         cx,
1124     const char *                        message,
1125     JSErrorReport *                     report)
1126 0 {
1127 0     char *prefix, *tmp, *linebuf;
1128 0     PrivateContext * ctx_handle;
1129 0     GlobusFuncName(internal_ErrorReporting);
1130 0     GlobusWSDLDebugEnter();
1131     
1132 0     ctx_handle = (PrivateContext *) JS_GetContextPrivate(cx);
1133 0     if(!ctx_handle)
1134     {
1135 0         goto exit;
1136     }
1137
1138 0     if (!report) {
1139 0         ctx_handle->result = globus_error_put(
1140             globus_error_construct_error(
1141                 GLOBUS_WSDL_PARSER_MODULE, 
1142                 (ctx_handle->result != GLOBUS_NULL)
1143                     ? globus_error_get(ctx_handle->result)
1144                     : NULL,
1145                 GLOBUS_WSDL_ERROR_JAVASCRIPT,
1146                 __FILE__,
1147                 _globus_func_name,
1148                 __LINE__,
1149                 "%s\n", 
1150                 message));
1151 0         goto exit;
1152     }
1153
1154     /* Conditionally ignore reported warnings. */
1155 0     if (JSREPORT_IS_WARNING(report->flags) && 
1156         !GlobusWSDLDebug(GLOBUS_WSDL_DEBUG_WARN))
1157     {
1158 0         goto exit;
1159     }
1160
1161 0     prefix = NULL;
1162 0     if (report->filename)
1163     {
1164 0         prefix = JS_smprintf("%s:", report->filename);
1165     }
1166
1167 0     if (JSREPORT_IS_WARNING(report->flags)) {
1168 0         tmp = prefix;
1169 0         prefix = JS_smprintf("%s%swarning: ",
1170                              tmp ? tmp : "",
1171                              JSREPORT_IS_STRICT(report->flags) ? "strict " : "");
1172 0         JS_free(cx, tmp);
1173     }
1174
1175 0     linebuf = NULL;
1176 0     if(report->linebuf)
1177     {
1178 0         linebuf = JS_smprintf("%s", report->linebuf);
1179     }
1180
1181 0     ctx_handle->result = globus_error_put(
1182         globus_error_construct_error(
1183             GLOBUS_WSDL_PARSER_MODULE, 
1184                 (ctx_handle->result != GLOBUS_NULL)
1185                     ? globus_error_get(ctx_handle->result)
1186                     : NULL,
1187             GLOBUS_WSDL_ERROR_JAVASCRIPT,
1188             __FILE__,
1189             _globus_func_name,
1190             __LINE__,
1191             (linebuf ? "%s%s at line:\n\t%s" : "%s%s%s"), 
1192             (prefix ? prefix : ""), 
1193             (message ? message : ""),
1194             (linebuf ? linebuf : "")));
1195
1196 0     if(prefix)
1197     {
1198 0         JS_free(cx, prefix);
1199     }
1200
1201 0     if(linebuf)
1202     {
1203 0         JS_free(cx, linebuf);
1204     }
1205
1206 0     if(JSREPORT_IS_WARNING(report->flags))
1207     {
1208 0         globus_object_t *               warn_obj;
1209 0         warn_obj = globus_error_get(ctx_handle->result);
1210          
1211 0         if(GlobusWSDLDebug(GLOBUS_WSDL_DEBUG_WARN))
1212         {
1213 0             char *                          warn_str;
1214             
1215 0             warn_str = globus_error_print_chain(warn_obj);
1216             
1217 0             GlobusWSDLDebugPrintf(GLOBUS_WSDL_DEBUG_WARN,
1218                                   ("%s", warn_str));
1219             
1220 0             if(warn_str)
1221             {
1222 0                 globus_free(warn_str);
1223             }
1224         }
1225
1226 0         if(warn_obj)
1227         {
1228 0             globus_object_free(warn_obj);
1229         }
1230
1231 0         ctx_handle->result = GLOBUS_SUCCESS;
1232     }
1233
1234 exit:
1235
1236 0     GlobusWSDLDebugExit();
1237 }
1238
1239 static
1240 JSString *
1241 globus_l_wsdl_jscript_qname_string(
1242     JSContext *                         ctx,
1243     const char *                        href,
1244     const char *                        local)
1245 25146 {
1246 25146     JSString *                          str;
1247 25146     char *                              qname;
1248 25146     size_t                              href_length = 0;
1249 25146     size_t                              local_length = 0;
1250
1251 25146     href_length = href ? strlen(href) : 0;
1252 25146     local_length = local ? strlen(local) : 0;
1253
1254 25146     qname = malloc(href_length + local_length + 2);
1255 25146     if(href)
1256     {
1257 24454         memcpy(qname, href, href_length);
1258 24454         qname[href_length] = '#';
1259 24454         href_length++;
1260     }
1261
1262 25146     memcpy(qname + href_length, local, local_length);
1263 25146     qname[href_length + local_length] = 0;
1264     
1265 25146     str = JS_InternString(ctx, qname);
1266
1267 25146     return str;
1268 }    
1269
1270 globus_result_t
1271 globus_wsdl_execute(
1272     globus_list_t *                     schema_files,
1273     const char *                        tmpl_filename,
1274     const char *                        out_filename,
1275     const char *                        out_dir,
1276     globus_hashtable_t                  nsmap,
1277     globus_hashtable_t                  vars,
1278     globus_list_t *                     template_paths,
1279     globus_hashtable_t                  ignorable_namespaces,
1280     globus_hashtable_t                  include_namespaces,
1281     const int                           rt_size)
1282 17 {
1283 17     JSRuntime *                         rt = NULL;
1284 17     JSContext *                         ctx = NULL;
1285 17     JSObject *                          glob = NULL;
1286 17     JSObject *                          ignore = NULL;
1287 17     char *                              ignore_entry = NULL;
1288 17     JSObject *                          include = NULL;
1289 17     char *                              include_entry = NULL;
1290 17     char **                             var_entry;
1291 17     globus_result_t                     result = GLOBUS_SUCCESS;
1292 17     char *                              sfile = NULL;
1293 17     globus_list_t *                     sfiles = NULL;
1294 17     globus_list_t *                     schemas = NULL;
1295 17     wsdlSchemaPtr                       schema = NULL;
1296 17     GlobusFuncName(globus_wsdl_execute);
1297 17     GlobusWSDLDebugEnter();
1298
1299 17     rt = JS_NewRuntime((rt_size <= 0) ? (64L * 1024L * 1024L) : rt_size);
1300 17     if(!rt)
1301     {
1302 0         result = GlobusWSDLErrorJSRuntime(GLOBUS_NULL);
1303 0         goto exit;
1304     }
1305     
1306 17     ctx = JS_NewContext(rt, gStackChunkSize);
1307 17     if(!ctx)
1308     {
1309 0         result = GlobusWSDLErrorJSContext(GLOBUS_NULL);
1310 0         goto exit;
1311     }
1312
1313 17     JS_SetErrorReporter(ctx, internal_ErrorReporter);
1314
1315 17     glob = JS_NewObject(ctx, &global_class, NULL, NULL);
1316 17     if(!glob)
1317     {
1318 0         result = GlobusWSDLErrorJSContext(GLOBUS_NULL);
1319 0         goto exit;
1320     }
1321
1322 17     if(!JS_InitStandardClasses(ctx, glob))
1323     {
1324 0         result = GlobusWSDLErrorJSContext(GLOBUS_NULL);
1325 0         goto exit;
1326     }
1327
1328 17     globus_i_wsdl_parser_classes_init(ctx, glob);
1329
1330 17     if(!JS_DefineFunctions(ctx, glob, functions_defs))
1331     {
1332 0         result = GlobusWSDLErrorJSContext(GLOBUS_NULL);
1333 0         goto exit;
1334     }
1335
1336 17     sfiles = schema_files;
1337 34     while(sfiles)
1338     {
1339 17         sfile = globus_list_first(sfiles);
1340
1341 17         result = globus_i_wsdl_parse_schema(sfile, &schema);
1342 17         if(result != GLOBUS_SUCCESS)
1343         {
1344 0             result = GlobusWSDLErrorParsingSchema(result, sfile);
1345 0             goto exit;
1346         }
1347
1348 17         result = globus_list_insert(&schemas, schema);
1349 17         if(result != GLOBUS_SUCCESS)
1350         {
1351 0             result = GlobusWSDLErrorParsingSchema(result, sfile);
1352 0             goto exit;
1353         }
1354
1355 17         result = globus_i_wsdl_js_load_schema(ctx, schema);
1356 17         if(result != GLOBUS_SUCCESS)
1357         {
1358 0             result = GlobusWSDLErrorLoadingSchema(result);
1359 0             goto exit;
1360         }
1361
1362 17         sfiles = globus_list_rest(sfiles);
1363     }
1364
1365 17     var_entry = globus_hashtable_first(&vars);
1366 153     while(var_entry)
1367     {
1368 136         if(!JS_DefineProperty(
1369                ctx, glob, var_entry[0],
1370                STRING_TO_JSVAL(JS_InternString(ctx, var_entry[1])),
1371                NULL, NULL,
1372                JSPROP_PERMANENT))
1373         {
1374 0             result = GlobusWSDLErrorLoadingSchema(GLOBUS_NULL);
1375 0             goto exit;
1376         }
1377
1378 136         var_entry = globus_hashtable_next(&vars);
1379     }
1380
1381 17     ignore = JS_NewObject(ctx, &basic_class, NULL, glob);
1382 17     if(!ignore)
1383     {
1384 0         result = GlobusWSDLErrorJSContext(GLOBUS_NULL);
1385 0         goto exit;
1386     }
1387
1388 17     if(!JS_DefineProperty(
1389            ctx, glob, "ignore_namespaces", 
1390            OBJECT_TO_JSVAL(ignore), NULL, 
1391            NULL, JSPROP_READONLY|JSPROP_PERMANENT|JSPROP_ENUMERATE))
1392     {
1393 0         result = GlobusWSDLErrorLoadingSchema(GLOBUS_NULL);
1394 0         goto exit;
1395     }
1396
1397 17     ignore_entry = globus_hashtable_first(&ignorable_namespaces);
1398 143     while(ignore_entry)
1399     {
1400 126         if(!JS_DefineProperty(
1401                ctx, ignore, ignore_entry, 
1402                STRING_TO_JSVAL(JS_InternString(ctx, ignore_entry)), 
1403                NULL, NULL, JSPROP_PERMANENT|JSPROP_READONLY|JSPROP_ENUMERATE))
1404         {
1405 0             result = GlobusWSDLErrorLoadingSchema(GLOBUS_NULL);
1406 0             goto exit;
1407         }
1408
1409 126         ignore_entry = globus_hashtable_next(&ignorable_namespaces);
1410     }
1411
1412     
1413 17     if(!include_namespaces)
1414     {
1415 17         if(!JS_DefineProperty(
1416                ctx, glob, "include_namespaces",
1417                JSVAL_NULL, NULL,
1418                NULL, JSPROP_READONLY|JSPROP_PERMANENT|JSPROP_ENUMERATE))
1419         {
1420 0             result = GlobusWSDLErrorLoadingSchema(GLOBUS_NULL);
1421 0             goto exit;
1422         }
1423     }
1424     else
1425     {
1426
1427 0         include = JS_NewObject(ctx, &basic_class, NULL, glob);
1428 0         if(!include)
1429         {
1430 0             result = GlobusWSDLErrorJSContext(GLOBUS_NULL);
1431 0             goto exit;
1432         }
1433
1434 0         if(!JS_DefineProperty(
1435                ctx, glob, "include_namespaces", 
1436                OBJECT_TO_JSVAL(include), NULL, 
1437                NULL, JSPROP_READONLY|JSPROP_PERMANENT|JSPROP_ENUMERATE))
1438         {
1439 0             result = GlobusWSDLErrorLoadingSchema(GLOBUS_NULL);
1440 0             goto exit;
1441         }
1442     
1443 0         include_entry = globus_hashtable_first(&include_namespaces);
1444 0         while(include_entry)
1445         {
1446 0             if(!JS_DefineProperty(
1447                    ctx, include, include_entry, 
1448                    STRING_TO_JSVAL(JS_InternString(ctx, include_entry)), 
1449                    NULL, NULL, 
1450                    JSPROP_PERMANENT|JSPROP_READONLY|JSPROP_ENUMERATE))
1451             {
1452 0                 result = GlobusWSDLErrorLoadingSchema(GLOBUS_NULL);
1453 0                 goto exit;
1454             }
1455
1456 0             include_entry = globus_hashtable_next(&include_namespaces);
1457         }
1458     }
1459
1460 17     result = globus_i_wsdl_execute_script(ctx, glob, 
1461                                           tmpl_filename, 
1462                                           out_filename,
1463                                           out_dir,
1464                                           nsmap,
1465                                           template_paths);
1466 17     if(result != GLOBUS_SUCCESS)
1467     {
1468 0         result = GlobusWSDLErrorExecutingScript(result, tmpl_filename);
1469         goto exit;
1470     }
1471
1472   exit:
1473     
1474 17     if(result != GLOBUS_SUCCESS)
1475     {
1476 0         if(GlobusWSDLDebug(GLOBUS_WSDL_DEBUG_WARN))
1477         {
1478 0             globus_object_t *           error_obj;
1479 0             char *                      error_str;
1480
1481 0             error_obj = globus_error_get(result);
1482 0             if(error_obj)
1483             {
1484 0                 error_str = globus_error_print_chain(
1485                     error_obj);
1486             
1487 0                 GlobusWSDLDebugPrintf(GLOBUS_WSDL_DEBUG_WARN, 
1488                                       ("[DEBUG::WSDL] %s:%d: %s", 
1489                                        _globus_func_name, 
1490                                        __LINE__, 
1491                                        error_str));
1492 0                 globus_free(error_str);
1493                 
1494 0                 result = globus_error_put(error_obj);
1495             }
1496         }
1497     }
1498
1499 17     if(schemas)
1500     {
1501 17         globus_list_destroy_all(schemas, (void(*)(void *))wsdlSchemaFree);
1502     }
1503     
1504 17     if(ctx)
1505     {
1506 17         JS_DestroyContext(ctx);
1507     }
1508     
1509 17     if(rt)
1510     {
1511 17         JS_DestroyRuntime(rt);
1512     }
1513     
1514 17     GlobusWSDLDebugExit();
1515 17     return result;
1516 }
1517
1518 static
1519 globus_result_t
1520 globus_i_wsdl_js_load_schema(
1521     JSContext *                         cx,
1522     wsdlSchemaPtr                       schema)
1523 17 {
1524 17     JSObject *                          glob = NULL;
1525 17     JSObject *                          wsdl = NULL;
1526 17     JSObject *                          types = NULL;
1527 17     JSObject *                          elements = NULL;
1528 17     JSObject *                          local_elements = NULL;
1529 17     JSObject *                          attributes = NULL;
1530 17     JSObject *                          local_attributes = NULL;
1531 17     JSObject *                          messages = NULL;
1532 17     JSObject *                          portTypes = NULL;
1533 17     JSObject *                          bindings = NULL;
1534 17     JSObject *                          services = NULL;
1535 17     JSObject *                          typeEnum = NULL;
1536 17     JSObject *                          attrEnum = NULL;
1537 17     JSObject *                          contentTypeEnum = NULL;
1538 17     JSObject *                          operationTypeEnum = NULL;
1539 17     JSObject *                          bindingType = NULL;
1540 17     JSObject *                          soapOperationStyleType = NULL;
1541 17     JSObject *                          soapUseType = NULL;
1542 17     ScannerData *                       data = NULL;
1543 17     jsval                               val;
1544 17     JSString *                          str;
1545 17     JSBool                              res = JS_TRUE;
1546 17     globus_result_t                     result = GLOBUS_SUCCESS;
1547 17     GlobusFuncName(globus_i_wsdl_js_load_schema);
1548 17     GlobusWSDLDebugEnter();
1549
1550 17     glob = JS_GetGlobalObject(cx);
1551 17     if(!glob)
1552     {
1553 0         result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1554 0         goto exit;
1555     }
1556
1557 17     res = JS_GetProperty(cx, glob, "wsdl", &val);
1558 17     if(val == JSVAL_VOID)
1559     {
1560 17         wsdl = JS_NewObject(cx, &basic_class, NULL, glob);
1561 17         if(!wsdl)
1562         {
1563 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1564 0             goto exit;
1565         }
1566
1567 17         val = OBJECT_TO_JSVAL(wsdl);
1568 17         if(!JS_DefineProperty(cx, glob, "wsdl", val, NULL, NULL,
1569                               JSPROP_READONLY|JSPROP_PERMANENT))
1570         {
1571 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1572 0             goto exit;
1573         }
1574     }
1575     else
1576     {
1577 0         wsdl = JSVAL_TO_OBJECT(val);
1578 0         if(!wsdl)
1579         {
1580 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1581 0             goto exit;
1582         }
1583     }
1584     
1585 17     res = JS_GetProperty(cx, wsdl, "types", &val);
1586 17     if(val == JSVAL_VOID)
1587     {
1588 17         types = JS_NewObject(cx, &basic_class, NULL, wsdl);
1589 17         if(!types)
1590         {
1591 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1592 0             goto exit;
1593         }
1594
1595 17         val = OBJECT_TO_JSVAL(types);
1596 17         if(!JS_DefineProperty(cx, wsdl, "types", val, NULL, NULL,
1597                               JSPROP_READONLY|JSPROP_PERMANENT))
1598         {
1599 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1600 0             goto exit;
1601         }
1602     }
1603     else
1604     {
1605 0         types = JSVAL_TO_OBJECT(val);
1606 0         if(!types)
1607         {
1608 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1609 0             goto exit;
1610         }
1611     }
1612
1613 17     res = JS_GetProperty(cx, wsdl, "elements", &val);
1614 17     if(val == JSVAL_VOID)
1615     {
1616 17         elements = JS_NewObject(cx, &basic_class, NULL, wsdl);
1617 17         if(!elements)
1618         {
1619 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1620 0             goto exit;
1621         }
1622
1623 17         val = OBJECT_TO_JSVAL(elements);
1624 17         if(!JS_DefineProperty(cx, wsdl, "elements", val, NULL, NULL,
1625                               JSPROP_READONLY|JSPROP_PERMANENT))
1626         {
1627 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1628 0             goto exit;
1629         }
1630     }
1631     else
1632     {
1633 0         elements = JSVAL_TO_OBJECT(val);
1634 0         if(!elements)
1635         {
1636 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1637 0             goto exit;
1638         }
1639     }
1640
1641 17     res = JS_GetProperty(cx, wsdl, "local_elements", &val);
1642 17     if(val == JSVAL_VOID)
1643     {
1644 17         local_elements = JS_NewObject(cx, &basic_class, NULL, wsdl);
1645 17         if(!local_elements)
1646         {
1647 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1648 0             goto exit;
1649         }
1650
1651 17         val = OBJECT_TO_JSVAL(local_elements);
1652 17         if(!JS_DefineProperty(cx, wsdl, "local_elements", val, NULL, NULL,
1653                               JSPROP_READONLY|JSPROP_PERMANENT))
1654         {
1655 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1656 0             goto exit;
1657         }
1658     }
1659     else
1660     {
1661 0         local_elements = JSVAL_TO_OBJECT(val);
1662 0         if(!local_elements)
1663         {
1664 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1665 0             goto exit;
1666         }
1667     }
1668
1669 17     res = JS_GetProperty(cx, wsdl, "attributes", &val);
1670 17     if(val == JSVAL_VOID)
1671     {
1672 17         attributes = JS_NewObject(cx, &basic_class, NULL, wsdl);
1673 17         if(!attributes)
1674         {
1675 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1676 0             goto exit;
1677         }
1678
1679 17         val = OBJECT_TO_JSVAL(attributes);
1680 17         if(!JS_DefineProperty(cx, wsdl, "attributes", val, NULL, NULL,
1681                               JSPROP_READONLY|JSPROP_PERMANENT))
1682         {
1683 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1684 0             goto exit;
1685         }
1686     }
1687     else
1688     {
1689 0         attributes = JSVAL_TO_OBJECT(val);
1690 0         if(!attributes)
1691         {
1692 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1693 0             goto exit;
1694         }
1695     }
1696
1697 17     res = JS_GetProperty(cx, wsdl, "local_attributes", &val);
1698 17     if(val == JSVAL_VOID)
1699     {
1700 17         local_attributes = JS_NewObject(cx, &basic_class, NULL, wsdl);
1701 17         if(!local_attributes)
1702         {
1703 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1704 0             goto exit;
1705         }
1706
1707 17         val = OBJECT_TO_JSVAL(local_attributes);
1708 17         if(!JS_DefineProperty(cx, wsdl, "local_attributes", val, NULL, NULL,
1709                               JSPROP_READONLY|JSPROP_PERMANENT))
1710         {
1711 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1712 0             goto exit;
1713         }
1714     }
1715     else
1716     {
1717 0         local_attributes = JSVAL_TO_OBJECT(val);
1718 0         if(!local_attributes)
1719         {
1720 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1721 0             goto exit;
1722         }
1723     }
1724
1725 17     res = JS_GetProperty(cx, wsdl, "messages", &val);
1726 17     if(val == JSVAL_VOID)
1727     {
1728 17         messages = JS_NewObject(cx, &basic_class, NULL, wsdl);
1729 17         if(!messages)
1730         {
1731 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1732 0             goto exit;
1733         }
1734
1735 17         val = OBJECT_TO_JSVAL(messages);
1736 17         if(!JS_DefineProperty(cx, wsdl, "messages", val, NULL, NULL,
1737                               JSPROP_READONLY|JSPROP_PERMANENT))
1738         {
1739 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1740 0             goto exit;
1741         }
1742     }
1743     else
1744     {
1745 0         messages = JSVAL_TO_OBJECT(val);
1746 0         if(!messages)
1747         {
1748 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1749 0             goto exit;
1750         }
1751     }
1752
1753 17     res = JS_GetProperty(cx, wsdl, "portTypes", &val);
1754 17     if(val == JSVAL_VOID)
1755     {
1756 17         portTypes = JS_NewObject(cx, &basic_class, NULL, wsdl);
1757 17         if(!portTypes)
1758         {
1759 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1760 0             goto exit;
1761         }
1762
1763 17         val = OBJECT_TO_JSVAL(portTypes);
1764 17         if(!JS_DefineProperty(cx, wsdl, "portTypes", val, NULL, NULL,
1765                               JSPROP_READONLY|JSPROP_PERMANENT))
1766         {
1767 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1768 0             goto exit;
1769         }
1770     }
1771     else
1772     {
1773 0         portTypes = JSVAL_TO_OBJECT(val);
1774 0         if(!portTypes)
1775         {
1776 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1777 0             goto exit;
1778         }
1779     }
1780
1781 17     res = JS_GetProperty(cx, wsdl, "bindings", &val);
1782 17     if(val == JSVAL_VOID)
1783     {
1784 17         bindings = JS_NewObject(cx, &basic_class, NULL, wsdl);
1785 17         if(!bindings)
1786         {
1787 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1788 0             goto exit;
1789         }
1790
1791 17         val = OBJECT_TO_JSVAL(bindings);
1792 17         if(!JS_DefineProperty(cx, wsdl, "bindings", val, NULL, NULL,
1793                               JSPROP_READONLY|JSPROP_PERMANENT))
1794         {
1795 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1796 0             goto exit;
1797         }
1798     }
1799     else
1800     {
1801 0         bindings = JSVAL_TO_OBJECT(val);
1802 0         if(!bindings)
1803         {
1804 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1805 0             goto exit;
1806         }
1807     }
1808
1809 17     res = JS_GetProperty(cx, wsdl, "services", &val);
1810 17     if(val == JSVAL_VOID)
1811     {
1812 17         services = JS_NewObject(cx, &basic_class, NULL, wsdl);
1813 17         if(!services)
1814         {
1815 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1816 0             goto exit;
1817         }
1818
1819 17         val = OBJECT_TO_JSVAL(services);
1820 17         if(!JS_DefineProperty(cx, wsdl, "services", val, NULL, NULL,
1821                               JSPROP_READONLY|JSPROP_PERMANENT))
1822         {
1823 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1824 0             goto exit;
1825         }
1826     }
1827     else
1828     {
1829 0         services = JSVAL_TO_OBJECT(val);
1830 0         if(!services)
1831         {
1832 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1833 0             goto exit;
1834         }
1835     }
1836
1837 17     data = (ScannerData *) malloc(sizeof(ScannerData));
1838 17     data->schema = schema;
1839 17     data->context = cx;
1840 17     data->global = glob;
1841 17     data->types = (void *)types;
1842 17     data->elements = (void *)elements;
1843 17     data->local_elements = (void *)local_elements;
1844 17     data->attributes = (void *)attributes;
1845 17     data->local_attributes = (void *)local_attributes;
1846 17     data->messages = (void *)messages;
1847 17     data->attributes = (void *)attributes;
1848 17     data->portTypes = (void *)portTypes;
1849 17     data->bindings = (void *)bindings;
1850 17     data->services = (void *)services;
1851 17     data->result = GLOBUS_SUCCESS;
1852
1853 17     if(schema->schemaTypes)
1854     {
1855 10         data->xsdSchema = schema->schemaTypes;
1856 10         xmlHashScan(schema->schemaTypes->schemasImports, 
1857                     globus_i_wsdl_parser_import_scanner, data);
1858 10         if(data->result != GLOBUS_SUCCESS)
1859         {
1860 0             result = GlobusWSDLErrorJSLoadSchema(data->result);
1861 0             goto exit;
1862         }
1863         
1864 10         data->xsdSchema = schema->schemaTypes;
1865 10         xmlHashScan(schema->schemaTypes->typeDecl, 
1866                     globus_i_wsdl_parser_type_scanner, data);
1867 10         if(data->result != GLOBUS_SUCCESS)
1868         {
1869 0             result = GlobusWSDLErrorJSLoadSchema(data->result);
1870 0             goto exit;
1871         }
1872         
1873 10         xmlHashScan(schema->schemaTypes->groupDecl,
1874                     globus_i_wsdl_parser_type_scanner, data);
1875 10         if(data->result != GLOBUS_SUCCESS)
1876         {
1877 0             result = GlobusWSDLErrorJSLoadSchema(data->result);
1878 0             goto exit;
1879         }
1880
1881 10         xmlHashScan(schema->schemaTypes->elemDecl, 
1882                     globus_i_wsdl_parser_element_scanner, data);
1883 10         if(data->result != GLOBUS_SUCCESS)
1884         {
1885 0             result = GlobusWSDLErrorJSLoadSchema(data->result);
1886 0             goto exit;
1887         }
1888         
1889 10         xmlHashScan(schema->schemaTypes->attrDecl, 
1890                     globus_i_wsdl_parser_attribute_scanner, 
1891                     data);
1892 10         if(data->result != GLOBUS_SUCCESS)
1893         {
1894 0             result = GlobusWSDLErrorJSLoadSchema(data->result);
1895 0             goto exit;
1896         }
1897     }
1898
1899 17     typeEnum = JS_NewObject(cx, &xsdEnum_class, NULL, wsdl);
1900 17     if(!typeEnum)
1901     {
1902 0         result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1903 0         goto exit;
1904     }
1905
1906 17     if(!JS_DefineProperties(cx, typeEnum, xsdTypeEnum_properties))
1907     {
1908 0         result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1909 0         goto exit;
1910     }
1911
1912 17     val = OBJECT_TO_JSVAL(typeEnum);
1913 17     if(!JS_DefineProperty(cx, wsdl, "xsdType", val, NULL, NULL,
1914                           JSPROP_READONLY|JSPROP_PERMANENT))
1915     {
1916 0         result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1917 0         goto exit;
1918     }
1919
1920 17     attrEnum = JS_NewObject(cx, &xsdEnum_class, NULL, wsdl);
1921 17     if(!attrEnum)
1922     {
1923 0         result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1924 0         goto exit;
1925     }
1926
1927 17     if(!JS_DefineProperties(cx, attrEnum, xsdAttrEnum_properties))
1928     {
1929 0         result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1930 0         goto exit;
1931     }
1932
1933 17     val = OBJECT_TO_JSVAL(attrEnum);
1934 17     if(!JS_DefineProperty(cx, wsdl, "xsdAttr", val, NULL, NULL,
1935                           JSPROP_READONLY|JSPROP_PERMANENT))
1936     {
1937 0         result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1938 0         goto exit;
1939     }
1940
1941 17     contentTypeEnum = JS_NewObject(cx, &xsdEnum_class, NULL, wsdl);
1942 17     if(!contentTypeEnum)
1943     {
1944 0         result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1945 0         goto exit;
1946     }
1947
1948 17     if(!JS_DefineProperties(cx, contentTypeEnum, 
1949                             xsdContentTypeEnum_properties))
1950     {
1951 0         result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1952 0         goto exit;
1953     }
1954
1955 17     val = OBJECT_TO_JSVAL(contentTypeEnum);
1956 17     if(!JS_SetProperty(cx, wsdl, "xsdContentType", &val))
1957     {
1958 0         result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
1959 0         goto exit;
1960     }
1961
1962 17     operationTypeEnum = JS_NewObject(cx, &xsdEnum_class, NULL, wsdl);
1963 17     JS_DefineProperties(cx, operationTypeEnum, operationTypeEnum_properties);
1964 17     val = OBJECT_TO_JSVAL(operationTypeEnum);
1965 17     JS_SetProperty(cx, wsdl, "operationType", &val);
1966
1967 17     bindingType = JS_NewObject(cx, &xsdEnum_class, NULL, wsdl);
1968 17     JS_DefineProperties(cx, bindingType, bindingType_properties);
1969 17     val = OBJECT_TO_JSVAL(bindingType);
1970 17     JS_SetProperty(cx, wsdl, "bindingType", &val);
1971
1972 17     soapOperationStyleType = JS_NewObject(cx, &xsdEnum_class, NULL, wsdl);
1973 17     JS_DefineProperties(cx, soapOperationStyleType, 
1974                         soapOperationStyleType_properties);
1975 17     val = OBJECT_TO_JSVAL(soapOperationStyleType);
1976 17     JS_SetProperty(cx, wsdl, "soapOperationStyleType", &val);
1977
1978 17     soapUseType = JS_NewObject(cx, &xsdEnum_class, NULL, wsdl);
1979 17     JS_DefineProperties(cx, soapUseType, 
1980                         soapUseType_properties);
1981 17     val = OBJECT_TO_JSVAL(soapUseType);
1982 17     JS_SetProperty(cx, wsdl, "soapUseType", &val);
1983
1984 17     xmlHashScan(schema->messagesDecl, 
1985                 globus_i_wsdl_parser_message_scanner, 
1986                 data);
1987 17     if(data->result != GLOBUS_SUCCESS)
1988     {
1989 0         result = GlobusWSDLErrorJSLoadSchema(data->result);
1990 0         goto exit;
1991     }
1992
1993 17     xmlHashScan(schema->portTypesDecl, 
1994                 globus_i_wsdl_parser_portType_scanner, data);
1995 17     if(data->result != GLOBUS_SUCCESS)
1996     {
1997 0         result = GlobusWSDLErrorJSLoadSchema(data->result);
1998 0         goto exit;
1999     }
2000
2001 17     xmlHashScan(schema->bindingsDecl, 
2002                 globus_i_wsdl_parser_binding_scanner, 
2003                 data);
2004 17     if(data->result != GLOBUS_SUCCESS)
2005     {
2006 0         result = GlobusWSDLErrorJSLoadSchema(data->result);
2007 0         goto exit;
2008     }
2009
2010 17     xmlHashScan(schema->servicesDecl, 
2011                 globus_i_wsdl_parser_service_scanner, 
2012                 data);
2013 17     if(data->result != GLOBUS_SUCCESS)
2014     {
2015 0         result = GlobusWSDLErrorJSLoadSchema(data->result);
2016 0         goto exit;
2017     }
2018
2019 17     xmlHashScan(schema->importsDecl, 
2020                 globus_i_wsdl_parser_wsdl_imports_scanner, 
2021                 data);
2022 17     if(data->result != GLOBUS_SUCCESS)
2023     {
2024 0         result = GlobusWSDLErrorJSLoadSchema(data->result);
2025 0         goto exit;
2026     }
2027
2028 17     if(!schema->targetNamespace)
2029     {
2030 6         val = JSVAL_NULL;
2031     }
2032     else
2033     {
2034 11         str = JS_InternString(cx, schema->targetNamespace);
2035 11         if(!str)
2036         {
2037 0             result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2038 0             goto exit;
2039         }
2040 11         val = STRING_TO_JSVAL(str);
2041     }
2042
2043 17     if(!JS_SetProperty(cx, wsdl, "targetNamespace", &val))
2044     {
2045 0         result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2046         goto exit;
2047     }
2048
2049   exit:
2050
2051 17     GlobusWSDLDebugExit(); 
2052 17     return result;
2053 }
2054
2055 static
2056 globus_result_t
2057 globus_i_wsdl_js_load_imported_schema(
2058     JSContext *                         cx,
2059     wsdlSchemaPtr                       schema)
2060 47 {
2061 47     JSObject *                          glob = NULL;
2062 47     JSObject *                          wsdl = NULL;
2063 47     JSObject *                          types = NULL;
2064 47     JSObject *                          elements = NULL;
2065 47     JSObject *                          local_elements = NULL;
2066 47     JSObject *                          attributes = NULL;    
2067 47     JSObject *                          local_attributes = NULL;
2068 47     JSObject *                          messages = NULL;
2069 47     JSObject *                          portTypes = NULL;
2070 47     JSObject *                          bindings = NULL;
2071 47     JSObject *                          services = NULL;
2072 47     ScannerData *                       data = NULL;
2073 47     jsval                               val;
2074 47     JSBool                              res = JS_TRUE;
2075 47     globus_result_t                     result = GLOBUS_SUCCESS;
2076 47     GlobusFuncName(globus_i_wsdl_js_load_imported_schema);
2077 47     GlobusWSDLDebugEnter();
2078
2079 47     glob = JS_GetGlobalObject(cx);
2080 47     if(!glob)
2081     {
2082 0         result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2083 0         goto exit;
2084     }
2085
2086 47     res = JS_GetProperty(cx, glob, "wsdl", &val);
2087 47     globus_assert(res);
2088
2089 47     wsdl = JSVAL_TO_OBJECT(val);
2090 47     if(!wsdl)
2091     {
2092 0         result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2093 0         goto exit;
2094     }
2095
2096 47     res = JS_GetProperty(cx, wsdl, "types", &val);
2097 47     globus_assert(res);
2098     
2099 47     types = JSVAL_TO_OBJECT(val);
2100 47     if(!types)
2101     {
2102 0         result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2103 0         goto exit;
2104     }
2105
2106 47     res = JS_GetProperty(cx, wsdl, "elements", &val);
2107 47     globus_assert(res);
2108
2109 47     elements = JSVAL_TO_OBJECT(val);
2110 47     if(!elements)
2111     {
2112 0         result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2113 0         goto exit;
2114     }
2115
2116 47     res = JS_GetProperty(cx, wsdl, "local_elements", &val);
2117 47     globus_assert(res);
2118
2119 47     local_elements = JSVAL_TO_OBJECT(val);
2120 47     if(!local_elements)
2121     {
2122 0         result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2123 0         goto exit;
2124     }
2125
2126 47     res = JS_GetProperty(cx, wsdl, "attributes", &val);
2127 47     globus_assert(res);
2128
2129 47     attributes = JSVAL_TO_OBJECT(val);
2130 47     if(!attributes)
2131     {
2132 0         result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2133 0         goto exit;
2134     }
2135
2136 47     res = JS_GetProperty(cx, wsdl, "local_attributes", &val);
2137 47     globus_assert(res);
2138
2139 47     local_attributes = JSVAL_TO_OBJECT(val);
2140 47     if(!local_attributes)
2141     {
2142 0         result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2143 0         goto exit;
2144     }
2145
2146 47     res = JS_GetProperty(cx, wsdl, "messages", &val);
2147 47     globus_assert(res);
2148
2149 47     messages = JSVAL_TO_OBJECT(val);
2150 47     if(!messages)
2151     {
2152 0         result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2153 0         goto exit;
2154     }
2155
2156 47     res = JS_GetProperty(cx, wsdl, "portTypes", &val);
2157 47     globus_assert(res);
2158
2159 47     portTypes = JSVAL_TO_OBJECT(val);
2160 47     if(!portTypes)
2161     {
2162 0         result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2163 0         goto exit;
2164     }
2165
2166 47     res = JS_GetProperty(cx, wsdl, "bindings", &val);
2167 47     globus_assert(res);
2168
2169 47     bindings = JSVAL_TO_OBJECT(val);
2170 47     if(!bindings)
2171     {
2172 0         result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2173 0         goto exit;
2174     }
2175
2176 47     res = JS_GetProperty(cx, wsdl, "services", &val);
2177 47     globus_assert(res);
2178
2179 47     services = JSVAL_TO_OBJECT(val);
2180 47     if(!services)
2181     {
2182 0         result = GlobusWSDLErrorJSLoadSchema(GLOBUS_NULL);
2183 0         goto exit;
2184     }
2185
2186 47     data = (ScannerData *) malloc(sizeof(ScannerData));
2187 47     data->schema = schema;
2188 47     data->context = cx;
2189 47     data->global = glob;
2190 47     data->types = (void *)types;
2191 47     data->elements = (void *)elements;
2192 47     data->attributes = (void *)attributes;
2193 47     data->local_elements = (void *)local_elements;
2194 47     data->local_attributes = (void *)local_attributes;
2195 47     data->messages = (void *)messages;
2196 47     data->portTypes = (void *)portTypes;
2197 47     data->bindings = (void *)bindings;
2198 47     data->services = (void *)services;
2199 47     data->result = GLOBUS_SUCCESS;
2200
2201 47     if(schema->schemaTypes)
2202     {
2203 40         data->xsdSchema = schema->schemaTypes;
2204 40         xmlHashScan(schema->schemaTypes->schemasImports, 
2205                     globus_i_wsdl_parser_import_scanner, 
2206                     data);
2207 40         if(data->result != GLOBUS_SUCCESS)
2208         {
2209 0             result = GlobusWSDLErrorJSLoadSchema(data->result);
2210 0             goto exit;
2211         }
2212         
2213 40         data->xsdSchema = schema->schemaTypes;
2214 40         xmlHashScan(schema->schemaTypes->typeDecl, 
2215                     globus_i_wsdl_parser_type_scanner, data);
2216 40         if(data->result != GLOBUS_SUCCESS)
2217         {
2218 0             result = GlobusWSDLErrorJSLoadSchema(data->result);
2219 0             goto exit;
2220         }
2221
2222 40         xmlHashScan(schema->schemaTypes->groupDecl, 
2223                     globus_i_wsdl_parser_type_scanner, data);
2224 40         if(data->result != GLOBUS_SUCCESS)
2225         {
2226 0             result = GlobusWSDLErrorJSLoadSchema(data->result);
2227 0             goto exit;
2228         }
2229         
2230 40         xmlHashScan(schema->schemaTypes->elemDecl, 
2231                     globus_i_wsdl_parser_element_scanner, data);
2232 40         if(data->result != GLOBUS_SUCCESS)
2233         {
2234 0             result = GlobusWSDLErrorJSLoadSchema(data->result);
2235 0             goto exit;
2236         }
2237         
2238 40         xmlHashScan(schema->schemaTypes->attrDecl, 
2239                     globus_i_wsdl_parser_attribute_scanner, 
2240                     data);
2241 40         if(data->result != GLOBUS_SUCCESS)
2242         {
2243 0             result = GlobusWSDLErrorJSLoadSchema(data->result);
2244 0             goto exit;
2245         }
2246     }
2247
2248 47     xmlHashScan(schema->messagesDecl, 
2249                 globus_i_wsdl_parser_message_scanner, data);
2250 47     if(data->result != GLOBUS_SUCCESS)
2251     {
2252 0         result = GlobusWSDLErrorJSLoadSchema(data->result);
2253 0         goto exit;
2254     }
2255     
2256 47     xmlHashScan(schema->portTypesDecl, 
2257                 globus_i_wsdl_parser_portType_scanner, data);
2258 47     if(data->result != GLOBUS_SUCCESS)
2259     {
2260 0         result = GlobusWSDLErrorJSLoadSchema(data->result);
2261 0         goto exit;
2262     }
2263
2264 47     xmlHashScan(schema->bindingsDecl, 
2265                 globus_i_wsdl_parser_binding_scanner, data);
2266 47     if(data->result != GLOBUS_SUCCESS)
2267     {
2268 0         result = GlobusWSDLErrorJSLoadSchema(data->result);
2269 0         goto exit;
2270     }
2271
2272 47     xmlHashScan(schema->servicesDecl, 
2273                 globus_i_wsdl_parser_service_scanner, data);
2274 47     if(data->result != GLOBUS_SUCCESS)
2275     {
2276 0         result = GlobusWSDLErrorJSLoadSchema(data->result);
2277 0         goto exit;
2278     }
2279
2280 47     xmlHashScan(schema->importsDecl, 
2281                 globus_i_wsdl_parser_wsdl_imports_scanner, data);
2282
2283   exit:
2284
2285 47     GlobusWSDLDebugExit(); 
2286 47     return result;
2287 }
2288
2289 static 
2290 globus_result_t
2291 globus_i_wsdl_execute_script(
2292     JSContext *                         ctx,
2293     JSObject *                          glob,
2294     const char *                        tmpl_filename,
2295     const char *                        out_filename,
2296     const char *                        out_dir,
2297     globus_hashtable_t                  nsmap,
2298     globus_list_t *                     template_paths)
2299 17 {
2300 17     PrivateContext *                    data;
2301 17     JSString *                          argString;
2302 17     jsval                               resval;
2303 17     jsval                               load_args[2];
2304 17     globus_result_t                     result = GLOBUS_SUCCESS;
2305 17     int                                 argcount = 0;
2306     
2307 17     GlobusFuncName(globus_i_wsdl_execute_script);
2308 17     GlobusWSDLDebugEnter();
2309     
2310 17     data = (PrivateContext *) globus_malloc(sizeof(PrivateContext));
2311 17     if(!data)
2312     {
2313 0         result = GlobusWSDLErrorOutOfMemory;
2314 0         goto exit;
2315     }
2316 17     memset(data, 0, sizeof(PrivateContext));
2317 17     if(out_dir)
2318     {
2319 17         data->outdir = globus_libc_strdup(out_dir);
2320 17         if(mkdir(data->outdir, S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH))
2321         {
2322 17             if(errno != EEXIST)
2323             {
2324 0                 result = GlobusWSDLErrorDirCreate(data->outdir);
2325 0                 goto exit;
2326             }
2327         }
2328     }
2329
2330 17     data->streams = (StreamContext *) malloc(sizeof(StreamContext));
2331 17     globus_assert_string(data->streams, "Memory allocation failed.");
2332 17     memset(data->streams, 0, sizeof(StreamContext));
2333
2334 17     if(!nsmap)
2335     {
2336 0         globus_hashtable_init(&data->nsmap, 10, 
2337                               globus_hashtable_string_hash,
2338                               globus_hashtable_string_keyeq);
2339 0         data->free_nsmap = 0;
2340     }
2341     else
2342     {
2343 17         data->nsmap = nsmap;
2344 17         data->free_nsmap = 0;
2345     }
2346
2347 17     data->template_paths = template_paths;
2348 17     JS_SetContextPrivate(ctx, (void *)data);
2349
2350 17     memset(load_args, 0, 2);
2351
2352 17     argString = JS_InternString(ctx, tmpl_filename);
2353 17     load_args[0] = STRING_TO_JSVAL(argString);
2354 17     argcount++;
2355
2356 17     if(out_filename)
2357     {
2358 0         argString = JS_InternString(ctx, out_filename);
2359 0         load_args[1] = STRING_TO_JSVAL(argString);
2360 0         argcount++;
2361     }
2362     else
2363     {
2364 17         load_args[1] = JSVAL_NULL;
2365 17         argcount++;
2366     }
2367
2368 17     if(JS_CallFunctionName(
2369            ctx, glob, "load", argcount, load_args, &resval) != JS_TRUE)
2370     {
2371 0         result = GlobusWSDLErrorTemplateLoad(data->result, tmpl_filename);
2372 0         data->result = result;
2373         goto exit;
2374     }
2375
2376   exit:
2377
2378 17     data = (PrivateContext *) JS_GetContextPrivate(ctx);
2379 17     if(data)
2380     {
2381 17         if(data->streams)
2382         {
2383 17             free(data->streams);
2384         }
2385
2386 17         if(data->nsmap && data->free_nsmap)
2387         {
2388 0             globus_wsdl_config_properties_destroy(data->nsmap);
2389         }
2390
2391 17         if(data->templates)
2392         {
2393 17             globus_hashtable_destroy_all(&data->templates, TemplateFree);
2394         }
2395
2396 17         if(data->outdir)
2397         {
2398 17             free(data->outdir);
2399         }
2400
2401 17         free(data);
2402     }
2403     
2404 17     GlobusWSDLDebugExit();
2405 17     return result;
2406 }
2407
2408 static
2409 JSBool
2410 xsdEnumGetter(
2411     JSContext *                         cx,
2412     JSObject *                          obj,
2413     jsval                               id,
2414     jsval *                             vp)
2415 115600 {
2416 115600     jsval                               res = JS_TRUE;
2417 115600     GlobusFuncName(xsdEnumGetter);
2418 115600     GlobusWSDLDebugEnter();
2419     
2420 115600     if(JSVAL_IS_INT(id))
2421     {
2422 115600         *vp = id;
2423     }
2424     else
2425     {
2426 0         res = JS_FALSE;
2427     }
2428
2429 115600     GlobusWSDLDebugExit();
2430 115600     return res;
2431 }
2432     
2433 static
2434 JSBool
2435 xsdAttrsGetter(
2436     JSContext *                         cx,
2437     JSObject *                          obj,
2438     jsval                               id,
2439     jsval *                             vp)
2440 7933 {
2441 7933     xmlSchemaAttributePtr               attr;
2442 7933     JSBool                              res = JS_TRUE;
2443 7933     JSObject *                          attrObj;
2444 7933     int                                 i = 0;
2445 7933     GlobusFuncName(xsdAttrsGetter);
2446 7933     GlobusWSDLDebugEnter();
2447     
2448 7933     attr = (xmlSchemaAttributePtr) JS_GetPrivate(cx, obj);
2449 7933     globus_assert(attr);
2450
2451 7933     if(JSVAL_IS_STRING(id))
2452     {
2453 0         while(attr)
2454         {
2455 0             JSString *                  name;
2456             
2457 0             name = JS_InternString(cx, attr->name);
2458 0             if(JS_CompareStrings(name, JSVAL_TO_STRING(id)))
2459             {
2460 0                 break;
2461             }
2462
2463 0             attr = attr->next;
2464         }
2465     }
2466 7933     else if(JSVAL_IS_INT(id))
2467     {
2468 12873         for(; i < JSVAL_TO_INT(id) && attr; ++i)
2469         {
2470 2470             attr = attr->next;
2471         }
2472 7933         globus_assert(attr);
2473     }
2474     else
2475     {
2476 0         attr = (xmlSchemaAttributePtr) JSVAL_TO_PRIVATE(id);
2477 0         globus_assert(attr);
2478     }
2479
2480 7933     attrObj = JS_NewObject(cx, &xsdAttr_class, xsdAttrClass, obj);
2481 7933     globus_assert(attrObj);
2482 7933     JS_SetPrivate(cx, attrObj, (void *)attr);
2483 7933     JS_DefineProperties(cx, attrObj, xsdAttr_properties);
2484
2485 7933     *vp = OBJECT_TO_JSVAL(attrObj);
2486
2487 7933     GlobusWSDLDebugExit();
2488 7933     return res;
2489 }
2490
2491 static
2492 JSBool
2493 xsdFacetsGetter(
2494     JSContext *                         cx,
2495     JSObject *                          obj,
2496     jsval                               id,
2497     jsval *                             vp)
2498 68 {
2499 68     xmlSchemaFacetPtr                   facet;
2500 68     JSObject *                          facetObj;
2501 68     int                                 i = 0;
2502 68     JSBool                              res = JS_TRUE;
2503 68     GlobusFuncName(xsdFacetsGetter);
2504 68     GlobusWSDLDebugEnter();
2505
2506 68     facet = (xmlSchemaFacetPtr) JS_GetPrivate(cx, obj);
2507 68     globus_assert(facet);
2508
2509 68     if(JSVAL_IS_STRING(id))
2510     {
2511 0         *vp = JSVAL_ZERO;
2512     }
2513 68     else if(JSVAL_IS_INT(id))
2514     {
2515 302         for(; i < JSVAL_TO_INT(id) && facet; ++i)
2516         {
2517 117             facet = facet->next;
2518         }
2519 68         globus_assert(facet);
2520     }
2521     else
2522     {
2523 0         facet = (xmlSchemaFacetPtr) JSVAL_TO_PRIVATE(id);
2524 0         globus_assert(facet);
2525     }
2526
2527 68     facetObj = JS_NewObject(cx, &xsdFacet_class, xsdFacetClass, obj);
2528 68     globus_assert(facetObj);
2529 68     JS_SetPrivate(cx, facetObj, (void *)facet);
2530 68     JS_DefineProperties(cx, facetObj, xsdFacet_properties);
2531 68     *vp = OBJECT_TO_JSVAL(facetObj);
2532
2533 68     GlobusWSDLDebugExit();
2534 68     return res;
2535 }
2536
2537 static
2538 JSBool
2539 xsdFacetsEnumerate(
2540     JSContext *                         cx,
2541     JSObject *                          obj,
2542     JSIterateOp                         enum_op,
2543     jsval *                             statep,
2544     jsid *                              idp)
2545 132 {
2546 132     JSBool                              res = JS_TRUE;
2547 132     xmlSchemaFacetPtr                   facet;
2548 132     int                                 index;
2549 132     int                                 i = 0;
2550 132     GlobusFuncName(xsdFacetsEnumerate);
2551 132     GlobusWSDLDebugEnter();
2552
2553 132     facet = (xmlSchemaFacetPtr) JS_GetPrivate(cx, obj);
2554 132     globus_assert(facet);
2555     
2556 132     switch(enum_op)
2557     {
2558     case JSENUMERATE_INIT:
2559         
2560 26         *statep = INT_TO_JSVAL(0);
2561 26         break;
2562
2563     case JSENUMERATE_NEXT:
2564
2565 106         index = JSVAL_TO_INT(*statep);
2566         
2567 518         for(; i < index && facet; ++i)
2568         {
2569 206             facet = facet->next;
2570         }
2571
2572 106         if(!facet)
2573         {
2574 26             *statep = JSVAL_NULL;
2575 26             *idp = JSVAL_ZERO;
2576 26             break;
2577         }
2578
2579 80         *idp = *statep;
2580 80         *statep = INT_TO_JSVAL(index + 1);
2581
2582         break;
2583
2584     case JSENUMERATE_DESTROY:
2585             
2586 132         break;
2587     }
2588
2589 132     GlobusWSDLDebugExit();
2590 132     return res;
2591 }
2592
2593 static
2594 JSBool
2595 xsdSubTypesGetter(
2596     JSContext *                         cx,
2597     JSObject *                          obj,
2598     jsval                               id,
2599     jsval *                             vp)
2600 29226 {
2601 29226     xmlSchemaTypePtr                    type;
2602 29226     JSObject *                          typeObj;
2603 29226     int                                 i = 0;
2604 29226     JSBool                              res = JS_TRUE;
2605 29226     GlobusFuncName(xsdSubTypesGetter);
2606 29226     GlobusWSDLDebugEnter();
2607
2608 29226     type = (xmlSchemaTypePtr) JS_GetPrivate(cx, obj);
2609 29226     globus_assert(type);
2610
2611 29226     if(JSVAL_IS_STRING(id))
2612     {
2613 0         while(type)
2614         {
2615 0             JSString *                  name;
2616             
2617 0             name = JS_InternString(cx, type->name);
2618 0             if(JS_CompareStrings(name, JSVAL_TO_STRING(id)))
2619             {
2620 0                 break;
2621             }
2622
2623 0             type = type->next;
2624         }
2625     }
2626 29226     else if(JSVAL_IS_INT(id))
2627     {
2628 54982         for(; i < JSVAL_TO_INT(id) && type; ++i)
2629         {
2630 12878             type = type->next;
2631         }
2632 29226         globus_assert(type);
2633     }
2634     else
2635     {
2636 0         type = (xmlSchemaTypePtr) JSVAL_TO_PRIVATE(id);
2637 0         globus_assert(type);
2638     }
2639
2640 29226     typeObj = JS_NewObject(cx, &xsdType_class, xsdTypeClass, obj);
2641 29226     globus_assert(typeObj);
2642 29226     JS_SetPrivate(cx, typeObj, (void *)type);
2643 29226     JS_DefineProperties(cx, typeObj, xsdType_properties);
2644 29226     *vp = OBJECT_TO_JSVAL(typeObj);
2645
2646 29226     GlobusWSDLDebugExit();
2647 29226     return res;
2648 }
2649
2650 static
2651 JSBool
2652 xsdSubTypesEnumerate(
2653     JSContext *                         cx,
2654     JSObject *                          obj,
2655     JSIterateOp                         enum_op,
2656     jsval *                             statep,
2657     jsid *                              idp)
2658 27577 {
2659 27577     JSBool                              res = JS_TRUE;
2660 27577     xmlSchemaTypePtr                    schemaType;
2661 27577     int                                 index;
2662 27577     int                                 i = 0;
2663 27577     GlobusFuncName(xsdSubTypesEnumerate);
2664 27577     GlobusWSDLDebugEnter();
2665
2666 27577     schemaType = (xmlSchemaTypePtr) JS_GetPrivate(cx, obj);
2667 27577     globus_assert(schemaType);
2668     
2669 27577     switch(enum_op)
2670     {
2671     case JSENUMERATE_INIT:
2672         
2673 8082         *statep = INT_TO_JSVAL(i);
2674 8082         if(idp)
2675         {
2676 0             *idp = JSVAL_ZERO;
2677         }
2678 0         break;
2679
2680     case JSENUMERATE_NEXT:
2681
2682 19493         index = JSVAL_TO_INT(*statep);
2683 58221         for(; i < index && schemaType; ++i)
2684         {
2685 19364             schemaType = schemaType->next;
2686         }
2687
2688 19493         if(!schemaType)
2689         {
2690 8080             *statep = JSVAL_NULL;
2691 8080             *idp = JSVAL_ZERO;
2692 8080             break;
2693         }
2694
2695 11413         *idp = *statep;
2696 11413         *statep = INT_TO_JSVAL(index + 1);
2697
2698         break;
2699
2700     case JSENUMERATE_DESTROY:
2701             
2702 27577         break;
2703     }
2704
2705 27577     GlobusWSDLDebugExit();
2706 27577     return res;
2707 }
2708
2709 static
2710 JSBool
2711 xsdAttrsEnumerate(
2712     JSContext *                         cx,
2713     JSObject *                          obj,
2714     JSIterateOp                         enum_op,
2715     jsval *                             statep,
2716     jsid *                              idp)
2717 6409 {
2718 6409     JSBool                              res = JS_TRUE;
2719 6409     xmlSchemaAttributePtr               schemaAttribute;
2720 6409     int                                 i = 0;
2721 6409     int                                 index;
2722 6409     GlobusFuncName(xsdAttrsEnumerate);
2723 6409     GlobusWSDLDebugEnter();
2724
2725 6409     schemaAttribute = (xmlSchemaAttributePtr) JS_GetPrivate(cx, obj);
2726 6409     globus_assert(schemaAttribute);
2727     
2728 6409     switch(enum_op)
2729     {
2730     case JSENUMERATE_INIT:
2731         
2732 1904         *statep = INT_TO_JSVAL(0);
2733 1904         break;
2734
2735     case JSENUMERATE_NEXT:
2736
2737 4505         index = JSVAL_TO_INT(*statep);
2738 11509         for(; i < index && schemaAttribute; ++i)
2739         {
2740 3502             schemaAttribute = schemaAttribute->next;
2741         }
2742
2743 4505         if(!schemaAttribute)
2744         {
2745 1904             *statep = JSVAL_NULL;
2746 1904             *idp = JSVAL_ZERO;
2747 1904             break;
2748         }
2749
2750 2601         *idp = *statep;
2751 2601         *statep = INT_TO_JSVAL(index + 1);
2752
2753         break;
2754
2755     case JSENUMERATE_DESTROY:
2756             
2757 6409         break;
2758     }
2759     
2760 6409     GlobusWSDLDebugExit();
2761 6409     return res;
2762 }
2763
2764 static
2765 JSBool
2766 xsdFacetGetter(
2767     JSContext *                         cx,
2768     JSObject *                          obj,
2769     jsval                               jid,
2770     jsval *                             vp)
2771 68 {
2772 68     int                                 idval;
2773 68     JSString *                          str;
2774 68     xmlSchemaFacetPtr                   facet;
2775 68     JSBool                              res = JS_TRUE;
2776 68     GlobusFuncName(xsdFacetGetter);
2777 68     GlobusWSDLDebugEnter();
2778
2779 68     facet = (xmlSchemaFacetPtr) JS_GetPrivate(cx, obj);
2780 68     globus_assert(facet);
2781
2782 68     if(!JSVAL_IS_INT(jid))
2783     {
2784 0         char *                          prop_name;
2785
2786 0         prop_name = JS_GetStringBytes(JSVAL_TO_STRING(jid));
2787 0         JS_ReportError(cx, 
2788                        "Unknown property: .%s for facet", prop_name);
2789 0         res = JS_FALSE;
2790 0         goto exit;
2791     }
2792         
2793 68     idval = JSVAL_TO_INT(jid);
2794 68     switch(idval)
2795     {
2796     case type:
2797
2798 0         *vp = INT_TO_JSVAL(facet->type);
2799 0         break;
2800
2801     case value:
2802
2803 68         if(!facet->value)
2804         {
2805 0             *vp = JSVAL_VOID;
2806 0             break;
2807         }
2808
2809 68         str = JS_InternString(cx, facet->value);
2810 68         *vp = STRING_TO_JSVAL(str);
2811 68         break;
2812
2813     case id:
2814
2815 0         *vp = INT_TO_JSVAL(facet->id);
2816 0         break;
2817     
2818     case fixed:
2819  
2820 0         *vp = INT_TO_JSVAL(facet->fixed);
2821 0         break;
2822
2823     default:
2824
2825 0         *vp = JSVAL_VOID;
2826 0         JS_ReportError(cx, "Unknown property for facet with id: %d", idval);
2827 0         res = JS_FALSE;
2828     }
2829
2830   exit:
2831
2832 68     GlobusWSDLDebugExit();
2833 68     return res;
2834 }
2835
2836 static
2837 JSBool
2838 xsdTypeGetter(
2839     JSContext *                         cx,
2840     JSObject *                          obj,
2841     jsval                               jid,
2842     jsval *                             vp)
2843 160698 {
2844 160698     int                                 idval;
2845 160698     JSObject *                          subTypesObj;
2846 160698     JSObject *                          attribObj;
2847 160698     JSObject *                          typeObj;
2848 160698     JSObject *                          wildcardObj;
2849 160698     JSObject *                          facetsObj;
2850 160698     JSString *                          str;
2851 160698     xmlSchemaTypePtr                    xsdType;
2852 160698     JSBool                              res = JS_TRUE;
2853 160698     GlobusFuncName(xsdTypeGetter);
2854 160698     GlobusWSDLDebugEnter();
2855
2856 160698     xsdType = (xmlSchemaTypePtr) JS_GetPrivate(cx, obj);
2857 160698     globus_assert(xsdType);
2858
2859 160698     if(!JSVAL_IS_INT(jid))
2860     {
2861 0         char *                          prop_name;
2862
2863 0         prop_name = JS_GetStringBytes(JSVAL_TO_STRING(jid));
2864 0         JS_ReportError(
2865             cx, 
2866             "Unknown property: .%s for xsd:type element", prop_name);
2867 0         res = JS_FALSE;
2868 0         goto exit;
2869     }
2870         
2871 160698     idval = JSVAL_TO_INT(jid);
2872 160698     switch(idval)
2873     {
2874     case type:
2875
2876 51676         *vp = INT_TO_JSVAL(xsdType->type);
2877 51676         break;
2878
2879     case name:
2880
2881 19893         if(!xsdType->name)
2882         {
2883 0             *vp = JSVAL_VOID;
2884 0             break;
2885         }
2886
2887 19893         str = JS_InternString(cx, xsdType->name);
2888 19893         *vp = STRING_TO_JSVAL(str);
2889 19893         break;
2890
2891     case id:
2892
2893 0         *vp = INT_TO_JSVAL(xsdType->id);
2894 0         break;
2895
2896     case subtypes:
2897         
2898 32626         if(!xsdType->subtypes)
2899         {
2900 2042             *vp = JSVAL_VOID;
2901 2042             break;
2902         }
2903
2904 30584         subTypesObj = JS_NewObject(cx, &xsdSubTypes_class, NULL, obj);
2905 30584         globus_assert(subTypesObj);
2906 30584         JS_SetPrivate(cx, subTypesObj, xsdType->subtypes);
2907
2908 30584         *vp = OBJECT_TO_JSVAL(subTypesObj);
2909 30584         break;
2910     
2911     case attributes:
2912
2913 8188         if(!xsdType->attributes)
2914         {
2915 6618             *vp = JSVAL_VOID;
2916 6618             break;
2917         }
2918
2919 1570         attribObj = JS_NewObject(cx, &xsdAttrs_class, NULL, obj);
2920 1570         globus_assert(attribObj);
2921 1570         JS_SetPrivate(cx, attribObj, xsdType->attributes);
2922
2923 1570         *vp = OBJECT_TO_JSVAL(attribObj);
2924 1570         break;
2925     
2926     case minOccurs:
2927
2928 3558         *vp = INT_TO_JSVAL(xsdType->minOccurs);
2929 3558         break;
2930
2931     case maxOccurs:
2932
2933 4476         *vp = 
2934         (xsdType->maxOccurs == GLOBUS_L_WSDL_JSCRIPT_UNBOUNDED) ? 
2935         JS_GetPositiveInfinityValue(cx) :
2936         INT_TO_JSVAL(xsdType->maxOccurs);
2937 4476         break;
2938
2939     case ref:
2940
2941 3251         if(!xsdType->ref)
2942         {
2943 1880             *vp = JSVAL_VOID;
2944 1880             break;
2945         }
2946
2947 1371         str = JS_InternString(cx, xsdType->ref);
2948 1371         *vp = STRING_TO_JSVAL(str);
2949 1371         break;
2950
2951     case refNs:
2952
2953 84         if(!xsdType->refNs)
2954         {
2955 0             *vp = JSVAL_VOID;
2956 0             break;
2957         }
2958
2959 84         str = JS_InternString(cx, xsdType->refNs);
2960 84         *vp = STRING_TO_JSVAL(str);
2961 84         break;
2962
2963     case refQname:
2964
2965 1245         if(!xsdType->ref)
2966         {
2967 0             *vp = JSVAL_VOID;
2968 0             break;
2969         }
2970 1245         else if(!xsdType->refNs)
2971         {
2972 0             str = JS_InternString(cx, xsdType->ref);
2973 0             *vp = STRING_TO_JSVAL(str);
2974 0             break;
2975         }
2976         else
2977         {
2978 1245             str = globus_l_wsdl_jscript_qname_string(
2979                 cx, xsdType->refNs, xsdType->ref);
2980 1245             *vp = STRING_TO_JSVAL(str);
2981 1245             break;
2982         }
2983
2984     case base:
2985
2986 431         if(!xsdType->base)
2987         {
2988 0             *vp = JSVAL_VOID;
2989 0             break;
2990         }
2991
2992 431         if(xsdType->type == XML_SCHEMA_TYPE_UNION)
2993         {
2994 54             char * memberTypes = NULL;
2995 54             int len = 0;
2996 54             int memberTypes_length = 1;
2997 54             xsdQNamePtr qnames, qn;
2998
2999 54             globus_i_wsdl_split_qnames(NULL, xsdType->node, xsdType->base, &qnames);
3000 54             qn = qnames;
3001 162             while(qn)
3002             {
3003 108                 len = strlen(qn->Namespace) + strlen(qn->name) + 2;
3004 108                 memberTypes = realloc(memberTypes, 
3005                                       (sizeof(char) * len) + 
3006                                       memberTypes_length);
3007 108                 sprintf(memberTypes + memberTypes_length - 1, "%s#%s ", 
3008                         qn->Namespace, qn->name);
3009 108                 memberTypes_length += len;
3010
3011 108                 qn = qn->next;
3012             }
3013
3014 54             xsdQNameFree(qnames);
3015
3016 54             str = JS_InternString(cx, memberTypes);
3017         }
3018         else
3019         {
3020 377             str = JS_InternString(cx, xsdType->base);
3021         }
3022         
3023 431         *vp = STRING_TO_JSVAL(str);
3024 431         break;
3025
3026     case baseNs:
3027
3028 1106         if(!xsdType->baseNs)
3029         {
3030 0             *vp = JSVAL_VOID;
3031 0             break;
3032         }
3033
3034 1106         str = JS_InternString(cx, xsdType->baseNs);
3035 1106         *vp = STRING_TO_JSVAL(str);
3036 1106         break;
3037
3038     case baseQName:
3039
3040 1088         if(!xsdType->base)
3041         {
3042 0             *vp = JSVAL_VOID;
3043 0             break;
3044         }
3045
3046 1088         if(!xsdType->baseNs)
3047         {
3048 0             str = JS_InternString(cx, xsdType->base);
3049 0             *vp = STRING_TO_JSVAL(str);
3050 0             break;
3051         }
3052
3053 1088         str = globus_l_wsdl_jscript_qname_string(
3054             cx, xsdType->baseNs, xsdType->base);
3055 1088         *vp = STRING_TO_JSVAL(str);
3056 1088         break;
3057         
3058     case baseType:
3059
3060 714         if(!xsdType->baseType)
3061         {
3062 0             *vp = JSVAL_VOID;
3063 0             break;
3064         }
3065
3066 714         typeObj = JS_NewObject(cx, &xsdType_class, xsdTypeClass, obj);
3067 714         globus_assert(typeObj);
3068 714         JS_SetPrivate(cx, typeObj, (void *)xsdType->baseType);
3069 714         JS_DefineProperties(cx, typeObj, xsdType_properties);
3070 714         *vp = OBJECT_TO_JSVAL(typeObj);
3071 714         break;
3072
3073     case targetNamespace:
3074
3075 13028         if(!xsdType->targetNamespace)
3076         {
3077 0             *vp = JSVAL_VOID;
3078 0             break;
3079         }
3080
3081 13028         str = JS_InternString(cx, xsdType->targetNamespace);
3082 13028         *vp = STRING_TO_JSVAL(str);
3083 13028         break;
3084
3085     case qname:
3086
3087 2273         if(!xsdType->name)
3088         {
3089 0             *vp = JSVAL_VOID;
3090 0             break;
3091         }
3092 2273         else if(!xsdType->targetNamespace)
3093         {
3094 0             str = JS_InternString(cx, xsdType->name);
3095 0             *vp = STRING_TO_JSVAL(str);
3096 0             break;
3097         }
3098         else
3099         {
3100 2273             str = globus_l_wsdl_jscript_qname_string(
3101                 cx, xsdType->targetNamespace, xsdType->name);
3102 2273             *vp = STRING_TO_JSVAL(str);
3103 2273             break;
3104         }
3105
3106     case attributeWildcard:
3107
3108 8170         if(!xsdType->attributeWildcard)
3109         {
3110 6844             *vp = JSVAL_VOID;
3111 6844             break;
3112         }
3113
3114 1326         wildcardObj = JS_NewObject(cx, 
3115                                    &xsdWildcard_class, 
3116                                    xsdWildcardClass, obj);
3117 1326         globus_assert(wildcardObj);
3118 1326         JS_SetPrivate(cx, wildcardObj, (void *)xsdType->attributeWildcard);
3119 1326         JS_DefineProperties(cx, wildcardObj, xsdWildcard_properties);
3120 1326         *vp = OBJECT_TO_JSVAL(wildcardObj);
3121 1326         break;
3122
3123     case facets:
3124
3125 111         if(!xsdType->facets)
3126         {
3127 17             *vp = JSVAL_VOID;
3128 17             break;
3129         }
3130
3131 94         facetsObj = JS_NewObject(cx, &xsdFacets_class, NULL, obj);
3132 94         globus_assert(facets);
3133 94         JS_SetPrivate(cx, facetsObj, xsdType->facets);
3134
3135 94         *vp = OBJECT_TO_JSVAL(facetsObj);
3136 94         break;
3137
3138     case namedType:
3139
3140 4640         if(xsdType->type != XML_SCHEMA_TYPE_ELEMENT || 
3141            !((xmlSchemaElementPtr)xsdType)->namedType)
3142         {
3143 500             *vp = JSVAL_VOID;
3144 500             break;
3145         }
3146
3147 4140         str = JS_InternString(cx, ((xmlSchemaElementPtr)xsdType)->namedType);
3148 4140         *vp = STRING_TO_JSVAL(str);
3149 4140         break;
3150
3151     case namedTypeNs:
3152
3153 4140         if(((xmlSchemaElementPtr)xsdType)->type != XML_SCHEMA_TYPE_ELEMENT || 
3154            !((xmlSchemaElementPtr)xsdType)->namedTypeNs)
3155         {
3156 0             *vp = JSVAL_VOID;
3157 0             break;
3158         }
3159
3160 4140         str = JS_InternString(cx, ((xmlSchemaElementPtr)xsdType)->namedTypeNs);
3161 4140         *vp = STRING_TO_JSVAL(str);
3162 4140         break;
3163
3164     default:
3165
3166 0         *vp = JSVAL_VOID;
3167 0         JS_ReportError(cx, "Unknown property for xsd type with id: %d", idval);
3168 0         res = JS_FALSE;
3169     }
3170
3171   exit:
3172
3173 160698     GlobusWSDLDebugExit();
3174 160698     return res;
3175 }
3176
3177 static
3178 JSBool
3179 xsdWildcardGetter(
3180     JSContext *                         cx,
3181     JSObject *                          obj,
3182     jsval                               jid,
3183     jsval *                             vp)
3184 0 {
3185 0     int                                 idval;
3186 0     xmlSchemaWildcardPtr                xsdWildcard;
3187 0     JSBool                              res = JS_TRUE;
3188 0     GlobusFuncName(xsdWildcardGetter);
3189 0     GlobusWSDLDebugEnter();
3190
3191 0     xsdWildcard = (xmlSchemaWildcardPtr) JS_GetPrivate(cx, obj);
3192 0     globus_assert(xsdWildcard);
3193
3194 0     if(!JSVAL_IS_INT(jid))
3195     {
3196 0         char *                          prop_name;
3197
3198 0         prop_name = JS_GetStringBytes(JSVAL_TO_STRING(jid));
3199 0         JS_ReportError(cx, 
3200                        "Unknown property: .%s for wildcard", prop_name);
3201 0         res = JS_FALSE;
3202 0         goto exit;
3203     }
3204         
3205 0     idval = JSVAL_TO_INT(jid);
3206 0     switch(idval)
3207     {
3208     case type:
3209
3210 0         *vp = INT_TO_JSVAL(xsdWildcard->type);
3211 0         break;
3212
3213     case id:
3214
3215 0         *vp = INT_TO_JSVAL(xsdWildcard->id);
3216 0         break;
3217
3218     case minOccurs:
3219
3220 0         *vp = INT_TO_JSVAL(xsdWildcard->minOccurs);
3221 0         break;
3222
3223     case maxOccurs:
3224
3225 0         *vp = 
3226         (xsdWildcard->maxOccurs == GLOBUS_L_WSDL_JSCRIPT_UNBOUNDED) ? 
3227         JS_GetPositiveInfinityValue(cx) :
3228         INT_TO_JSVAL(xsdWildcard->maxOccurs);
3229 0         break;
3230
3231     case any:
3232
3233 0         *vp = INT_TO_JSVAL(xsdWildcard->any);
3234 0         break;
3235         
3236     default:
3237
3238 0         *vp = JSVAL_VOID;
3239 0         JS_ReportError(cx, 
3240                        "Unknown property for xsd "
3241                        "wildcard with id: %d", idval);
3242 0         res = JS_FALSE;
3243     }
3244
3245   exit:
3246
3247 0     GlobusWSDLDebugExit();
3248 0     return res;
3249 }
3250
3251 static
3252 JSBool
3253 xsdAttrGetter(
3254     JSContext *                         cx,
3255     JSObject *                          obj,
3256     jsval                               jid,
3257     jsval *                             vp)
3258 56657 {
3259 56657     int                                 idval;
3260 56657     xmlSchemaAttributePtr               attr;
3261 56657     JSBool                              res = JS_TRUE;
3262 56657     JSObject *                          subTypesObj;
3263 56657     JSObject *                          attribObj;
3264 56657     JSString *                          str;
3265 56657     JSObject *                          typeObj;
3266 56657     GlobusFuncName(xsdAttrGetter);
3267 56657     GlobusWSDLDebugEnter();
3268
3269 56657     attr = (xmlSchemaAttributePtr) JS_GetPrivate(cx, obj);
3270 56657     globus_assert(attr);
3271
3272 56657     if(!JSVAL_IS_INT(jid))
3273     {
3274 0         JS_ReportError(cx, 
3275                        "Invalid id for xsd attribute property, "
3276                        "expected int not string");
3277 0         res = JS_FALSE;
3278 0         goto exit;
3279     }
3280     
3281     
3282 56657     idval = JSVAL_TO_INT(jid);
3283 56657     switch(idval)
3284     {
3285     case type:
3286       
3287 3327         *vp = INT_TO_JSVAL(attr->type);
3288 3327         break;
3289
3290     case name:
3291
3292 10591         if(!attr->name)
3293         {
3294 0             *vp = JSVAL_VOID;
3295 0             break;
3296         }
3297
3298 10591         str = JS_InternString(cx, attr->name);
3299 10591         *vp = STRING_TO_JSVAL(str);
3300 10591         break;
3301
3302     case id:
3303
3304 0         *vp = INT_TO_JSVAL(attr->id);
3305 0         break;
3306
3307     case ref:
3308
3309 5563         if(!attr->ref)
3310         {
3311 4647             *vp = JSVAL_VOID;
3312 4647             break;
3313         }
3314
3315 916         str = JS_InternString(cx, attr->ref);
3316 916         *vp = STRING_TO_JSVAL(str);
3317 916         break;
3318
3319     case refNs:
3320
3321 0         if(!attr->refNs)
3322         {
3323 0             *vp = JSVAL_VOID;
3324 0             break;
3325         }
3326
3327 0         str = JS_InternString(cx, attr->refNs);
3328 0         *vp = STRING_TO_JSVAL(str);
3329 0         break;
3330
3331     case refQname:
3332
3333 916         if(!attr->ref)
3334         {
3335 0             *vp = JSVAL_VOID;
3336 0             break;
3337         }
3338 916         else if(!attr->refNs)
3339         {
3340 0             str = JS_InternString(cx, attr->ref);
3341 0             *vp = STRING_TO_JSVAL(str);
3342 0             break;
3343         }
3344         else
3345         {
3346 916             str = globus_l_wsdl_jscript_qname_string(
3347                 cx, attr->refNs, attr->ref);
3348 916             *vp = STRING_TO_JSVAL(str);
3349 916             break;
3350         }
3351
3352     case typeName:
3353
3354 4876         if(!attr->typeName)
3355         {
3356 36             *vp = JSVAL_VOID;
3357 36             break;
3358         }
3359
3360 4840         str = JS_InternString(cx, attr->typeName);
3361 4840         *vp = STRING_TO_JSVAL(str);
3362 4840         break;
3363
3364     case typeNs:
3365
3366 13375         if(!attr->typeNs)
3367         {
3368 0             *vp = JSVAL_VOID;
3369 0             break;
3370         }
3371
3372 13375         str = JS_InternString(cx, attr->typeNs);
3373 13375         *vp = STRING_TO_JSVAL(str);
3374 13375         break;
3375
3376     case typeQname:
3377
3378 8764         if(!attr->typeName)
3379         {
3380 0             *vp = JSVAL_VOID;
3381 0             break;
3382         }
3383
3384 8764         if(!attr->typeNs)
3385         {
3386 0             str = JS_InternString(cx, attr->typeNs);
3387 0             *vp = STRING_TO_JSVAL(str);
3388 0             break;
3389         }
3390         
3391 8764         str = globus_l_wsdl_jscript_qname_string(cx, attr->typeNs, attr->typeName);
3392 8764         *vp = STRING_TO_JSVAL(str);
3393 8764         break;
3394
3395     case subtypes:
3396         
3397 0         if(!attr->subtypes)
3398         {
3399 0             *vp = JSVAL_VOID;
3400 0             break;
3401         }
3402
3403 0         subTypesObj = JS_NewObject(cx, &xsdSubTypes_class, NULL, obj);
3404 0         globus_assert(subTypesObj);
3405 0         JS_SetPrivate(cx, subTypesObj, attr->subtypes);
3406
3407 0         *vp = OBJECT_TO_JSVAL(subTypesObj);
3408 0         break;
3409     
3410     case occurs:
3411
3412 3776         *vp = INT_TO_JSVAL(attr->occurs);
3413 3776         break;
3414
3415     case base:
3416
3417 0         if(!attr->base)
3418         {
3419 0             *vp = JSVAL_VOID;
3420 0             break;
3421         }
3422
3423 0         typeObj = JS_NewObject(cx, &xsdType_class, xsdTypeClass, obj);
3424 0         globus_assert(typeObj);
3425 0         JS_SetPrivate(cx, typeObj, (void *)attr->base);
3426 0         JS_DefineProperties(cx, typeObj, xsdType_properties);
3427 0         *vp = OBJECT_TO_JSVAL(typeObj);
3428 0         break;
3429
3430     case defValue:
3431         
3432 0         if(!attr->defValue)
3433         {
3434 0             *vp = JSVAL_VOID;
3435 0             break;
3436         }
3437         
3438 0         str = JS_InternString(cx, attr->defValue);
3439 0         *vp = STRING_TO_JSVAL(str);
3440 0         break;
3441
3442     case targetNamespace:
3443
3444 5129         if(!attr->targetNamespace)
3445         {
3446 3416             str = JS_InternString(cx, "");
3447         }
3448         else
3449         {
3450 1713             str = JS_InternString(cx, attr->targetNamespace);
3451         }
3452
3453 5129         *vp = STRING_TO_JSVAL(str);
3454 5129         break;
3455
3456     case qname:
3457
3458 0         if(!attr->name)
3459         {
3460 0             *vp = JSVAL_VOID;
3461 0             break;
3462         }
3463 0         else if(!attr->targetNamespace)
3464         {
3465 0             str = JS_InternString(cx, attr->name);
3466 0             *vp = STRING_TO_JSVAL(str);
3467 0             break;
3468         }
3469         else
3470         {
3471 0             str = globus_l_wsdl_jscript_qname_string(
3472                 cx, attr->targetNamespace, attr->name);
3473 0             *vp = STRING_TO_JSVAL(str);
3474 0             break;
3475         }
3476
3477     case attributes:
3478       
3479 340         if(attr->type != XML_SCHEMA_TYPE_ATTRIBUTEGROUP)
3480         {
3481 0             *vp = JSVAL_VOID;
3482 0             break;
3483         }
3484
3485 340         attribObj = JS_NewObject(cx, &xsdAttrs_class, NULL, obj);
3486 340         globus_assert(attribObj);
3487
3488 340         JS_SetPrivate(cx, attribObj, 
3489                       ((xmlSchemaAttributeGroupPtr)attr)->attributes);
3490
3491 340         *vp = OBJECT_TO_JSVAL(attribObj);
3492 340         break;
3493         
3494     default:
3495
3496 0         *vp = JSVAL_VOID;
3497 0         JS_ReportError(cx, 
3498                        "Unknown property for xsd "
3499                        "attribute with id: %d", idval);
3500 0         res = JS_FALSE;
3501     }
3502
3503   exit:
3504
3505 56657     GlobusWSDLDebugExit();
3506 56657     return res;
3507 }
3508
3509 static
3510 JSBool
3511 xsdElementGetter(
3512     JSContext *                         cx,
3513     JSObject *                          obj,
3514     jsval                               jid,
3515     jsval *                             vp)
3516 57755 {
3517 57755     int                                 idval;
3518 57755     xmlSchemaElementPtr                 element;
3519 57755     JSString *                          str;
3520 57755     JSObject *                          attribObj;
3521 57755     JSBool                              res = JS_TRUE;
3522 57755     JSObject *                          subTypesObj;
3523         
3524 57755     GlobusFuncName(xsdElementGetter);
3525 57755     GlobusWSDLDebugEnter();
3526
3527 57755     element = (xmlSchemaElementPtr) JS_GetPrivate(cx, obj);
3528 57755     globus_assert(element);
3529
3530 57755     if(!JSVAL_IS_INT(jid))
3531     {
3532 0         JS_ReportError(cx, 
3533                        "Invalid id type (expected int) for "
3534                        "xsd element property");
3535 0         res = JS_FALSE;
3536 0         goto exit;
3537     }
3538     
3539     
3540 57755     idval = JSVAL_TO_INT(jid);
3541 57755     switch(idval)
3542     {
3543     case type:
3544       
3545 0         *vp = INT_TO_JSVAL(element->type);
3546 0         break;
3547
3548     case name:
3549
3550 13300         if(!element->name)
3551         {
3552 0             *vp = JSVAL_VOID;
3553 0             break;
3554         }
3555
3556 13300         str = JS_InternString(cx, element->name);
3557 13300         *vp = STRING_TO_JSVAL(str);
3558 13300         break;
3559
3560     case id:
3561
3562 0         *vp = INT_TO_JSVAL(element->id);
3563 0         break;
3564
3565     case subtypes:
3566         
3567 8788         if(!element->subtypes)
3568         {
3569 22             *vp = JSVAL_VOID;
3570 22             break;
3571         }
3572
3573 8766         subTypesObj = JS_NewObject(cx, &xsdSubTypes_class, NULL, obj);
3574 8766         globus_assert(subTypesObj);
3575
3576 8766         JS_SetPrivate(cx, subTypesObj, element->subtypes);
3577
3578 8766         *vp = OBJECT_TO_JSVAL(subTypesObj);
3579 8766         break;
3580     
3581     case attributes:
3582
3583 0         if(!element->attributes)
3584         {
3585 0             *vp = JSVAL_VOID;
3586 0             break;
3587         }
3588
3589 0         attribObj = JS_NewObject(cx, &xsdAttrs_class, NULL, obj);
3590 0         globus_assert(attribObj);
3591
3592 0         JS_SetPrivate(cx, attribObj, element->attributes);
3593
3594 0         *vp = OBJECT_TO_JSVAL(attribObj);
3595 0         break;
3596     
3597     case minOccurs:
3598
3599 0         *vp = INT_TO_JSVAL(element->minOccurs);
3600 0         break;
3601
3602     case maxOccurs:
3603
3604 0         *vp = 
3605         (element->maxOccurs == GLOBUS_L_WSDL_JSCRIPT_UNBOUNDED) ? 
3606         JS_GetPositiveInfinityValue(cx) :
3607         INT_TO_JSVAL(element->maxOccurs);
3608 0         break;
3609
3610     case ref:
3611
3612 5963         if(!element->ref)
3613         {
3614 5658             *vp = JSVAL_VOID;
3615 5658             break;
3616         }
3617
3618 305         str = JS_InternString(cx, element->ref);
3619 305         *vp = STRING_TO_JSVAL(str);
3620 305         break;
3621
3622     case refNs:
3623
3624 0         if(!element->refNs)
3625         {
3626 0             *vp = JSVAL_VOID;
3627 0             break;
3628         }
3629
3630 0         str = JS_InternString(cx, element->refNs);
3631 0         *vp = STRING_TO_JSVAL(str);
3632 0         break;
3633
3634     case refQname:
3635
3636 305         if(!element->ref)
3637         {
3638 0             *vp = JSVAL_VOID;
3639 0             break;
3640         }
3641 305         else if(!element->refNs)
3642         {
3643 0             str = JS_InternString(cx, element->ref);
3644 0             *vp = STRING_TO_JSVAL(str);
3645 0             break;
3646         }
3647         else
3648         {
3649 305             str = globus_l_wsdl_jscript_qname_string(
3650                 cx, element->refNs, element->ref);
3651 305             *vp = STRING_TO_JSVAL(str);
3652 305             break;
3653         }
3654
3655     case targetNamespace:
3656
3657 5855         if(!element->targetNamespace)
3658         {
3659 0             str = JS_InternString(cx, "");
3660         }
3661         else
3662         {
3663 5855             str = JS_InternString(cx, element->targetNamespace);
3664         }
3665
3666 5855         *vp = STRING_TO_JSVAL(str);
3667 5855         break;
3668     
3669     case namedType:
3670
3671 13768         if(!element->namedType)
3672         {
3673 1636             *vp = JSVAL_VOID;
3674 1636             break;
3675         }
3676
3677 12132         str = JS_InternString(cx, element->namedType);
3678 12132         *vp = STRING_TO_JSVAL(str);
3679 12132         break;
3680
3681     case namedTypeNs:
3682
3683 9776         if(!element->namedTypeNs)
3684         {
3685 0             *vp = JSVAL_VOID;
3686 0             break;
3687         }
3688
3689 9776         str = JS_InternString(cx, element->namedTypeNs);
3690 9776         *vp = STRING_TO_JSVAL(str);
3691 9776         break;
3692
3693     case substGroup:
3694
3695 0         if(!element->substGroup)
3696         {
3697 0             *vp = JSVAL_VOID;
3698 0             break;
3699         }
3700
3701 0         str = JS_InternString(cx, element->substGroup);
3702 0         *vp = STRING_TO_JSVAL(str);
3703 0         break;
3704
3705     case substGroupNs:
3706
3707 0         if(!element->substGroupNs)
3708         {
3709 0             *vp = JSVAL_VOID;
3710 0             break;
3711         }
3712
3713 0         str = JS_InternString(cx, element->substGroupNs);
3714 0         *vp = STRING_TO_JSVAL(str);
3715 0         break;
3716
3717     case contentType:
3718
3719 0         *vp = INT_TO_JSVAL(element->contentType);
3720 0         break;
3721
3722     case qname:
3723
3724 0         if(!element->name)
3725         {
3726 0             *vp = JSVAL_VOID;
3727 0             break;
3728         }
3729 0         else if(!element->targetNamespace)
3730         {
3731 0             str = JS_InternString(cx, element->name);
3732 0             *vp = STRING_TO_JSVAL(str);
3733 0             break;
3734         }
3735         else
3736         {
3737 0             str = globus_l_wsdl_jscript_qname_string(
3738                 cx, element->targetNamespace, element->name);
3739 0             *vp = STRING_TO_JSVAL(str);
3740 0             break;
3741         }
3742
3743     default:
3744
3745 0         *vp = JSVAL_VOID;
3746 0         JS_ReportError(cx, "Unknown property with id %d for element", idval);
3747 0         res = JS_FALSE;
3748         goto exit;
3749     }
3750
3751   exit:
3752
3753 57755     GlobusWSDLDebugExit();
3754 57755     return res;
3755 }
3756
3757 static
3758 JSBool
3759 messageGetter(
3760     JSContext *                         cx,
3761     JSObject *                          obj,
3762     jsval                               jid,
3763     jsval *                             vp)
3764 774 {
3765 774     JSBool                              res = JS_TRUE;
3766 774     int                                 idval;
3767 774     JSString *                          str = NULL;
3768 774     JSObject *                          partsObj = NULL;
3769 774     wsdlMessagePtr                      message = NULL;
3770 774     GlobusFuncName(messageGetter);
3771 774     GlobusWSDLDebugEnter();
3772
3773 774     message = (wsdlMessagePtr) JS_GetPrivate(cx, obj);
3774 774     globus_assert(message);
3775
3776 774     if(!JSVAL_IS_INT(jid))
3777     {
3778 0         JS_ReportError(cx, 
3779                        "Invalid id type (expected int) for "
3780                        "wsdl element property");
3781 0         res = JS_FALSE;
3782 0         goto exit;
3783     }
3784     
3785     
3786 774     idval = JSVAL_TO_INT(jid);
3787 774     switch(idval)
3788     {
3789
3790     case name:
3791     
3792 0         if(!message->name)
3793         {
3794 0             *vp = JSVAL_VOID;
3795 0             break;
3796         }
3797
3798 0         str = JS_InternString(cx, message->name);
3799 0         globus_assert(str);
3800
3801 0         *vp = STRING_TO_JSVAL(str);
3802 0         break;
3803
3804     case parts:
3805
3806 774         if(!message->parts)
3807         {
3808 0             *vp = JSVAL_VOID;
3809 0             break;
3810         }
3811
3812 774         partsObj = JS_NewObject(cx, &parts_class, NULL, obj);
3813 774         globus_assert(partsObj);
3814
3815 774         JS_SetPrivate(cx, partsObj, (void *) message->parts);
3816
3817 774         *vp = OBJECT_TO_JSVAL(partsObj);
3818 774         break;
3819         
3820     case targetNamespace:
3821
3822 0         if(!message->schema || !message->schema->targetNamespace)
3823         {
3824 0             *vp = JSVAL_VOID;
3825 0             break;
3826         }
3827
3828 0         str = JS_InternString(cx, message->schema->targetNamespace);
3829 0         globus_assert(str);
3830         
3831 0         *vp = STRING_TO_JSVAL(str);
3832 0         break;
3833
3834     default:
3835
3836 0         *vp = JSVAL_VOID;
3837 0         JS_ReportError(cx, 
3838                        "Unknown message property with "
3839                        "id %d for element", idval);
3840 0         res = JS_FALSE;
3841         goto exit;
3842     }
3843
3844   exit:
3845
3846 774     GlobusWSDLDebugExit();
3847 774     return res;
3848 }
3849
3850 #include "wsdlInternals.h"
3851
3852 static
3853 JSBool
3854 xsdQNamesGetter(
3855     JSContext *                         cx,
3856     JSObject *                          obj,
3857     jsval                               id,
3858     jsval *                             vp)
3859 15 {
3860 15     xsdQNamePtr                         qn;
3861 15     JSObject *                          qnObj;
3862 15     JSBool                              res = JS_TRUE;
3863 15     JSString *                          str;
3864 15     int                                 i = 0;
3865 15     GlobusFuncName(xsdQNamesGetter);
3866 15     GlobusWSDLDebugEnter();
3867
3868 15     qn = (xsdQNamePtr) JS_GetPrivate(cx, obj);
3869 15     globus_assert(qn);
3870
3871 15     if(JSVAL_IS_STRING(id))
3872     {
3873 0         while(qn)
3874         {
3875 0             str = globus_l_wsdl_jscript_qname_string(
3876                 cx, qn->Namespace, qn->name);
3877 0             *vp = STRING_TO_JSVAL(str);
3878 0             if(JS_CompareStrings(str, JSVAL_TO_STRING(id)))
3879             {
3880 0                 break;
3881             }
3882
3883 0             qn = qn->next;
3884         }
3885     }
3886 15     else if(JSVAL_IS_INT(id))
3887     {
3888 30         for(; i < JSVAL_TO_INT(id) && type; ++i)
3889         {
3890 15             qn = qn->next;
3891         }
3892 15         globus_assert(qn);  
3893     }
3894     else
3895     {
3896 0         qn = (xsdQNamePtr) JSVAL_TO_PRIVATE(id);
3897 0         globus_assert(qn);
3898     }
3899
3900 15     qnObj = JS_NewObject(cx, &xsdQName_class, 
3901                          xsdQNameClass, obj);
3902 15     globus_assert(qnObj);
3903 15     JS_SetPrivate(cx, qnObj, (void *)qn);
3904 15     JS_DefineProperties(cx, qnObj, xsdQName_properties);
3905 15     *vp = OBJECT_TO_JSVAL(qnObj);
3906
3907 15     GlobusWSDLDebugExit();
3908 15     return res;
3909 }
3910
3911 static
3912 JSBool
3913 xsdQNamesEnumerate(
3914     JSContext *                         cx,
3915     JSObject *                          obj,
3916     JSIterateOp                         enum_op,
3917     jsval *                             statep,
3918     jsid *                              idp)
3919 45 {
3920 45     xsdQNamePtr                         qn = NULL;
3921 45     JSBool                              res = JS_TRUE;
3922 45     int                                 i = 0;
3923 45     int                                 index;
3924 45     GlobusFuncName(xsdQNameEnumerate);
3925 45     GlobusWSDLDebugEnter();
3926
3927 45     qn = (xsdQNamePtr) JS_GetPrivate(cx, obj);
3928 45     globus_assert(qn);
3929     
3930 45     switch(enum_op)
3931     {
3932     case JSENUMERATE_INIT:
3933         
3934 15         *statep = INT_TO_JSVAL(0);
3935 15         if(idp)
3936         {
3937 0             *idp = JSVAL_ZERO;
3938         }
3939 0         break;
3940
3941     case JSENUMERATE_NEXT:
3942
3943 30         index = JSVAL_TO_INT(*statep);
3944 60         for(; i < index && qn; ++i)
3945         {
3946 15             qn = qn->next;
3947         }
3948
3949 30         if(!qn)
3950         {
3951 15             *statep = JSVAL_NULL;
3952 15             *idp = JSVAL_ZERO;
3953 15             break;
3954         }
3955
3956 15         *idp = *statep;
3957 15         *statep = INT_TO_JSVAL(index + 1);
3958
3959         break;
3960
3961     case JSENUMERATE_DESTROY:
3962             
3963 45         break;
3964     }
3965
3966 45     GlobusWSDLDebugExit();
3967 45     return res;
3968 }
3969
3970 static
3971 JSBool
3972 xsdQNameGetter(
3973     JSContext *                         cx,
3974     JSObject *                          obj,
3975     jsval                               jid,
3976     jsval *                             vp)
3977 15 {               
3978 15     xsdQNamePtr                         qn;
3979 15     JSBool                              res = JS_TRUE;
3980 15     jsval                               idval;
3981 15     JSString *                          str;
3982 15     GlobusFuncName(portTypeGetter);
3983 15     GlobusWSDLDebugEnter();
3984
3985 15     qn = (xsdQNamePtr) JS_GetPrivate(cx, obj);
3986 15     globus_assert(qn);
3987
3988 15     if(!JSVAL_IS_INT(jid))
3989     {
3990 0         JS_ReportError(cx, 
3991                        "Invalid id type (expected int) for "
3992                        "wsdl xsdQName property");
3993 0         res = JS_FALSE;
3994 0         goto exit;
3995     }
3996     
3997 15     idval = JSVAL_TO_INT(jid);
3998 15     switch(idval)
3999     {
4000     case name:
4001
4002 0         if(!qn->name)
4003         {
4004 0             *vp = JSVAL_VOID;
4005 0             break;
4006         }
4007
4008 0         str = JS_InternString(cx, qn->name);
4009 0         if(!str)
4010         {
4011 0             *vp = JSVAL_VOID;
4012 0             break;
4013         }
4014
4015 0         *vp = STRING_TO_JSVAL(str);
4016 0         break;
4017
4018     case Namespace:
4019
4020 0         if(!qn->Namespace)
4021         {
4022 0             *vp = JSVAL_VOID;
4023 0             break;
4024         }
4025
4026 0         str = JS_InternString(cx, qn->Namespace);
4027 0         if(!str)
4028         {
4029 0             *vp = JSVAL_VOID;
4030 0             break;
4031         }
4032
4033 0         *vp = STRING_TO_JSVAL(str);
4034 0         break;
4035
4036     case qname:
4037
4038 15         if(!qn->name)
4039         {
4040 0             *vp = JSVAL_VOID;
4041 0             break;
4042         }
4043 15         else if(!qn->Namespace)
4044         {
4045 0             str = JS_InternString(cx, qn->name);
4046 0             if(!str)
4047             {
4048 0                 *vp = JSVAL_VOID;
4049 0                 break;
4050             }
4051
4052 0             *vp = STRING_TO_JSVAL(str);
4053 0             break;
4054         }
4055         else
4056         {
4057 15             str = globus_l_wsdl_jscript_qname_string(
4058                 cx, qn->Namespace, qn->name);
4059 15             *vp = STRING_TO_JSVAL(str);
4060 15             break;
4061         }
4062     
4063     default:
4064
4065 0         *vp = JSVAL_VOID;
4066 0         JS_ReportError(cx, 
4067                        "Unknown xsdQName property "
4068                        "with id %d for element", idval);
4069 0         res = JS_FALSE;
4070         goto exit;
4071     }
4072
4073   exit:
4074
4075 15     GlobusWSDLDebugExit();
4076 15     return res;
4077 }
4078
4079 static
4080 JSBool
4081 portTypeGetter(
4082     JSContext *                         cx,
4083     JSObject *                          obj,
4084     jsval                               jid,
4085     jsval *                             vp)
4086 1368 {
4087 1368     JSBool                              res = JS_TRUE;
4088 1368     JSString *                          str = NULL;
4089 1368     int                                 idval;
4090 1368     JSObject *                          operationsObj = NULL;
4091 1368     JSObject *                          xsdQNamesObj = NULL;
4092 1368     wsdlPortTypePtr                     portType = NULL;
4093 1368     GlobusFuncName(portTypeGetter);
4094 1368     GlobusWSDLDebugEnter();
4095
4096 1368     portType = (wsdlPortTypePtr) JS_GetPrivate(cx, obj);
4097 1368     globus_assert(portType);
4098
4099 1368     if(!JSVAL_IS_INT(jid))
4100     {
4101 0         JS_ReportError(cx, 
4102                        "Invalid id type (expected int) for "
4103                        "wsdl PortType property");
4104 0         res = JS_FALSE;
4105 0         goto exit;
4106     }
4107     
4108 1368     idval = JSVAL_TO_INT(jid);
4109 1368     switch(idval)
4110     {
4111     case name:
4112
4113 638         if(!portType->name)
4114         {
4115 0             *vp = JSVAL_VOID;
4116 0             break;
4117         }
4118
4119 638         str = JS_InternString(cx, portType->name);
4120 638         if(!str)
4121         {
4122 0             *vp = JSVAL_VOID;
4123 0             break;
4124         }
4125
4126 638         *vp = STRING_TO_JSVAL(str);
4127 638         break;
4128
4129     case operations:
4130
4131 526         if(!portType->operations)
4132         {
4133 0             *vp = JSVAL_VOID;
4134 0             break;
4135         }
4136
4137 526         operationsObj = JS_NewObject(cx, &operations_class, NULL, obj);
4138 526         globus_assert(operationsObj);
4139
4140 526         JS_SetPrivate(cx, operationsObj, (void *) portType->operations);
4141         
4142 526         *vp = OBJECT_TO_JSVAL(operationsObj);
4143 526         break;
4144
4145     case ResourceProperties:
4146
4147 50         if(!portType->ResourceProperties)
4148         {
4149 20             *vp = JSVAL_VOID;
4150 20             break;
4151         }
4152
4153 30         xsdQNamesObj = JS_NewObject(cx, &xsdQNames_class, NULL, obj);
4154 30         globus_assert(xsdQNamesObj);
4155         
4156 30         JS_SetPrivate(cx, xsdQNamesObj, (void *) portType->ResourceProperties);
4157
4158 30         *vp = OBJECT_TO_JSVAL(xsdQNamesObj);
4159 30         break;
4160
4161     case implements:
4162
4163 0         if(!portType->implements)
4164         {
4165 0             *vp = JSVAL_VOID;
4166 0             break;
4167         }
4168
4169 0         xsdQNamesObj = JS_NewObject(cx, &xsdQNames_class, NULL, obj);
4170 0         globus_assert(xsdQNamesObj);
4171
4172 0         JS_SetPrivate(cx, xsdQNamesObj, (void *) portType->implements);
4173
4174 0         *vp = OBJECT_TO_JSVAL(xsdQNamesObj);
4175 0         break;
4176
4177     case targetNamespace:
4178
4179 154         if(!portType->schema || !portType->schema->targetNamespace)
4180         {
4181 0             *vp = JSVAL_VOID;
4182 0             break;
4183         }
4184
4185 154         str = JS_InternString(cx, portType->schema->targetNamespace);
4186 154         globus_assert(str);
4187         
4188 154         *vp = STRING_TO_JSVAL(str);
4189 154         break;
4190     
4191     default:
4192
4193 0         *vp = JSVAL_VOID;
4194 0         JS_ReportError(cx, 
4195                        "Unknown portType property "
4196                        "with id %d for element", idval);
4197 0         res = JS_FALSE;
4198         goto exit;
4199     }
4200
4201   exit:
4202
4203 1368     GlobusWSDLDebugExit();
4204 1368     return res;
4205 }
4206
4207 static
4208 JSBool
4209 bindingGetter(
4210     JSContext *                         cx,
4211     JSObject *                          obj,
4212     jsval                               jid,
4213     jsval *                             vp)
4214 461 {
4215 461     JSBool                              res = JS_TRUE;
4216 461     int                                 idval;
4217 461     JSString *                          str = NULL;
4218 461     JSObject *                          portTypeObj = NULL;
4219 461     JSObject *                          operationsObj = NULL;
4220 461     JSObject *                          soapBindingObj = NULL;
4221 461     wsdlBindingPtr                      binding = NULL;
4222 461     GlobusFuncName(bindingGetter);
4223 461     GlobusWSDLDebugEnter();
4224
4225 461     binding = (wsdlBindingPtr) JS_GetPrivate(cx, obj);
4226 461     globus_assert(binding);
4227
4228 461     if(!JSVAL_IS_INT(jid))
4229     {
4230 0         JS_ReportError(cx, 
4231                        "Invalid id type (expected int) for "
4232                        "wsdl binding property");
4233 0         res = JS_FALSE;
4234 0         goto exit;
4235     }
4236     
4237     
4238 461     idval = JSVAL_TO_INT(jid);
4239 461     switch(idval)
4240     {
4241     case name:
4242
4243 0         if(!binding->name)
4244         {
4245 0             *vp = JSVAL_VOID;
4246 0             break;
4247         }
4248
4249 0         str = JS_InternString(cx, binding->name);
4250 0         if(!str)
4251         {
4252 0             *vp = JSVAL_VOID;
4253 0             break;
4254         }
4255
4256 0         *vp = STRING_TO_JSVAL(str);
4257 0         break;
4258         
4259     case type:
4260
4261 96         if(!binding->type)
4262         {
4263 0             *vp = JSVAL_VOID;
4264 0             break;
4265         }
4266
4267 96         portTypeObj = JS_NewObject(cx, &portType_class, 
4268                                    portTypeClass, obj);
4269 96         globus_assert(portTypeObj);
4270 96         JS_SetPrivate(cx, portTypeObj, (void *)binding->type);
4271 96         JS_DefineProperties(cx, portTypeObj, portType_properties);
4272 96         *vp = OBJECT_TO_JSVAL(portTypeObj);
4273 96         break;
4274
4275     case operations:
4276
4277 365         if(!binding->operations)
4278         {
4279 0             *vp = JSVAL_VOID;
4280 0             break;
4281         }
4282
4283 365         operationsObj = JS_NewObject(cx, &bindingOperations_class, 
4284                                      NULL, obj);
4285 365         globus_assert(operationsObj);
4286 365         JS_SetPrivate(cx, operationsObj, (void *)binding->operations);
4287
4288 365         *vp = OBJECT_TO_JSVAL(operationsObj);
4289 365         break;
4290
4291     case soap:
4292
4293 0         if(!binding->extension || (binding->extensionType != SOAP_BINDING))
4294         {
4295 0             *vp = JSVAL_VOID;
4296 0             break;
4297         }
4298
4299 0         soapBindingObj = JS_NewObject(cx, &soapBinding_class, 
4300                                       soapBindingClass, obj);
4301 0         globus_assert(soapBindingObj);
4302 0         JS_SetPrivate(cx, soapBindingObj, 
4303                                 (void *)binding->extension);
4304 0         JS_DefineProperties(cx, soapBindingObj, 
4305                                       soapBinding_properties);
4306 0         *vp = OBJECT_TO_JSVAL(soapBindingObj);
4307 0         break;
4308         
4309     case extensionType:
4310
4311 0         *vp = INT_TO_JSVAL(binding->extensionType);
4312 0         break;
4313
4314     case targetNamespace:
4315
4316 0         if(!binding->schema || !binding->schema->targetNamespace)
4317         {
4318 0             *vp = JSVAL_VOID;
4319 0             break;
4320         }
4321
4322 0         str = JS_InternString(cx, binding->schema->targetNamespace);
4323 0         globus_assert(str);
4324         
4325 0         *vp = STRING_TO_JSVAL(str);
4326 0         break;
4327
4328     default:
4329
4330 0         *vp = JSVAL_VOID;
4331 0         JS_ReportError(cx, 
4332                        "Unknown property for binding "
4333                        "with id %d for element", idval);
4334 0         res = JS_FALSE;
4335         goto exit;
4336     }
4337
4338   exit:
4339
4340 461     GlobusWSDLDebugExit();
4341 461     return res;
4342 }
4343
4344 static
4345 JSBool
4346 bindingOperationsGetter(
4347     JSContext *                         cx,
4348     JSObject *                          obj,
4349     jsval                               id,
4350     jsval *                             vp)
4351 326 {
4352 326     JSBool                              res = JS_TRUE;
4353 326     wsdlBindingOperationPtr             bop;
4354 326     JSObject *                          bopObj;
4355 326     int                                 i = 0;
4356 326     GlobusFuncName(bindingOperationsGetter);
4357 326     GlobusWSDLDebugEnter();
4358
4359 326     bop = (wsdlBindingOperationPtr) JS_GetPrivate(cx, obj);
4360 326     globus_assert(bop);
4361
4362 326     if(JSVAL_IS_STRING(id))
4363     {
4364 0         while(bop)
4365         {
4366 0             JSString *                  name;
4367             
4368 0             name = JS_InternString(cx, bop->name);
4369 0             if(JS_CompareStrings(name, JSVAL_TO_STRING(id)))
4370             {
4371 0                 break;
4372             }
4373
4374 0             bop = bop->next;
4375         }
4376     }
4377 326     else if(JSVAL_IS_INT(id))
4378     {
4379 2558         for(; i < JSVAL_TO_INT(id) && bop; ++i)
4380         {
4381 1116             bop = bop->next;
4382         }
4383 326         globus_assert(bop);
4384     }
4385     else
4386     {
4387 0         bop = (wsdlBindingOperationPtr) JSVAL_TO_PRIVATE(id);
4388 0         globus_assert(bop);
4389     }
4390
4391 326     bopObj = JS_NewObject(cx, &bindingOperation_class, 
4392                           bindingOperationClass, obj);
4393 326     globus_assert(bopObj);
4394 326     JS_SetPrivate(cx, bopObj, (void *)bop);
4395 326     JS_DefineProperties(cx, bopObj, bindingOperation_properties);
4396 326     *vp = OBJECT_TO_JSVAL(bopObj);
4397
4398 326     GlobusWSDLDebugExit();
4399 326     return res;
4400 }
4401
4402 static
4403 JSBool
4404 bindingOperationsEnumerate(
4405     JSContext *                         cx,
4406     JSObject *                          obj,
4407     JSIterateOp                         enum_op,
4408     jsval *                             statep,
4409     jsid *                              idp)
4410 365 {
4411 365     JSBool                              res = JS_TRUE;
4412 365     wsdlBindingOperationPtr             boperation;
4413 365     int                                 i = 0;
4414 365     int                                 index;
4415 365     GlobusFuncName(bindingOperationsEnumerate);
4416 365     GlobusWSDLDebugEnter();
4417
4418 365     boperation = (wsdlBindingOperationPtr) JS_GetPrivate(cx, obj);
4419 365     globus_assert(boperation);
4420     
4421 365     switch(enum_op)
4422     {
4423     case JSENUMERATE_INIT:
4424         
4425 39         *statep = INT_TO_JSVAL(i);
4426 39         break;
4427
4428     case JSENUMERATE_NEXT:
4429
4430 326         index = JSVAL_TO_INT(*statep);
4431 2884         for(; i < index && boperation; ++i)
4432         {
4433 1279             boperation = boperation->next;
4434         }
4435
4436 326         if(!boperation)
4437         {
4438 39             *statep = JSVAL_NULL;
4439 39             *idp = JSVAL_ZERO;
4440 39             break;
4441         }
4442
4443 287         *idp = *statep;
4444 287         *statep = INT_TO_JSVAL(index + 1);
4445
4446         break;
4447
4448     case JSENUMERATE_DESTROY:
4449             
4450 365         break;
4451     }
4452
4453 365     GlobusWSDLDebugExit();
4454 365     return res;
4455 }
4456
4457 static
4458 JSBool
4459 bindingOperationGetter(
4460     JSContext *                         cx,
4461     JSObject *                          obj,
4462     jsval                               jid,
4463     jsval *                             vp)
4464 287 {
4465 287     int                                 idval;
4466 287     JSString *                          str;
4467 287     JSBool                              res = JS_TRUE;
4468 287     JSObject *                          inObj = NULL;
4469 287     JSObject *                          outObj = NULL;
4470 287     JSObject *                          faultsObj = NULL;
4471 287     JSObject *                          soapObj = NULL;
4472 287     wsdlBindingOperationPtr             bop = NULL;
4473 287     GlobusFuncName(bindingOperationGetter);
4474 287     GlobusWSDLDebugEnter();
4475     
4476 287     bop = (wsdlBindingOperationPtr) JS_GetPrivate(cx, obj);
4477 287     globus_assert(bop);
4478
4479 287     if(!JSVAL_IS_INT(jid))
4480     {
4481 0         JS_ReportError(cx, 
4482                        "Invalid id type (expected int) "
4483                        "for wsdl bindingOperation property");
4484 0         res = JS_FALSE;
4485 0         goto exit;
4486     }
4487
4488 287     idval = JSVAL_TO_INT(jid);
4489
4490 287     switch(idval)
4491     {
4492     case name:
4493
4494 287         if(!bop->name)
4495         {
4496 0             *vp = JSVAL_VOID;
4497 0             break;
4498         }
4499         
4500 287         str = JS_InternString(cx, bop->name);
4501 287         globus_assert(str);
4502
4503 287         *vp = STRING_TO_JSVAL(str);
4504 287         break;
4505
4506     case input:
4507
4508 0         if(!bop->input || (bop->inputType != SOAP_BINDING))
4509         {
4510 0             *vp = JSVAL_VOID;
4511 0             break;
4512         }
4513
4514 0         inObj = JS_NewObject(cx, &soapBindingParam_class, 
4515                              soapBindingParamClass, obj);
4516 0         globus_assert(inObj);
4517 0         JS_SetPrivate(cx, inObj, (void *)bop->input);
4518 0         JS_DefineProperties(cx, inObj, soapBindingParam_properties);
4519 0         *vp = OBJECT_TO_JSVAL(inObj);
4520 0         break;
4521     
4522     case output:
4523
4524 0         if(!bop->output || (bop->outputType != SOAP_BINDING))
4525         {
4526 0             *vp = JSVAL_VOID;
4527 0             break;
4528         }
4529
4530 0         outObj = JS_NewObject(cx, &soapBindingParam_class, 
4531                               soapBindingParamClass, obj);
4532 0         globus_assert(outObj);
4533 0         JS_SetPrivate(cx, outObj, (void *)bop->output);
4534 0         JS_DefineProperties(cx, outObj, soapBindingParam_properties);
4535 0         *vp = OBJECT_TO_JSVAL(outObj);
4536 0         break;
4537     
4538     case inputType:
4539
4540 0         *vp = INT_TO_JSVAL(bop->inputType);
4541 0         break;
4542
4543     case outputType:
4544
4545 0         *vp = INT_TO_JSVAL(bop->outputType);
4546 0         break;
4547
4548     case faults:
4549
4550 0         if(!bop->faults)
4551         {
4552 0             *vp = JSVAL_VOID;
4553 0             break;
4554         }
4555
4556 0         faultsObj = JS_NewObject(cx, &bindingOperationFaults_class, 
4557                                  NULL, obj);
4558 0         globus_assert(faultsObj);
4559 0         JS_SetPrivate(cx, faultsObj, (void *) bop->faults);
4560         
4561 0         *vp = OBJECT_TO_JSVAL(faultsObj);
4562 0         break;
4563
4564     case soap:
4565
4566 0         if(!bop->extension || (bop->extensionType != SOAP_BINDING))
4567         {
4568 0             *vp = JSVAL_VOID;
4569 0             break;
4570         }
4571
4572 0         soapObj = JS_NewObject(cx, &soapOperation_class, 
4573                                soapOperationClass, obj);
4574 0         globus_assert(soapObj);
4575 0         JS_SetPrivate(cx, soapObj, (void *)bop->extension);
4576 0         JS_DefineProperties(cx, soapObj, soapOperation_properties);
4577 0         *vp = OBJECT_TO_JSVAL(soapObj);
4578 0         break;
4579
4580     default:
4581
4582 0         *vp = JSVAL_VOID;
4583 0         JS_ReportError(cx, 
4584                        "Unknown binding operation property "
4585                        "with id %d for part", idval);
4586 0         res = JS_FALSE;
4587         goto exit;
4588     }
4589
4590   exit:
4591
4592 287     GlobusWSDLDebugExit();
4593 287     return res;
4594 }
4595
4596 static
4597 JSBool
4598 bindingOperationFaultsGetter(
4599     JSContext *                         cx,
4600     JSObject *                          obj,
4601     jsval                               id,
4602     jsval *                             vp)
4603 0 {
4604 0     wsdlBindingOperationFaultPtr        bopf;
4605 0     JSObject *                          bopfObj;
4606 0     JSBool                              res = JS_TRUE;
4607 0     int                                 i = 0;
4608 0     GlobusFuncName(bindingOperationFaultsGetter);
4609 0     GlobusWSDLDebugEnter();
4610     
4611 0     bopf = (wsdlBindingOperationFaultPtr) JS_GetPrivate(cx, obj);
4612 0     globus_assert(bopf);
4613     
4614 0     if(JSVAL_IS_STRING(id))
4615     {
4616 0         while(bopf)
4617         {
4618 0             JSString *                  name;
4619             
4620 0             name = JS_InternString(cx, bopf->name);
4621 0             if(JS_CompareStrings(name, JSVAL_TO_STRING(id)))
4622             {
4623 0                 break;
4624             }
4625             
4626 0             bopf = bopf->next;
4627         }
4628     }
4629 0     else if(JSVAL_IS_INT(id))
4630     {
4631 0         for(; i < JSVAL_TO_INT(id) && bopf; ++i)
4632         {
4633 0             bopf = bopf->next;
4634         }
4635 0         globus_assert(bopf);
4636     }
4637     else
4638     {
4639 0         bopf = (wsdlBindingOperationFaultPtr) JSVAL_TO_PRIVATE(id);
4640 0         globus_assert(bopf);
4641     }
4642     
4643 0     bopfObj = JS_NewObject(cx, &bindingOperationFault_class, 
4644                            bindingOperationFaultClass, obj);
4645 0     globus_assert(bopfObj);
4646 0     JS_SetPrivate(cx, bopfObj, (void *)bopf);
4647 0     JS_DefineProperties(cx, bopfObj, 
4648                                   bindingOperationFault_properties);
4649     
4650 0     *vp = OBJECT_TO_JSVAL(bopfObj);
4651     
4652 0     GlobusWSDLDebugExit();
4653 0     return res;
4654 }
4655
4656 static
4657 JSBool
4658 bindingOperationFaultsEnumerate(
4659     JSContext *                         cx,
4660     JSObject *                          obj,
4661     JSIterateOp                         enum_op,
4662     jsval *                             statep,
4663     jsid *                              idp)
4664 0 {
4665 0     JSBool                              res = JS_TRUE;
4666 0     wsdlBindingOperationFaultPtr        bopf;
4667 0     int                                 i = 0;
4668 0     int                                 index;
4669 0     GlobusFuncName(bindingOperationFaultsEnumerate);
4670 0     GlobusWSDLDebugEnter();
4671     
4672 0     bopf = (wsdlBindingOperationFaultPtr) JS_GetPrivate(cx, obj);
4673 0     globus_assert(bopf);
4674     
4675 0     switch(enum_op)
4676     {
4677     case JSENUMERATE_INIT:
4678         
4679 0         *statep = INT_TO_JSVAL(i);
4680 0         break;
4681
4682     case JSENUMERATE_NEXT:
4683         
4684 0         index = JSVAL_TO_INT(*statep);
4685 0         for(; i < index && bopf; ++i)
4686         {
4687 0             bopf = bopf->next;
4688         }
4689
4690 0         if(!bopf)
4691         {
4692 0             *statep = JSVAL_NULL;
4693 0             *idp = JSVAL_ZERO;
4694 0             break;
4695         }
4696         
4697 0         *idp = *statep;
4698 0         *statep = INT_TO_JSVAL(index + 1);
4699         
4700         break;
4701         
4702     case JSENUMERATE_DESTROY:
4703         
4704 0         break;
4705     }
4706
4707 0     GlobusWSDLDebugExit();
4708 0     return res;
4709 }
4710
4711 static
4712 JSBool
4713 bindingOperationFaultGetter(
4714     JSContext *                         cx,
4715     JSObject *                          obj,
4716     jsval                               jid,
4717     jsval *                             vp)
4718 0 {
4719 0     int                                 idval;
4720 0     JSString *                          str = NULL;
4721 0     JSBool                              res = JS_TRUE;
4722 0     wsdlBindingOperationFaultPtr        bopf = NULL;
4723 0     JSObject *                          soapObj = NULL;
4724 0     GlobusFuncName(bindingOperationFaultGetter);
4725 0     GlobusWSDLDebugEnter();
4726     
4727 0     bopf = (wsdlBindingOperationFaultPtr) JS_GetPrivate(cx, obj);
4728 0     globus_assert(bopf);
4729     
4730 0     if(!JSVAL_IS_INT(jid))
4731     {
4732 0         JS_ReportError(cx, 
4733                        "Invalid id type (expected int) "
4734                        "for wsdl bindingOperationFault property");
4735 0         res = JS_FALSE;
4736 0         goto exit;
4737     }
4738     
4739 0     idval = JSVAL_TO_INT(jid);
4740     
4741 0     switch(idval)
4742     {
4743     case name:
4744
4745 0         if(!bopf->name)
4746         {
4747 0             *vp = JSVAL_VOID;
4748 0             break;
4749         }
4750         
4751 0         str = JS_InternString(cx, bopf->name);
4752 0         globus_assert(str);
4753
4754 0         *vp = STRING_TO_JSVAL(str);
4755 0         break;
4756
4757     case soap:
4758
4759 0         if(!bopf->extension || (bopf->extensionType != SOAP_BINDING))
4760         {
4761 0             *vp = JSVAL_VOID;
4762 0             break;
4763         }
4764
4765 0         soapObj = JS_NewObject(cx, &soapFault_class, soapFaultClass, obj);
4766 0         globus_assert(soapObj);
4767 0         JS_SetPrivate(cx, soapObj, bopf->extension);
4768 0         JS_DefineProperties(cx, soapObj, soapFault_properties);
4769 0         *vp = OBJECT_TO_JSVAL(soapObj);
4770 0         break;
4771
4772     default:
4773
4774 0         *vp = JSVAL_VOID;
4775 0         JS_ReportError(cx, "Unknown part property with id %d for part", idval);
4776 0         res = JS_FALSE;
4777         goto exit;
4778     }
4779
4780   exit:
4781
4782 0     GlobusWSDLDebugExit();
4783 0     return res;
4784 }
4785
4786 static
4787 JSBool
4788 partsEnumerate(
4789     JSContext *                         cx,
4790     JSObject *                          obj,
4791     JSIterateOp                         enum_op,
4792     jsval *                             statep,
4793     jsid *                              idp)
4794 0 {
4795 0     JSBool                              res = JS_TRUE;
4796 0     wsdlPartPtr                         parts;
4797 0     int                                 i = 0;
4798 0     int                                 index;
4799 0     GlobusFuncName(partsEnumerate);
4800 0     GlobusWSDLDebugEnter();
4801
4802 0     parts = (wsdlPartPtr) JS_GetPrivate(cx, obj);
4803 0     globus_assert(parts);
4804     
4805 0     switch(enum_op)
4806     {
4807     case JSENUMERATE_INIT:
4808         
4809 0         *statep = INT_TO_JSVAL(i);
4810 0         break;
4811
4812     case JSENUMERATE_NEXT:
4813
4814 0         index = JSVAL_TO_INT(*statep);
4815 0         for(; i < index && parts; ++i)
4816         {
4817 0             parts = parts->next;
4818         }
4819
4820 0         if(!parts)
4821         {
4822 0             *statep = JSVAL_NULL;
4823 0             *idp = JSVAL_ZERO;
4824 0             break;
4825         }
4826
4827 0         *idp = *statep;
4828 0         *statep = INT_TO_JSVAL(index + 1);
4829
4830         break;
4831
4832     case JSENUMERATE_DESTROY:
4833             
4834 0         break;
4835     }
4836
4837 0     GlobusWSDLDebugExit();
4838 0     return res;
4839 }
4840
4841 static
4842 JSBool
4843 partsGetter(
4844     JSContext *                         cx,
4845     JSObject *                          obj,
4846     jsval                               id,
4847     jsval *                             vp)
4848 774 {
4849 774     wsdlPartPtr                         part = NULL;
4850 774     JSObject *                          partObj = NULL;
4851 774     JSBool                              res = JS_TRUE;
4852 774     int                                 i = 0;
4853 774     GlobusFuncName(partsGetter);
4854 774     GlobusWSDLDebugEnter();
4855
4856 774     part = (wsdlPartPtr) JS_GetPrivate(cx, obj);
4857 774     globus_assert(part);
4858
4859 774     if(JSVAL_IS_STRING(id))
4860     {
4861 0         while(part)
4862         {
4863 0             JSString *                  name;
4864             
4865 0             name = JS_InternString(cx, part->name);
4866 0             if(JS_CompareStrings(name, JSVAL_TO_STRING(id)))
4867             {
4868 0                 break;
4869             }
4870
4871 0             part = part->next;
4872         }
4873     }
4874 774     else if(JSVAL_IS_INT(id))
4875     {
4876 774         for(; i < JSVAL_TO_INT(id) && part; ++i)
4877         {
4878 0             part = part->next;
4879         }
4880 774         globus_assert(part); 
4881     }
4882
4883 774     partObj = JS_NewObject(cx, &part_class, 
4884                           partClass, obj);
4885 774     globus_assert(partObj);
4886 774     JS_SetPrivate(cx, partObj, (void *)part);
4887 774     JS_DefineProperties(cx, partObj, part_properties);
4888
4889 774     *vp = OBJECT_TO_JSVAL(partObj);
4890
4891 774     GlobusWSDLDebugExit();
4892 774     return res;
4893 }
4894
4895 static
4896 JSBool
4897 partGetter(
4898     JSContext *                         cx,
4899     JSObject *                          obj,
4900     jsval                               jid,
4901     jsval *                             vp)
4902 774 {
4903 774     int                                 idval;
4904 774     JSString *                          str = NULL;
4905 774     JSObject *                          typeObj = NULL;
4906 774     JSObject *                          elementObj = NULL;
4907 774     JSBool                              res = JS_TRUE;
4908 774     wsdlPartPtr                         part = NULL;
4909 774     GlobusFuncName(partGetter);
4910 774     GlobusWSDLDebugEnter();
4911     
4912 774     part = (wsdlPartPtr) JS_GetPrivate(cx, obj);
4913 774     globus_assert(part);
4914
4915 774     if(!JSVAL_IS_INT(jid))
4916     {
4917 0         JS_ReportError(cx, 
4918                        "Invalid id type (expected int) "
4919                        "for wsdl part property");
4920 0         res = JS_FALSE;
4921 0         goto exit;
4922     }
4923
4924 774     idval = JSVAL_TO_INT(jid);
4925
4926 774     switch(idval)
4927     {
4928     case name:
4929
4930 0         if(!part->name)
4931         {
4932 0             *vp = JSVAL_VOID;
4933 0             break;
4934         }
4935         
4936 0         str = JS_InternString(cx, part->name);
4937 0         globus_assert(str);
4938
4939 0         *vp = STRING_TO_JSVAL(str);
4940 0         break;
4941
4942     case type:
4943
4944 0         if(!part->type)
4945         {
4946 0             *vp = JSVAL_VOID;
4947 0             break;
4948         }
4949         
4950 0         typeObj = JS_NewObject(cx, &xsdType_class, xsdTypeClass, obj);
4951 0         globus_assert(typeObj);
4952 0         JS_SetPrivate(cx, typeObj, (void *)part->type);
4953 0         JS_DefineProperties(cx, typeObj, xsdType_properties);
4954 0         *vp = OBJECT_TO_JSVAL(typeObj);
4955 0         break;
4956
4957     case element:
4958
4959 774         if(!part->element)
4960         {
4961 0             *vp = JSVAL_VOID;
4962 0             break;
4963         }
4964
4965 774         elementObj = JS_NewObject(cx, &xsdElement_class, xsdElementClass, obj);
4966 774         globus_assert(elementObj);
4967 774         JS_SetPrivate(cx, elementObj, (void *)part->element);
4968 774         JS_DefineProperties(cx, elementObj, xsdElement_properties);
4969 774         *vp = OBJECT_TO_JSVAL(elementObj);
4970 774         break;
4971
4972     default:
4973
4974 0         *vp = JSVAL_VOID;
4975 0         JS_ReportError(cx, "Unknown part property with id %d for part", idval);
4976 0         res = JS_FALSE;
4977         goto exit;
4978     }
4979
4980   exit:
4981
4982 774     GlobusWSDLDebugExit();
4983 774     return res;
4984 }
4985
4986 static
4987 JSBool
4988 operationsGetter(
4989     JSContext *                         cx,
4990     JSObject *                          obj,
4991     jsval                               id,
4992     jsval *                             vp)
4993 453 {
4994 453     wsdlOperationPtr                    operation;
4995 453     JSObject *                          operationObj;
4996 453     JSBool                              res = JS_TRUE;
4997 453     int                                 i = 0;
4998 453     GlobusFuncName(operationsGetter);
4999 453     GlobusWSDLDebugEnter();
5000
5001 453     operation = (wsdlOperationPtr) JS_GetPrivate(cx, obj);
5002 453     globus_assert(operation);
5003
5004 453     if(JSVAL_IS_STRING(id))
5005     {
5006 0         while(operation)
5007         {
5008 0             JSString *                  name;
5009             
5010 0             name = JS_InternString(cx, operation->name);
5011 0             if(JS_CompareStrings(name, JSVAL_TO_STRING(id)))
5012             {
5013 0                 break;
5014             }
5015
5016 0             operation = operation->next;
5017         }
5018     }
5019 453     else if(JSVAL_IS_INT(id))
5020     {
5021 3497         for(; i < JSVAL_TO_INT(id) && operation; ++i)
5022         {
5023 1522             operation = operation->next;
5024         }
5025 453         globus_assert(operation);
5026     }
5027     else
5028     {
5029 0         operation = (wsdlOperationPtr) JSVAL_TO_PRIVATE(id);
5030 0         globus_assert(operation);
5031     }
5032
5033 453     operationObj = JS_NewObject(cx, &operation_class, 
5034                                 operationClass, obj);
5035 453     globus_assert(operationObj);
5036 453     JS_SetPrivate(cx, operationObj, (void *)operation);
5037 453     JS_DefineProperties(cx, operationObj, operation_properties);
5038 453     *vp = OBJECT_TO_JSVAL(operationObj);
5039
5040 453     GlobusWSDLDebugExit();
5041 453     return res;
5042 }
5043
5044 static
5045 JSBool
5046 operationsEnumerate(
5047     JSContext *                         cx,
5048     JSObject *                          obj,
5049     JSIterateOp                         enum_op,
5050     jsval *                             statep,
5051     jsid *                              idp)
5052 599 {
5053 599     JSBool                              res = JS_TRUE;
5054 599     wsdlOperationPtr                    operations;
5055 599     int                                 i = 0;
5056 599     int                                 index;
5057 599     GlobusFuncName(operationsEnumerate);
5058 599     GlobusWSDLDebugEnter();
5059
5060 599     operations = (wsdlOperationPtr) JS_GetPrivate(cx, obj);
5061 599     globus_assert(operations);
5062     
5063 599     switch(enum_op)
5064     {
5065     case JSENUMERATE_INIT:
5066         
5067 73         *statep = INT_TO_JSVAL(i);
5068 73         break;
5069
5070     case JSENUMERATE_NEXT:
5071
5072 526         index = JSVAL_TO_INT(*statep);
5073 4476         for(; i < index && operations; ++i)
5074         {
5075 1975             operations = operations->next;
5076         }
5077
5078 526         if(!operations)
5079         {
5080 73             *statep = JSVAL_NULL;
5081 73             *idp = JSVAL_ZERO;
5082 73             break;
5083         }
5084
5085 453         *idp = *statep;
5086 453         *statep = INT_TO_JSVAL(index + 1);
5087
5088         break;
5089
5090     case JSENUMERATE_DESTROY:
5091             
5092 599         break;
5093     }
5094
5095 599     GlobusWSDLDebugExit();
5096 599     return res;
5097 }
5098
5099 static
5100 JSBool
5101 operationGetter(
5102     JSContext *                         cx,
5103     JSObject *                          obj,
5104     jsval                               jid,
5105     jsval *                             vp)
5106 4658 {
5107 4658     JSString *                          str = NULL;
5108 4658     JSObject *                          paramObj = NULL;
5109 4658     JSObject *                          faultsObj = NULL;
5110 4658     int                                 idval;
5111 4658     JSBool                              res = JS_TRUE;
5112 4658     wsdlOperationPtr                    operation = NULL;
5113 4658     GlobusFuncName(operationGetter);
5114 4658     GlobusWSDLDebugEnter();
5115     
5116 4658     operation = (wsdlOperationPtr) JS_GetPrivate(cx, obj);
5117 4658     globus_assert(operation);
5118
5119 4658     if(!JSVAL_IS_INT(jid))
5120     {
5121 0         JS_ReportError(cx, 
5122                        "Invalid id type (expected int) "
5123                        "for wsdl operation property");
5124 0         res = JS_FALSE;
5125 0         goto exit;
5126     }
5127
5128 4658     idval = JSVAL_TO_INT(jid);
5129
5130 4658     switch(idval)
5131     {
5132     case name:
5133
5134 1446         if(!operation->name)
5135         {
5136 0             *vp = JSVAL_VOID;
5137 0             break;
5138         }
5139         
5140 1446         str = JS_InternString(cx, operation->name);
5141 1446         globus_assert(str);
5142
5143 1446         *vp = STRING_TO_JSVAL(str);
5144 1446         break;
5145
5146     case type:
5147
5148 1648         *vp = INT_TO_JSVAL(operation->type);
5149 1648         break;
5150
5151     case input:
5152
5153 396         if(!operation->input)
5154         {
5155 0             *vp = JSVAL_VOID;
5156 0             break;
5157         }
5158         
5159 396         paramObj = JS_NewObject(cx, &param_class, paramClass, obj);
5160 396         globus_assert(paramObj);
5161 396         JS_SetPrivate(cx, paramObj, (void *)operation->input);
5162 396         JS_DefineProperties(cx, paramObj, param_properties);
5163 396         *vp = OBJECT_TO_JSVAL(paramObj);
5164 396         break;
5165
5166     case output:
5167
5168 314         if(!operation->output)
5169         {
5170 0             *vp = JSVAL_VOID;
5171 0             break;
5172         }
5173         
5174 314         paramObj = JS_NewObject(cx, &param_class, paramClass, obj);
5175 314         globus_assert(paramObj);
5176 314         JS_SetPrivate(cx, paramObj, (void *)operation->output);
5177 314         JS_DefineProperties(cx, paramObj, param_properties);
5178 314         *vp = OBJECT_TO_JSVAL(paramObj);
5179 314         break;
5180
5181     case faults:
5182
5183 854         if(!operation->faults)
5184         {
5185 36             *vp = JSVAL_VOID;
5186 36             break;
5187         }
5188         
5189 818         faultsObj = JS_NewObject(cx, &faults_class, NULL, obj);
5190 818         globus_assert(faultsObj);
5191
5192 818         JS_SetPrivate(cx, faultsObj, (void *)operation->faults);
5193 818         *vp = OBJECT_TO_JSVAL(faultsObj);
5194 818         break;
5195
5196     default:
5197
5198 0         *vp = JSVAL_VOID;
5199 0         JS_ReportError(cx, "Unknown property with id %d for part", idval);
5200 0         res = JS_FALSE;
5201         goto exit;
5202     }
5203
5204   exit:
5205
5206 4658     GlobusWSDLDebugExit();
5207 4658     return res;
5208 }
5209
5210
5211 static
5212 JSBool
5213 faultsGetter(
5214     JSContext *                         cx,
5215     JSObject *                          obj,
5216     jsval                               id,
5217     jsval *                             vp)
5218 621 {
5219 621     wsdlFaultPtr                        fault;
5220 621     JSObject *                          faultObj;
5221 621     JSBool                              res = JS_TRUE;
5222 621     int                                 i = 0;
5223 621     GlobusFuncName(faultsGetter);
5224 621     GlobusWSDLDebugEnter();
5225
5226 621     fault = (wsdlFaultPtr) JS_GetPrivate(cx, obj);
5227 621     globus_assert(fault);
5228
5229 621     if(JSVAL_IS_STRING(id))
5230     {
5231 0         while(fault)
5232         {
5233 0             JSString *                  name;
5234             
5235 0             name = JS_InternString(cx, fault->name);
5236 0             if(JS_CompareStrings(name, JSVAL_TO_STRING(id)))
5237             {
5238 0                 break;
5239             }
5240
5241 0             fault = fault->next;
5242         }
5243     }
5244 621     else if(JSVAL_IS_INT(id))
5245     {
5246 2287         for(; i < JSVAL_TO_INT(id) && fault; ++i)
5247         {
5248 833             fault = fault->next;
5249         }
5250 621         globus_assert(fault);
5251     }
5252     else
5253     {
5254 0         fault = (wsdlFaultPtr) JSVAL_TO_PRIVATE(id);
5255 0         globus_assert(fault);
5256     }
5257
5258 621     faultObj = JS_NewObject(cx, &fault_class, 
5259                             faultClass, obj);
5260 621     globus_assert(faultObj);
5261 621     JS_SetPrivate(cx, faultObj, (void *)fault);
5262 621     JS_DefineProperties(cx, faultObj, fault_properties);
5263 621     *vp = OBJECT_TO_JSVAL(faultObj);
5264
5265 621     GlobusWSDLDebugExit();
5266 621     return res;
5267 }
5268
5269 static
5270 JSBool
5271 faultsEnumerate(
5272     JSContext *                         cx,
5273     JSObject *                          obj,
5274     JSIterateOp                         enum_op,
5275     jsval *                             statep,
5276     jsid *                              idp)
5277 1015 {
5278 1015     JSBool                              res = JS_TRUE;
5279 1015     wsdlFaultPtr                        faults;
5280 1015     int                                 i = 0;
5281 1015     int                                 index;
5282 1015     GlobusFuncName(faultsEnumerate);
5283 1015     GlobusWSDLDebugEnter();
5284
5285 1015     faults = (wsdlFaultPtr) JS_GetPrivate(cx, obj);
5286 1015     globus_assert(faults);
5287     
5288 1015     switch(enum_op)
5289     {
5290     case JSENUMERATE_INIT:
5291         
5292 197         *statep = INT_TO_JSVAL(i);
5293 197         break;
5294
5295     case JSENUMERATE_NEXT:
5296
5297 818         index = JSVAL_TO_INT(*statep);
5298 3726         for(; i < index && faults; ++i)
5299         {
5300 1454             faults = faults->next;
5301         }
5302             
5303 818         if(!faults)
5304         {
5305 197             *statep = JSVAL_NULL;
5306 197             *idp = JSVAL_ZERO;
5307 197             break;
5308         }
5309
5310 621         *idp = *statep;
5311 621         *statep = INT_TO_JSVAL(index + 1);
5312
5313         break;
5314
5315     case JSENUMERATE_DESTROY:
5316             
5317 1015         break;
5318     }
5319
5320 1015     GlobusWSDLDebugExit();
5321 1015     return res;
5322 }
5323
5324 static
5325 JSBool
5326 faultGetter(
5327     JSContext *                         cx,
5328     JSObject *                          obj,
5329     jsval                               jid,
5330     jsval *                             vp)
5331 826 {
5332 826     int                                 idval;
5333 826     JSString *                          str;
5334 826     JSObject *                          messageObj;
5335 826     JSBool                              res = JS_TRUE;
5336 826     wsdlFaultPtr                        fault = NULL;
5337 826     GlobusFuncName(faultGetter);
5338 826     GlobusWSDLDebugEnter();
5339     
5340 826     fault = (wsdlFaultPtr) JS_GetPrivate(cx, obj);
5341 826     globus_assert(fault);
5342
5343 826     if(!JSVAL_IS_INT(jid))
5344     {
5345 0         JS_ReportError(cx, 
5346                        "Invalid id type (expected int) "
5347                        "for wsdl fault property");
5348 0         res = JS_FALSE;
5349 0         goto exit;
5350     }
5351
5352 826     idval = JSVAL_TO_INT(jid);
5353
5354 826     switch(idval)
5355     {
5356     case name:
5357
5358 552         if(!fault->name)
5359         {
5360 0             *vp = JSVAL_VOID;
5361 0             break;
5362         }
5363         
5364 552         str = JS_InternString(cx, fault->name);
5365 552         globus_assert(str);
5366
5367 552         *vp = STRING_TO_JSVAL(str);
5368 552         break;
5369
5370     case message:
5371
5372 274         if(!fault->message)
5373         {
5374 0             *vp = JSVAL_VOID;
5375 0             break;
5376         }
5377
5378 274         messageObj = JS_NewObject(cx, &message_class, messageClass, obj);
5379 274         globus_assert(messageObj);
5380 274         JS_SetPrivate(cx, messageObj, (void *)fault->message);
5381 274         JS_DefineProperties(cx, messageObj, message_properties);
5382 274         *vp = OBJECT_TO_JSVAL(messageObj);
5383 274         break;
5384
5385     default:
5386
5387 0         *vp = JSVAL_VOID;
5388 0         JS_ReportError(cx, "Unknown fault property with id %d for part", idval);
5389 0         res = JS_FALSE;
5390         goto exit;
5391     }
5392
5393   exit:
5394
5395 826     GlobusWSDLDebugExit();
5396 826     return res;
5397 }
5398
5399
5400 static
5401 JSBool
5402 paramGetter(
5403     JSContext *                         cx,
5404     JSObject *                          obj,
5405     jsval                               jid,
5406     jsval *                             vp)
5407 710 {
5408 710     int                                 idval;
5409 710     JSString *                          str;
5410 710     JSObject *                          messageObj;
5411 710     JSBool                              res = JS_TRUE;
5412 710     wsdlParamPtr                        param = NULL;
5413 710     GlobusFuncName(paramGetter);
5414 710     GlobusWSDLDebugEnter();
5415     
5416 710     param = (wsdlParamPtr) JS_GetPrivate(cx, obj);
5417 710     globus_assert(param);
5418
5419 710     if(!JSVAL_IS_INT(jid))
5420     {
5421 0         JS_ReportError(cx, 
5422                        "Invalid id type (expected int) "
5423                        "for wsdl param property");
5424 0         res = JS_FALSE;
5425 0         goto exit;
5426     }
5427
5428 710     idval = JSVAL_TO_INT(jid);
5429
5430 710     switch(idval)
5431     {
5432     case name:
5433
5434 0         if(!param->name)
5435         {
5436 0             *vp = JSVAL_VOID;
5437 0             break;
5438         }
5439         
5440 0         str = JS_InternString(cx, param->name);
5441 0         globus_assert(str);
5442
5443 0         *vp = STRING_TO_JSVAL(str);
5444 0         break;
5445
5446     case Action:
5447
5448 210         if(!param->Action)
5449         {
5450 72             *vp = JSVAL_VOID;
5451 72             break;
5452         }
5453
5454 138         str = JS_InternString(cx, param->Action);
5455 138         globus_assert(str);
5456         
5457 138         *vp = STRING_TO_JSVAL(str);
5458 138         break;
5459
5460     case message:
5461
5462 500         if(!param->message)
5463         {
5464 0             *vp = JSVAL_VOID;
5465 0             break;
5466         }
5467
5468 500         messageObj = JS_NewObject(cx, &message_class, messageClass, obj);
5469 500         globus_assert(messageObj);
5470 500         JS_SetPrivate(cx, messageObj, (void *)param->message);
5471 500         JS_DefineProperties(cx, messageObj, message_properties);
5472 500         *vp = OBJECT_TO_JSVAL(messageObj);
5473 500         break;
5474
5475     default:
5476
5477 0         *vp = JSVAL_VOID;
5478 0         JS_ReportError(cx, "Unknown param property with id %d for part", idval);
5479 0         res = JS_FALSE;
5480         goto exit;
5481     }
5482
5483   exit:
5484
5485 710     GlobusWSDLDebugExit();
5486 710     return res;
5487 }
5488
5489 static
5490 JSBool
5491 portsGetter(
5492     JSContext *                         cx,
5493     JSObject *                          obj,
5494     jsval                               id,
5495     jsval *                             vp)
5496 103 {
5497 103     wsdlPortPtr                         port;
5498 103     JSObject *                          portObj;
5499 103     JSBool                              res = JS_TRUE;
5500 103     int                                 i = 0;
5501 103     GlobusFuncName(portsGetter);
5502 103     GlobusWSDLDebugEnter();
5503
5504 103     port = (wsdlPortPtr) JS_GetPrivate(cx, obj);
5505 103     globus_assert(port);
5506
5507 103     if(JSVAL_IS_STRING(id))
5508     {
5509 0         while(port)
5510         {
5511 0             JSString *                  name;
5512             
5513 0             name = JS_InternString(cx, port->name);
5514 0             if(JS_CompareStrings(name, JSVAL_TO_STRING(id)))
5515             {
5516 0                 break;
5517             }
5518
5519 0             port = port->next;
5520         }
5521     }
5522 103     else if(JSVAL_IS_INT(id))
5523     {
5524 103         for(; i < JSVAL_TO_INT(id) && port; ++i)
5525         {
5526 0             port = port->next;
5527         }
5528 103         globus_assert(port);
5529     }
5530     else
5531     {
5532 0         port = (wsdlPortPtr) JSVAL_TO_PRIVATE(id);
5533 0         globus_assert(port);
5534     }
5535
5536 103     portObj = JS_NewObject(cx, &port_class, 
5537                            portClass, obj);
5538 103     globus_assert(portObj);
5539 103     JS_SetPrivate(cx, portObj, (void *)port);
5540 103     JS_DefineProperties(cx, portObj, port_properties);
5541 103     *vp = OBJECT_TO_JSVAL(portObj);
5542
5543 103     GlobusWSDLDebugExit();
5544 103     return res;
5545 }
5546
5547 static
5548 JSBool
5549 portsEnumerate(
5550     JSContext *                         cx,
5551     JSObject *                          obj,
5552     JSIterateOp                         enum_op,
5553     jsval *                             statep,
5554     jsid *                              idp)
5555 288 {
5556 288     JSBool                              res = JS_TRUE;
5557 288     wsdlPortPtr                         ports;
5558 288     int                                 i = 0;
5559 288     int                                 index;
5560 288     GlobusFuncName(portsEnumerate);
5561 288     GlobusWSDLDebugEnter();
5562
5563 288     ports = (wsdlPortPtr) JS_GetPrivate(cx, obj);
5564 288     globus_assert(ports);
5565     
5566 288     switch(enum_op)
5567     {
5568     case JSENUMERATE_INIT:
5569         
5570 96         *statep = INT_TO_JSVAL(i);
5571 96         break;
5572
5573     case JSENUMERATE_NEXT:
5574
5575 192         index = JSVAL_TO_INT(*statep);
5576 384         for(; i < index && ports; ++i)
5577         {
5578 96             ports = ports->next;
5579         }
5580
5581 192         if(!ports)
5582         {
5583 96             *statep = JSVAL_NULL;
5584 96             *idp = JSVAL_ZERO;
5585 96             break;
5586         }
5587
5588 96         *idp = *statep;
5589 96         *statep = INT_TO_JSVAL(index + 1);
5590
5591         break;
5592
5593     case JSENUMERATE_DESTROY:
5594             
5595 288         break;
5596     }
5597
5598 288     GlobusWSDLDebugExit();
5599 288     return res;
5600 }
5601
5602 static
5603 JSBool
5604 portGetter(
5605     JSContext *                         cx,
5606     JSObject *                          obj,
5607     jsval                               jid,
5608     jsval *                             vp)
5609 103 {
5610 103     int                                 idval;
5611 103     JSString *                          str = NULL;
5612 103     JSObject *                          bindingObj = NULL;
5613 103     JSObject *                          soapObj = NULL;
5614 103     JSBool                              res = JS_TRUE;
5615 103     wsdlPortPtr                         port = NULL;
5616 103     GlobusFuncName(portGetter);
5617 103     GlobusWSDLDebugEnter();
5618     
5619 103     port = (wsdlPortPtr) JS_GetPrivate(cx, obj);
5620 103     globus_assert(port);
5621
5622 103     if(!JSVAL_IS_INT(jid))
5623     {
5624 0         JS_ReportError(cx, 
5625                        "Invalid id type (expected int) "
5626                        "for wsdl port property");
5627 0         res = JS_FALSE;
5628 0         goto exit;
5629     }
5630
5631 103     idval = JSVAL_TO_INT(jid);
5632
5633 103     switch(idval)
5634     {
5635     case name:
5636
5637 0         if(!port->name)
5638         {
5639 0             *vp = JSVAL_VOID;
5640 0             break;
5641         }
5642         
5643 0         str = JS_InternString(cx, port->name);
5644 0         globus_assert(str);
5645
5646 0         *vp = STRING_TO_JSVAL(str);
5647 0         break;
5648
5649     case binding:
5650
5651 96         if(!port->binding)
5652         {
5653 0             *vp = JSVAL_VOID;
5654 0             break;
5655         }
5656
5657 96         bindingObj = JS_NewObject(cx, &binding_class, bindingClass, obj);
5658 96         globus_assert(bindingObj);
5659 96         JS_SetPrivate(cx, bindingObj, (void *)port->binding);
5660 96         JS_DefineProperties(cx, bindingObj, binding_properties);
5661         
5662 96         *vp = OBJECT_TO_JSVAL(bindingObj);
5663 96         break;
5664
5665     case soap:
5666
5667 7         if(!port->extension || (port->extensionType != SOAP_BINDING))
5668         {
5669 0             *vp = JSVAL_VOID;
5670 0             break;
5671         }
5672
5673 7         soapObj = JS_NewObject(cx, &soapAddress_class, soapAddressClass, obj);
5674 7         globus_assert(soapObj);
5675 7         JS_SetPrivate(cx, soapObj, (void *)port->extension);
5676 7         JS_DefineProperties(cx, soapObj, soapAddress_properties);
5677 7         *vp = OBJECT_TO_JSVAL(soapObj);
5678 7         break;
5679
5680     default:
5681
5682 0         *vp = JSVAL_VOID;
5683 0         JS_ReportError(cx, "Unknown port property with id %d for part", idval);
5684 0         res = JS_FALSE;
5685         goto exit;
5686     }
5687
5688   exit:
5689
5690 103     GlobusWSDLDebugExit();
5691 103     return res;
5692 }
5693
5694 static
5695 JSBool
5696 serviceGetter(
5697     JSContext *                         cx,
5698     JSObject *                          obj,
5699     jsval                               jid,
5700     jsval *                             vp)
5701 218 {
5702 218     int                                 idval;
5703 218     JSString *                          str = NULL;
5704 218     JSObject *                          portsObj = NULL;
5705 218     JSBool                              res = JS_TRUE;
5706 218     wsdlServicePtr                      service = NULL;
5707 218     GlobusFuncName(serviceGetter);
5708 218     GlobusWSDLDebugEnter();
5709     
5710 218     service = (wsdlServicePtr) JS_GetPrivate(cx, obj);
5711 218     globus_assert(service);
5712
5713 218     if(!JSVAL_IS_INT(jid))
5714     {
5715 0         char *                          prop_name;
5716
5717 0         prop_name = JS_GetStringBytes(JSVAL_TO_STRING(jid));
5718 0         JS_ReportError(cx, 
5719                        "Invalid property access .%s on wsdl service element",
5720                        prop_name);
5721 0         res = JS_FALSE;
5722 0         goto exit;
5723     }
5724
5725 218     idval = JSVAL_TO_INT(jid);
5726
5727 218     switch(idval)
5728     {
5729     case name:
5730
5731 7         if(!service->name)
5732         {
5733 0             *vp = JSVAL_VOID;
5734 0             break;
5735         }
5736         
5737 7         str = JS_InternString(cx, service->name);
5738 7         globus_assert(str);
5739
5740 7         *vp = STRING_TO_JSVAL(str);
5741 7         break;
5742
5743     case ports:
5744
5745 199         if(!service->ports)
5746         {
5747 0             *vp = JSVAL_VOID;
5748 0             break;
5749         }
5750
5751 199         portsObj = JS_NewObject(cx, &ports_class, NULL, obj);
5752 199         globus_assert(portsObj);
5753 199         JS_SetPrivate(cx, portsObj, (void *) service->ports);
5754 199         *vp = OBJECT_TO_JSVAL(portsObj);
5755 199         break;
5756
5757     case soap:
5758
5759 0         *vp = JSVAL_VOID;
5760 0         break;
5761         
5762     case targetNamespace:
5763
5764 12         if(!service->schema || !service->schema->targetNamespace)
5765         {
5766 0             *vp = JSVAL_VOID;
5767 0             break;
5768         }
5769
5770 12         str = JS_InternString(cx, service->schema->targetNamespace);
5771 12         globus_assert(str);
5772         
5773 12         *vp = STRING_TO_JSVAL(str);
5774 12         break;
5775
5776     default:
5777
5778 0         *vp = JSVAL_VOID;
5779 0         JS_ReportError(cx, "Unknown service property with id %d for part", idval);
5780 0         res = JS_FALSE;
5781         goto exit;
5782     }
5783
5784   exit:
5785
5786 218     GlobusWSDLDebugExit();
5787 218     return res;
5788 }
5789
5790 static
5791 JSBool
5792 soapBindingGetter(
5793     JSContext *                         cx,
5794     JSObject *                          obj,
5795     jsval                               jid,
5796     jsval *                             vp)
5797 0 {
5798 0     JSString *                          str = NULL;
5799 0     int                                 idval;
5800 0     JSBool                              res = JS_TRUE;
5801 0     soapBindingPtr                      binding = NULL;
5802 0     GlobusFuncName(soapBindingGetter);
5803 0     GlobusWSDLDebugEnter();
5804     
5805 0     binding = (soapBindingPtr) JS_GetPrivate(cx, obj);
5806 0     globus_assert(binding);
5807
5808 0     if(!JSVAL_IS_INT(jid))
5809     {
5810 0         JS_ReportError(cx, 
5811                        "Invalid id type (expected int) "
5812                        "for soap binding property");
5813 0         res = JS_FALSE;
5814 0         goto exit;
5815     }
5816
5817 0     idval = JSVAL_TO_INT(jid);
5818
5819 0     switch(idval)
5820     {
5821     case style:
5822
5823 0         *vp = INT_TO_JSVAL(binding->style);
5824 0         break;
5825
5826     case transport:
5827
5828 0         if(!binding->transport)
5829         {
5830 0             *vp = JSVAL_VOID;
5831 0             break;
5832         }
5833
5834 0         str = JS_InternString(cx, binding->transport);
5835 0         globus_assert(str);
5836 0         *vp = STRING_TO_JSVAL(str);
5837 0         break;
5838
5839     default:
5840
5841 0         *vp = JSVAL_VOID;
5842 0         JS_ReportError(cx, 
5843                        "Unknown soap binding property "
5844                        "with id %d for part", idval);
5845 0         res = JS_FALSE;
5846         goto exit;
5847     }
5848
5849   exit:
5850
5851 0     GlobusWSDLDebugExit();
5852 0     return res;
5853 }
5854
5855 static
5856 JSBool
5857 soapOperationGetter(
5858     JSContext *                         cx,
5859     JSObject *                          obj,
5860     jsval                               jid,
5861     jsval *                             vp)
5862 0 {
5863 0     JSString *                          str = NULL;
5864 0     int                                 idval;
5865 0     JSBool                              res = JS_TRUE;
5866 0     soapOperationPtr                    operation = NULL;
5867 0     GlobusFuncName(soapOperationGetter);
5868 0     GlobusWSDLDebugEnter();
5869
5870 0     operation = (soapOperationPtr) JS_GetPrivate(cx, obj);
5871 0     globus_assert(operation);
5872
5873 0     if(!JSVAL_IS_INT(jid))
5874     {
5875 0         JS_ReportError(cx, 
5876                        "Invalid id type (expected int) "
5877                        "for soap operation property");
5878 0         res = JS_FALSE;
5879 0         goto exit;
5880     }
5881
5882 0     idval = JSVAL_TO_INT(jid);
5883
5884 0     switch(idval)
5885     {
5886     case soapAction:
5887         
5888 0         if(!operation->soapAction)
5889         {
5890 0             *vp = JSVAL_VOID;
5891 0             break;
5892         }
5893
5894 0         str = JS_InternString(cx, operation->soapAction);
5895 0         globus_assert(str);
5896 0         *vp = STRING_TO_JSVAL(str);
5897 0         break;
5898
5899     case style:
5900
5901 0         *vp = INT_TO_JSVAL(operation->style);
5902 0         break;
5903
5904
5905     default:
5906
5907 0         *vp = JSVAL_VOID;
5908 0         JS_ReportError(cx, 
5909                        "Unknown soap operation property "
5910                        "with id %d", idval);
5911 0         res = JS_FALSE;
5912         goto exit;
5913     }
5914
5915   exit:
5916
5917 0     GlobusWSDLDebugExit();
5918 0     return res;
5919 }
5920
5921 static
5922 JSBool
5923 soapHeaderGetter(
5924     JSContext *                         cx,
5925     JSObject *                          obj,
5926     jsval                               jid,
5927     jsval *                             vp)
5928 0 {
5929 0     JSString *                          str = NULL;
5930 0     int                                 idval;
5931 0     JSBool                              res = JS_TRUE;
5932 0     soapHeaderPtr                       header = NULL;
5933 0     GlobusFuncName(soapHeaderGetter);
5934 0     GlobusWSDLDebugEnter();
5935
5936 0     header = (soapHeaderPtr) JS_GetPrivate(cx, obj);
5937 0     globus_assert(header);
5938
5939 0     if(!JSVAL_IS_INT(jid))
5940     {
5941 0         JS_ReportError(cx, 
5942                        "Invalid id type (expected int) "
5943                        "for soap header property");
5944 0         res = JS_FALSE;
5945 0         goto exit;
5946     }
5947
5948 0     idval = JSVAL_TO_INT(jid);
5949
5950 0     switch(idval)
5951     {
5952     case message:
5953         
5954 0         if(!header->message)
5955         {
5956 0             *vp = JSVAL_VOID;
5957 0             break;
5958         }
5959
5960 0         str = JS_InternString(cx, header->message);
5961 0         globus_assert(str);
5962 0         *vp = STRING_TO_JSVAL(str);
5963 0         break;
5964
5965     case parts:
5966
5967 0         if(!header->parts)
5968         {
5969 0             *vp = JSVAL_VOID;
5970 0             break;
5971         }
5972
5973 0         str = JS_InternString(cx, header->parts);
5974 0         globus_assert(str);
5975 0         *vp = STRING_TO_JSVAL(str);
5976 0         break;
5977
5978     case use:
5979
5980 0         *vp = INT_TO_JSVAL(header->use);
5981 0         break;
5982
5983     case encodingStyle:
5984
5985 0         if(!header->encodingStyle)
5986         {
5987 0             *vp = JSVAL_VOID;
5988 0             break;
5989         }
5990
5991 0         str = JS_InternString(cx, header->encodingStyle);
5992 0         globus_assert(str);
5993 0         *vp = STRING_TO_JSVAL(str);
5994 0         break;
5995
5996     case Namespace:
5997
5998 0         if(!header->Namespace)
5999         {
6000 0             *vp = JSVAL_VOID;
6001         }
6002
6003 0         str = JS_InternString(cx, header->Namespace);
6004 0         globus_assert(str);
6005 0         *vp = STRING_TO_JSVAL(str);
6006 0         break;
6007
6008     default:
6009
6010 0         *vp = JSVAL_VOID;
6011 0         JS_ReportError(cx, 
6012                        "Unknown soap header property "
6013                        "with id %d", idval);
6014 0         res = JS_FALSE;
6015         goto exit;
6016     }
6017
6018   exit:
6019
6020 0     GlobusWSDLDebugExit();
6021 0     return res;
6022 }
6023
6024 static
6025 JSBool
6026 soapBodyGetter(
6027     JSContext *                         cx,
6028     JSObject *                          obj,
6029     jsval                               jid,
6030     jsval *                             vp)
6031 0 {
6032 0     JSString *                          str = NULL;
6033 0     int                                 idval;
6034 0     JSBool                              res = JS_TRUE;
6035 0     soapBodyPtr                       body = NULL;
6036 0     GlobusFuncName(soapBodyGetter);
6037 0     GlobusWSDLDebugEnter();
6038
6039 0     body = (soapBodyPtr) JS_GetPrivate(cx, obj);
6040 0     globus_assert(body);
6041
6042 0     if(!JSVAL_IS_INT(jid))
6043     {
6044 0         JS_ReportError(cx, 
6045                        "Invalid id type (expected int) "
6046                        "for soap body property");
6047 0         res = JS_FALSE;
6048 0         goto exit;
6049     }
6050
6051 0     idval = JSVAL_TO_INT(jid);
6052
6053 0     switch(idval)
6054     {
6055     case parts:
6056
6057 0         if(!body->parts)
6058         {
6059 0             *vp = JSVAL_VOID;
6060 0             break;
6061         }
6062
6063 0         str = JS_InternString(cx, body->parts);
6064 0         globus_assert(str);
6065 0         *vp = STRING_TO_JSVAL(str);
6066 0         break;
6067
6068     case use:
6069
6070 0         *vp = INT_TO_JSVAL(body->use);
6071 0         break;
6072
6073     case encodingStyle:
6074
6075 0         if(!body->encodingStyle)
6076         {
6077 0             *vp = JSVAL_VOID;
6078 0             break;
6079         }
6080
6081 0         str = JS_InternString(cx, body->encodingStyle);
6082 0         globus_assert(str);
6083 0         *vp = STRING_TO_JSVAL(str);
6084 0         break;
6085
6086     case Namespace:
6087
6088 0         if(!body->Namespace)
6089         {
6090 0             *vp = JSVAL_VOID;
6091         }
6092
6093 0         str = JS_InternString(cx, body->Namespace);
6094 0         globus_assert(str);
6095 0         *vp = STRING_TO_JSVAL(str);
6096 0         break;
6097
6098     default:
6099
6100 0         *vp = JSVAL_VOID;
6101 0         JS_ReportError(cx, 
6102                        "Unknown soap body property "
6103                        "with id %d", idval);
6104 0         res = JS_FALSE;
6105         goto exit;
6106     }
6107
6108   exit:
6109
6110 0     GlobusWSDLDebugExit();
6111 0     return res;
6112 }
6113
6114 static
6115 JSBool
6116 soapFaultGetter(
6117     JSContext *                         cx,
6118     JSObject *                          obj,
6119     jsval                               jid,
6120     jsval *                             vp)
6121 0 {
6122 0     JSString *                          str = NULL;
6123 0     int                                 idval;
6124 0     JSBool                              res = JS_TRUE;
6125 0     soapFaultPtr                       fault = NULL;
6126 0     GlobusFuncName(soapFaultGetter);
6127 0     GlobusWSDLDebugEnter();
6128
6129 0     fault = (soapFaultPtr) JS_GetPrivate(cx, obj);
6130 0     globus_assert(fault);
6131
6132 0     if(!JSVAL_IS_INT(jid))
6133     {
6134 0         JS_ReportError(cx, 
6135                        "Invalid id type (expected int) "
6136                        "for soap fault property");
6137 0         res = JS_FALSE;
6138 0         goto exit;
6139     }
6140
6141 0     idval = JSVAL_TO_INT(jid);
6142
6143 0     switch(idval)
6144     {
6145     case use:
6146
6147 0         *vp = INT_TO_JSVAL(fault->use);
6148 0         break;
6149
6150     case encodingStyle:
6151
6152 0         if(!fault->encodingStyle)
6153         {
6154 0             *vp = JSVAL_VOID;
6155 0             break;
6156         }
6157
6158 0         str = JS_InternString(cx, fault->encodingStyle);
6159 0         globus_assert(str);
6160 0         *vp = STRING_TO_JSVAL(str);
6161 0         break;
6162
6163     case Namespace:
6164
6165 0         if(!fault->Namespace)
6166         {
6167 0             *vp = JSVAL_VOID;
6168         }
6169
6170 0         str = JS_InternString(cx, fault->Namespace);
6171 0         globus_assert(str);
6172 0         *vp = STRING_TO_JSVAL(str);
6173 0         break;
6174
6175     default:
6176
6177 0         *vp = JSVAL_VOID;
6178 0         JS_ReportError(cx, 
6179                        "Unknown soap fault property "
6180                        "with id %d", idval);
6181 0         res = JS_FALSE;
6182         goto exit;
6183     }
6184
6185   exit:
6186
6187 0     GlobusWSDLDebugExit();
6188 0     return res;
6189 }
6190
6191 static
6192 JSBool
6193 soapAddressGetter(
6194     JSContext *                         cx,
6195     JSObject *                          obj,
6196     jsval                               jid,
6197     jsval *                             vp)
6198 7 {
6199 7     JSString *                          str = NULL;
6200 7     int                                 idval;
6201 7     JSBool                              res = JS_TRUE;
6202 7     soapAddressPtr                       address = NULL;
6203 7     GlobusFuncName(soapAddressGetter);
6204 7     GlobusWSDLDebugEnter();
6205
6206 7     address = (soapAddressPtr) JS_GetPrivate(cx, obj);
6207 7     globus_assert(address);
6208
6209 7     if(!JSVAL_IS_INT(jid))
6210     {
6211 0         JS_ReportError(cx, 
6212                        "Invalid id type (expected int) "
6213                        "for soap address property");
6214 0         res = JS_FALSE;
6215 0         goto exit;
6216     }
6217
6218 7     idval = JSVAL_TO_INT(jid);
6219
6220 7     switch(idval)
6221     {
6222     case location:
6223
6224 7         if(!address->location)
6225         {
6226 0             *vp = JSVAL_VOID;
6227 0             break;
6228         }
6229
6230 7         str = JS_InternString(cx, address->location);
6231 7         globus_assert(str);
6232 7         *vp = STRING_TO_JSVAL(str);
6233 7         break;
6234
6235     default:
6236
6237 0         *vp = JSVAL_VOID;
6238 0         JS_ReportError(cx, 
6239                        "Unknown soap address property "
6240                        "with id %d", idval);
6241 0         res = JS_FALSE;
6242         goto exit;
6243     }
6244
6245   exit:
6246
6247 7     GlobusWSDLDebugExit();
6248 7     return res;
6249 }
6250     
6251 static
6252 JSBool
6253 soapBindingParamGetter(
6254     JSContext *                         cx,
6255     JSObject *                          obj,
6256     jsval                               jid,
6257     jsval *                             vp)
6258 0 {
6259 0     JSObject *                          newObj = NULL;
6260 0     int                                 idval;
6261 0     JSBool                              res = JS_TRUE;
6262 0     soapBindingParamPtr                 param = NULL;
6263 0     GlobusFuncName(soapBindingParamGetter);
6264 0     GlobusWSDLDebugEnter();
6265     
6266 0     param = (soapBindingParamPtr) JS_GetPrivate(cx, obj);
6267 0     globus_assert(param);
6268
6269 0     if(!JSVAL_IS_INT(jid))
6270     {
6271 0         JS_ReportError(cx, 
6272                        "Invalid id type (expected int) "
6273                        "for soap binding param property");
6274 0         res = JS_FALSE;
6275 0         goto exit;
6276     }
6277
6278 0     idval = JSVAL_TO_INT(jid);
6279
6280 0     switch(idval)
6281     {
6282     case header:
6283
6284 0         if(!param->header)
6285         {
6286 0             *vp = JSVAL_VOID;
6287 0             break;
6288         }
6289
6290 0         newObj = JS_NewObject(cx, &soapHeader_class, soapHeaderClass, obj);
6291 0         globus_assert(newObj);
6292 0         JS_SetPrivate(cx, newObj, (void *)param->header);
6293 0         JS_DefineProperties(cx, newObj, soapHeader_properties);
6294 0         *vp = OBJECT_TO_JSVAL(newObj);
6295 0         break;
6296
6297     case body:
6298
6299 0         if(!param->body)
6300         {
6301 0             *vp = JSVAL_VOID;
6302 0             break;
6303         }
6304
6305 0         newObj = JS_NewObject(cx, &soapBody_class, soapBodyClass, obj);
6306 0         globus_assert(newObj);
6307 0         JS_SetPrivate(cx, newObj, (void *)param->body);
6308 0         JS_DefineProperties(cx, newObj, soapBody_properties);
6309 0         *vp = OBJECT_TO_JSVAL(newObj);
6310 0         break;
6311
6312     case fault:
6313
6314 0         if(!param->fault)
6315         {
6316 0             *vp = JSVAL_VOID;
6317 0             break;
6318         }
6319
6320 0         newObj = JS_NewObject(cx, &soapFault_class, soapFaultClass, obj);
6321 0         globus_assert(newObj);
6322 0         JS_SetPrivate(cx, newObj, (void *)param->fault);
6323 0         JS_DefineProperties(cx, newObj, soapFault_properties);
6324 0         *vp = OBJECT_TO_JSVAL(newObj);
6325 0         break;
6326
6327     default:
6328
6329 0         *vp = JSVAL_VOID;
6330 0         JS_ReportError(cx, 
6331                        "Unknown soap binding property "
6332                        "with id %d for part", idval);
6333 0         res = JS_FALSE;
6334         goto exit;
6335     }
6336
6337   exit:
6338
6339 0     GlobusWSDLDebugExit();
6340 0     return res;
6341 }
6342
6343 static
6344 void
6345 globus_i_wsdl_parser_import_scanner(
6346     void *                              payload,
6347     void *                              data,
6348     xmlChar *                           name)
6349 253 {
6350 253     xmlSchemaImportPtr                  import;
6351 253     xmlSchemaPtr                        schema;
6352 253     ScannerData *                       dt;
6353 253     GlobusFuncName(globus_i_wsdl_parser_import_scanner);
6354 253     GlobusWSDLDebugEnter();
6355     
6356 253     dt = (ScannerData *) data;
6357 253     import = (xmlSchemaImportPtr) payload;
6358
6359 253     if(dt->result != GLOBUS_SUCCESS)
6360     {
6361 0         goto exit;
6362     }
6363
6364 253     schema = import->schema;
6365
6366 253     if(schema)
6367     {
6368 253         dt->xsdSchema = schema;
6369 253         xmlHashScan(schema->schemasImports, 
6370                     globus_i_wsdl_parser_import_scanner, data);
6371 253         if(dt->result != GLOBUS_SUCCESS)
6372         {
6373 0             dt->result = GlobusWSDLErrorJSLoadSchema(dt->result);
6374 0             goto exit;
6375         }
6376
6377 253         dt->xsdSchema = schema;
6378 253         xmlHashScan(schema->typeDecl, globus_i_wsdl_parser_type_scanner, data);
6379 253         if(dt->result != GLOBUS_SUCCESS)
6380         {
6381 0             dt->result = GlobusWSDLErrorJSLoadSchema(dt->result);
6382 0             goto exit;
6383         }
6384
6385 253         xmlHashScan(schema->groupDecl, globus_i_wsdl_parser_type_scanner, data);
6386 253         if(dt->result != GLOBUS_SUCCESS)
6387         {
6388 0             dt->result = GlobusWSDLErrorJSLoadSchema(dt->result);
6389 0             goto exit;
6390         }
6391
6392 253         xmlHashScan(schema->elemDecl, 
6393                     globus_i_wsdl_parser_element_scanner, 
6394                     data);
6395 253         if(dt->result != GLOBUS_SUCCESS)
6396         {
6397 0             dt->result = GlobusWSDLErrorJSLoadSchema(dt->result);
6398 0             goto exit;
6399         }
6400
6401 253         xmlHashScan(schema->attrDecl, 
6402                     globus_i_wsdl_parser_attribute_scanner, 
6403                     data);
6404 253         if(dt->result != GLOBUS_SUCCESS)
6405         {
6406 0             dt->result = GlobusWSDLErrorJSLoadSchema(dt->result);
6407             goto exit;
6408         }
6409     }
6410
6411  exit:
6412
6413 253     GlobusWSDLDebugExit();
6414 }
6415
6416 static
6417 void
6418 globus_i_wsdl_parser_type_scanner(
6419     void *                              payload,
6420     void *                              data,
6421     xmlChar *                           name)
6422 5910 {
6423 5910     xmlSchemaTypePtr                    xsdType;
6424 5910     wsdlSchemaPtr                       schema;
6425 5910     xmlSchemaPtr                        xsdSchema;
6426 5910     JSContext *                         cx;
6427 5910     jsval                               val;
6428 5910     JSObject *                          typeObj;
6429 5910     JSObject *                          types;
6430 5910     JSObject *                          global;
6431 5910     JSString *                          str;
6432 5910     globus_result_t                     result = GLOBUS_SUCCESS;
6433 5910     GlobusFuncName(globus_i_wsdl_parser_type_scanner);
6434 5910     GlobusWSDLDebugEnter();
6435
6436 5910     xsdType = (xmlSchemaTypePtr) payload;
6437 5910     schema = ((ScannerData *)data)->schema;
6438 5910     xsdSchema = ((ScannerData *)data)->xsdSchema;
6439 5910     cx = ((ScannerData *)data)->context;
6440 5910     global = ((ScannerData *)data)->global;
6441 5910     types = ((ScannerData *)data)->types;
6442 5910     result = ((ScannerData *)data)->result;
6443
6444 5910     if(result != GLOBUS_SUCCESS)
6445     {
6446 0         goto exit;
6447     }
6448
6449 5910     if(xsdType->targetNamespace)
6450     {
6451 5900         str = globus_l_wsdl_jscript_qname_string(
6452             cx, xsdType->targetNamespace, xsdType->name);
6453     }
6454 10     else if(xsdSchema->targetNamespace)
6455     {
6456 10         xsdType->targetNamespace = xsdSchema->targetNamespace;
6457 10         str = globus_l_wsdl_jscript_qname_string(
6458             cx, xsdSchema->targetNamespace, xsdType->name);
6459     }
6460 0     else if(schema->targetNamespace)
6461     {
6462 0         xsdType->targetNamespace = schema->targetNamespace;
6463 0         str = globus_l_wsdl_jscript_qname_string(
6464             cx, schema->targetNamespace, xsdType->name);
6465     }
6466     else
6467     {
6468 0         JS_ReportError(cx, 
6469                        "Can't find namespace for type: %s", 
6470                        xsdType->name);
6471 0         result = GlobusWSDLErrorScanningTypes(
6472             GLOBUS_NULL, xsdType->name);
6473 0         goto exit;
6474     }
6475
6476 5910     typeObj = JS_NewObject(cx, &xsdType_class, xsdTypeClass, types);
6477 5910     globus_assert(typeObj);
6478 5910     JS_SetPrivate(cx, typeObj, (void *)xsdType);
6479 5910     JS_DefineProperties(cx, typeObj, xsdType_properties);
6480     
6481 5910     val = OBJECT_TO_JSVAL(typeObj);
6482     
6483 5910     if(!JS_DefineProperty(
6484                       cx, types, (const char *)JS_GetStringBytes(str), 
6485                       val, NULL, NULL, 
6486                       JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT))
6487     {
6488 0         JS_ReportError(cx, "Failed to define type from parsed WSDL");
6489 0         result = GlobusWSDLErrorScanningTypes(
6490             GLOBUS_NULL, xsdType->name);
6491         goto exit;
6492     }
6493
6494 exit:
6495
6496 5910     GlobusWSDLDebugExit();
6497 5910     ((ScannerData *)data)->result = result;
6498 }    
6499
6500 static
6501 void
6502 globus_i_wsdl_parser_element_scanner(
6503     void *                              payload,
6504     void *                              data,
6505     xmlChar *                           name)
6506 3662 {
6507 3662     xmlSchemaElementPtr                 element;
6508 3662     wsdlSchemaPtr                       schema;
6509 3662     xmlSchemaPtr                        xsdSchema;
6510 3662     JSContext *                         cx;
6511 3662     jsval                               val;
6512 3662     JSObject *                          elements;
6513 3662     JSObject *                          local_elements;
6514 3662     JSObject *                          global;
6515 3662     JSObject *                          elemObj;
6516 3662     JSString *                          str;
6517 3662     globus_result_t                     result = GLOBUS_SUCCESS;
6518 3662     GlobusFuncName(globus_i_wsdl_parser_element_scanner);
6519 3662     GlobusWSDLDebugEnter();
6520     
6521 3662     element = (xmlSchemaElementPtr) payload;
6522 3662     schema = ((ScannerData *)data)->schema;
6523 3662     xsdSchema = ((ScannerData *)data)->xsdSchema;
6524 3662     cx = ((ScannerData *)data)->context;
6525 3662     global = ((ScannerData *)data)->global;
6526 3662     elements = ((ScannerData *)data)->elements;
6527 3662     local_elements = ((ScannerData *)data)->local_elements;
6528 3662     result = ((ScannerData *)data)->result;
6529
6530 3662     if(result != GLOBUS_SUCCESS)
6531     {
6532 0         goto exit;
6533     }
6534
6535
6536 3662     if(!element->targetNamespace)
6537     {
6538 339         if((element->flags & XML_SCHEMAS_ELEM_GLOBAL) ||
6539            (xsdSchema->flags & XML_SCHEMAS_QUALIF_ELEM))
6540         {
6541 308             element->targetNamespace = xsdSchema->targetNamespace;
6542         }
6543     }
6544         
6545 3662     str = globus_l_wsdl_jscript_qname_string(
6546         cx, element->targetNamespace, element->name);
6547
6548 3662     if(element->flags & XML_SCHEMAS_ELEM_GLOBAL)
6549     {
6550 2200         elemObj = JS_NewObject(cx, &xsdElement_class, 
6551                                xsdElementClass, elements);
6552 2200         globus_assert(elemObj);
6553 2200         JS_SetPrivate(cx, elemObj, (void *)element);
6554 2200         JS_DefineProperties(cx, elemObj, xsdElement_properties);
6555     
6556 2200         val = OBJECT_TO_JSVAL(elemObj);
6557     
6558 2200         if(!JS_DefineProperty(
6559                cx, elements, (const char *) JS_GetStringBytes(str), 
6560                val, NULL, NULL, 
6561                JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT))
6562         {
6563 0             JS_ReportError(cx, "Failed to define element from parsed WSDL");
6564 0             result = GlobusWSDLErrorScanningElements(
6565                 GLOBUS_NULL, element->name);
6566 0             goto exit;
6567         }
6568     }
6569     else
6570     {
6571 1462         elemObj = JS_NewObject(cx, &xsdElement_class, 
6572                                xsdElementClass, local_elements);
6573 1462         globus_assert(elemObj);
6574 1462         JS_SetPrivate(cx, elemObj, (void *)element);
6575 1462         JS_DefineProperties(cx, elemObj, xsdElement_properties);
6576     
6577 1462         val = OBJECT_TO_JSVAL(elemObj);
6578     
6579 1462         if(!JS_DefineProperty(
6580                cx, local_elements, (const char *) JS_GetStringBytes(str), 
6581                val, NULL, NULL, 
6582                JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT))
6583         {
6584 0             JS_ReportError(cx, "Failed to define element from parsed WSDL");
6585 0             result = GlobusWSDLErrorScanningElements(
6586                 GLOBUS_NULL, element->name);
6587             goto exit;
6588         }
6589     }
6590
6591 exit:
6592
6593 3662     GlobusWSDLDebugExit();
6594 3662     ((ScannerData *)data)->result = result;
6595 }    
6596
6597 static
6598 void
6599 globus_i_wsdl_parser_attribute_scanner(
6600     void *                              payload,
6601     void *                              data,
6602     xmlChar *                           name)
6603 968 {
6604 968     xmlSchemaAttributePtr               attribute;
6605 968     wsdlSchemaPtr                       schema;
6606 968     xmlSchemaPtr                        xsdSchema;
6607 968     JSContext *                         cx;
6608 968     jsval                               val;
6609 968     JSObject *                          attributes;
6610 968     JSObject *                          local_attributes;
6611 968     JSObject *                          global;
6612 968     JSObject *                          attrObj;
6613 968     JSString *                          str;
6614 968     globus_result_t                     result = GLOBUS_SUCCESS;
6615 968     GlobusFuncName(globus_i_wsdl_parser_attribute_scanner);
6616 968     GlobusWSDLDebugEnter();
6617     
6618 968     attribute = (xmlSchemaAttributePtr) payload;
6619 968     schema = ((ScannerData *)data)->schema;
6620 968     xsdSchema = ((ScannerData *)data)->xsdSchema;
6621 968     cx = ((ScannerData *)data)->context;
6622 968     global = ((ScannerData *)data)->global;
6623 968     attributes = ((ScannerData *)data)->attributes;
6624 968     local_attributes = ((ScannerData *)data)->local_attributes;
6625 968     result = ((ScannerData *)data)->result;
6626
6627 968     if(result != GLOBUS_SUCCESS)
6628     {
6629 0         goto exit;
6630     }
6631
6632 968     if(!attribute->targetNamespace)
6633     {
6634 661         if((attribute->flags & XML_SCHEMAS_ATTR_GLOBAL) ||
6635            (xsdSchema->flags & XML_SCHEMAS_QUALIF_ATTR))
6636         {
6637 0             attribute->targetNamespace = xsdSchema->targetNamespace;
6638         }
6639     }
6640     
6641 968     str = globus_l_wsdl_jscript_qname_string(
6642         cx, attribute->targetNamespace, attribute->name);
6643
6644 968     if(attribute->flags & XML_SCHEMAS_ATTR_GLOBAL)
6645     {
6646 307         attrObj = JS_NewObject(
6647             cx, &xsdAttr_class, xsdAttrClass, attributes);
6648 307         globus_assert(attrObj);
6649 307         JS_SetPrivate(cx, attrObj, (void *)attribute);
6650 307         JS_DefineProperties(cx, attrObj, xsdAttr_properties);
6651
6652 307         val = OBJECT_TO_JSVAL(attrObj);
6653
6654 307         JS_DefineProperty(
6655             cx, attributes, (const char *) JS_GetStringBytes(str), 
6656             val, NULL, NULL, 
6657             JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT);
6658     }
6659     else
6660     {
6661 661         attrObj = JS_NewObject(
6662             cx, &xsdAttr_class, xsdAttrClass, local_attributes);
6663 661         globus_assert(attrObj);
6664 661         JS_SetPrivate(cx, attrObj, (void *)attribute);
6665 661         JS_DefineProperties(cx, attrObj, xsdAttr_properties);
6666
6667 661         val = OBJECT_TO_JSVAL(attrObj);
6668
6669 661         JS_DefineProperty(
6670             cx, local_attributes, (const char *) JS_GetStringBytes(str), 
6671             val, NULL, NULL, 
6672             JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT);
6673     }
6674         
6675  exit:
6676     
6677 968     GlobusWSDLDebugExit();
6678 968     ((ScannerData *)data)->result = result;
6679 }
6680
6681 static
6682 void
6683 globus_i_wsdl_parser_message_scanner(
6684     void *                              payload,
6685     void *                              data,
6686     xmlChar *                           name)
6687 474 {
6688 474     wsdlMessagePtr                      message;
6689 474     JSContext *                         cx;
6690 474     jsval                               val;
6691 474     JSObject *                          messages;
6692 474     JSObject *                          messageObj;
6693 474     JSObject *                          global;
6694 474     globus_result_t                     result = GLOBUS_SUCCESS;
6695 474     GlobusFuncName(globus_i_wsdl_parser_message_scanner);
6696 474     GlobusWSDLDebugEnter();
6697     
6698 474     message = (wsdlMessagePtr) payload;
6699 474     cx = ((ScannerData *)data)->context;
6700 474     global = ((ScannerData *)data)->global;
6701 474     messages = ((ScannerData *)data)->messages;
6702 474     result = ((ScannerData *)data)->result;
6703
6704 474     if(result != GLOBUS_SUCCESS)
6705     {
6706 0         goto exit;
6707     }
6708
6709 474     messageObj = JS_NewObject(cx, &message_class, messageClass, messages);
6710 474     globus_assert(messageObj);
6711 474     JS_SetPrivate(cx, messageObj, (void *)message);
6712 474     JS_DefineProperties(cx, messageObj, message_properties);
6713
6714 474     val = OBJECT_TO_JSVAL(messageObj);
6715
6716 474     if(!JS_DefineProperty(cx, messages, (const char *)name, val, NULL, NULL, 
6717                           JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT))
6718     {
6719 0         JS_ReportError(cx, "Failed to define message from parsed WSDL");
6720 0         result = GlobusWSDLErrorScanningMessages(GLOBUS_NULL, message->name);
6721         goto exit;
6722     }
6723
6724
6725 exit:
6726
6727 474     GlobusWSDLDebugExit();
6728 474     ((ScannerData *)data)->result = result;
6729 }    
6730
6731 static
6732 void
6733 globus_i_wsdl_parser_portType_scanner(
6734     void *                              payload,
6735     void *                              data,
6736     xmlChar *                           name)
6737 119 {
6738 119     wsdlPortTypePtr                     portType;
6739 119     JSContext *                         cx;
6740 119     jsval                               val;
6741 119     JSObject *                          portTypes;
6742 119     JSObject *                          global;
6743 119     JSObject *                          portTypeObj;
6744 119     globus_result_t                     result = GLOBUS_SUCCESS;
6745 119     GlobusFuncName(globus_i_wsdl_parser_portType_scanner);
6746 119     GlobusWSDLDebugEnter();
6747     
6748 119     portType = (wsdlPortTypePtr) payload;
6749 119     cx = ((ScannerData *)data)->context;
6750 119     global = ((ScannerData *)data)->global;
6751 119     portTypes = ((ScannerData *)data)->portTypes;
6752 119     result = ((ScannerData *)data)->result;
6753
6754 119     if(result != GLOBUS_SUCCESS)
6755     {
6756 0         goto exit;
6757     }
6758
6759 119     portTypeObj = JS_NewObject(cx, &portType_class, portTypeClass, portTypes);
6760 119     globus_assert(portTypeObj);
6761 119     JS_SetPrivate(cx, portTypeObj, (void *)portType);
6762 119     JS_DefineProperties(cx, portTypeObj, portType_properties);
6763
6764 119     val = OBJECT_TO_JSVAL(portTypeObj);
6765
6766 119     if(!JS_DefineProperty(cx, portTypes, (const char *)name, val, NULL, NULL, 
6767                           JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT))
6768     {
6769 0         JS_ReportError(cx, "Failed to define portType from parsed WSDL");
6770 0         result = GlobusWSDLErrorScanningPortTypes(GLOBUS_NULL, portType->name);
6771         goto exit;
6772     }
6773
6774
6775 exit:
6776
6777 119     GlobusWSDLDebugExit();
6778 119     ((ScannerData *)data)->result = result;
6779 }    
6780
6781 static
6782 void
6783 globus_i_wsdl_parser_binding_scanner(
6784     void *                              payload,
6785     void *                              data,
6786     xmlChar *                           name)
6787 7 {
6788 7     wsdlBindingPtr                      binding;
6789 7     JSContext *                         cx;
6790 7     jsval                               val;
6791 7     JSObject *                          bindings;
6792 7     JSObject *                          global;
6793 7     JSObject *                          bindingObj;
6794 7     globus_result_t                     result = GLOBUS_SUCCESS;
6795 7     GlobusFuncName(globus_i_wsdl_parser_binding_scanner);
6796 7     GlobusWSDLDebugEnter();
6797     
6798 7     binding = (wsdlBindingPtr) payload;
6799 7     cx = ((ScannerData *)data)->context;
6800 7     global = ((ScannerData *)data)->global;
6801 7     bindings = ((ScannerData *)data)->bindings;
6802 7     result = ((ScannerData *)data)->result;
6803
6804 7     if(result != GLOBUS_SUCCESS)
6805     {
6806 0         goto exit;
6807     }
6808
6809 7     bindingObj = JS_NewObject(cx, &binding_class, bindingClass, bindings);
6810 7     globus_assert(bindingObj);
6811 7     JS_SetPrivate(cx, bindingObj, (void *)binding);
6812
6813 7     val = OBJECT_TO_JSVAL(bindingObj);
6814
6815 7     if(!JS_DefineProperty(cx, bindings, (const char *)name, val, NULL, NULL, 
6816                           JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT))
6817     {
6818 0         JS_ReportError(cx, "Failed to define binding from parsed WSDL");
6819 0         result = GlobusWSDLErrorScanningBindings(GLOBUS_NULL, binding->name);
6820         goto exit;
6821     }
6822
6823
6824 exit:
6825
6826 7     GlobusWSDLDebugExit();
6827 7     ((ScannerData *)data)->result = result;
6828 }    
6829
6830 static
6831 void
6832 globus_i_wsdl_parser_service_scanner(
6833     void *                              payload,
6834     void *                              data,
6835     xmlChar *                           name)
6836 7 {
6837 7     wsdlServicePtr                      service = NULL;
6838 7     JSContext *                         cx = NULL;
6839 7     jsval                               val;
6840 7     JSObject *                          services = NULL;
6841 7     JSObject *                          global = NULL;
6842 7     JSObject *                          serviceObj = NULL;
6843 7     globus_result_t                     result = GLOBUS_SUCCESS;
6844 7     GlobusFuncName(globus_i_wsdl_parser_service_scanner);
6845 7     GlobusWSDLDebugEnter();
6846     
6847 7     service = (wsdlServicePtr) payload;
6848 7     cx = ((ScannerData *)data)->context;
6849 7     global = ((ScannerData *)data)->global;
6850 7     services = ((ScannerData *)data)->services;
6851 7     result = ((ScannerData *)data)->result;
6852
6853 7     if(result != GLOBUS_SUCCESS)
6854     {
6855 0         goto exit;
6856     }
6857
6858 7     serviceObj = JS_NewObject(cx, &service_class, serviceClass, services);
6859 7     globus_assert(serviceObj);
6860 7     JS_SetPrivate(cx, serviceObj, (void *)service);
6861 7     JS_DefineProperties(cx, serviceObj, service_properties);
6862
6863 7     val = OBJECT_TO_JSVAL(serviceObj);
6864
6865 7     if(!JS_DefineProperty(cx, services, (const char *)name, val, NULL, NULL, 
6866                           JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT))
6867     {
6868 0         JS_ReportError(cx, "Failed to define service from parsed WSDL");
6869 0         result = GlobusWSDLErrorScanningServices(GLOBUS_NULL, service->name);
6870         goto exit;
6871     }
6872
6873 exit:
6874
6875 7     GlobusWSDLDebugExit();
6876 7     ((ScannerData *)data)->result = result;
6877 }    
6878
6879 static
6880 void
6881 globus_i_wsdl_parser_wsdl_imports_scanner(
6882     void *                              payload,
6883     void *                              data,
6884     xmlChar *                           name)
6885 47 {
6886 47     wsdlImportPtr                       import = NULL;
6887 47     JSContext *                         cx = NULL;
6888 47     JSObject *                          global = NULL;
6889 47     globus_result_t                     result = GLOBUS_SUCCESS;
6890 47     GlobusFuncName(globus_i_wsdl_parser_wsdl_imports_scanner);
6891 47     GlobusWSDLDebugEnter();
6892     
6893 47     import = (wsdlImportPtr) payload;
6894 47     cx = ((ScannerData *)data)->context;
6895 47     global = ((ScannerData *)data)->global;
6896 47     result = ((ScannerData *)data)->result;
6897
6898 47     if(result != GLOBUS_SUCCESS)
6899     {
6900 0         goto exit;
6901     }
6902
6903 47     ((ScannerData *)data)->schema = import->schema;
6904 47     result = globus_i_wsdl_js_load_imported_schema(cx, import->schema);
6905 47     if(result != GLOBUS_SUCCESS)
6906     {
6907 0         JS_ReportError(cx, "Failed to load WSDL schema");
6908 0         result = GlobusWSDLErrorScanningImports(
6909             GLOBUS_NULL, import->wsdlLocation);
6910         goto exit;
6911     }
6912
6913 exit:
6914
6915 47     GlobusWSDLDebugExit();
6916 47     ((ScannerData *)data)->result = result;
6917 }
6918
6919 static void
6920 TemplateFree(
6921     void *                              template)
6922 245 {
6923 245     Template *                          tmpl = (Template *) template;
6924 245     if(tmpl)
6925     {
6926 245         if(tmpl->filename)
6927         {
6928 245             free(tmpl->filename);
6929         }
6930         
6931 245         if(tmpl->buffer)
6932         {
6933 245             free(tmpl->buffer);
6934         }
6935         
6936 245         free(tmpl);
6937     }