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